diff options
Diffstat (limited to 'Homework/cs5300/project-three/cfgparser')
6 files changed, 1001 insertions, 0 deletions
diff --git a/Homework/cs5300/project-three/cfgparser/Grammar.java b/Homework/cs5300/project-three/cfgparser/Grammar.java new file mode 100644 index 0000000..4de9ae4 --- /dev/null +++ b/Homework/cs5300/project-three/cfgparser/Grammar.java @@ -0,0 +1,65 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package cfgparser; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashSet; +import org.antlr.v4.runtime.ANTLRFileStream; +import org.antlr.v4.runtime.BufferedTokenStream; +import org.antlr.v4.runtime.ParserRuleContext; +import org.antlr.v4.runtime.tree.ParseTreeWalker; +import parser.Rule; + +/** + * + * @author edwajohn + */ +public class Grammar { + + private String name; + private ArrayList<Rule> rules; + private String startSymbol; + + public Grammar(String filename) throws IOException { + GrammarLexer cfglexer = new GrammarLexer(new ANTLRFileStream(filename)); + GrammarParser cfgparser = new GrammarParser(new BufferedTokenStream(cfglexer)); + ParserRuleContext tree = cfgparser.getContext(); // parse + + GrammarParser.GoalContext context = cfgparser.goal(); + + // Walk it and attach our listener + GrammarListenerImpl listener = new GrammarListenerImpl(); + ParseTreeWalker walker = new ParseTreeWalker(); + walker.walk(listener, context); + name = listener.name; + rules = listener.rules; + startSymbol = listener.startSymbol; + } + + public ArrayList<Rule> getRules() { + return rules; + } + + public String getName() { + return name; + } + + public ArrayList<String> getSymbols() { + HashSet<String> symbols = new HashSet<>(); + for (Rule rule : rules) { + symbols.add(rule.getLhs()); + for (String symbol : rule.getRhs()) { + symbols.add(symbol); + } + } + return new ArrayList<>(symbols); + } + + public String getStartSymbol() { + return startSymbol; + } +} diff --git a/Homework/cs5300/project-three/cfgparser/GrammarBaseListener.java b/Homework/cs5300/project-three/cfgparser/GrammarBaseListener.java new file mode 100644 index 0000000..29038f1 --- /dev/null +++ b/Homework/cs5300/project-three/cfgparser/GrammarBaseListener.java @@ -0,0 +1,135 @@ +// Generated from Grammar.g4 by ANTLR 4.9.1 +package cfgparser; + +import org.antlr.v4.runtime.ParserRuleContext; +import org.antlr.v4.runtime.tree.ErrorNode; +import org.antlr.v4.runtime.tree.TerminalNode; + +/** + * This class provides an empty implementation of {@link GrammarListener}, + * which can be extended to create a listener which only needs to handle a subset + * of the available methods. + */ +public class GrammarBaseListener implements GrammarListener { + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void enterGoal(GrammarParser.GoalContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void exitGoal(GrammarParser.GoalContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void enterName(GrammarParser.NameContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void exitName(GrammarParser.NameContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void enterRule_list(GrammarParser.Rule_listContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void exitRule_list(GrammarParser.Rule_listContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void enterLhs(GrammarParser.LhsContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void exitLhs(GrammarParser.LhsContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void enterRhs(GrammarParser.RhsContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void exitRhs(GrammarParser.RhsContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void enterOr_list(GrammarParser.Or_listContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void exitOr_list(GrammarParser.Or_listContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void enterSymbol_list(GrammarParser.Symbol_listContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void exitSymbol_list(GrammarParser.Symbol_listContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void enterSymbol(GrammarParser.SymbolContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void exitSymbol(GrammarParser.SymbolContext ctx) { } + + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void enterEveryRule(ParserRuleContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void exitEveryRule(ParserRuleContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void visitTerminal(TerminalNode node) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void visitErrorNode(ErrorNode node) { } +}
\ No newline at end of file diff --git a/Homework/cs5300/project-three/cfgparser/GrammarLexer.java b/Homework/cs5300/project-three/cfgparser/GrammarLexer.java new file mode 100644 index 0000000..653cc9c --- /dev/null +++ b/Homework/cs5300/project-three/cfgparser/GrammarLexer.java @@ -0,0 +1,137 @@ +// Generated from Grammar.g4 by ANTLR 4.9.1 +package cfgparser; +import org.antlr.v4.runtime.Lexer; +import org.antlr.v4.runtime.CharStream; +import org.antlr.v4.runtime.Token; +import org.antlr.v4.runtime.TokenStream; +import org.antlr.v4.runtime.*; +import org.antlr.v4.runtime.atn.*; +import org.antlr.v4.runtime.dfa.DFA; +import org.antlr.v4.runtime.misc.*; + +@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast"}) +public class GrammarLexer extends Lexer { + static { RuntimeMetaData.checkVersion("4.9.1", RuntimeMetaData.VERSION); } + + protected static final DFA[] _decisionToDFA; + protected static final PredictionContextCache _sharedContextCache = + new PredictionContextCache(); + public static final int + T__0=1, T__1=2, T__2=3, GRAMMAR=4, IDENT=5, WS=6, COMMENT=7; + public static String[] channelNames = { + "DEFAULT_TOKEN_CHANNEL", "HIDDEN" + }; + + public static String[] modeNames = { + "DEFAULT_MODE" + }; + + private static String[] makeRuleNames() { + return new String[] { + "T__0", "T__1", "T__2", "GRAMMAR", "IDENT", "WS", "COMMENT", "LETTER", + "DIGIT" + }; + } + public static final String[] ruleNames = makeRuleNames(); + + private static String[] makeLiteralNames() { + return new String[] { + null, "';'", "':'", "'|'", "'grammar'" + }; + } + private static final String[] _LITERAL_NAMES = makeLiteralNames(); + private static String[] makeSymbolicNames() { + return new String[] { + null, null, null, null, "GRAMMAR", "IDENT", "WS", "COMMENT" + }; + } + private static final String[] _SYMBOLIC_NAMES = makeSymbolicNames(); + public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES); + + /** + * @deprecated Use {@link #VOCABULARY} instead. + */ + @Deprecated + public static final String[] tokenNames; + static { + tokenNames = new String[_SYMBOLIC_NAMES.length]; + for (int i = 0; i < tokenNames.length; i++) { + tokenNames[i] = VOCABULARY.getLiteralName(i); + if (tokenNames[i] == null) { + tokenNames[i] = VOCABULARY.getSymbolicName(i); + } + + if (tokenNames[i] == null) { + tokenNames[i] = "<INVALID>"; + } + } + } + + @Override + @Deprecated + public String[] getTokenNames() { + return tokenNames; + } + + @Override + + public Vocabulary getVocabulary() { + return VOCABULARY; + } + + + public GrammarLexer(CharStream input) { + super(input); + _interp = new LexerATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache); + } + + @Override + public String getGrammarFileName() { return "Grammar.g4"; } + + @Override + public String[] getRuleNames() { return ruleNames; } + + @Override + public String getSerializedATN() { return _serializedATN; } + + @Override + public String[] getChannelNames() { return channelNames; } + + @Override + public String[] getModeNames() { return modeNames; } + + @Override + public ATN getATN() { return _ATN; } + + public static final String _serializedATN = + "\3\u608b\ua72a\u8133\ub9ed\u417c\u3be7\u7786\u5964\2\tR\b\1\4\2\t\2\4"+ + "\3\t\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7\t\7\4\b\t\b\4\t\t\t\4\n\t\n\3\2\3\2"+ + "\3\3\3\3\3\4\3\4\3\5\3\5\3\5\3\5\3\5\3\5\3\5\3\5\3\6\3\6\3\6\7\6\'\n\6"+ + "\f\6\16\6*\13\6\3\7\6\7-\n\7\r\7\16\7.\3\7\3\7\3\b\3\b\3\b\3\b\7\b\67"+ + "\n\b\f\b\16\b:\13\b\3\b\5\b=\n\b\3\b\3\b\3\b\3\b\3\b\7\bD\n\b\f\b\16\b"+ + "G\13\b\3\b\3\b\5\bK\n\b\3\b\3\b\3\t\3\t\3\n\3\n\3E\2\13\3\3\5\4\7\5\t"+ + "\6\13\7\r\b\17\t\21\2\23\2\3\2\5\5\2\13\f\16\17\"\"\4\2\f\f\17\17\4\2"+ + "C\\c|\2V\2\3\3\2\2\2\2\5\3\2\2\2\2\7\3\2\2\2\2\t\3\2\2\2\2\13\3\2\2\2"+ + "\2\r\3\2\2\2\2\17\3\2\2\2\3\25\3\2\2\2\5\27\3\2\2\2\7\31\3\2\2\2\t\33"+ + "\3\2\2\2\13#\3\2\2\2\r,\3\2\2\2\17J\3\2\2\2\21N\3\2\2\2\23P\3\2\2\2\25"+ + "\26\7=\2\2\26\4\3\2\2\2\27\30\7<\2\2\30\6\3\2\2\2\31\32\7~\2\2\32\b\3"+ + "\2\2\2\33\34\7i\2\2\34\35\7t\2\2\35\36\7c\2\2\36\37\7o\2\2\37 \7o\2\2"+ + " !\7c\2\2!\"\7t\2\2\"\n\3\2\2\2#(\5\21\t\2$\'\5\21\t\2%\'\5\23\n\2&$\3"+ + "\2\2\2&%\3\2\2\2\'*\3\2\2\2(&\3\2\2\2()\3\2\2\2)\f\3\2\2\2*(\3\2\2\2+"+ + "-\t\2\2\2,+\3\2\2\2-.\3\2\2\2.,\3\2\2\2./\3\2\2\2/\60\3\2\2\2\60\61\b"+ + "\7\2\2\61\16\3\2\2\2\62\63\7\61\2\2\63\64\7\61\2\2\648\3\2\2\2\65\67\n"+ + "\3\2\2\66\65\3\2\2\2\67:\3\2\2\28\66\3\2\2\289\3\2\2\29<\3\2\2\2:8\3\2"+ + "\2\2;=\7\17\2\2<;\3\2\2\2<=\3\2\2\2=>\3\2\2\2>K\7\f\2\2?@\7\61\2\2@A\7"+ + ",\2\2AE\3\2\2\2BD\13\2\2\2CB\3\2\2\2DG\3\2\2\2EF\3\2\2\2EC\3\2\2\2FH\3"+ + "\2\2\2GE\3\2\2\2HI\7,\2\2IK\7\61\2\2J\62\3\2\2\2J?\3\2\2\2KL\3\2\2\2L"+ + "M\b\b\2\2M\20\3\2\2\2NO\t\4\2\2O\22\3\2\2\2PQ\4\62;\2Q\24\3\2\2\2\n\2"+ + "&(.8<EJ\3\b\2\2"; + public static final ATN _ATN = + new ATNDeserializer().deserialize(_serializedATN.toCharArray()); + static { + _decisionToDFA = new DFA[_ATN.getNumberOfDecisions()]; + for (int i = 0; i < _ATN.getNumberOfDecisions(); i++) { + _decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i); + } + } +}
\ No newline at end of file diff --git a/Homework/cs5300/project-three/cfgparser/GrammarListener.java b/Homework/cs5300/project-three/cfgparser/GrammarListener.java new file mode 100644 index 0000000..e24999c --- /dev/null +++ b/Homework/cs5300/project-three/cfgparser/GrammarListener.java @@ -0,0 +1,90 @@ +// Generated from Grammar.g4 by ANTLR 4.9.1 +package cfgparser; +import org.antlr.v4.runtime.tree.ParseTreeListener; + +/** + * This interface defines a complete listener for a parse tree produced by + * {@link GrammarParser}. + */ +public interface GrammarListener extends ParseTreeListener { + /** + * Enter a parse tree produced by {@link GrammarParser#goal}. + * @param ctx the parse tree + */ + void enterGoal(GrammarParser.GoalContext ctx); + /** + * Exit a parse tree produced by {@link GrammarParser#goal}. + * @param ctx the parse tree + */ + void exitGoal(GrammarParser.GoalContext ctx); + /** + * Enter a parse tree produced by {@link GrammarParser#name}. + * @param ctx the parse tree + */ + void enterName(GrammarParser.NameContext ctx); + /** + * Exit a parse tree produced by {@link GrammarParser#name}. + * @param ctx the parse tree + */ + void exitName(GrammarParser.NameContext ctx); + /** + * Enter a parse tree produced by {@link GrammarParser#rule_list}. + * @param ctx the parse tree + */ + void enterRule_list(GrammarParser.Rule_listContext ctx); + /** + * Exit a parse tree produced by {@link GrammarParser#rule_list}. + * @param ctx the parse tree + */ + void exitRule_list(GrammarParser.Rule_listContext ctx); + /** + * Enter a parse tree produced by {@link GrammarParser#lhs}. + * @param ctx the parse tree + */ + void enterLhs(GrammarParser.LhsContext ctx); + /** + * Exit a parse tree produced by {@link GrammarParser#lhs}. + * @param ctx the parse tree + */ + void exitLhs(GrammarParser.LhsContext ctx); + /** + * Enter a parse tree produced by {@link GrammarParser#rhs}. + * @param ctx the parse tree + */ + void enterRhs(GrammarParser.RhsContext ctx); + /** + * Exit a parse tree produced by {@link GrammarParser#rhs}. + * @param ctx the parse tree + */ + void exitRhs(GrammarParser.RhsContext ctx); + /** + * Enter a parse tree produced by {@link GrammarParser#or_list}. + * @param ctx the parse tree + */ + void enterOr_list(GrammarParser.Or_listContext ctx); + /** + * Exit a parse tree produced by {@link GrammarParser#or_list}. + * @param ctx the parse tree + */ + void exitOr_list(GrammarParser.Or_listContext ctx); + /** + * Enter a parse tree produced by {@link GrammarParser#symbol_list}. + * @param ctx the parse tree + */ + void enterSymbol_list(GrammarParser.Symbol_listContext ctx); + /** + * Exit a parse tree produced by {@link GrammarParser#symbol_list}. + * @param ctx the parse tree + */ + void exitSymbol_list(GrammarParser.Symbol_listContext ctx); + /** + * Enter a parse tree produced by {@link GrammarParser#symbol}. + * @param ctx the parse tree + */ + void enterSymbol(GrammarParser.SymbolContext ctx); + /** + * Exit a parse tree produced by {@link GrammarParser#symbol}. + * @param ctx the parse tree + */ + void exitSymbol(GrammarParser.SymbolContext ctx); +}
\ No newline at end of file diff --git a/Homework/cs5300/project-three/cfgparser/GrammarListenerImpl.java b/Homework/cs5300/project-three/cfgparser/GrammarListenerImpl.java new file mode 100644 index 0000000..560b412 --- /dev/null +++ b/Homework/cs5300/project-three/cfgparser/GrammarListenerImpl.java @@ -0,0 +1,71 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package cfgparser; + +import cfgparser.GrammarBaseListener; +import cfgparser.GrammarParser; +import java.util.ArrayList; +import org.antlr.v4.runtime.tree.ErrorNode; +import parser.Rule; + +/** + * + * @author edwajohn + */ +public class GrammarListenerImpl extends GrammarBaseListener { + + String name; + String curLhs; + Rule curRule; + ArrayList<Rule> rules; + String startSymbol; + + public GrammarListenerImpl() { + rules = new ArrayList<>(); + startSymbol = null; + } + + public void print() { + for (Rule rule : rules) { + System.out.println(rule); + } + } + + @Override + public void enterName(GrammarParser.NameContext ctx) { + name = ctx.getText(); + } + + @Override + public void enterLhs(GrammarParser.LhsContext ctx) { + curLhs = ctx.getText(); + if (startSymbol == null) { + startSymbol = curLhs; + } + } + + @Override + public void enterRhs(GrammarParser.RhsContext ctx) { + curRule = new Rule(curLhs); + } + + @Override + public void exitRhs(GrammarParser.RhsContext ctx) { + curRule.setName(rules.size()); + rules.add(curRule); + } + + @Override + public void enterSymbol(GrammarParser.SymbolContext ctx) { + curRule.addRhs(ctx.getText()); + } + + @Override + public void visitErrorNode(ErrorNode node) { + System.out.println("Error!"); + } + +} diff --git a/Homework/cs5300/project-three/cfgparser/GrammarParser.java b/Homework/cs5300/project-three/cfgparser/GrammarParser.java new file mode 100644 index 0000000..20c523c --- /dev/null +++ b/Homework/cs5300/project-three/cfgparser/GrammarParser.java @@ -0,0 +1,503 @@ +// Generated from Grammar.g4 by ANTLR 4.9.1 +package cfgparser; +import org.antlr.v4.runtime.atn.*; +import org.antlr.v4.runtime.dfa.DFA; +import org.antlr.v4.runtime.*; +import org.antlr.v4.runtime.misc.*; +import org.antlr.v4.runtime.tree.*; +import java.util.List; +import java.util.Iterator; +import java.util.ArrayList; + +@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast"}) +public class GrammarParser extends Parser { + static { RuntimeMetaData.checkVersion("4.9.1", RuntimeMetaData.VERSION); } + + protected static final DFA[] _decisionToDFA; + protected static final PredictionContextCache _sharedContextCache = + new PredictionContextCache(); + public static final int + T__0=1, T__1=2, T__2=3, GRAMMAR=4, IDENT=5, WS=6, COMMENT=7; + public static final int + RULE_goal = 0, RULE_name = 1, RULE_rule_list = 2, RULE_lhs = 3, RULE_rhs = 4, + RULE_or_list = 5, RULE_symbol_list = 6, RULE_symbol = 7; + private static String[] makeRuleNames() { + return new String[] { + "goal", "name", "rule_list", "lhs", "rhs", "or_list", "symbol_list", + "symbol" + }; + } + public static final String[] ruleNames = makeRuleNames(); + + private static String[] makeLiteralNames() { + return new String[] { + null, "';'", "':'", "'|'", "'grammar'" + }; + } + private static final String[] _LITERAL_NAMES = makeLiteralNames(); + private static String[] makeSymbolicNames() { + return new String[] { + null, null, null, null, "GRAMMAR", "IDENT", "WS", "COMMENT" + }; + } + private static final String[] _SYMBOLIC_NAMES = makeSymbolicNames(); + public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES); + + /** + * @deprecated Use {@link #VOCABULARY} instead. + */ + @Deprecated + public static final String[] tokenNames; + static { + tokenNames = new String[_SYMBOLIC_NAMES.length]; + for (int i = 0; i < tokenNames.length; i++) { + tokenNames[i] = VOCABULARY.getLiteralName(i); + if (tokenNames[i] == null) { + tokenNames[i] = VOCABULARY.getSymbolicName(i); + } + + if (tokenNames[i] == null) { + tokenNames[i] = "<INVALID>"; + } + } + } + + @Override + @Deprecated + public String[] getTokenNames() { + return tokenNames; + } + + @Override + + public Vocabulary getVocabulary() { + return VOCABULARY; + } + + @Override + public String getGrammarFileName() { return "Grammar.g4"; } + + @Override + public String[] getRuleNames() { return ruleNames; } + + @Override + public String getSerializedATN() { return _serializedATN; } + + @Override + public ATN getATN() { return _ATN; } + + public GrammarParser(TokenStream input) { + super(input); + _interp = new ParserATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache); + } + + public static class GoalContext extends ParserRuleContext { + public TerminalNode GRAMMAR() { return getToken(GrammarParser.GRAMMAR, 0); } + public NameContext name() { + return getRuleContext(NameContext.class,0); + } + public Rule_listContext rule_list() { + return getRuleContext(Rule_listContext.class,0); + } + public GoalContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_goal; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof GrammarListener ) ((GrammarListener)listener).enterGoal(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof GrammarListener ) ((GrammarListener)listener).exitGoal(this); + } + } + + public final GoalContext goal() throws RecognitionException { + GoalContext _localctx = new GoalContext(_ctx, getState()); + enterRule(_localctx, 0, RULE_goal); + try { + enterOuterAlt(_localctx, 1); + { + setState(16); + match(GRAMMAR); + setState(17); + name(); + setState(18); + match(T__0); + setState(19); + rule_list(); + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + public static class NameContext extends ParserRuleContext { + public TerminalNode IDENT() { return getToken(GrammarParser.IDENT, 0); } + public NameContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_name; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof GrammarListener ) ((GrammarListener)listener).enterName(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof GrammarListener ) ((GrammarListener)listener).exitName(this); + } + } + + public final NameContext name() throws RecognitionException { + NameContext _localctx = new NameContext(_ctx, getState()); + enterRule(_localctx, 2, RULE_name); + try { + enterOuterAlt(_localctx, 1); + { + setState(21); + match(IDENT); + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + public static class Rule_listContext extends ParserRuleContext { + public LhsContext lhs() { + return getRuleContext(LhsContext.class,0); + } + public RhsContext rhs() { + return getRuleContext(RhsContext.class,0); + } + public Or_listContext or_list() { + return getRuleContext(Or_listContext.class,0); + } + public Rule_listContext rule_list() { + return getRuleContext(Rule_listContext.class,0); + } + public Rule_listContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_rule_list; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof GrammarListener ) ((GrammarListener)listener).enterRule_list(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof GrammarListener ) ((GrammarListener)listener).exitRule_list(this); + } + } + + public final Rule_listContext rule_list() throws RecognitionException { + Rule_listContext _localctx = new Rule_listContext(_ctx, getState()); + enterRule(_localctx, 4, RULE_rule_list); + try { + setState(31); + _errHandler.sync(this); + switch (_input.LA(1)) { + case IDENT: + enterOuterAlt(_localctx, 1); + { + setState(23); + lhs(); + setState(24); + match(T__1); + setState(25); + rhs(); + setState(26); + or_list(); + setState(27); + match(T__0); + setState(28); + rule_list(); + } + break; + case EOF: + enterOuterAlt(_localctx, 2); + { + } + break; + default: + throw new NoViableAltException(this); + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + public static class LhsContext extends ParserRuleContext { + public TerminalNode IDENT() { return getToken(GrammarParser.IDENT, 0); } + public LhsContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_lhs; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof GrammarListener ) ((GrammarListener)listener).enterLhs(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof GrammarListener ) ((GrammarListener)listener).exitLhs(this); + } + } + + public final LhsContext lhs() throws RecognitionException { + LhsContext _localctx = new LhsContext(_ctx, getState()); + enterRule(_localctx, 6, RULE_lhs); + try { + enterOuterAlt(_localctx, 1); + { + setState(33); + match(IDENT); + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + public static class RhsContext extends ParserRuleContext { + public Symbol_listContext symbol_list() { + return getRuleContext(Symbol_listContext.class,0); + } + public RhsContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_rhs; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof GrammarListener ) ((GrammarListener)listener).enterRhs(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof GrammarListener ) ((GrammarListener)listener).exitRhs(this); + } + } + + public final RhsContext rhs() throws RecognitionException { + RhsContext _localctx = new RhsContext(_ctx, getState()); + enterRule(_localctx, 8, RULE_rhs); + try { + enterOuterAlt(_localctx, 1); + { + setState(35); + symbol_list(); + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + public static class Or_listContext extends ParserRuleContext { + public RhsContext rhs() { + return getRuleContext(RhsContext.class,0); + } + public Or_listContext or_list() { + return getRuleContext(Or_listContext.class,0); + } + public Or_listContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_or_list; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof GrammarListener ) ((GrammarListener)listener).enterOr_list(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof GrammarListener ) ((GrammarListener)listener).exitOr_list(this); + } + } + + public final Or_listContext or_list() throws RecognitionException { + Or_listContext _localctx = new Or_listContext(_ctx, getState()); + enterRule(_localctx, 10, RULE_or_list); + try { + setState(42); + _errHandler.sync(this); + switch (_input.LA(1)) { + case T__2: + enterOuterAlt(_localctx, 1); + { + setState(37); + match(T__2); + setState(38); + rhs(); + setState(39); + or_list(); + } + break; + case T__0: + enterOuterAlt(_localctx, 2); + { + } + break; + default: + throw new NoViableAltException(this); + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + public static class Symbol_listContext extends ParserRuleContext { + public SymbolContext symbol() { + return getRuleContext(SymbolContext.class,0); + } + public Symbol_listContext symbol_list() { + return getRuleContext(Symbol_listContext.class,0); + } + public Symbol_listContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_symbol_list; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof GrammarListener ) ((GrammarListener)listener).enterSymbol_list(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof GrammarListener ) ((GrammarListener)listener).exitSymbol_list(this); + } + } + + public final Symbol_listContext symbol_list() throws RecognitionException { + Symbol_listContext _localctx = new Symbol_listContext(_ctx, getState()); + enterRule(_localctx, 12, RULE_symbol_list); + try { + setState(48); + _errHandler.sync(this); + switch (_input.LA(1)) { + case IDENT: + enterOuterAlt(_localctx, 1); + { + setState(44); + symbol(); + setState(45); + symbol_list(); + } + break; + case T__0: + case T__2: + enterOuterAlt(_localctx, 2); + { + } + break; + default: + throw new NoViableAltException(this); + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + public static class SymbolContext extends ParserRuleContext { + public TerminalNode IDENT() { return getToken(GrammarParser.IDENT, 0); } + public SymbolContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_symbol; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof GrammarListener ) ((GrammarListener)listener).enterSymbol(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof GrammarListener ) ((GrammarListener)listener).exitSymbol(this); + } + } + + public final SymbolContext symbol() throws RecognitionException { + SymbolContext _localctx = new SymbolContext(_ctx, getState()); + enterRule(_localctx, 14, RULE_symbol); + try { + enterOuterAlt(_localctx, 1); + { + setState(50); + match(IDENT); + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + public static final String _serializedATN = + "\3\u608b\ua72a\u8133\ub9ed\u417c\u3be7\u7786\u5964\3\t\67\4\2\t\2\4\3"+ + "\t\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7\t\7\4\b\t\b\4\t\t\t\3\2\3\2\3\2\3\2\3"+ + "\2\3\3\3\3\3\4\3\4\3\4\3\4\3\4\3\4\3\4\3\4\5\4\"\n\4\3\5\3\5\3\6\3\6\3"+ + "\7\3\7\3\7\3\7\3\7\5\7-\n\7\3\b\3\b\3\b\3\b\5\b\63\n\b\3\t\3\t\3\t\2\2"+ + "\n\2\4\6\b\n\f\16\20\2\2\2\61\2\22\3\2\2\2\4\27\3\2\2\2\6!\3\2\2\2\b#"+ + "\3\2\2\2\n%\3\2\2\2\f,\3\2\2\2\16\62\3\2\2\2\20\64\3\2\2\2\22\23\7\6\2"+ + "\2\23\24\5\4\3\2\24\25\7\3\2\2\25\26\5\6\4\2\26\3\3\2\2\2\27\30\7\7\2"+ + "\2\30\5\3\2\2\2\31\32\5\b\5\2\32\33\7\4\2\2\33\34\5\n\6\2\34\35\5\f\7"+ + "\2\35\36\7\3\2\2\36\37\5\6\4\2\37\"\3\2\2\2 \"\3\2\2\2!\31\3\2\2\2! \3"+ + "\2\2\2\"\7\3\2\2\2#$\7\7\2\2$\t\3\2\2\2%&\5\16\b\2&\13\3\2\2\2\'(\7\5"+ + "\2\2()\5\n\6\2)*\5\f\7\2*-\3\2\2\2+-\3\2\2\2,\'\3\2\2\2,+\3\2\2\2-\r\3"+ + "\2\2\2./\5\20\t\2/\60\5\16\b\2\60\63\3\2\2\2\61\63\3\2\2\2\62.\3\2\2\2"+ + "\62\61\3\2\2\2\63\17\3\2\2\2\64\65\7\7\2\2\65\21\3\2\2\2\5!,\62"; + public static final ATN _ATN = + new ATNDeserializer().deserialize(_serializedATN.toCharArray()); + static { + _decisionToDFA = new DFA[_ATN.getNumberOfDecisions()]; + for (int i = 0; i < _ATN.getNumberOfDecisions(); i++) { + _decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i); + } + } +}
\ No newline at end of file |
