Created
December 22, 2011 16:23
-
-
Save kakkun61/1510874 to your computer and use it in GitHub Desktop.
Java Advent Calendar 2011 code 7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PARSER_BEGIN (Parser) | |
public class Parser { | |
} | |
PARSER_END (Parser) | |
SKIP: { | |
" " | |
} | |
TOKEN: { | |
<INTEGER: (["0"-"9"])+> | |
| <PLUS: "+"> | |
| <MINUS: "-"> | |
| <NL: "\r\n" | "\n" | "\r"> | |
} | |
void List(): { | |
int val; | |
} { | |
val = Expression() <NL> { | |
System.out.println(val); | |
} | |
} | |
int Expression(): { | |
int val1; | |
int val2; | |
} { | |
val1 = PrimaryExpression() ( | |
<PLUS> val2 = PrimaryExpression() { | |
val1 += val2; | |
} | |
| <MINUS> val2 = PrimaryExpression() { | |
val1 -= val2; | |
} | |
)* { | |
return val1; | |
} | |
} | |
int PrimaryExpression(): { | |
Token token; | |
} { | |
token = <INTEGER> { | |
return Integer.parseInt(token.image); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment