// $ANTLR 3.0.1 Expr.g 2010-02-24 23:26:54 import org.antlr.runtime.*; import java.util.Stack; import java.util.List; import java.util.ArrayList; public class ExprParser extends Parser { public static final String[] tokenNames = new String[] { "", "", "", "", "NEWLINE", "ID", "INT", "WS", "'='", "'+'", "'-'", "'*'", "'('", "')'" }; public static final int WS=7; public static final int NEWLINE=4; public static final int INT=6; public static final int ID=5; public static final int EOF=-1; public ExprParser(TokenStream input) { super(input); } public String[] getTokenNames() { return tokenNames; } public String getGrammarFileName() { return "Expr.g"; } // $ANTLR start prog // Expr.g:3:1: prog : ( stat )+ ; public final void prog() throws RecognitionException { try { // Expr.g:3:5: ( ( stat )+ ) // Expr.g:3:9: ( stat )+ { // Expr.g:3:9: ( stat )+ int cnt1=0; loop1: do { int alt1=2; int LA1_0 = input.LA(1); if ( ((LA1_0>=NEWLINE && LA1_0<=INT)||LA1_0==12) ) { alt1=1; } switch (alt1) { case 1 : // Expr.g:3:9: stat { pushFollow(FOLLOW_stat_in_prog11); stat(); _fsp--; } break; default : if ( cnt1 >= 1 ) break loop1; EarlyExitException eee = new EarlyExitException(1, input); throw eee; } cnt1++; } while (true); } } catch (RecognitionException re) { reportError(re); recover(input,re); } finally { } return ; } // $ANTLR end prog // $ANTLR start stat // Expr.g:5:1: stat : ( expr NEWLINE | ID '=' expr NEWLINE | NEWLINE ); public final void stat() throws RecognitionException { try { // Expr.g:5:5: ( expr NEWLINE | ID '=' expr NEWLINE | NEWLINE ) int alt2=3; switch ( input.LA(1) ) { case INT: case 12: { alt2=1; } break; case ID: { int LA2_2 = input.LA(2); if ( (LA2_2==8) ) { alt2=2; } else if ( (LA2_2==NEWLINE||(LA2_2>=9 && LA2_2<=11)) ) { alt2=1; } else { NoViableAltException nvae = new NoViableAltException("5:1: stat : ( expr NEWLINE | ID '=' expr NEWLINE | NEWLINE );", 2, 2, input); throw nvae; } } break; case NEWLINE: { alt2=3; } break; default: NoViableAltException nvae = new NoViableAltException("5:1: stat : ( expr NEWLINE | ID '=' expr NEWLINE | NEWLINE );", 2, 0, input); throw nvae; } switch (alt2) { case 1 : // Expr.g:5:9: expr NEWLINE { pushFollow(FOLLOW_expr_in_stat38); expr(); _fsp--; match(input,NEWLINE,FOLLOW_NEWLINE_in_stat40); } break; case 2 : // Expr.g:6:9: ID '=' expr NEWLINE { match(input,ID,FOLLOW_ID_in_stat51); match(input,8,FOLLOW_8_in_stat53); pushFollow(FOLLOW_expr_in_stat55); expr(); _fsp--; match(input,NEWLINE,FOLLOW_NEWLINE_in_stat57); } break; case 3 : // Expr.g:7:9: NEWLINE { match(input,NEWLINE,FOLLOW_NEWLINE_in_stat67); } break; } } catch (RecognitionException re) { reportError(re); recover(input,re); } finally { } return ; } // $ANTLR end stat // $ANTLR start expr // Expr.g:10:1: expr : multExpr ( '+' multExpr | '-' multExpr )* ; public final void expr() throws RecognitionException { try { // Expr.g:11:5: ( multExpr ( '+' multExpr | '-' multExpr )* ) // Expr.g:11:9: multExpr ( '+' multExpr | '-' multExpr )* { pushFollow(FOLLOW_multExpr_in_expr87); multExpr(); _fsp--; // Expr.g:12:9: ( '+' multExpr | '-' multExpr )* loop3: do { int alt3=3; int LA3_0 = input.LA(1); if ( (LA3_0==9) ) { alt3=1; } else if ( (LA3_0==10) ) { alt3=2; } switch (alt3) { case 1 : // Expr.g:12:13: '+' multExpr { match(input,9,FOLLOW_9_in_expr102); pushFollow(FOLLOW_multExpr_in_expr104); multExpr(); _fsp--; } break; case 2 : // Expr.g:13:13: '-' multExpr { match(input,10,FOLLOW_10_in_expr119); pushFollow(FOLLOW_multExpr_in_expr121); multExpr(); _fsp--; } break; default : break loop3; } } while (true); } } catch (RecognitionException re) { reportError(re); recover(input,re); } finally { } return ; } // $ANTLR end expr // $ANTLR start multExpr // Expr.g:17:1: multExpr : atom ( '*' atom )* ; public final void multExpr() throws RecognitionException { try { // Expr.g:18:5: ( atom ( '*' atom )* ) // Expr.g:18:9: atom ( '*' atom )* { pushFollow(FOLLOW_atom_in_multExpr152); atom(); _fsp--; // Expr.g:18:14: ( '*' atom )* loop4: do { int alt4=2; int LA4_0 = input.LA(1); if ( (LA4_0==11) ) { alt4=1; } switch (alt4) { case 1 : // Expr.g:18:15: '*' atom { match(input,11,FOLLOW_11_in_multExpr155); pushFollow(FOLLOW_atom_in_multExpr157); atom(); _fsp--; } break; default : break loop4; } } while (true); } } catch (RecognitionException re) { reportError(re); recover(input,re); } finally { } return ; } // $ANTLR end multExpr // $ANTLR start atom // Expr.g:21:1: atom : ( INT | ID | '(' expr ')' ); public final void atom() throws RecognitionException { try { // Expr.g:22:5: ( INT | ID | '(' expr ')' ) int alt5=3; switch ( input.LA(1) ) { case INT: { alt5=1; } break; case ID: { alt5=2; } break; case 12: { alt5=3; } break; default: NoViableAltException nvae = new NoViableAltException("21:1: atom : ( INT | ID | '(' expr ')' );", 5, 0, input); throw nvae; } switch (alt5) { case 1 : // Expr.g:22:9: INT { match(input,INT,FOLLOW_INT_in_atom180); } break; case 2 : // Expr.g:23:9: ID { match(input,ID,FOLLOW_ID_in_atom191); } break; case 3 : // Expr.g:24:9: '(' expr ')' { match(input,12,FOLLOW_12_in_atom201); pushFollow(FOLLOW_expr_in_atom203); expr(); _fsp--; match(input,13,FOLLOW_13_in_atom205); } break; } } catch (RecognitionException re) { reportError(re); recover(input,re); } finally { } return ; } // $ANTLR end atom public static final BitSet FOLLOW_stat_in_prog11 = new BitSet(new long[]{0x0000000000001072L}); public static final BitSet FOLLOW_expr_in_stat38 = new BitSet(new long[]{0x0000000000000010L}); public static final BitSet FOLLOW_NEWLINE_in_stat40 = new BitSet(new long[]{0x0000000000000002L}); public static final BitSet FOLLOW_ID_in_stat51 = new BitSet(new long[]{0x0000000000000100L}); public static final BitSet FOLLOW_8_in_stat53 = new BitSet(new long[]{0x0000000000001060L}); public static final BitSet FOLLOW_expr_in_stat55 = new BitSet(new long[]{0x0000000000000010L}); public static final BitSet FOLLOW_NEWLINE_in_stat57 = new BitSet(new long[]{0x0000000000000002L}); public static final BitSet FOLLOW_NEWLINE_in_stat67 = new BitSet(new long[]{0x0000000000000002L}); public static final BitSet FOLLOW_multExpr_in_expr87 = new BitSet(new long[]{0x0000000000000602L}); public static final BitSet FOLLOW_9_in_expr102 = new BitSet(new long[]{0x0000000000001060L}); public static final BitSet FOLLOW_multExpr_in_expr104 = new BitSet(new long[]{0x0000000000000602L}); public static final BitSet FOLLOW_10_in_expr119 = new BitSet(new long[]{0x0000000000001060L}); public static final BitSet FOLLOW_multExpr_in_expr121 = new BitSet(new long[]{0x0000000000000602L}); public static final BitSet FOLLOW_atom_in_multExpr152 = new BitSet(new long[]{0x0000000000000802L}); public static final BitSet FOLLOW_11_in_multExpr155 = new BitSet(new long[]{0x0000000000001060L}); public static final BitSet FOLLOW_atom_in_multExpr157 = new BitSet(new long[]{0x0000000000000802L}); public static final BitSet FOLLOW_INT_in_atom180 = new BitSet(new long[]{0x0000000000000002L}); public static final BitSet FOLLOW_ID_in_atom191 = new BitSet(new long[]{0x0000000000000002L}); public static final BitSet FOLLOW_12_in_atom201 = new BitSet(new long[]{0x0000000000001060L}); public static final BitSet FOLLOW_expr_in_atom203 = new BitSet(new long[]{0x0000000000002000L}); public static final BitSet FOLLOW_13_in_atom205 = new BitSet(new long[]{0x0000000000000002L}); }