info.scce.addlib.parser.ADDLanguageParser Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of addlib Show documentation
Show all versions of addlib Show documentation
The Java Library for Algebraic Decision Diagrams, Code Generation, and Layouting
// Generated from info/scce/addlib/parser/ADDLanguage.g4 by ANTLR 4.5
package info.scce.addlib.parser;
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 ADDLanguageParser extends Parser {
static { RuntimeMetaData.checkVersion("4.5", 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, T__3=4, LPAREN=5, RPAREN=6, DOUBLE=7, ID=8, WS=9;
public static final int
RULE_expr = 0;
public static final String[] ruleNames = {
"expr"
};
private static final String[] _LITERAL_NAMES = {
null, "'*'", "'/'", "'+'", "'-'", "'('", "')'"
};
private static final String[] _SYMBOLIC_NAMES = {
null, null, null, null, null, "LPAREN", "RPAREN", "DOUBLE", "ID", "WS"
};
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] = "";
}
}
}
@Override
@Deprecated
public String[] getTokenNames() {
return tokenNames;
}
@Override
public Vocabulary getVocabulary() {
return VOCABULARY;
}
@Override
public String getGrammarFileName() { return "ADDLanguage.g4"; }
@Override
public String[] getRuleNames() { return ruleNames; }
@Override
public String getSerializedATN() { return _serializedATN; }
@Override
public ATN getATN() { return _ATN; }
public ADDLanguageParser(TokenStream input) {
super(input);
_interp = new ParserATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache);
}
public static class ExprContext extends ParserRuleContext {
public ExprContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_expr; }
public ExprContext() { }
public void copyFrom(ExprContext ctx) {
super.copyFrom(ctx);
}
}
public static class VarExprContext extends ExprContext {
public Token var;
public TerminalNode ID() { return getToken(ADDLanguageParser.ID, 0); }
public VarExprContext(ExprContext ctx) { copyFrom(ctx); }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof ADDLanguageListener ) ((ADDLanguageListener)listener).enterVarExpr(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof ADDLanguageListener ) ((ADDLanguageListener)listener).exitVarExpr(this);
}
@Override
public T accept(ParseTreeVisitor extends T> visitor) {
if ( visitor instanceof ADDLanguageVisitor ) return ((ADDLanguageVisitor extends T>)visitor).visitVarExpr(this);
else return visitor.visitChildren(this);
}
}
public static class RealExprContext extends ExprContext {
public Token real;
public TerminalNode DOUBLE() { return getToken(ADDLanguageParser.DOUBLE, 0); }
public RealExprContext(ExprContext ctx) { copyFrom(ctx); }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof ADDLanguageListener ) ((ADDLanguageListener)listener).enterRealExpr(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof ADDLanguageListener ) ((ADDLanguageListener)listener).exitRealExpr(this);
}
@Override
public T accept(ParseTreeVisitor extends T> visitor) {
if ( visitor instanceof ADDLanguageVisitor ) return ((ADDLanguageVisitor extends T>)visitor).visitRealExpr(this);
else return visitor.visitChildren(this);
}
}
public static class PlusMinusExprContext extends ExprContext {
public ExprContext left;
public Token op;
public ExprContext right;
public List expr() {
return getRuleContexts(ExprContext.class);
}
public ExprContext expr(int i) {
return getRuleContext(ExprContext.class,i);
}
public PlusMinusExprContext(ExprContext ctx) { copyFrom(ctx); }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof ADDLanguageListener ) ((ADDLanguageListener)listener).enterPlusMinusExpr(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof ADDLanguageListener ) ((ADDLanguageListener)listener).exitPlusMinusExpr(this);
}
@Override
public T accept(ParseTreeVisitor extends T> visitor) {
if ( visitor instanceof ADDLanguageVisitor ) return ((ADDLanguageVisitor extends T>)visitor).visitPlusMinusExpr(this);
else return visitor.visitChildren(this);
}
}
public static class MulDivExprContext extends ExprContext {
public ExprContext left;
public Token op;
public ExprContext right;
public List expr() {
return getRuleContexts(ExprContext.class);
}
public ExprContext expr(int i) {
return getRuleContext(ExprContext.class,i);
}
public MulDivExprContext(ExprContext ctx) { copyFrom(ctx); }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof ADDLanguageListener ) ((ADDLanguageListener)listener).enterMulDivExpr(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof ADDLanguageListener ) ((ADDLanguageListener)listener).exitMulDivExpr(this);
}
@Override
public T accept(ParseTreeVisitor extends T> visitor) {
if ( visitor instanceof ADDLanguageVisitor ) return ((ADDLanguageVisitor extends T>)visitor).visitMulDivExpr(this);
else return visitor.visitChildren(this);
}
}
public static class ParenExprContext extends ExprContext {
public ExprContext ex;
public TerminalNode LPAREN() { return getToken(ADDLanguageParser.LPAREN, 0); }
public TerminalNode RPAREN() { return getToken(ADDLanguageParser.RPAREN, 0); }
public ExprContext expr() {
return getRuleContext(ExprContext.class,0);
}
public ParenExprContext(ExprContext ctx) { copyFrom(ctx); }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof ADDLanguageListener ) ((ADDLanguageListener)listener).enterParenExpr(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof ADDLanguageListener ) ((ADDLanguageListener)listener).exitParenExpr(this);
}
@Override
public T accept(ParseTreeVisitor extends T> visitor) {
if ( visitor instanceof ADDLanguageVisitor ) return ((ADDLanguageVisitor extends T>)visitor).visitParenExpr(this);
else return visitor.visitChildren(this);
}
}
public final ExprContext expr() throws RecognitionException {
return expr(0);
}
private ExprContext expr(int _p) throws RecognitionException {
ParserRuleContext _parentctx = _ctx;
int _parentState = getState();
ExprContext _localctx = new ExprContext(_ctx, _parentState);
ExprContext _prevctx = _localctx;
int _startState = 0;
enterRecursionRule(_localctx, 0, RULE_expr, _p);
int _la;
try {
int _alt;
enterOuterAlt(_localctx, 1);
{
setState(9);
switch (_input.LA(1)) {
case LPAREN:
{
_localctx = new ParenExprContext(_localctx);
_ctx = _localctx;
_prevctx = _localctx;
setState(3);
match(LPAREN);
setState(4);
((ParenExprContext)_localctx).ex = expr(0);
setState(5);
match(RPAREN);
}
break;
case ID:
{
_localctx = new VarExprContext(_localctx);
_ctx = _localctx;
_prevctx = _localctx;
setState(7);
((VarExprContext)_localctx).var = match(ID);
}
break;
case DOUBLE:
{
_localctx = new RealExprContext(_localctx);
_ctx = _localctx;
_prevctx = _localctx;
setState(8);
((RealExprContext)_localctx).real = match(DOUBLE);
}
break;
default:
throw new NoViableAltException(this);
}
_ctx.stop = _input.LT(-1);
setState(19);
_errHandler.sync(this);
_alt = getInterpreter().adaptivePredict(_input,2,_ctx);
while ( _alt!=2 && _alt!=org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER ) {
if ( _alt==1 ) {
if ( _parseListeners!=null ) triggerExitRuleEvent();
_prevctx = _localctx;
{
setState(17);
switch ( getInterpreter().adaptivePredict(_input,1,_ctx) ) {
case 1:
{
_localctx = new MulDivExprContext(new ExprContext(_parentctx, _parentState));
((MulDivExprContext)_localctx).left = _prevctx;
pushNewRecursionContext(_localctx, _startState, RULE_expr);
setState(11);
if (!(precpred(_ctx, 4))) throw new FailedPredicateException(this, "precpred(_ctx, 4)");
setState(12);
((MulDivExprContext)_localctx).op = _input.LT(1);
_la = _input.LA(1);
if ( !(_la==T__0 || _la==T__1) ) {
((MulDivExprContext)_localctx).op = (Token)_errHandler.recoverInline(this);
} else {
consume();
}
setState(13);
((MulDivExprContext)_localctx).right = expr(5);
}
break;
case 2:
{
_localctx = new PlusMinusExprContext(new ExprContext(_parentctx, _parentState));
((PlusMinusExprContext)_localctx).left = _prevctx;
pushNewRecursionContext(_localctx, _startState, RULE_expr);
setState(14);
if (!(precpred(_ctx, 3))) throw new FailedPredicateException(this, "precpred(_ctx, 3)");
setState(15);
((PlusMinusExprContext)_localctx).op = _input.LT(1);
_la = _input.LA(1);
if ( !(_la==T__2 || _la==T__3) ) {
((PlusMinusExprContext)_localctx).op = (Token)_errHandler.recoverInline(this);
} else {
consume();
}
setState(16);
((PlusMinusExprContext)_localctx).right = expr(4);
}
break;
}
}
}
setState(21);
_errHandler.sync(this);
_alt = getInterpreter().adaptivePredict(_input,2,_ctx);
}
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
unrollRecursionContexts(_parentctx);
}
return _localctx;
}
public boolean sempred(RuleContext _localctx, int ruleIndex, int predIndex) {
switch (ruleIndex) {
case 0:
return expr_sempred((ExprContext)_localctx, predIndex);
}
return true;
}
private boolean expr_sempred(ExprContext _localctx, int predIndex) {
switch (predIndex) {
case 0:
return precpred(_ctx, 4);
case 1:
return precpred(_ctx, 3);
}
return true;
}
public static final String _serializedATN =
"\3\u0430\ud6d1\u8206\uad2d\u4417\uaef1\u8d80\uaadd\3\13\31\4\2\t\2\3\2"+
"\3\2\3\2\3\2\3\2\3\2\3\2\5\2\f\n\2\3\2\3\2\3\2\3\2\3\2\3\2\7\2\24\n\2"+
"\f\2\16\2\27\13\2\3\2\2\3\2\3\2\2\4\3\2\3\4\3\2\5\6\33\2\13\3\2\2\2\4"+
"\5\b\2\1\2\5\6\7\7\2\2\6\7\5\2\2\2\7\b\7\b\2\2\b\f\3\2\2\2\t\f\7\n\2\2"+
"\n\f\7\t\2\2\13\4\3\2\2\2\13\t\3\2\2\2\13\n\3\2\2\2\f\25\3\2\2\2\r\16"+
"\f\6\2\2\16\17\t\2\2\2\17\24\5\2\2\7\20\21\f\5\2\2\21\22\t\3\2\2\22\24"+
"\5\2\2\6\23\r\3\2\2\2\23\20\3\2\2\2\24\27\3\2\2\2\25\23\3\2\2\2\25\26"+
"\3\2\2\2\26\3\3\2\2\2\27\25\3\2\2\2\5\13\23\25";
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);
}
}
}