001: /*
002: * GrammarParser.java
003: *
004: * THIS FILE HAS BEEN GENERATED AUTOMATICALLY. DO NOT EDIT!
005: *
006: * This work is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU General Public License as published
008: * by the Free Software Foundation; either version 2 of the License,
009: * or (at your option) any later version.
010: *
011: * This work is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * As a special exception, the copyright holders of this library give
022: * you permission to link this library with independent modules to
023: * produce an executable, regardless of the license terms of these
024: * independent modules, and to copy and distribute the resulting
025: * executable under terms of your choice, provided that you also meet,
026: * for each linked independent module, the terms and conditions of the
027: * license of that module. An independent module is a module which is
028: * not derived from or based on this library. If you modify this
029: * library, you may extend this exception to your version of the
030: * library, but you are not obligated to do so. If you do not wish to
031: * do so, delete this exception statement from your version.
032: *
033: * Copyright (c) 2003 Per Cederberg. All rights reserved.
034: */
035:
036: package net.percederberg.grammatica;
037:
038: import java.io.Reader;
039:
040: import net.percederberg.grammatica.parser.Analyzer;
041: import net.percederberg.grammatica.parser.ParserCreationException;
042: import net.percederberg.grammatica.parser.ProductionPattern;
043: import net.percederberg.grammatica.parser.ProductionPatternAlternative;
044: import net.percederberg.grammatica.parser.RecursiveDescentParser;
045:
046: /**
047: * A token stream parser.
048: *
049: * @author Per Cederberg, <per at percederberg dot net>
050: * @version 1.2
051: */
052: class GrammarParser extends RecursiveDescentParser {
053:
054: /**
055: * A generated production node identity constant.
056: */
057: private static final int SUBPRODUCTION_1 = 3001;
058:
059: /**
060: * A generated production node identity constant.
061: */
062: private static final int SUBPRODUCTION_2 = 3002;
063:
064: /**
065: * A generated production node identity constant.
066: */
067: private static final int SUBPRODUCTION_3 = 3003;
068:
069: /**
070: * A generated production node identity constant.
071: */
072: private static final int SUBPRODUCTION_4 = 3004;
073:
074: /**
075: * Creates a new parser.
076: *
077: * @param in the input stream to read from
078: *
079: * @throws ParserCreationException if the parser couldn't be
080: * initialized correctly
081: */
082: public GrammarParser(Reader in) throws ParserCreationException {
083: super (new GrammarTokenizer(in));
084: createPatterns();
085: }
086:
087: /**
088: * Creates a new parser.
089: *
090: * @param in the input stream to read from
091: * @param analyzer the analyzer to use while parsing
092: *
093: * @throws ParserCreationException if the parser couldn't be
094: * initialized correctly
095: */
096: public GrammarParser(Reader in, Analyzer analyzer)
097: throws ParserCreationException {
098:
099: super (new GrammarTokenizer(in), analyzer);
100: createPatterns();
101: }
102:
103: /**
104: * Initializes the parser by creating all the production patterns.
105: *
106: * @throws ParserCreationException if the parser couldn't be
107: * initialized correctly
108: */
109: private void createPatterns() throws ParserCreationException {
110: ProductionPattern pattern;
111: ProductionPatternAlternative alt;
112:
113: pattern = new ProductionPattern(GrammarConstants.GRAMMAR,
114: "Grammar");
115: alt = new ProductionPatternAlternative();
116: alt.addProduction(GrammarConstants.HEADER_PART, 0, 1);
117: alt.addProduction(GrammarConstants.TOKEN_PART, 1, 1);
118: alt.addProduction(GrammarConstants.PRODUCTION_PART, 0, 1);
119: pattern.addAlternative(alt);
120: addPattern(pattern);
121:
122: pattern = new ProductionPattern(GrammarConstants.HEADER_PART,
123: "HeaderPart");
124: alt = new ProductionPatternAlternative();
125: alt.addToken(GrammarConstants.HEADER, 1, 1);
126: alt.addProduction(GrammarConstants.HEADER_DECLARATION, 0, -1);
127: pattern.addAlternative(alt);
128: addPattern(pattern);
129:
130: pattern = new ProductionPattern(
131: GrammarConstants.HEADER_DECLARATION,
132: "HeaderDeclaration");
133: alt = new ProductionPatternAlternative();
134: alt.addToken(GrammarConstants.IDENTIFIER, 1, 1);
135: alt.addToken(GrammarConstants.EQUALS, 1, 1);
136: alt.addToken(GrammarConstants.QUOTED_STRING, 1, 1);
137: pattern.addAlternative(alt);
138: addPattern(pattern);
139:
140: pattern = new ProductionPattern(GrammarConstants.TOKEN_PART,
141: "TokenPart");
142: alt = new ProductionPatternAlternative();
143: alt.addToken(GrammarConstants.TOKENS, 1, 1);
144: alt.addProduction(GrammarConstants.TOKEN_DECLARATION, 0, -1);
145: pattern.addAlternative(alt);
146: addPattern(pattern);
147:
148: pattern = new ProductionPattern(
149: GrammarConstants.TOKEN_DECLARATION, "TokenDeclaration");
150: alt = new ProductionPatternAlternative();
151: alt.addToken(GrammarConstants.IDENTIFIER, 1, 1);
152: alt.addToken(GrammarConstants.EQUALS, 1, 1);
153: alt.addProduction(GrammarConstants.TOKEN_VALUE, 1, 1);
154: alt.addProduction(GrammarConstants.TOKEN_HANDLING, 0, 1);
155: pattern.addAlternative(alt);
156: addPattern(pattern);
157:
158: pattern = new ProductionPattern(GrammarConstants.TOKEN_VALUE,
159: "TokenValue");
160: alt = new ProductionPatternAlternative();
161: alt.addToken(GrammarConstants.QUOTED_STRING, 1, 1);
162: pattern.addAlternative(alt);
163: alt = new ProductionPatternAlternative();
164: alt.addToken(GrammarConstants.REGEXP, 1, 1);
165: pattern.addAlternative(alt);
166: addPattern(pattern);
167:
168: pattern = new ProductionPattern(
169: GrammarConstants.TOKEN_HANDLING, "TokenHandling");
170: alt = new ProductionPatternAlternative();
171: alt.addToken(GrammarConstants.IGNORE, 1, 1);
172: pattern.addAlternative(alt);
173: alt = new ProductionPatternAlternative();
174: alt.addToken(GrammarConstants.ERROR, 1, 1);
175: pattern.addAlternative(alt);
176: addPattern(pattern);
177:
178: pattern = new ProductionPattern(
179: GrammarConstants.PRODUCTION_PART, "ProductionPart");
180: alt = new ProductionPatternAlternative();
181: alt.addToken(GrammarConstants.PRODUCTIONS, 1, 1);
182: alt.addProduction(GrammarConstants.PRODUCTION_DECLARATION, 0,
183: -1);
184: pattern.addAlternative(alt);
185: addPattern(pattern);
186:
187: pattern = new ProductionPattern(
188: GrammarConstants.PRODUCTION_DECLARATION,
189: "ProductionDeclaration");
190: alt = new ProductionPatternAlternative();
191: alt.addToken(GrammarConstants.IDENTIFIER, 1, 1);
192: alt.addToken(GrammarConstants.EQUALS, 1, 1);
193: alt.addProduction(GrammarConstants.PRODUCTION, 1, 1);
194: alt.addToken(GrammarConstants.SEMICOLON, 1, 1);
195: pattern.addAlternative(alt);
196: addPattern(pattern);
197:
198: pattern = new ProductionPattern(GrammarConstants.PRODUCTION,
199: "Production");
200: alt = new ProductionPatternAlternative();
201: alt.addProduction(GrammarConstants.PRODUCTION_ATOM, 1, -1);
202: alt.addProduction(SUBPRODUCTION_1, 0, 1);
203: pattern.addAlternative(alt);
204: addPattern(pattern);
205:
206: pattern = new ProductionPattern(
207: GrammarConstants.PRODUCTION_ATOM, "ProductionAtom");
208: alt = new ProductionPatternAlternative();
209: alt.addToken(GrammarConstants.IDENTIFIER, 1, 1);
210: alt.addProduction(SUBPRODUCTION_2, 0, 1);
211: pattern.addAlternative(alt);
212: alt = new ProductionPatternAlternative();
213: alt.addToken(GrammarConstants.QUOTED_STRING, 1, 1);
214: alt.addProduction(SUBPRODUCTION_3, 0, 1);
215: pattern.addAlternative(alt);
216: alt = new ProductionPatternAlternative();
217: alt.addToken(GrammarConstants.LEFT_PAREN, 1, 1);
218: alt.addProduction(GrammarConstants.PRODUCTION, 1, 1);
219: alt.addToken(GrammarConstants.RIGHT_PAREN, 1, 1);
220: alt.addProduction(SUBPRODUCTION_4, 0, 1);
221: pattern.addAlternative(alt);
222: alt = new ProductionPatternAlternative();
223: alt.addToken(GrammarConstants.LEFT_BRACE, 1, 1);
224: alt.addProduction(GrammarConstants.PRODUCTION, 1, 1);
225: alt.addToken(GrammarConstants.RIGHT_BRACE, 1, 1);
226: pattern.addAlternative(alt);
227: alt = new ProductionPatternAlternative();
228: alt.addToken(GrammarConstants.LEFT_BRACKET, 1, 1);
229: alt.addProduction(GrammarConstants.PRODUCTION, 1, 1);
230: alt.addToken(GrammarConstants.RIGHT_BRACKET, 1, 1);
231: pattern.addAlternative(alt);
232: addPattern(pattern);
233:
234: pattern = new ProductionPattern(SUBPRODUCTION_1,
235: "Subproduction1");
236: pattern.setSyntetic(true);
237: alt = new ProductionPatternAlternative();
238: alt.addToken(GrammarConstants.VERTICAL_BAR, 1, 1);
239: alt.addProduction(GrammarConstants.PRODUCTION, 1, 1);
240: pattern.addAlternative(alt);
241: addPattern(pattern);
242:
243: pattern = new ProductionPattern(SUBPRODUCTION_2,
244: "Subproduction2");
245: pattern.setSyntetic(true);
246: alt = new ProductionPatternAlternative();
247: alt.addToken(GrammarConstants.QUESTION_MARK, 1, 1);
248: pattern.addAlternative(alt);
249: alt = new ProductionPatternAlternative();
250: alt.addToken(GrammarConstants.ASTERISK, 1, 1);
251: pattern.addAlternative(alt);
252: alt = new ProductionPatternAlternative();
253: alt.addToken(GrammarConstants.PLUS_SIGN, 1, 1);
254: pattern.addAlternative(alt);
255: addPattern(pattern);
256:
257: pattern = new ProductionPattern(SUBPRODUCTION_3,
258: "Subproduction3");
259: pattern.setSyntetic(true);
260: alt = new ProductionPatternAlternative();
261: alt.addToken(GrammarConstants.QUESTION_MARK, 1, 1);
262: pattern.addAlternative(alt);
263: alt = new ProductionPatternAlternative();
264: alt.addToken(GrammarConstants.ASTERISK, 1, 1);
265: pattern.addAlternative(alt);
266: alt = new ProductionPatternAlternative();
267: alt.addToken(GrammarConstants.PLUS_SIGN, 1, 1);
268: pattern.addAlternative(alt);
269: addPattern(pattern);
270:
271: pattern = new ProductionPattern(SUBPRODUCTION_4,
272: "Subproduction4");
273: pattern.setSyntetic(true);
274: alt = new ProductionPatternAlternative();
275: alt.addToken(GrammarConstants.QUESTION_MARK, 1, 1);
276: pattern.addAlternative(alt);
277: alt = new ProductionPatternAlternative();
278: alt.addToken(GrammarConstants.ASTERISK, 1, 1);
279: pattern.addAlternative(alt);
280: alt = new ProductionPatternAlternative();
281: alt.addToken(GrammarConstants.PLUS_SIGN, 1, 1);
282: pattern.addAlternative(alt);
283: addPattern(pattern);
284: }
285: }
|