public void Build(TokenList tokens)
		{
			// store the "list each [variable] in [list_expression]" tokens
			token = tokens.Current;
			Token eachToken = tokens.Peek(1);
			iteratorToken = tokens.Peek(2);
			Token inToken = tokens.Peek(3);
			listToken = tokens.Peek(4); // the first token of the list expression
			tokens.Advance(4);

			// make sure the "each" token is actually the word "each"
			if (eachToken.Value != "each" || eachToken.TokenType != TokenType.Word)
				throw new TokenParserException("\"list\" must be followed by the word \"each\".", eachToken);

			// validate the various tokens
			if (iteratorToken.TokenType != TokenType.Word)
				throw new TokenParserException("You must specify a word here that can be used as a variable, e.g. \"list each item in whatever\"", iteratorToken);
			if (TokenParser.IsReservedWord(iteratorToken.Value))
				throw new TokenParserException("You can't use \"" + iteratorToken.Value + "\" as a variable name. It is the keyword for either an expression or an instruction.", iteratorToken);
			if (inToken.Value != "in" || inToken.TokenType != TokenType.Word)
				throw new TokenParserException("\"list each [something] must be followed by the word \"in\".", inToken);

			// build the list expression and the subsequent instruction list to loop through
			expr = TokenParser.BuildExpression(tokens);
			instructions = new InstructionList();
			instructions.IsLoopBlock = true;
			instructions.Build(tokens);
		}
Exemplo n.º 2
0
        public void Build(TokenList tokens)
        {
            //store the "while" token
            token = tokens.Current;
            tokens.Advance();

            // build the expression to evaluate for each iteration through the loop
            expr = TokenParser.BuildExpression(tokens);

            // build the list of instructions to execute inside the loop
            list = new InstructionList();
            list.IsLoopBlock = true;
            list.Build(tokens);
        }
Exemplo n.º 3
0
        public void Build(TokenList tokens)
        {
            instructionToken = tokens.Current;
            Token token = instructionToken;
            // advance past the instruction token/symbol
            tokens.Advance();

            // build condition expression
            IExpression expr = TokenParser.BuildExpression(tokens);

            // build the instruction list that will execute if the expression evaluates to true
            InstructionList list = new InstructionList();
            list.AcceptELSEInPlaceOfEND = true;
            list.Build(tokens);
            executionPaths.Add(new ExecutionPath(expr, list, token));

            // if any elseif statements were used, build the execution paths for each one
            while (list.Terminator == InstructionList.TerminatorType.ElseIf)
            {
                token = tokens.Previous;
                expr = TokenParser.BuildExpression(tokens);
                list = new InstructionList();
                list.AcceptELSEInPlaceOfEND = true;
                list.Build(tokens);
                executionPaths.Add(new ExecutionPath(expr, list, token));
            }

            // if an else statement was used, build the instruction list that will execute if the expression evaluates to false
            if (list.Terminator == InstructionList.TerminatorType.Else)
            {
                token = tokens.Previous;
                list = new InstructionList();
                list.AcceptELSEInPlaceOfEND = true;
                list.Build(tokens);
                executionPaths.Add(new ExecutionPath(null, list, token));
            }
        }
Exemplo n.º 4
0
 public ExecutionPath(IExpression condition, InstructionList instructions, Token token)
 {
     Condition = condition;
     Instructions = instructions;
     Token = token;
 }
Exemplo n.º 5
0
 public ExecutionPath(IExpression condition, InstructionList instructions, Token token)
 {
     Condition    = condition;
     Instructions = instructions;
     Token        = token;
 }