// =========================================================================== // This file has been generated by // Rats! Parser Generator, version 2.3.1, // (C) 2004-2012 Robert Grimm, // on Tuesday, February 3, 2015 at 9:57:03 AM. // Edit at your own risk. // =========================================================================== import java.io.Reader; import java.io.IOException; import xtc.util.Pair; import xtc.parser.ParserBase; import xtc.parser.Column; import xtc.parser.Result; import xtc.parser.SemanticValue; import xtc.parser.ParseError; /** * Packrat parser for grammar <code>Simple</code>. * * <p />This class has been generated by the <i>Rats!</i> parser * generator, version 2.3.1, (C) 2004-2012 Robert Grimm. */ public final class SimpleParser extends ParserBase { // ========================================================================= /** Memoization table column. */ static final class SimpleParserColumn extends Column { Result frest; Result fterm; } // ========================================================================= /** * Create a new packrat parser. * * @param reader The reader. * @param file The file name. */ public SimpleParser(final Reader reader, final String file) { super(reader, file); } /** * Create a new packrat parser. * * @param reader The file reader. * @param file The file name. * @param size The file size. */ public SimpleParser(final Reader reader, final String file, final int size) { super(reader, file, size); } // ========================================================================= protected Column newColumn() { return new SimpleParserColumn(); } // ========================================================================= /** * Parse nonterminal Simple.program. * * @param yyStart The index. * @return The result. * @throws IOException Signals an I/O error. */ public Result pprogram(final int yyStart) throws IOException { Result yyResult; String yyValue; ParseError yyError = ParseError.DUMMY; // Alternative 1. yyResult = pexpr(yyStart); yyError = yyResult.select(yyError); if (yyResult.hasValue()) { String e = yyResult.semanticValue(); yyResult = pEOF(yyResult.index); yyError = yyResult.select(yyError); if (yyResult.hasValue()) { yyValue=e; return yyResult.createValue(yyValue, yyError); } } // Done. return yyError; } // ========================================================================= /** * Parse nonterminal Simple.expr. * * @param yyStart The index. * @return The result. * @throws IOException Signals an I/O error. */ private Result pexpr(final int yyStart) throws IOException { Result yyResult; String yyValue; ParseError yyError = ParseError.DUMMY; // Alternative 1. yyResult = pterm(yyStart); yyError = yyResult.select(yyError); if (yyResult.hasValue()) { String t = yyResult.semanticValue(); yyResult = prest(yyResult.index); yyError = yyResult.select(yyError); if (yyResult.hasValue()) { String r = yyResult.semanticValue(); yyValue=t+r; return yyResult.createValue(yyValue, yyError); } } // Done. return yyError; } // ========================================================================= /** * Parse nonterminal Simple.rest. * * @param yyStart The index. * @return The result. * @throws IOException Signals an I/O error. */ private Result prest(final int yyStart) throws IOException { SimpleParserColumn yyColumn = (SimpleParserColumn)column(yyStart); if (null == yyColumn.frest) yyColumn.frest = prest$1(yyStart); return yyColumn.frest; } /** Actually parse Simple.rest. */ private Result prest$1(final int yyStart) throws IOException { Result yyResult; String yyValue; ParseError yyError = ParseError.DUMMY; // Alternative 1. yyResult = pPLUS(yyStart); yyError = yyResult.select(yyError); if (yyResult.hasValue()) { yyResult = pterm(yyResult.index); yyError = yyResult.select(yyError); if (yyResult.hasValue()) { String t = yyResult.semanticValue(); yyResult = prest(yyResult.index); yyError = yyResult.select(yyError); if (yyResult.hasValue()) { String r = yyResult.semanticValue(); yyValue=t+"+"+r; return yyResult.createValue(yyValue, yyError); } } } // Alternative 2. yyResult = pMINUS(yyStart); yyError = yyResult.select(yyError); if (yyResult.hasValue()) { yyResult = pterm(yyResult.index); yyError = yyResult.select(yyError); if (yyResult.hasValue()) { String t = yyResult.semanticValue(); yyResult = prest(yyResult.index); yyError = yyResult.select(yyError); if (yyResult.hasValue()) { String r = yyResult.semanticValue(); yyValue=t+"-"+r; return yyResult.createValue(yyValue, yyError); } } } // Alternative 3. yyValue=""; return new SemanticValue(yyValue, yyStart, yyError); } // ========================================================================= /** * Parse nonterminal Simple.term. * * @param yyStart The index. * @return The result. * @throws IOException Signals an I/O error. */ private Result pterm(final int yyStart) throws IOException { SimpleParserColumn yyColumn = (SimpleParserColumn)column(yyStart); if (null == yyColumn.fterm) yyColumn.fterm = pterm$1(yyStart); return yyColumn.fterm; } /** Actually parse Simple.term. */ private Result pterm$1(final int yyStart) throws IOException { int yyC; int yyIndex; String yyValue; ParseError yyError = ParseError.DUMMY; // Alternative 1. yyC = character(yyStart); if (-1 != yyC) { yyIndex = yyStart + 1; switch (yyC) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': { yyValue = difference(yyStart, yyIndex); return new SemanticValue(yyValue, yyIndex, yyError); } default: /* No match. */ } } // Done. yyError = yyError.select("term expected", yyStart); return yyError; } // ========================================================================= /** * Parse nonterminal Simple.PLUS. * * @param yyStart The index. * @return The result. * @throws IOException Signals an I/O error. */ private Result pPLUS(final int yyStart) throws IOException { int yyC; int yyIndex; Void yyValue; ParseError yyError = ParseError.DUMMY; // Alternative 1. yyC = character(yyStart); if ('+' == yyC) { yyIndex = yyStart + 1; yyValue = null; return new SemanticValue(yyValue, yyIndex, yyError); } // Done. yyError = yyError.select("PLUS expected", yyStart); return yyError; } // ========================================================================= /** * Parse nonterminal Simple.MINUS. * * @param yyStart The index. * @return The result. * @throws IOException Signals an I/O error. */ private Result pMINUS(final int yyStart) throws IOException { int yyC; int yyIndex; Void yyValue; ParseError yyError = ParseError.DUMMY; // Alternative 1. yyC = character(yyStart); if ('-' == yyC) { yyIndex = yyStart + 1; yyValue = null; return new SemanticValue(yyValue, yyIndex, yyError); } // Done. yyError = yyError.select("MINUS expected", yyStart); return yyError; } // ========================================================================= /** * Parse nonterminal Simple.EOF. * * @param yyStart The index. * @return The result. * @throws IOException Signals an I/O error. */ private Result pEOF(final int yyStart) throws IOException { int yyC; boolean yyPredMatched; Void yyValue; ParseError yyError = ParseError.DUMMY; // Alternative 1. yyPredMatched = false; yyC = character(yyStart); if (-1 != yyC) { yyPredMatched = true; } if (! yyPredMatched) { yyValue = null; return new SemanticValue(yyValue, yyStart, yyError); } else { yyError = yyError.select("EOF expected", yyStart); } // Done. return yyError; } }