KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > percederberg > grammatica > GrammarParser


1 /*
2  * GrammarParser.java
3  *
4  * THIS FILE HAS BEEN GENERATED AUTOMATICALLY. DO NOT EDIT!
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public License
8  * as published by the Free Software Foundation; either version 2.1
9  * of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free
18  * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
19  * MA 02111-1307, USA.
20  *
21  * Copyright (c) 2003-2005 Per Cederberg. All rights reserved.
22  */

23
24 package net.percederberg.grammatica;
25
26 import java.io.Reader JavaDoc;
27
28 import net.percederberg.grammatica.parser.Analyzer;
29 import net.percederberg.grammatica.parser.ParserCreationException;
30 import net.percederberg.grammatica.parser.ProductionPattern;
31 import net.percederberg.grammatica.parser.ProductionPatternAlternative;
32 import net.percederberg.grammatica.parser.RecursiveDescentParser;
33
34 /**
35  * A token stream parser.
36  *
37  * @author Per Cederberg, <per at percederberg dot net>
38  * @version 1.5
39  */

40 class GrammarParser extends RecursiveDescentParser {
41
42     /**
43      * A generated production node identity constant.
44      */

45     private static final int SUBPRODUCTION_1 = 3001;
46
47     /**
48      * A generated production node identity constant.
49      */

50     private static final int SUBPRODUCTION_2 = 3002;
51
52     /**
53      * A generated production node identity constant.
54      */

55     private static final int SUBPRODUCTION_3 = 3003;
56
57     /**
58      * A generated production node identity constant.
59      */

60     private static final int SUBPRODUCTION_4 = 3004;
61
62     /**
63      * Creates a new parser.
64      *
65      * @param in the input stream to read from
66      *
67      * @throws ParserCreationException if the parser couldn't be
68      * initialized correctly
69      */

70     public GrammarParser(Reader JavaDoc in) throws ParserCreationException {
71         super(new GrammarTokenizer(in));
72         createPatterns();
73     }
74
75     /**
76      * Creates a new parser.
77      *
78      * @param in the input stream to read from
79      * @param analyzer the analyzer to use while parsing
80      *
81      * @throws ParserCreationException if the parser couldn't be
82      * initialized correctly
83      */

84     public GrammarParser(Reader JavaDoc in, Analyzer analyzer)
85         throws ParserCreationException {
86
87         super(new GrammarTokenizer(in), analyzer);
88         createPatterns();
89     }
90
91     /**
92      * Initializes the parser by creating all the production patterns.
93      *
94      * @throws ParserCreationException if the parser couldn't be
95      * initialized correctly
96      */

97     private void createPatterns() throws ParserCreationException {
98         ProductionPattern pattern;
99         ProductionPatternAlternative alt;
100
101         pattern = new ProductionPattern(GrammarConstants.GRAMMAR,
102                                         "Grammar");
103         alt = new ProductionPatternAlternative();
104         alt.addProduction(GrammarConstants.HEADER_PART, 0, 1);
105         alt.addProduction(GrammarConstants.TOKEN_PART, 1, 1);
106         alt.addProduction(GrammarConstants.PRODUCTION_PART, 0, 1);
107         pattern.addAlternative(alt);
108         addPattern(pattern);
109
110         pattern = new ProductionPattern(GrammarConstants.HEADER_PART,
111                                         "HeaderPart");
112         alt = new ProductionPatternAlternative();
113         alt.addToken(GrammarConstants.HEADER, 1, 1);
114         alt.addProduction(GrammarConstants.HEADER_DECLARATION, 0, -1);
115         pattern.addAlternative(alt);
116         addPattern(pattern);
117
118         pattern = new ProductionPattern(GrammarConstants.HEADER_DECLARATION,
119                                         "HeaderDeclaration");
120         alt = new ProductionPatternAlternative();
121         alt.addToken(GrammarConstants.IDENTIFIER, 1, 1);
122         alt.addToken(GrammarConstants.EQUALS, 1, 1);
123         alt.addToken(GrammarConstants.QUOTED_STRING, 1, 1);
124         pattern.addAlternative(alt);
125         addPattern(pattern);
126
127         pattern = new ProductionPattern(GrammarConstants.TOKEN_PART,
128                                         "TokenPart");
129         alt = new ProductionPatternAlternative();
130         alt.addToken(GrammarConstants.TOKENS, 1, 1);
131         alt.addProduction(GrammarConstants.TOKEN_DECLARATION, 0, -1);
132         pattern.addAlternative(alt);
133         addPattern(pattern);
134
135         pattern = new ProductionPattern(GrammarConstants.TOKEN_DECLARATION,
136                                         "TokenDeclaration");
137         alt = new ProductionPatternAlternative();
138         alt.addToken(GrammarConstants.IDENTIFIER, 1, 1);
139         alt.addToken(GrammarConstants.EQUALS, 1, 1);
140         alt.addProduction(GrammarConstants.TOKEN_VALUE, 1, 1);
141         alt.addProduction(GrammarConstants.TOKEN_HANDLING, 0, 1);
142         pattern.addAlternative(alt);
143         addPattern(pattern);
144
145         pattern = new ProductionPattern(GrammarConstants.TOKEN_VALUE,
146                                         "TokenValue");
147         alt = new ProductionPatternAlternative();
148         alt.addToken(GrammarConstants.QUOTED_STRING, 1, 1);
149         pattern.addAlternative(alt);
150         alt = new ProductionPatternAlternative();
151         alt.addToken(GrammarConstants.REGEXP, 1, 1);
152         pattern.addAlternative(alt);
153         addPattern(pattern);
154
155         pattern = new ProductionPattern(GrammarConstants.TOKEN_HANDLING,
156                                         "TokenHandling");
157         alt = new ProductionPatternAlternative();
158         alt.addToken(GrammarConstants.IGNORE, 1, 1);
159         pattern.addAlternative(alt);
160         alt = new ProductionPatternAlternative();
161         alt.addToken(GrammarConstants.ERROR, 1, 1);
162         pattern.addAlternative(alt);
163         addPattern(pattern);
164
165         pattern = new ProductionPattern(GrammarConstants.PRODUCTION_PART,
166                                         "ProductionPart");
167         alt = new ProductionPatternAlternative();
168         alt.addToken(GrammarConstants.PRODUCTIONS, 1, 1);
169         alt.addProduction(GrammarConstants.PRODUCTION_DECLARATION, 0, -1);
170         pattern.addAlternative(alt);
171         addPattern(pattern);
172
173         pattern = new ProductionPattern(GrammarConstants.PRODUCTION_DECLARATION,
174                                         "ProductionDeclaration");
175         alt = new ProductionPatternAlternative();
176         alt.addToken(GrammarConstants.IDENTIFIER, 1, 1);
177         alt.addToken(GrammarConstants.EQUALS, 1, 1);
178         alt.addProduction(GrammarConstants.PRODUCTION, 1, 1);
179         alt.addToken(GrammarConstants.SEMICOLON, 1, 1);
180         pattern.addAlternative(alt);
181         addPattern(pattern);
182
183         pattern = new ProductionPattern(GrammarConstants.PRODUCTION,
184                                         "Production");
185         alt = new ProductionPatternAlternative();
186         alt.addProduction(GrammarConstants.PRODUCTION_ATOM, 1, -1);
187         alt.addProduction(SUBPRODUCTION_1, 0, 1);
188         pattern.addAlternative(alt);
189         addPattern(pattern);
190
191         pattern = new ProductionPattern(GrammarConstants.PRODUCTION_ATOM,
192                                         "ProductionAtom");
193         alt = new ProductionPatternAlternative();
194         alt.addToken(GrammarConstants.IDENTIFIER, 1, 1);
195         alt.addProduction(SUBPRODUCTION_2, 0, 1);
196         pattern.addAlternative(alt);
197         alt = new ProductionPatternAlternative();
198         alt.addToken(GrammarConstants.QUOTED_STRING, 1, 1);
199         alt.addProduction(SUBPRODUCTION_3, 0, 1);
200         pattern.addAlternative(alt);
201         alt = new ProductionPatternAlternative();
202         alt.addToken(GrammarConstants.LEFT_PAREN, 1, 1);
203         alt.addProduction(GrammarConstants.PRODUCTION, 1, 1);
204         alt.addToken(GrammarConstants.RIGHT_PAREN, 1, 1);
205         alt.addProduction(SUBPRODUCTION_4, 0, 1);
206         pattern.addAlternative(alt);
207         alt = new ProductionPatternAlternative();
208         alt.addToken(GrammarConstants.LEFT_BRACE, 1, 1);
209         alt.addProduction(GrammarConstants.PRODUCTION, 1, 1);
210         alt.addToken(GrammarConstants.RIGHT_BRACE, 1, 1);
211         pattern.addAlternative(alt);
212         alt = new ProductionPatternAlternative();
213         alt.addToken(GrammarConstants.LEFT_BRACKET, 1, 1);
214         alt.addProduction(GrammarConstants.PRODUCTION, 1, 1);
215         alt.addToken(GrammarConstants.RIGHT_BRACKET, 1, 1);
216         pattern.addAlternative(alt);
217         addPattern(pattern);
218
219         pattern = new ProductionPattern(SUBPRODUCTION_1,
220                                         "Subproduction1");
221         pattern.setSynthetic(true);
222         alt = new ProductionPatternAlternative();
223         alt.addToken(GrammarConstants.VERTICAL_BAR, 1, 1);
224         alt.addProduction(GrammarConstants.PRODUCTION, 1, 1);
225         pattern.addAlternative(alt);
226         addPattern(pattern);
227
228         pattern = new ProductionPattern(SUBPRODUCTION_2,
229                                         "Subproduction2");
230         pattern.setSynthetic(true);
231         alt = new ProductionPatternAlternative();
232         alt.addToken(GrammarConstants.QUESTION_MARK, 1, 1);
233         pattern.addAlternative(alt);
234         alt = new ProductionPatternAlternative();
235         alt.addToken(GrammarConstants.ASTERISK, 1, 1);
236         pattern.addAlternative(alt);
237         alt = new ProductionPatternAlternative();
238         alt.addToken(GrammarConstants.PLUS_SIGN, 1, 1);
239         pattern.addAlternative(alt);
240         addPattern(pattern);
241
242         pattern = new ProductionPattern(SUBPRODUCTION_3,
243                                         "Subproduction3");
244         pattern.setSynthetic(true);
245         alt = new ProductionPatternAlternative();
246         alt.addToken(GrammarConstants.QUESTION_MARK, 1, 1);
247         pattern.addAlternative(alt);
248         alt = new ProductionPatternAlternative();
249         alt.addToken(GrammarConstants.ASTERISK, 1, 1);
250         pattern.addAlternative(alt);
251         alt = new ProductionPatternAlternative();
252         alt.addToken(GrammarConstants.PLUS_SIGN, 1, 1);
253         pattern.addAlternative(alt);
254         addPattern(pattern);
255
256         pattern = new ProductionPattern(SUBPRODUCTION_4,
257                                         "Subproduction4");
258         pattern.setSynthetic(true);
259         alt = new ProductionPatternAlternative();
260         alt.addToken(GrammarConstants.QUESTION_MARK, 1, 1);
261         pattern.addAlternative(alt);
262         alt = new ProductionPatternAlternative();
263         alt.addToken(GrammarConstants.ASTERISK, 1, 1);
264         pattern.addAlternative(alt);
265         alt = new ProductionPatternAlternative();
266         alt.addToken(GrammarConstants.PLUS_SIGN, 1, 1);
267         pattern.addAlternative(alt);
268         addPattern(pattern);
269     }
270 }
271
Popular Tags