示例#1
1
		public FunctionCall(Expression root, Token parenToken, IList<Expression> args, Executable owner)
			: base(root.FirstToken, owner)
		{
			this.Root = root;
			this.ParenToken = parenToken;
			this.Args = args.ToArray();
		}
示例#2
0
		public static BinaryOpChain Build(IList<Expression> expressions, IList<Token> ops, Executable owner)
		{
			// TODO: don't pop from the front, you fool. that's silly slow. 
			List<Expression> mutableList = new List<Expression>(expressions);
			List<Token> mutableOps = new List<Token>(ops);
			Expression left = mutableList[0];
			Expression right = mutableList[1];

			// Pop! Pop! \o/
			mutableList.RemoveAt(0);
			mutableList.RemoveAt(0);

			Token op = mutableOps[0];
			mutableOps.RemoveAt(0);

			BinaryOpChain boc = new BinaryOpChain(left, op, right, owner);
			while (mutableList.Count > 0)
			{
				right = mutableList[0];
				mutableList.RemoveAt(0);
				op = mutableOps[0];
				mutableOps.RemoveAt(0);
				boc = new BinaryOpChain(boc, op, right, owner);
			}

			return boc;
		}
示例#3
0
		public BaseMethodReference(Token firstToken, Token dotToken, Token stepToken, Executable owner)
			: base(firstToken, owner)
		{
			this.DotToken = dotToken;
			this.StepToken = stepToken;
			ClassDefinition cd = null;
			if (owner is FunctionDefinition)
			{
				cd = (ClassDefinition)((FunctionDefinition)owner).FunctionOrClassOwner;
			}
			else if (owner is ClassDefinition)
			{
				cd = (ClassDefinition)owner;
			}
			else
			{
				throw new System.InvalidOperationException(); // this should not happen.
			}
			this.ClassToWhichThisMethodRefers = cd.BaseClass;
			this.FunctionDefinition = this.ClassToWhichThisMethodRefers.GetMethod(this.StepToken.Value, true);
			if (this.FunctionDefinition == null)
			{
				throw new ParserException(this.StepToken, "There is no method named '" + this.StepToken.Value + "' on any base class.");
			}
		}
示例#4
0
		public BinaryOpChain(Expression left, Token op, Expression right, Executable owner)
			: base(left.FirstToken, owner)
		{
			this.Left = left;
			this.Right = right;
			this.Op = op;
		}
示例#5
0
		public Instantiate(Token firstToken, Token firstClassNameToken, string name, IList<Expression> args, Executable owner)
			: base(firstToken, owner)
		{
			this.NameToken = firstClassNameToken;
			this.Name = name;
			this.Args = args.ToArray();
		}
示例#6
0
文件: Node.cs 项目: geofrey/crayon
		internal void BatchExecutableNameResolver(Parser parser, Dictionary<string, Executable> lookup, string[] imports, Executable[] executables)
		{
			for (int i = 0; i < executables.Length; ++i) 
			{
				executables[i] = executables[i].ResolveNames(parser, lookup, imports);
			}
		}
示例#7
0
		public SwitchStatement(Token switchToken, Expression condition, List<Token> firstTokens, List<List<Expression>> cases, List<List<Executable>> code, Expression explicitMax, Token explicitMaxToken, Executable owner)
			: base(switchToken, owner)
		{
			if (cases.Count == 0) throw new ParserException(switchToken, "Switch statement needs cases.");
			if (code.Count == 0) throw new ParserException(switchToken, "Switch statement needs code.");
			if (cases[0] == null) throw new ParserException(switchToken, "Switch statement must start with a case.");
			if (cases[cases.Count - 1] != null) throw new ParserException(switchToken, "Last case in switch statement is empty.");

			this.Condition = condition;
			this.explicitMax = explicitMax;
			this.explicitMaxToken = explicitMaxToken;

			List<Chunk> chunks = new List<Chunk>();
			int counter = 0;
			for (int i = 0; i < cases.Count; i += 2)
			{
				if (cases[i] == null) throw new Exception("This should not happen.");
				if (code[i + 1] == null) throw new Exception("This should not happen.");
				Chunk chunk = new Chunk(counter++, firstTokens[i], cases[i], code[i + 1]);
				if (chunk.Code.Length > 0 && chunk.ContainsFallthrough)
				{
					throw new ParserException(firstTokens[i], "This switch statement case contains code, but falls through to the next case. Cases that contain code must end with a return or break statement.");
				}
				chunks.Add(chunk);
			}
			this.chunks = chunks.ToArray();

			if (this.chunks.Length == 1 && this.chunks[0].Cases.Length == 1 && this.chunks[0].Cases[0] == null)
			{
				throw new ParserException(switchToken, "Switches need at least 1 case to indicate type.");
			}
		}
示例#8
0
文件: DotStep.cs 项目: geofrey/crayon
		public DotStep(Expression root, Token dotToken, Token stepToken, Executable owner)
			: base(root.FirstToken, owner)
		{
			this.Root = root;
			this.DotToken = dotToken;
			this.StepToken = stepToken;
		}
示例#9
0
		public ForEachLoop(Token forToken, Token iterationVariable, Expression iterationExpression, IList<Executable> code, Executable owner)
			: base(forToken, owner)
		{
			this.IterationVariable = iterationVariable;
			this.IterationExpression = iterationExpression;
			this.Code = code.ToArray();
		}
示例#10
0
		public IfStatement(Token ifToken, Expression condition, IList<Executable> trueCode, IList<Executable> falseCode, Executable owner)
			: base(ifToken, owner)
		{
			this.Condition = condition;
			this.TrueCode = trueCode.ToArray();
			this.FalseCode = falseCode.ToArray();
		}
示例#11
0
		public ConstStatement(Token constToken, Token nameToken, string ns, Expression expression, Executable owner)
			: base(constToken, owner)
		{
			this.Expression = expression;
			this.NameToken = nameToken;
			this.Name = nameToken.Value;
			this.Namespace = ns;
		}
示例#12
0
文件: ForLoop.cs 项目: geofrey/crayon
		public ForLoop(Token forToken, IList<Executable> init, Expression condition, IList<Executable> step, IList<Executable> code, Executable owner)
			: base(forToken, owner)
		{
			this.Init = init.ToArray();
			this.Condition = condition ?? new BooleanConstant(forToken, true, owner);
			this.Step = step.ToArray();
			this.Code = code.ToArray();
		}
示例#13
0
		public Assignment(Expression target, Token assignmentOpToken, string assignmentOp, Expression assignedValue, Executable owner)
			: base(target.FirstToken, owner)
		{
			this.Target = target;
			this.AssignmentOpToken = assignmentOpToken;
			this.AssignmentOp = assignmentOp;
			this.Value = assignedValue;
		}
		public SwitchStatementUnsafeBlotchy(SwitchStatement switchStatement, bool useExplicitMax, int explicitMax, Executable owner)
			: base(switchStatement.FirstToken, owner)
		{
			this.OriginalSwitchStatement = switchStatement;
			this.Condition = switchStatement.Condition;

			this.UsesStrings = switchStatement.UsesStrings;
			this.UseExplicitMax = useExplicitMax;
			this.ExplicitMax = explicitMax;
			if (this.UsesStrings)
			{
				this.StringUnsafeToSafeMapping = new Dictionary<string, int>();
			}
			else
			{
				this.IntegerUnsafeToSafeMapping = new Dictionary<int, int>();
			}
			this.codeMapping = new Dictionary<int, Executable[]>();
			this.tokenMapping = new Dictionary<int, Token>();

			this.max = switchStatement.Chunks.Length - 1;

			for (int i = 0; i < switchStatement.Chunks.Length; ++i)
			{
				SwitchStatement.Chunk chunk = switchStatement.Chunks[i];
				this.codeMapping[i] = chunk.Code;
				this.tokenMapping[i] = chunk.CaseOrDefaultToken;

				foreach (Expression expression in chunk.Cases)
				{
					if (expression == null)
					{
						this.DefaultCaseId = i;
					}
					else
					{
						IntegerConstant ic = expression as IntegerConstant;
						StringConstant sc = expression as StringConstant;
						if (ic == null && sc == null) throw new Exception("This shouldn't happen.");
						if (ic != null)
						{
							int c = ic.Value;
							this.IntegerUnsafeToSafeMapping[c] = i;
						}
						else
						{
							string s = sc.Value;
							this.StringUnsafeToSafeMapping[s] = i;
						}
					}
				}
			}

			if (useExplicitMax)
			{
				if (this.UsesStrings) throw new Exception("Cannot use explicit max on string switch statements.");
			}
		}
示例#15
0
		public DotStepStruct(Token token, StructDefinition structDef, DotStep original, Executable owner)
			: base(token, owner)
		{
			this.DotToken = original.DotToken;
			this.RawRoot = original.Root;
			this.RootVar = "v_" + ((Variable)original.Root).Name.Split('$')[1];
			this.FieldName = original.StepToken.Value;
			this.StructDefinition = structDef;
		}
示例#16
0
		public ConstructorDefinition(Token constructorToken, IList<Token> args, IList<Expression> defaultValues, IList<Expression> baseArgs, IList<Executable> code, Token baseToken, Executable owner)
			: base(constructorToken, owner)
		{
			this.ArgNames = args.ToArray();
			//this.ArgVarIDs = new int[this.Args.Length];
			this.DefaultValues = defaultValues.ToArray();
			this.BaseArgs = baseArgs.ToArray();
			this.Code = code.ToArray();
			this.BaseToken = baseToken;
		}
示例#17
0
		private static Expression ParseNullCoalescing(TokenStream tokens, Executable owner)
		{
			Expression root = ParseBooleanCombination(tokens, owner);
			if (tokens.PopIfPresent("??"))
			{
				Expression secondaryExpression = ParseNullCoalescing(tokens, owner);
				return new NullCoalescer(root, secondaryExpression, owner);
			}
			return root;
		}
示例#18
0
		public EnumDefinition(Token enumToken, Token nameToken, string ns, IList<Token> items, IList<Expression> values, Executable owner)
			: base(enumToken, owner)
		{
			this.NameToken = nameToken;
			this.Name = nameToken.Value;
			this.Namespace = ns;
			this.Items = items.ToArray();
			this.Values = values.ToArray();
			this.IntValue = new Dictionary<string, int>();
		}
		public SwitchStatementContinuousSafe(SwitchStatement switchStatement, Executable owner)
			: base(switchStatement.FirstToken, owner)
		{
			this.OriginalSwitchStatement = switchStatement;
			this.Condition = switchStatement.Condition;
			this.codeByCondition = new Dictionary<int, Executable[]>();
			foreach (SwitchStatement.Chunk chunk in switchStatement.Chunks)
			{
				this.codeByCondition.Add(((IntegerConstant)chunk.Cases[0]).Value, chunk.Code);
			}
		}
示例#20
0
		protected override void TranslateFunctionDefinition(List<string> output, FunctionDefinition functionDef)
		{
			output.Add(this.CurrentTabIndention);
			output.Add("public static ");

			string returnType = "object";
			Annotation returnTypeAnnotation = functionDef.GetAnnotation("type");
			if (returnTypeAnnotation != null)
			{
				returnType = this.CSharpPlatform.GetTypeStringFromAnnotation(returnTypeAnnotation);
			}
			output.Add(returnType);
			output.Add(" ");

			output.Add("v_" + functionDef.NameToken.Value);
			output.Add("(");
			for (int i = 0; i < functionDef.ArgNames.Length; ++i)
			{
				if (i > 0) output.Add(", ");
				if (functionDef.ArgAnnotations[i] == null)
				{
					output.Add("object ");
				}
				else
				{
					string argType = functionDef.ArgAnnotations[i].GetSingleArgAsString(null);
					string type = this.CSharpPlatform.GetTypeStringFromAnnotation(functionDef.ArgAnnotations[i].FirstToken, argType);
					output.Add(type);
					output.Add(" ");
				}
				output.Add("v_" + functionDef.ArgNames[i].Value);
			}
			output.Add(")");
			output.Add(this.NL);
			output.Add(this.CurrentTabIndention);
			output.Add("{");
			output.Add(this.NL);
			this.CurrentIndention++;

			Executable[] code = functionDef.Code;
			if (functionDef.GetAnnotation("omitReturn") != null)
			{
				Executable[] newCode = new Executable[code.Length - 1];
				Array.Copy(code, newCode, newCode.Length);
				code = newCode;
			}
			this.Translate(output, code);

			this.CurrentIndention--;
			output.Add(this.CurrentTabIndention);
			output.Add("}");
			output.Add(this.NL);
		}
示例#21
0
		private static Expression ParseEqualityComparison(TokenStream tokens, Executable owner)
		{
			Expression expr = ParseInequalityComparison(tokens, owner);
			string next = tokens.PeekValue();
			if (next == "==" || next == "!=")
			{
				Token equalityToken = tokens.Pop();
				Expression rightExpr = ParseEqualityComparison(tokens, owner);
				return new BinaryOpChain(expr, equalityToken, rightExpr, owner);
			}
			return expr;
		}
示例#22
0
		private static Expression ParseTernary(TokenStream tokens, Executable owner)
		{
			Expression root = ParseNullCoalescing(tokens, owner);
			if (tokens.PopIfPresent("?"))
			{
				Expression trueExpr = ParseTernary(tokens, owner);
				tokens.PopExpected(":");
				Expression falseExpr = ParseTernary(tokens, owner);

				return new Ternary(root, trueExpr, falseExpr, owner);
			}
			return root;
		}
示例#23
0
		public StructDefinition(Token structToken, Token nameToken, IList<Token> fields, IList<Annotation> annotations, Executable owner)
			: base(structToken, owner)
		{
			this.Name = nameToken;
			this.Fields = fields.ToArray();
			this.FieldsByIndex = fields.Select<Token, string>(t => t.Value).ToArray();
			this.IndexByField = new Dictionary<string, int>();
			for (int i = 0; i < this.FieldsByIndex.Length; ++i)
			{
				this.IndexByField[this.FieldsByIndex[i]] = i;
			}

			this.Types = annotations.ToArray();
		}
示例#24
0
		public ClassDefinition(
			Token classToken, 
			Token nameToken, 
			IList<Token> subclassTokens,
			IList<string> subclassNames,
			string ns, 
			Executable owner)
			: base(classToken, owner)
		{
			this.ClassID = ClassDefinition.classIdAlloc++;

			this.Namespace = ns;
			this.NameToken = nameToken;
			this.BaseClassTokens = subclassTokens.ToArray();
			this.BaseClassDeclarations = subclassNames.ToArray();
		}
示例#25
0
		public static Expression Parse(TokenStream tokens, Executable owner)
		{
			Dictionary<string, Annotation> annotations = null;
			if (tokens.IsNext("@"))
			{
				annotations = new Dictionary<string, Annotation>();
				while (tokens.IsNext("@"))
				{
					Annotation annotation = AnnotationParser.ParseAnnotation(tokens);
					annotations[annotation.Type] = annotation;
				}
			}
			Expression output = ParseTernary(tokens, owner);
			output.Annotations = annotations;
			return output;
		}
示例#26
0
		private static Expression ParseBooleanCombination(TokenStream tokens, Executable owner)
		{
			Expression expr = ParseBitwiseOp(tokens, owner);
			string next = tokens.PeekValue();
			if (next == "||" || next == "&&")
			{
				List<Expression> expressions = new List<Expression>() { expr };
				List<Token> ops = new List<Token>();
				while (next == "||" || next == "&&")
				{
					ops.Add(tokens.Pop());
					expressions.Add(ParseBitwiseOp(tokens, owner));
					next = tokens.PeekValue();
				}
				return new BooleanCombination(expressions, ops, owner);
			}
			return expr;
		}
示例#27
0
		public FunctionDefinition(
			Token functionToken,
			Executable nullableOwner,
			bool isStaticMethod,
			Token nameToken,
			IList<Annotation> functionAnnotations,
			string namespyace)
			: base(functionToken, nullableOwner)
		{
			this.IsStaticMethod = isStaticMethod;
			this.Namespace = namespyace;
			this.NameToken = nameToken;
			this.annotations = new Dictionary<string, Annotation>();
			foreach (Annotation annotation in functionAnnotations)
			{
				this.annotations[annotation.Type] = annotation;
			}
			this.MemberID = -1;
		}
示例#28
0
		public LibraryFunctionCall(Token token, string name, IList<Expression> args, Executable owner)
			: base(token, owner)
		{
			string callingLibrary = owner.LibraryName;

			if (callingLibrary == null)
			{
				throw new ParserException(this.FirstToken, "Cannot call native library functions from outside a library.");
			}

			this.LibraryName = callingLibrary;

			string expectedPrefix = "lib_" + callingLibrary.ToLower() + "_";
			if (!name.StartsWith(expectedPrefix))
			{
				throw new ParserException(this.FirstToken, "Invalid library function name. Must begin with a '$$" + expectedPrefix + "' prefix.");
			}
			this.Name = name;
			this.Args = args.ToArray();
		}
示例#29
0
		protected override void TranslateFunctionDefinition(List<string> output, ParseTree.FunctionDefinition functionDef)
		{
			Annotation returnType = functionDef.GetAnnotation("type");
			string type = returnType == null ? "Object" : this.JavaPlatform.GetTypeStringFromString(returnType.GetSingleArgAsString(null), false, false);

			output.Add(this.CurrentTabIndention);
			output.Add("public static ");
			output.Add(type);
			output.Add(" v_");
			output.Add(functionDef.NameToken.Value);
			output.Add("(");
			for (int i = 0; i < functionDef.ArgNames.Length; ++i)
			{
				if (i > 0) {
					output.Add(", ");
				}
				Annotation annotation = functionDef.ArgAnnotations[i];
				string argType = annotation == null ? "Object" : annotation.GetSingleArgAsString(null);
				output.Add(this.JavaPlatform.GetTypeStringFromString(argType, false, false));
				output.Add(" v_");
				output.Add(functionDef.ArgNames[i].Value);
			}
			output.Add(") {");
			output.Add(this.NL);

			this.CurrentIndention++;
			Executable[] code = functionDef.Code;
			if (functionDef.GetAnnotation("omitReturn") != null)
			{
				Executable[] newCode = new Executable[code.Length - 1];
				Array.Copy(code, newCode, newCode.Length);
				code = newCode;
			}
			this.Translate(output, code);
			this.CurrentIndention--;

			output.Add(this.CurrentTabIndention);
			output.Add("}");
			output.Add(this.NL);
		}
示例#30
0
		public ListSlice(Expression root, List<Expression> items, Token bracketToken, Executable owner)
			: base(root.FirstToken, owner)
		{
			this.Root = root;
			this.BracketToken = bracketToken;
			if (items.Count == 2)
			{
				items.Add(new IntegerConstant(null, 1, owner));
			}

			if (items.Count != 3)
			{
				throw new Exception("Slices must have 2 or 3 components before passed into the constructor.");
			}

			if (items[2] == null)
			{
				items[2] = new IntegerConstant(null, 1, owner);
			}

			this.Items = items.ToArray();
		}
示例#31
0
        public TryStatement(
            Token tryToken,
            IList <Executable> tryBlock,
            Token catchToken,
            Token exceptionVariableToken,
            IList <Executable> catchBlock,
            Token finallyToken,
            IList <Executable> finallyBlock,
            Executable owner) : base(tryToken, owner)
        {
            this.TryToken       = tryToken;
            this.CatchToken     = catchToken;
            this.FinallyToken   = finallyToken;
            this.ExceptionToken = exceptionVariableToken;
            this.TryBlock       = tryBlock.ToArray();
            this.CatchBlock     = catchBlock == null ? null : catchBlock.ToArray();
            this.FinallyBlock   = finallyBlock == null ? null : finallyBlock.ToArray();

            if (this.CatchBlock == null && this.FinallyBlock == null)
            {
                throw new ParserException(this.TryToken, "Cannot have a try block without a catch or finally block.");
            }
        }
示例#32
0
        public void ResolveBaseClasses(Dictionary <string, Executable> lookup, string[] imports)
        {
            List <ClassDefinition> baseClasses       = new List <ClassDefinition>();
            List <Token>           baseClassesTokens = new List <Token>();

            for (int i = 0; i < this.BaseClassDeclarations.Length; ++i)
            {
                string     value             = this.BaseClassDeclarations[i];
                Token      token             = this.BaseClassTokens[i];
                Executable baseClassInstance = Executable.DoNameLookup(lookup, imports, value);
                if (baseClassInstance == null)
                {
                    throw new ParserException(token, "No class named '" + token.Value + "' was found.");
                }

                if (baseClassInstance is ClassDefinition)
                {
                    baseClasses.Add((ClassDefinition)baseClassInstance);
                    baseClassesTokens.Add(token);
                }
                // TODO: else if (baseClassInstance is InterfaceDefinition) { ... }
                else
                {
                    throw new ParserException(token, "This is not a class.");
                }
            }

            if (baseClasses.Count > 1)
            {
                throw new ParserException(baseClassesTokens[1], "Multiple base classes found. Did you mean to use an interface?");
            }

            if (baseClasses.Count == 1)
            {
                this.BaseClass = baseClasses[0];
            }
        }
示例#33
0
 public CompileTimeDictionary(Token firstToken, string type, Executable owner)
     : base(firstToken, owner)
 {
     this.Type = type;
 }
示例#34
0
 protected static IList <Executable> Listify(Executable ex)
 {
     return(new Executable[] { ex });
 }
示例#35
0
 public NullCoalescer(Expression primaryExpression, Expression secondaryExpression, Executable owner)
     : base(primaryExpression.FirstToken, owner)
 {
     this.PrimaryExpression   = primaryExpression;
     this.SecondaryExpression = secondaryExpression;
 }
示例#36
0
 public Expression CloneValue(Token token, Executable owner)
 {
     return(new BooleanConstant(token, this.Value, owner));
 }
示例#37
0
 public PartialNamespaceReference(Token token, string name, Executable owner)
     : base(token, owner)
 {
     this.Name = name;
 }
示例#38
0
 public Expression(Token firstToken, Executable owner)
     : base(firstToken, owner)
 {
     this.Annotations = null;
 }
示例#39
0
 public LibraryFunctionReference(Token token, string name, Executable owner)
     : base(token, owner)
 {
     this.Name = name;
 }
示例#40
0
文件: Node.cs 项目: geofrey/crayon
 internal Node(Token firstToken, Executable functionOrClassOwner)
 {
     this.FirstToken           = firstToken;
     this.FunctionOrClassOwner = functionOrClassOwner;
 }
示例#41
0
 public BooleanNot(Token bang, Expression root, Executable owner)
     : base(bang, owner)
 {
     this.Root = root;
 }
示例#42
0
 public ContinueStatement(Token continueToken, Executable owner)
     : base(continueToken, owner)
 {
 }
示例#43
0
 public DictionaryDefinition(Token braceToken, IList <Expression> keys, IList <Expression> values, Executable owner)
     : base(braceToken, owner)
 {
     this.Keys   = keys.ToArray();
     this.Values = values.ToArray();
 }
示例#44
0
 public StructInstance(Token firstToken, Token nameToken, IList <Expression> args, Executable owner)
     : base(firstToken, owner)
 {
     this.NameToken = nameToken;
     this.Args      = args.ToArray();
 }
示例#45
0
        public EnumDefinition(Token enumToken, Token nameToken, string ns, IList <Token> items, IList <Expression> values, Executable owner)
            : base(enumToken, owner)
        {
            this.NameToken = nameToken;
            this.Name      = nameToken.Value;
            this.Namespace = ns;
            this.Items     = items.ToArray();
            this.Values    = values.ToArray();
            this.IntValue  = new Dictionary <string, int>();

            if (this.Items.Length == 0)
            {
                throw new ParserException(enumToken, "Enum definitions cannot be empty.");
            }
        }
示例#46
0
 public Namespace(Token namespaceToken, string name, Executable owner)
     : base(namespaceToken, owner)
 {
     this.Name = name;
 }
示例#47
0
        public SwitchStatement(Token switchToken, Expression condition, List <Token> firstTokens, List <List <Expression> > cases, List <List <Executable> > code, Expression explicitMax, Token explicitMaxToken, Executable owner)
            : base(switchToken, owner)
        {
            if (cases.Count == 0)
            {
                throw new ParserException(switchToken, "Switch statement needs cases.");
            }
            if (code.Count == 0)
            {
                throw new ParserException(switchToken, "Switch statement needs code.");
            }
            if (cases[0] == null)
            {
                throw new ParserException(switchToken, "Switch statement must start with a case.");
            }
            if (cases[cases.Count - 1] != null)
            {
                throw new ParserException(switchToken, "Last case in switch statement is empty.");
            }

            this.Condition        = condition;
            this.explicitMax      = explicitMax;
            this.explicitMaxToken = explicitMaxToken;

            List <Chunk> chunks  = new List <Chunk>();
            int          counter = 0;

            for (int i = 0; i < cases.Count; i += 2)
            {
                if (cases[i] == null)
                {
                    throw new Exception("This should not happen.");
                }
                if (code[i + 1] == null)
                {
                    throw new Exception("This should not happen.");
                }
                Chunk chunk = new Chunk(counter++, firstTokens[i], cases[i], code[i + 1]);
                if (chunk.Code.Length > 0 && chunk.ContainsFallthrough)
                {
                    throw new ParserException(firstTokens[i], "This switch statement case contains code, but falls through to the next case. Cases that contain code must end with a return or break statement. Alternatively, you may just have mismatched curly braces somewhere.");
                }
                chunks.Add(chunk);
            }
            this.chunks = chunks.ToArray();

            if (this.chunks.Length == 1 && this.chunks[0].Cases.Length == 1 && this.chunks[0].Cases[0] == null)
            {
                throw new ParserException(switchToken, "Switches need at least 1 case to indicate type.");
            }
        }
示例#48
0
 public ExpressionAsExecutable(Expression expression, Executable owner)
     : base(expression.FirstToken, owner)
 {
     this.Expression = expression;
 }
示例#49
0
 internal override Executable PastelResolve(Parser parser)
 {
     this.Condition = this.Condition.PastelResolve(parser);
     this.Code      = Executable.PastelResolveExecutables(parser, this.Code);
     return(this);
 }
示例#50
0
 public BooleanConstant(Token token, bool value, Executable owner)
     : base(token, owner)
 {
     this.Value = value;
 }
示例#51
0
 public BaseKeyword(Token token, Executable owner)
     : base(token, owner)
 {
 }
示例#52
0
        public static BinaryOpChain Build(IList <Expression> expressions, IList <Token> ops, Executable owner)
        {
            // TODO: don't pop from the front, you fool. that's silly slow.
            List <Expression> mutableList = new List <Expression>(expressions);
            List <Token>      mutableOps  = new List <Token>(ops);
            Expression        left        = mutableList[0];
            Expression        right       = mutableList[1];

            // Pop! Pop! \o/
            mutableList.RemoveAt(0);
            mutableList.RemoveAt(0);

            Token op = mutableOps[0];

            mutableOps.RemoveAt(0);

            BinaryOpChain boc = new BinaryOpChain(left, op, right, owner);

            while (mutableList.Count > 0)
            {
                right = mutableList[0];
                mutableList.RemoveAt(0);
                op = mutableOps[0];
                mutableOps.RemoveAt(0);
                boc = new BinaryOpChain(boc, op, right, owner);
            }

            return(boc);
        }
示例#53
0
 public DoWhileLoop(Token doToken, IList <Executable> code, Expression condition, Executable owner)
     : base(doToken, owner)
 {
     this.Code      = code.ToArray();
     this.Condition = condition;
 }
示例#54
0
 public NegativeSign(Token sign, Expression root, Executable owner)
     : base(sign, owner)
 {
     this.Root = root;
 }
示例#55
0
 public Executable(Token firstToken, Executable owner)
     : base(firstToken, owner)
 {
 }
示例#56
0
 public Instantiate(Token firstToken, Token firstClassNameToken, string name, IList <Expression> args, Executable owner)
     : base(firstToken, owner)
 {
     this.NameToken = firstClassNameToken;
     this.Name      = name;
     this.Args      = args.ToArray();
 }
示例#57
0
 public Ternary(Expression condition, Expression trueValue, Expression falseValue, Executable owner)
     : base(condition.FirstToken, owner)
 {
     this.Condition  = condition;
     this.TrueValue  = trueValue;
     this.FalseValue = falseValue;
 }
示例#58
0
 public ClassReference(Token token, ClassDefinition clazz, Executable owner)
     : base(token, owner)
 {
     this.ClassDefinition = clazz;
 }
示例#59
0
 public ListDefinition(Token openBracket, IList <Expression> items, Executable owner)
     : base(openBracket, owner)
 {
     this.Items = items.ToArray();
 }
示例#60
0
        public ConstructorDefinition(Token constructorToken, IList <Token> args, IList <Expression> defaultValues, IList <Expression> baseArgs, IList <Executable> code, Token baseToken, Executable owner)
            : base(constructorToken, owner)
        {
            this.IsDefault     = false;
            this.ArgNames      = args.ToArray();
            this.DefaultValues = defaultValues.ToArray();
            this.BaseArgs      = baseArgs.ToArray();
            this.Code          = code.ToArray();
            this.BaseToken     = baseToken;

            TODO.VerifyDefaultArgumentsAreAtTheEnd();

            this.MaxArgCount = this.ArgNames.Length;
            int minArgCount = 0;

            for (int i = 0; i < this.ArgNames.Length; ++i)
            {
                if (this.DefaultValues[i] == null)
                {
                    minArgCount++;
                }
                else
                {
                    break;
                }
            }
            this.MinArgCount = minArgCount;
        }