it.tidalwave.image.codegenerator.grammar.TIFFParser Maven / Gradle / Ivy
The newest version!
// Generated from it/tidalwave/image/codegenerator/grammar/TIFF.g4 by ANTLR 4.3
package it.tidalwave.image.codegenerator.grammar;
import java.util.Optional;
import it.tidalwave.image.codegenerator.TIFFRecord;
import it.tidalwave.image.codegenerator.TIFFEnumValueName;
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 TIFFParser extends Parser {
static { RuntimeMetaData.checkVersion("4.3", RuntimeMetaData.VERSION); }
protected static final DFA[] _decisionToDFA;
protected static final PredictionContextCache _sharedContextCache =
new PredictionContextCache();
public static final int
COMMA=1, ENUM=2, EQUALS=3, HEX=4, WS=5, COMMENT=6, INT=7, NEWLINE=8, TYPE=9,
CHARS=10;
public static final String[] tokenNames = {
"", "','", "'enum:'", "'='", "HEX", "WS", "COMMENT", "INT", "'\n'",
"TYPE", "CHARS"
};
public static final int
RULE_prog = 0, RULE_stat = 1, RULE_expr = 2, RULE_enumSet = 3, RULE_enumV = 4,
RULE_name = 5;
public static final String[] ruleNames = {
"prog", "stat", "expr", "enumSet", "enumV", "name"
};
@Override
public String getGrammarFileName() { return "TIFF.g4"; }
@Override
public String[] getTokenNames() { return tokenNames; }
@Override
public String[] getRuleNames() { return ruleNames; }
@Override
public String getSerializedATN() { return _serializedATN; }
@Override
public ATN getATN() { return _ATN; }
public TIFFParser(TokenStream input) {
super(input);
_interp = new ParserATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache);
}
public static class ProgContext extends ParserRuleContext {
public List result;
public StatContext stat;
public StatContext stat(int i) {
return getRuleContext(StatContext.class,i);
}
public List stat() {
return getRuleContexts(StatContext.class);
}
public ProgContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_prog; }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof TIFFListener ) ((TIFFListener)listener).enterProg(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof TIFFListener ) ((TIFFListener)listener).exitProg(this);
}
}
public final ProgContext prog() throws RecognitionException {
ProgContext _localctx = new ProgContext(_ctx, getState());
enterRule(_localctx, 0, RULE_prog);
int _la;
try {
enterOuterAlt(_localctx, 1);
{
((ProgContext)_localctx).result = new ArrayList();
setState(16);
_errHandler.sync(this);
_la = _input.LA(1);
do {
{
{
setState(13); ((ProgContext)_localctx).stat = stat();
if (((ProgContext)_localctx).stat.result != null) _localctx.result.add(((ProgContext)_localctx).stat.result);
}
}
setState(18);
_errHandler.sync(this);
_la = _input.LA(1);
} while ( _la==INT || _la==NEWLINE );
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
public static class StatContext extends ParserRuleContext {
public TIFFRecord result;
public ExprContext tiffRecord;
public ExprContext expr;
public ExprContext expr() {
return getRuleContext(ExprContext.class,0);
}
public TerminalNode NEWLINE() { return getToken(TIFFParser.NEWLINE, 0); }
public StatContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_stat; }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof TIFFListener ) ((TIFFListener)listener).enterStat(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof TIFFListener ) ((TIFFListener)listener).exitStat(this);
}
}
public final StatContext stat() throws RecognitionException {
StatContext _localctx = new StatContext(_ctx, getState());
enterRule(_localctx, 2, RULE_stat);
try {
setState(25);
switch (_input.LA(1)) {
case INT:
enterOuterAlt(_localctx, 1);
{
setState(20); ((StatContext)_localctx).tiffRecord = ((StatContext)_localctx).expr = expr();
setState(21); match(NEWLINE);
((StatContext)_localctx).result = ((StatContext)_localctx).expr.result;
}
break;
case NEWLINE:
enterOuterAlt(_localctx, 2);
{
setState(24); match(NEWLINE);
}
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 ExprContext extends ParserRuleContext {
public TIFFRecord result;
public Token id;
public NameContext name;
public Token type;
public EnumSetContext enums;
public TerminalNode TYPE() { return getToken(TIFFParser.TYPE, 0); }
public EnumSetContext enumSet() {
return getRuleContext(EnumSetContext.class,0);
}
public NameContext name() {
return getRuleContext(NameContext.class,0);
}
public TerminalNode INT() { return getToken(TIFFParser.INT, 0); }
public ExprContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_expr; }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof TIFFListener ) ((TIFFListener)listener).enterExpr(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof TIFFListener ) ((TIFFListener)listener).exitExpr(this);
}
}
public final ExprContext expr() throws RecognitionException {
ExprContext _localctx = new ExprContext(_ctx, getState());
enterRule(_localctx, 4, RULE_expr);
int _la;
try {
enterOuterAlt(_localctx, 1);
{
setState(27); ((ExprContext)_localctx).id = match(INT);
setState(28); ((ExprContext)_localctx).name = name();
setState(29); ((ExprContext)_localctx).type = match(TYPE);
setState(31);
_la = _input.LA(1);
if (_la==ENUM) {
{
setState(30); ((ExprContext)_localctx).enums = enumSet();
}
}
((ExprContext)_localctx).result = new TIFFRecord((((ExprContext)_localctx).id!=null?((ExprContext)_localctx).id.getText():null), (((ExprContext)_localctx).name!=null?_input.getText(((ExprContext)_localctx).name.start,((ExprContext)_localctx).name.stop):null), (((ExprContext)_localctx).type!=null?((ExprContext)_localctx).type.getText():null),
((ExprContext)_localctx).enums != null ? ((ExprContext)_localctx).enums.result : new ArrayList()); // FIXME
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
public static class EnumSetContext extends ParserRuleContext {
public List result;
public EnumVContext enumv1;
public EnumVContext enumvX;
public List enumV() {
return getRuleContexts(EnumVContext.class);
}
public TerminalNode ENUM() { return getToken(TIFFParser.ENUM, 0); }
public List COMMA() { return getTokens(TIFFParser.COMMA); }
public EnumVContext enumV(int i) {
return getRuleContext(EnumVContext.class,i);
}
public TerminalNode COMMA(int i) {
return getToken(TIFFParser.COMMA, i);
}
public EnumSetContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_enumSet; }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof TIFFListener ) ((TIFFListener)listener).enterEnumSet(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof TIFFListener ) ((TIFFListener)listener).exitEnumSet(this);
}
}
public final EnumSetContext enumSet() throws RecognitionException {
EnumSetContext _localctx = new EnumSetContext(_ctx, getState());
enterRule(_localctx, 6, RULE_enumSet);
int _la;
try {
enterOuterAlt(_localctx, 1);
{
((EnumSetContext)_localctx).result = new ArrayList();
setState(36); match(ENUM);
setState(37); ((EnumSetContext)_localctx).enumv1 = enumV();
_localctx.result.add(((EnumSetContext)_localctx).enumv1.result);
setState(45);
_errHandler.sync(this);
_la = _input.LA(1);
while (_la==COMMA) {
{
{
setState(39); match(COMMA);
setState(40); ((EnumSetContext)_localctx).enumvX = enumV();
_localctx.result.add(((EnumSetContext)_localctx).enumvX.result);
}
}
setState(47);
_errHandler.sync(this);
_la = _input.LA(1);
}
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
public static class EnumVContext extends ParserRuleContext {
public TIFFEnumValueName result;
public Token id;
public NameContext name;
public TerminalNode EQUALS() { return getToken(TIFFParser.EQUALS, 0); }
public TerminalNode HEX() { return getToken(TIFFParser.HEX, 0); }
public NameContext name() {
return getRuleContext(NameContext.class,0);
}
public TerminalNode INT() { return getToken(TIFFParser.INT, 0); }
public EnumVContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_enumV; }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof TIFFListener ) ((TIFFListener)listener).enterEnumV(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof TIFFListener ) ((TIFFListener)listener).exitEnumV(this);
}
}
public final EnumVContext enumV() throws RecognitionException {
EnumVContext _localctx = new EnumVContext(_ctx, getState());
enterRule(_localctx, 8, RULE_enumV);
int _la;
try {
enterOuterAlt(_localctx, 1);
{
setState(48);
((EnumVContext)_localctx).id = _input.LT(1);
_la = _input.LA(1);
if ( !(_la==HEX || _la==INT) ) {
((EnumVContext)_localctx).id = (Token)_errHandler.recoverInline(this);
}
consume();
setState(49); match(EQUALS);
setState(50); ((EnumVContext)_localctx).name = name();
((EnumVContext)_localctx).result = new TIFFEnumValueName((((EnumVContext)_localctx).id!=null?((EnumVContext)_localctx).id.getText():null), (((EnumVContext)_localctx).name!=null?_input.getText(((EnumVContext)_localctx).name.start,((EnumVContext)_localctx).name.stop):null));
}
}
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 INT(int i) {
return getToken(TIFFParser.INT, i);
}
public List CHARS() { return getTokens(TIFFParser.CHARS); }
public TerminalNode CHARS(int i) {
return getToken(TIFFParser.CHARS, i);
}
public List INT() { return getTokens(TIFFParser.INT); }
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 TIFFListener ) ((TIFFListener)listener).enterName(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof TIFFListener ) ((TIFFListener)listener).exitName(this);
}
}
public final NameContext name() throws RecognitionException {
NameContext _localctx = new NameContext(_ctx, getState());
enterRule(_localctx, 10, RULE_name);
int _la;
try {
enterOuterAlt(_localctx, 1);
{
setState(53); match(CHARS);
setState(57);
_errHandler.sync(this);
_la = _input.LA(1);
while (_la==INT || _la==CHARS) {
{
{
setState(54);
_la = _input.LA(1);
if ( !(_la==INT || _la==CHARS) ) {
_errHandler.recoverInline(this);
}
consume();
}
}
setState(59);
_errHandler.sync(this);
_la = _input.LA(1);
}
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
public static final String _serializedATN =
"\3\u0430\ud6d1\u8206\uad2d\u4417\uaef1\u8d80\uaadd\3\f?\4\2\t\2\4\3\t"+
"\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7\t\7\3\2\3\2\3\2\3\2\6\2\23\n\2\r\2\16\2"+
"\24\3\3\3\3\3\3\3\3\3\3\5\3\34\n\3\3\4\3\4\3\4\3\4\5\4\"\n\4\3\4\3\4\3"+
"\5\3\5\3\5\3\5\3\5\3\5\3\5\3\5\7\5.\n\5\f\5\16\5\61\13\5\3\6\3\6\3\6\3"+
"\6\3\6\3\7\3\7\7\7:\n\7\f\7\16\7=\13\7\3\7\2\2\b\2\4\6\b\n\f\2\4\4\2\6"+
"\6\t\t\4\2\t\t\f\f=\2\16\3\2\2\2\4\33\3\2\2\2\6\35\3\2\2\2\b%\3\2\2\2"+
"\n\62\3\2\2\2\f\67\3\2\2\2\16\22\b\2\1\2\17\20\5\4\3\2\20\21\b\2\1\2\21"+
"\23\3\2\2\2\22\17\3\2\2\2\23\24\3\2\2\2\24\22\3\2\2\2\24\25\3\2\2\2\25"+
"\3\3\2\2\2\26\27\5\6\4\2\27\30\7\n\2\2\30\31\b\3\1\2\31\34\3\2\2\2\32"+
"\34\7\n\2\2\33\26\3\2\2\2\33\32\3\2\2\2\34\5\3\2\2\2\35\36\7\t\2\2\36"+
"\37\5\f\7\2\37!\7\13\2\2 \"\5\b\5\2! \3\2\2\2!\"\3\2\2\2\"#\3\2\2\2#$"+
"\b\4\1\2$\7\3\2\2\2%&\b\5\1\2&\'\7\4\2\2\'(\5\n\6\2(/\b\5\1\2)*\7\3\2"+
"\2*+\5\n\6\2+,\b\5\1\2,.\3\2\2\2-)\3\2\2\2.\61\3\2\2\2/-\3\2\2\2/\60\3"+
"\2\2\2\60\t\3\2\2\2\61/\3\2\2\2\62\63\t\2\2\2\63\64\7\5\2\2\64\65\5\f"+
"\7\2\65\66\b\6\1\2\66\13\3\2\2\2\67;\7\f\2\28:\t\3\2\298\3\2\2\2:=\3\2"+
"\2\2;9\3\2\2\2;<\3\2\2\2<\r\3\2\2\2=;\3\2\2\2\7\24\33!/;";
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);
}
}
}