Exemplo n.º 1
0
 Expression StringLiteral()
 {
     StringLiteral literal = new StringLiteral(lexer.Value, lexer.LineId);
     Match(Token.String);
     return literal;
 }
Exemplo n.º 2
0
        private Statement InputStatement()
        {
            // Requires more than one token of lookahead. If we encounter a string variable
            // after input, it could be an input prompt or the variable to store the input in.
            // It's not until we look past that and check for a colon do we know.

            LineId line = lexer.LineId;
            Match(Token.Input);
            List<Statement> inputs = new List<Statement>();
            Expression inputPrompt;

            // Assume that an input prompt is given and parse it as an expression
            // If it later turns out that it is not the input prompt, then it must
            // be convert to an assignment.

            Expression expr = Expression();

            if (lookahead == Token.Colon)
            {
                inputPrompt = expr;
                Match(Token.Colon);
            }
            else // if there is no colon then what we read shouldn't be
                // treated as an Expression, but as an Assignment.
            {
                inputPrompt = new StringLiteral("? ", LineId.None);
                LocationReference vr = (LocationReference)expr; // The expr must have been a Location Reference
                Location location = vr.Location;
                inputs.Add(Assign.ReadConsole(location, line));
                if (lookahead == Token.Comma) Match(Token.Comma);
            }

            while (lookahead != Token.EOF && lookahead != Token.EndOfLine)
            {
                Location location = Location();
                inputs.Add(Assign.ReadConsole(location, line));
                if (lookahead == Token.Comma) Match(Token.Comma);
            }
            return new Input(inputPrompt, new Block(inputs), line);
        }