| 1 |
PARSER_BEGIN(Simple) |
| 2 |
|
| 3 |
package org; |
| 4 |
|
| 5 |
class Simple { |
| 6 |
public static void main(String args[]) { |
| 7 |
System.out.println("Reading from standard input..."); |
| 8 |
Simple t = new Simple(System.in); |
| 9 |
try { |
| 10 |
SimpleNode n = t.Start(); |
| 11 |
n.dump(""); |
| 12 |
System.out.println("Thank you."); |
| 13 |
} catch (Exception e) { |
| 14 |
System.out.println("Oops."); |
| 15 |
System.out.println(e.getMessage()); |
| 16 |
e.printStackTrace(); |
| 17 |
} |
| 18 |
} |
| 19 |
} |
| 20 |
|
| 21 |
PARSER_END(Simple) |
| 22 |
|
| 23 |
|
| 24 |
SKIP : |
| 25 |
{ |
| 26 |
" " |
| 27 |
| "\t" |
| 28 |
| "\n" |
| 29 |
| "\r" |
| 30 |
| <"//" (~["\n","\r"])* ("\n"|"\r"|"\r\n")> |
| 31 |
| <"/*" (~["*"])* "*" (~["/"] (~["*"])* "*")* "/"> |
| 32 |
} |
| 33 |
|
| 34 |
TOKEN : /* LITERALS */ |
| 35 |
{ |
| 36 |
< INTEGER_LITERAL: |
| 37 |
<DECIMAL_LITERAL> (["l","L"])? |
| 38 |
| <HEX_LITERAL> (["l","L"])? |
| 39 |
| <OCTAL_LITERAL> (["l","L"])? |
| 40 |
> |
| 41 |
| |
| 42 |
< #DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* > |
| 43 |
| |
| 44 |
< #HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ > |
| 45 |
| |
| 46 |
< #OCTAL_LITERAL: "0" (["0"-"7"])* > |
| 47 |
} |
| 48 |
|
| 49 |
TOKEN : /* IDENTIFIERS */ |
| 50 |
{ |
| 51 |
< IDENTIFIER: <LETTER> (<LETTER>|<DIGIT>)* > |
| 52 |
| |
| 53 |
< #LETTER: ["_","a"-"z","A"-"Z"] > |
| 54 |
| |
| 55 |
< #DIGIT: ["0"-"9"] > |
| 56 |
} |
| 57 |
|
| 58 |
SimpleNode Start() : {} |
| 59 |
{ |
| 60 |
Expression() ";" |
| 61 |
{ return jjtThis; } |
| 62 |
} |
| 63 |
|
| 64 |
|
| 65 |
void Expression() : {} |
| 66 |
{ |
| 67 |
AdditiveExpression() |
| 68 |
} |
| 69 |
|
| 70 |
void AdditiveExpression() : {} |
| 71 |
{ |
| 72 |
MultiplicativeExpression() ( ( "+" | "-" ) MultiplicativeExpression() )* |
| 73 |
} |
| 74 |
|
| 75 |
void MultiplicativeExpression() : {} |
| 76 |
{ |
| 77 |
UnaryExpression() ( ( "*" | "/" | "%" ) UnaryExpression() )* |
| 78 |
} |
| 79 |
|
| 80 |
void UnaryExpression() : {} |
| 81 |
{ |
| 82 |
"(" Expression() ")" | Identifier() | Integer() |
| 83 |
} |
| 84 |
|
| 85 |
void Identifier() : {} |
| 86 |
{ |
| 87 |
<IDENTIFIER> |
| 88 |
} |
| 89 |
|
| 90 |
void Integer() : {} |
| 91 |
{ |
| 92 |
<INTEGER_LITERAL> |
| 93 |
} |