Beispiel #1
0
        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);
        }
Beispiel #2
0
        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);
        }