Example #1
0
        public void TestRealLiteral()
        {
            var programSource = new TokenList()
            {
                { TokenType.Identifier, "x" },
                { TokenType.OpAssignment },
                { TokenType.RealLiteral, "2.4e3" }
            };
            Parser      parser  = new Parser(CreateMockScanner(programSource), new ErrorHandler());
            ProgramNode program = parser.Parse();

            var expr = new IntLiteralExpr(0, 0, 5);

            expr.Sign = ExprSign.Minus;
            var assignment = new AssignmentStmt(0, 0);

            assignment.Variable       = new VariableExpr(0, 0, "x");
            assignment.AssignmentExpr = new RealLiteralExpr(0, 0, 2400);
            expected.Block.Statements.Add(assignment);
            program.ShouldBeEquivalentTo(expected);
        }
Example #2
0
 private Expression ParseFactor()
 {
     if (Accept(Token.Types.IntLiteral))
     {
         IntLiteralExpr exp = new IntLiteralExpr(AcceptedToken.Line, AcceptedToken.Column);
         exp.ExprValue = int.Parse(AcceptedToken.Content);
         return exp;
     }
     else if (Accept(Token.Types.StringLiteral))
     {
         StringLiteralExpr expr = new StringLiteralExpr(AcceptedToken.Line, AcceptedToken.Column);
         expr.ExprValue = AcceptedToken.Content;
         return expr;
     }
     else if (Accept(Token.Types.Identifier))
     {
         IdentifierExpr node = new IdentifierExpr(AcceptedToken.Line, AcceptedToken.Column, AcceptedToken.Content);
         return node;
     }
     else if (Accept(Token.Types.LParen))
     {
         Expression exp = ParseExpression();
         Match(Token.Types.RParen);
         return exp;
     }
     else throw new ParserException(String.Format("Expected literal or identifier, got {0} instead at line {1} column {2}.",
         CurrentToken.Type, CurrentToken.Line, CurrentToken.Column));
 }
 public void Visit(IntLiteralExpr intLiteralExpr)
 {
     PrintNode("Int " + intLiteralExpr.ExprValue.ToString(), true);
 }