1.1 --- a/jitcraft/Parser.cpp Tue Jun 26 00:58:55 2012 -0700
1.2 +++ b/jitcraft/Parser.cpp Wed Jun 27 02:21:56 2012 -0700
1.3 @@ -68,6 +68,25 @@
1.4 return proxy;
1.5 }
1.6
1.7 +bool
1.8 +Parser::matchName(Name **name, TokenKind kind)
1.9 +{
1.10 + assert(kind == TOK_NAME || kind == TOK_LABEL);
1.11 + *name = NULL;
1.12 + if (!match(kind))
1.13 + return false;
1.14 + *name = strings_.add(scanner_.literal());
1.15 + return true;
1.16 +}
1.17 +
1.18 +Name *
1.19 +Parser::expectName()
1.20 +{
1.21 + if (!expect(TOK_NAME))
1.22 + return NULL;
1.23 + return strings_.add(scanner_.literal());
1.24 +}
1.25 +
1.26 Expression *
1.27 Parser::primitive()
1.28 {
1.29 @@ -79,11 +98,18 @@
1.30 return bind(name);
1.31 }
1.32
1.33 + case TOK_FLOAT_LITERAL:
1.34 + {
1.35 + scanner_.scan();
1.36 + double value = Scanner::ParseDouble(scanner_.literal());
1.37 + return new (pool_) FloatLiteral(value);
1.38 + }
1.39 +
1.40 case TOK_INTEGER_LITERAL:
1.41 {
1.42 scanner_.scan();
1.43 int value = atoi(scanner_.literal());
1.44 - return new (pool_) IntegerLiteralExpression(value);
1.45 + return new (pool_) IntegerLiteral(value);
1.46 }
1.47
1.48 default:
1.49 @@ -326,11 +352,13 @@
1.50 if (!expect(TOK_NEW))
1.51 return NULL;
1.52
1.53 - // Get the name.
1.54 - if (!expect(TOK_NAME))
1.55 + Name *tag;
1.56 + if (matchName(&tag, TOK_LABEL) && !tag)
1.57 return NULL;
1.58 -
1.59 - Name *name = strings_.add(scanner_.literal());
1.60 +
1.61 + Name *name = expectName();
1.62 + if (!name)
1.63 + return NULL;
1.64
1.65 ExpressionList *postDimensions = NULL;
1.66 if (scanner_.peek() == TOK_LBRACKET) {
1.67 @@ -359,7 +387,7 @@
1.68 }
1.69
1.70 Variable *var = scope_->declareVariable(name);
1.71 - VariableDeclaration *decl = new (pool_) VariableDeclaration(var, postDimensions, expr);
1.72 + VariableDeclaration *decl = new (pool_) VariableDeclaration(var, tag, postDimensions, expr);
1.73
1.74 return decl;
1.75 }
1.76 @@ -549,10 +577,7 @@
1.77 if (scanner_.peek() == TOK_RBRACE)
1.78 break;
1.79
1.80 - if (!expect(TOK_NAME))
1.81 - return NULL;
1.82 -
1.83 - Name *name = strings_.add(scanner_.literal());
1.84 + Name *name = expectName();
1.85 if (!name)
1.86 return NULL;
1.87
1.88 @@ -582,9 +607,7 @@
1.89 Statement *
1.90 Parser::function()
1.91 {
1.92 - expect(TOK_NAME);
1.93 -
1.94 - Name *name = strings_.add(scanner_.literal());
1.95 + Name *name = expectName();
1.96 if (!name)
1.97 return NULL;
1.98
1.99 @@ -607,10 +630,7 @@
1.100 return NULL;
1.101 if (!match(TOK_RPAREN)) {
1.102 while (true) {
1.103 - if (!expect(TOK_NAME))
1.104 - return NULL;
1.105 -
1.106 - Name *name = strings_.add(scanner_.literal());
1.107 + Name *name = expectName();
1.108 if (!name)
1.109 return NULL;
1.110
1.111 @@ -783,9 +803,13 @@
1.112 node->initialization()->accept(this);
1.113 unindent();
1.114 }
1.115 - void visit(IntegerLiteralExpression *node) {
1.116 + void visit(IntegerLiteral *node) {
1.117 prefix();
1.118 - fprintf(fp_, "[ LiteralExpression (%d)\n", node->value());
1.119 + fprintf(fp_, "[ IntegerLiteral (%d)\n", node->value());
1.120 + }
1.121 + void visit(FloatLiteral *node) {
1.122 + prefix();
1.123 + fprintf(fp_, "[ FloatLiteral (%f)\n", node->value());
1.124 }
1.125 void visit(IfStatement *node) {
1.126 prefix();