📄 antlrparser.java
字号:
} } returnAST = id_AST; } public final Map optionsSpec() throws RecognitionException, TokenStreamException { Map opts=new HashMap(); returnAST = null; ASTPair currentAST = new ASTPair(); GrammarAST optionsSpec_AST = null; try { // for error handling GrammarAST tmp9_AST = null; tmp9_AST = (GrammarAST)astFactory.create(LT(1)); astFactory.makeASTRoot(currentAST, tmp9_AST); match(OPTIONS); { int _cnt17=0; _loop17: do { if ((LA(1)==TOKEN_REF||LA(1)==RULE_REF)) { option(opts); astFactory.addASTChild(currentAST, returnAST); match(SEMI); } else { if ( _cnt17>=1 ) { break _loop17; } else {throw new NoViableAltException(LT(1), getFilename());} } _cnt17++; } while (true); } match(RCURLY); optionsSpec_AST = (GrammarAST)currentAST.root; } catch (RecognitionException ex) { if (inputState.guessing==0) { reportError(ex); recover(ex,_tokenSet_3); } else { throw ex; } } returnAST = optionsSpec_AST; return opts; } public final void tokensSpec() throws RecognitionException, TokenStreamException { returnAST = null; ASTPair currentAST = new ASTPair(); GrammarAST tokensSpec_AST = null; try { // for error handling GrammarAST tmp12_AST = null; tmp12_AST = (GrammarAST)astFactory.create(LT(1)); astFactory.makeASTRoot(currentAST, tmp12_AST); match(TOKENS); { int _cnt22=0; _loop22: do { if ((LA(1)==TOKEN_REF)) { tokenSpec(); astFactory.addASTChild(currentAST, returnAST); } else { if ( _cnt22>=1 ) { break _loop22; } else {throw new NoViableAltException(LT(1), getFilename());} } _cnt22++; } while (true); } match(RCURLY); tokensSpec_AST = (GrammarAST)currentAST.root; } catch (RecognitionException ex) { if (inputState.guessing==0) { reportError(ex); recover(ex,_tokenSet_4); } else { throw ex; } } returnAST = tokensSpec_AST; } public final void attrScopes() throws RecognitionException, TokenStreamException { returnAST = null; ASTPair currentAST = new ASTPair(); GrammarAST attrScopes_AST = null; try { // for error handling { _loop28: do { if ((LA(1)==SCOPE)) { attrScope(); astFactory.addASTChild(currentAST, returnAST); } else { break _loop28; } } while (true); } attrScopes_AST = (GrammarAST)currentAST.root; } catch (RecognitionException ex) { if (inputState.guessing==0) { reportError(ex); recover(ex,_tokenSet_5); } else { throw ex; } } returnAST = attrScopes_AST; } public final void actions() throws RecognitionException, TokenStreamException { returnAST = null; ASTPair currentAST = new ASTPair(); GrammarAST actions_AST = null; try { // for error handling { int _cnt11=0; _loop11: do { if ((LA(1)==AMPERSAND)) { action(); astFactory.addASTChild(currentAST, returnAST); } else { if ( _cnt11>=1 ) { break _loop11; } else {throw new NoViableAltException(LT(1), getFilename());} } _cnt11++; } while (true); } actions_AST = (GrammarAST)currentAST.root; } catch (RecognitionException ex) { if (inputState.guessing==0) { reportError(ex); recover(ex,_tokenSet_6); } else { throw ex; } } returnAST = actions_AST; } public final void rules() throws RecognitionException, TokenStreamException { returnAST = null; ASTPair currentAST = new ASTPair(); GrammarAST rules_AST = null; try { // for error handling { int _cnt32=0; _loop32: do { if ((_tokenSet_6.member(LA(1)))) { rule(); astFactory.addASTChild(currentAST, returnAST); } else { if ( _cnt32>=1 ) { break _loop32; } else {throw new NoViableAltException(LT(1), getFilename());} } _cnt32++; } while (true); } rules_AST = (GrammarAST)currentAST.root; } catch (RecognitionException ex) { if (inputState.guessing==0) { reportError(ex); recover(ex,_tokenSet_0); } else { throw ex; } } returnAST = rules_AST; } /** Match stuff like @parser::members {int i;} */ public final void action() throws RecognitionException, TokenStreamException { returnAST = null; ASTPair currentAST = new ASTPair(); GrammarAST action_AST = null; try { // for error handling GrammarAST tmp14_AST = null; tmp14_AST = (GrammarAST)astFactory.create(LT(1)); astFactory.makeASTRoot(currentAST, tmp14_AST); match(AMPERSAND); { if ((_tokenSet_7.member(LA(1))) && (LA(2)==COLON)) { actionScopeName(); astFactory.addASTChild(currentAST, returnAST); match(COLON); match(COLON); } else if ((LA(1)==TOKEN_REF||LA(1)==RULE_REF) && (LA(2)==ACTION)) { } else { throw new NoViableAltException(LT(1), getFilename()); } } id(); astFactory.addASTChild(currentAST, returnAST); GrammarAST tmp17_AST = null; tmp17_AST = (GrammarAST)astFactory.create(LT(1)); astFactory.addASTChild(currentAST, tmp17_AST); match(ACTION); action_AST = (GrammarAST)currentAST.root; } catch (RecognitionException ex) { if (inputState.guessing==0) { reportError(ex); recover(ex,_tokenSet_5); } else { throw ex; } } returnAST = action_AST; } /** Sometimes the scope names will collide with keywords; allow them as * ids for action scopes. */ public final void actionScopeName() throws RecognitionException, TokenStreamException { returnAST = null; ASTPair currentAST = new ASTPair(); GrammarAST actionScopeName_AST = null; Token l = null; GrammarAST l_AST = null; Token p = null; GrammarAST p_AST = null; try { // for error handling switch ( LA(1)) { case TOKEN_REF: case RULE_REF: { id(); astFactory.addASTChild(currentAST, returnAST); actionScopeName_AST = (GrammarAST)currentAST.root; break; } case LITERAL_lexer: { l = LT(1); l_AST = (GrammarAST)astFactory.create(l); astFactory.addASTChild(currentAST, l_AST); match(LITERAL_lexer); if ( inputState.guessing==0 ) { l_AST.setType(ID); } actionScopeName_AST = (GrammarAST)currentAST.root; break; } case PARSER: { p = LT(1); p_AST = (GrammarAST)astFactory.create(p); astFactory.addASTChild(currentAST, p_AST); match(PARSER); if ( inputState.guessing==0 ) { p_AST.setType(ID); } actionScopeName_AST = (GrammarAST)currentAST.root; break; } default: { throw new NoViableAltException(LT(1), getFilename()); } } } catch (RecognitionException ex) { if (inputState.guessing==0) { reportError(ex); recover(ex,_tokenSet_8); } else { throw ex; } } returnAST = actionScopeName_AST; } public final void option( Map opts ) throws RecognitionException, TokenStreamException { returnAST = null; ASTPair currentAST = new ASTPair(); GrammarAST option_AST = null; GrammarAST o_AST = null; Object value=null; try { // for error handling id(); o_AST = (GrammarAST)returnAST; astFactory.addASTChild(currentAST, returnAST); GrammarAST tmp18_AST = null; tmp18_AST = (GrammarAST)astFactory.create(LT(1)); astFactory.makeASTRoot(currentAST, tmp18_AST); match(ASSIGN); value=optionValue(); astFactory.addASTChild(currentAST, returnAST); if ( inputState.guessing==0 ) { opts.put(o_AST.getText(), value); } option_AST = (GrammarAST)currentAST.root; } catch (RecognitionException ex) { if (inputState.guessing==0) { reportError(ex); recover(ex,_tokenSet_9); } else { throw ex; } } returnAST = option_AST; } public final Object optionValue() throws RecognitionException, TokenStreamException { Object value=null; returnAST = null; ASTPair currentAST = new ASTPair(); GrammarAST optionValue_AST = null; GrammarAST x_AST = null; Token s = null; GrammarAST s_AST = null; Token c = null; GrammarAST c_AST = null; Token i = null; GrammarAST i_AST = null; Token ss = null; GrammarAST ss_AST = null; try { // for error handling switch ( LA(1)) { case TOKEN_REF: case RULE_REF: { id(); x_AST = (GrammarAST)returnAST; astFactory.addASTChild(currentAST, returnAST); if ( inputState.guessing==0 ) { value = x_AST.getText(); } optionValue_AST = (GrammarAST)currentAST.root; break; } case STRING_LITERAL: { s = LT(1); s_AST = (GrammarAST)astFactory.create(s); astFactory.addASTChild(currentAST, s_AST); match(STRING_LITERAL); if ( inputState.guessing==0 ) { String vs = s_AST.getText(); value=vs.substring(1,vs.length()-1); } optionValue_AST = (GrammarAST)currentAST.root; break; } case CHAR_LITERAL: { c = LT(1); c_AST = (GrammarAST)astFactory.create(c); astFactory.addASTChild(currentAST, c_AST); match(CHAR_LITERAL); if ( inputState.guessing==0 ) { String vs = c_AST.getText(); value=vs.substring(1,vs.length()-1); } optionValue_AST = (GrammarAST)currentAST.root; break; } case INT: { i = LT(1); i_AST = (GrammarAST)astFactory.create(i); astFactory.addASTChild(currentAST, i_AST); match(INT); if ( inputState.guessing==0 ) { value = new Integer(i_AST.getText()); } optionValue_AST = (GrammarAST)currentAST.root; break; } case STAR: { ss = LT(1); ss_AST = (GrammarAST)astFactory.create(ss); astFactory.addASTChild(currentAST, ss_AST); match(STAR); if ( inputState.guessing==0 ) { ss_AST.setType(STRING_LITERAL); value = "*"; } optionValue_AST = (GrammarAST)currentAST.root; break; } default: { throw new NoViableAltException(LT(1), getFilename()); } } } catch (RecognitionException ex) { if (inputState.guessing==0) { reportError(ex); recover(ex,_tokenSet_10); } else { throw ex; } } returnAST = optionValue_AST; return value; } public final void tokenSpec() throws RecognitionException, TokenStreamException { returnAST = null; ASTPair currentAST = new ASTPair(); GrammarAST tokenSpec_AST = null; try { // for error handling GrammarAST tmp19_AST = null; tmp19_AST = (GrammarAST)astFactory.create(LT(1)); astFactory.addASTChild(currentAST, tmp19_AST); match(TOKEN_REF); { switch ( LA(1)) { case ASSIGN: { GrammarAST tmp20_AST = null; tmp20_AST = (GrammarAST)astFactory.create(LT(1)); astFactory.makeASTRoot(currentAST, tmp20_AST); match(ASSIGN); { switch ( LA(1)) { case STRING_LITERAL: { GrammarAST tmp21_AST = null; tmp21_AST = (GrammarAST)astFactory.create(LT(1)); astFactory.addASTChild(currentAST, tmp21_AST); match(STRING_LITERAL); break; } case CHAR_LITERAL: { GrammarAST tmp22_AST = null; tmp22_AST = (GrammarAST)astFactory.create(LT(1)); astFactory.addASTChild(currentAST, tmp22_AST); match(CHAR_LITERAL); break; } default: { throw new NoViableAltException(LT(1), getFilename()); } } } break; } case SEMI: { break; } default: { throw new NoViableAltException(LT(1), getFilename()); } } } match(SEMI); tokenSpec_AST = (GrammarAST)currentAST.root; } catch (RecognitionException ex) { if (inputState.guessing==0) { reportError(ex); recover(ex,_tokenSet_11); } else { throw ex; } } returnAST = tokenSpec_AST; } public final void attrScope() throws RecognitionException, TokenStreamException { returnAST = null; ASTPair currentAST = new ASTPair(); GrammarAST attrScope_AST = null; try { // for error handling GrammarAST tmp24_AST = null; tmp24_AST = (GrammarAST)astFactory.create(LT(1)); astFactory.makeASTRoot(currentAST, tmp24_AST); match(SCOPE); id(); astFactory.addASTChild(currentAST, returnAST); GrammarAST tmp25_AST = null; tmp25_AST = (GrammarAST)astFactory.create(LT(1)); astFactory.addASTChild(currentAST, tmp25_AST); match(ACTION); attrScope_AST = (GrammarAST)currentAST.root; } catch (RecognitionException ex) { if (inputState.guessing==0) { reportError(ex); recover(ex,_tokenSet_4); } else { throw ex; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -