public void Build(TokenList tokens) { // read "set varname to" tokens.Advance(); varNameToken = tokens.Current; tokens.Advance(); Token toToken = tokens.Current; tokens.Advance(); // make sure the variable name token is a valid word/name for a variable if (varNameToken.TokenType != TokenType.Word) { throw new TokenParserException("The \"set\" instruction must be followed by a word of your choice that will be subsequently used to hold some value.", tokens.Previous); } if (TokenParser.IsReservedWord(varNameToken.Value)) { throw new TokenParserException("You can't use \"" + varNameToken.Value + "\" as a variable name. It is the keyword for either an expression or an instruction.", varNameToken); } // make sure the "to" token is actually the word "to" if (toToken.TokenType != TokenType.Word || toToken.Value != "to") { throw new TokenParserException("The \"set\" instruction must be formatted like this: \"set something to some_expression\"", toToken); } // build the expression that will be evaluated and assigned to the variable at run time expr = TokenParser.BuildExpression(tokens); }
public void Build(TokenList tokens) { token = tokens.Current; // advance past the instruction token/symbol tokens.Advance(); // build the expression to evaluate and display at execution time expression = TokenParser.BuildExpression(tokens); }
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); }
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)); } }
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); }
public void PrepareExpression(TokenList tokens, Stack <int?> precedenceStack) { tokens.Advance(); expression = TokenParser.BuildExpression(tokens, precedenceStack); }
public virtual void PrepareExpression(TokenList tokens, Stack <int?> precedenceStack) { token = tokens.Current; tokens.Advance(); right = TokenParser.BuildExpression(tokens, precedenceStack); }