📄 exprparser.cs
字号:
followingStackPointer_--; adaptor.AddChild(root_0, e.Tree); dbg.Location(26,20); retval.value = e.value; dbg.Location(27,9); // G:\\expr.g:27:9: ( '+' e= multExpr | '-' e= multExpr )* try { dbg.EnterSubRule(3); do { int alt3 = 3; try { dbg.EnterDecision(3); int LA3_0 = input.LA(1); if ( (LA3_0 == 9) ) { alt3 = 1; } else if ( (LA3_0 == 10) ) { alt3 = 2; } } finally { dbg.ExitDecision(3); } switch (alt3) { case 1 : dbg.EnterAlt(1); // G:\\expr.g:27:13: '+' e= multExpr { dbg.Location(27,13); char_literal9 = (IToken)input.LT(1); Match(input,9,FOLLOW_9_in_expr162); char_literal9_tree = (CommonTree)adaptor.Create(char_literal9); adaptor.AddChild(root_0, char_literal9_tree); dbg.Location(27,18); PushFollow(FOLLOW_multExpr_in_expr166); e = multExpr(); followingStackPointer_--; adaptor.AddChild(root_0, e.Tree); dbg.Location(27,28); retval.value += e.value; } break; case 2 : dbg.EnterAlt(2); // G:\\expr.g:28:13: '-' e= multExpr { dbg.Location(28,13); char_literal10 = (IToken)input.LT(1); Match(input,10,FOLLOW_10_in_expr182); char_literal10_tree = (CommonTree)adaptor.Create(char_literal10); adaptor.AddChild(root_0, char_literal10_tree); dbg.Location(28,18); PushFollow(FOLLOW_multExpr_in_expr186); e = multExpr(); followingStackPointer_--; adaptor.AddChild(root_0, e.Tree); dbg.Location(28,28); retval.value -= e.value; } break; default: goto loop3; } } while (true); loop3: ; // Stops C# compiler whinging that label 'loop3' has no statements } finally { dbg.ExitSubRule(3); } } retval.stop = input.LT(-1); retval.tree = (CommonTree)adaptor.RulePostProcessing(root_0); adaptor.SetTokenBoundaries(retval.Tree, retval.start, retval.stop); } catch (RecognitionException re) { ReportError(re); Recover(input,re); } finally { } dbg.Location(30, 5); } finally { dbg.ExitRule("expr"); ruleLevel--; if ( ruleLevel==0 ) {dbg.Terminate();} } return retval; } // $ANTLR end expr public class multExpr_return : ParserRuleReturnScope { public int value; internal CommonTree tree; override public object Tree { get { return tree; } } }; // $ANTLR start multExpr // G:\\expr.g:32:1: multExpr returns [int value] : e= atom ( '*' e= atom )* ; public multExpr_return multExpr() // throws RecognitionException [1] { multExpr_return retval = new multExpr_return(); retval.start = input.LT(1); CommonTree root_0 = null; IToken char_literal11 = null; atom_return e = null; CommonTree char_literal11_tree=null; try { dbg.EnterRule("multExpr"); if ( ruleLevel==0 ) {dbg.Commence();} ruleLevel++; dbg.Location(32, 1); try { // G:\\expr.g:33:5: (e= atom ( '*' e= atom )* ) dbg.EnterAlt(1); // G:\\expr.g:33:9: e= atom ( '*' e= atom )* { root_0 = (CommonTree)adaptor.GetNilNode(); dbg.Location(33,10); PushFollow(FOLLOW_atom_in_multExpr224); e = atom(); followingStackPointer_--; adaptor.AddChild(root_0, e.Tree); dbg.Location(33,16); retval.value = e.value; dbg.Location(33,37); // G:\\expr.g:33:37: ( '*' e= atom )* try { dbg.EnterSubRule(4); do { int alt4 = 2; try { dbg.EnterDecision(4); int LA4_0 = input.LA(1); if ( (LA4_0 == 11) ) { alt4 = 1; } } finally { dbg.ExitDecision(4); } switch (alt4) { case 1 : dbg.EnterAlt(1); // G:\\expr.g:33:38: '*' e= atom { dbg.Location(33,38); char_literal11 = (IToken)input.LT(1); Match(input,11,FOLLOW_11_in_multExpr229); char_literal11_tree = (CommonTree)adaptor.Create(char_literal11); adaptor.AddChild(root_0, char_literal11_tree); dbg.Location(33,43); PushFollow(FOLLOW_atom_in_multExpr233); e = atom(); followingStackPointer_--; adaptor.AddChild(root_0, e.Tree); dbg.Location(33,49); retval.value *= e.value; } break; default: goto loop4; } } while (true); loop4: ; // Stops C# compiler whinging that label 'loop4' has no statements } finally { dbg.ExitSubRule(4); } } retval.stop = input.LT(-1); retval.tree = (CommonTree)adaptor.RulePostProcessing(root_0); adaptor.SetTokenBoundaries(retval.Tree, retval.start, retval.stop); } catch (RecognitionException re) { ReportError(re); Recover(input,re); } finally { } dbg.Location(34, 5); } finally { dbg.ExitRule("multExpr"); ruleLevel--; if ( ruleLevel==0 ) {dbg.Terminate();} } return retval; } // $ANTLR end multExpr public class atom_return : ParserRuleReturnScope { public int value; internal CommonTree tree; override public object Tree { get { return tree; } } }; // $ANTLR start atom // G:\\expr.g:36:1: atom returns [int value] : ( INT | ID | '(' expr ')' ); public atom_return atom() // throws RecognitionException [1] { atom_return retval = new atom_return(); retval.start = input.LT(1); CommonTree root_0 = null; IToken INT12 = null; IToken ID13 = null; IToken char_literal14 = null; IToken char_literal16 = null; expr_return expr15 = null; CommonTree INT12_tree=null; CommonTree ID13_tree=null; CommonTree char_literal14_tree=null; CommonTree char_literal16_tree=null; try { dbg.EnterRule("atom"); if ( ruleLevel==0 ) {dbg.Commence();} ruleLevel++; dbg.Location(36, 1); try { // G:\\expr.g:37:5: ( INT | ID | '(' expr ')' ) int alt5 = 3; try { dbg.EnterDecision(5); switch ( input.LA(1) ) { case INT: { alt5 = 1; } break; case ID: { alt5 = 2; } break; case 12: { alt5 = 3; } break; default: NoViableAltException nvae_d5s0 = new NoViableAltException("36:1: atom returns [int value] : ( INT | ID | '(' expr ')' );", 5, 0, input); dbg.RecognitionException(nvae_d5s0); throw nvae_d5s0; } } finally { dbg.ExitDecision(5); } switch (alt5) { case 1 : dbg.EnterAlt(1); // G:\\expr.g:37:9: INT { root_0 = (CommonTree)adaptor.GetNilNode(); dbg.Location(37,9); INT12 = (IToken)input.LT(1); Match(input,INT,FOLLOW_INT_in_atom261); INT12_tree = (CommonTree)adaptor.Create(INT12); adaptor.AddChild(root_0, INT12_tree); dbg.Location(37,13); retval.value = Integer.parseInt(INT12.Text); } break; case 2 : dbg.EnterAlt(2); // G:\\expr.g:38:9: ID { root_0 = (CommonTree)adaptor.GetNilNode(); dbg.Location(38,9); ID13 = (IToken)input.LT(1); Match(input,ID,FOLLOW_ID_in_atom273); ID13_tree = (CommonTree)adaptor.Create(ID13); adaptor.AddChild(root_0, ID13_tree); dbg.Location(39,9); Integer v = (Integer)memory.get(ID13.Text); if ( v!=null ) retval.value = v.intValue(); else System.err.println("undefined variable "+ID13.Text); } break; case 3 : dbg.EnterAlt(3); // G:\\expr.g:44:9: '(' expr ')' { root_0 = (CommonTree)adaptor.GetNilNode(); dbg.Location(44,9); char_literal14 = (IToken)input.LT(1); Match(input,12,FOLLOW_12_in_atom293); char_literal14_tree = (CommonTree)adaptor.Create(char_literal14); adaptor.AddChild(root_0, char_literal14_tree); dbg.Location(44,13); PushFollow(FOLLOW_expr_in_atom295); expr15 = expr(); followingStackPointer_--; adaptor.AddChild(root_0, expr15.Tree); dbg.Location(44,18); char_literal16 = (IToken)input.LT(1); Match(input,13,FOLLOW_13_in_atom297); char_literal16_tree = (CommonTree)adaptor.Create(char_literal16); adaptor.AddChild(root_0, char_literal16_tree); dbg.Location(44,22); retval.value = expr15.value; } break; } retval.stop = input.LT(-1); retval.tree = (CommonTree)adaptor.RulePostProcessing(root_0); adaptor.SetTokenBoundaries(retval.Tree, retval.start, retval.stop); } catch (RecognitionException re) { ReportError(re); Recover(input,re); } finally { } dbg.Location(45, 5); } finally { dbg.ExitRule("atom"); ruleLevel--; if ( ruleLevel==0 ) {dbg.Terminate();} } return retval; } // $ANTLR end atom private void InitializeCyclicDFAs() { } public static readonly BitSet FOLLOW_stat_in_prog54 = new BitSet(new ulong[]{0x0000000000001072UL}); public static readonly BitSet FOLLOW_expr_in_stat81 = new BitSet(new ulong[]{0x0000000000000010UL}); public static readonly BitSet FOLLOW_NEWLINE_in_stat83 = new BitSet(new ulong[]{0x0000000000000002UL}); public static readonly BitSet FOLLOW_ID_in_stat95 = new BitSet(new ulong[]{0x0000000000000100UL}); public static readonly BitSet FOLLOW_8_in_stat97 = new BitSet(new ulong[]{0x0000000000001060UL}); public static readonly BitSet FOLLOW_expr_in_stat99 = new BitSet(new ulong[]{0x0000000000000010UL}); public static readonly BitSet FOLLOW_NEWLINE_in_stat101 = new BitSet(new ulong[]{0x0000000000000002UL}); public static readonly BitSet FOLLOW_NEWLINE_in_stat121 = new BitSet(new ulong[]{0x0000000000000002UL}); public static readonly BitSet FOLLOW_multExpr_in_expr146 = new BitSet(new ulong[]{0x0000000000000602UL}); public static readonly BitSet FOLLOW_9_in_expr162 = new BitSet(new ulong[]{0x0000000000001060UL}); public static readonly BitSet FOLLOW_multExpr_in_expr166 = new BitSet(new ulong[]{0x0000000000000602UL}); public static readonly BitSet FOLLOW_10_in_expr182 = new BitSet(new ulong[]{0x0000000000001060UL}); public static readonly BitSet FOLLOW_multExpr_in_expr186 = new BitSet(new ulong[]{0x0000000000000602UL}); public static readonly BitSet FOLLOW_atom_in_multExpr224 = new BitSet(new ulong[]{0x0000000000000802UL}); public static readonly BitSet FOLLOW_11_in_multExpr229 = new BitSet(new ulong[]{0x0000000000001060UL}); public static readonly BitSet FOLLOW_atom_in_multExpr233 = new BitSet(new ulong[]{0x0000000000000802UL}); public static readonly BitSet FOLLOW_INT_in_atom261 = new BitSet(new ulong[]{0x0000000000000002UL}); public static readonly BitSet FOLLOW_ID_in_atom273 = new BitSet(new ulong[]{0x0000000000000002UL}); public static readonly BitSet FOLLOW_12_in_atom293 = new BitSet(new ulong[]{0x0000000000001060UL}); public static readonly BitSet FOLLOW_expr_in_atom295 = new BitSet(new ulong[]{0x0000000000002000UL}); public static readonly BitSet FOLLOW_13_in_atom297 = new BitSet(new ulong[]{0x0000000000000002UL});}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -