KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > percederberg > grammatica > test > RegexpParser


1 /*
2  * RegexpParser.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 Per Cederberg. All rights reserved.
22  */

23
24 package net.percederberg.grammatica.test;
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.0
39  */

40 class RegexpParser 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      * Creates a new parser.
54      *
55      * @param in the input stream to read from
56      *
57      * @throws ParserCreationException if the parser couldn't be
58      * initialized correctly
59      */

60     public RegexpParser(Reader JavaDoc in) throws ParserCreationException {
61         super(new RegexpTokenizer(in));
62         createPatterns();
63     }
64
65     /**
66      * Creates a new parser.
67      *
68      * @param in the input stream to read from
69      * @param analyzer the analyzer to use while parsing
70      *
71      * @throws ParserCreationException if the parser couldn't be
72      * initialized correctly
73      */

74     public RegexpParser(Reader JavaDoc in, Analyzer analyzer)
75         throws ParserCreationException {
76
77         super(new RegexpTokenizer(in), analyzer);
78         createPatterns();
79     }
80
81     /**
82      * Initializes the parser by creating all the production patterns.
83      *
84      * @throws ParserCreationException if the parser couldn't be
85      * initialized correctly
86      */

87     private void createPatterns() throws ParserCreationException {
88         ProductionPattern pattern;
89         ProductionPatternAlternative alt;
90
91         pattern = new ProductionPattern(RegexpConstants.EXPR,
92                                         "Expr");
93         alt = new ProductionPatternAlternative();
94         alt.addProduction(RegexpConstants.TERM, 1, 1);
95         alt.addProduction(SUBPRODUCTION_1, 0, 1);
96         pattern.addAlternative(alt);
97         addPattern(pattern);
98
99         pattern = new ProductionPattern(RegexpConstants.TERM,
100                                         "Term");
101         alt = new ProductionPatternAlternative();
102         alt.addProduction(RegexpConstants.FACT, 1, -1);
103         pattern.addAlternative(alt);
104         addPattern(pattern);
105
106         pattern = new ProductionPattern(RegexpConstants.FACT,
107                                         "Fact");
108         alt = new ProductionPatternAlternative();
109         alt.addProduction(RegexpConstants.ATOM, 1, 1);
110         alt.addProduction(RegexpConstants.ATOM_MODIFIER, 0, 1);
111         pattern.addAlternative(alt);
112         addPattern(pattern);
113
114         pattern = new ProductionPattern(RegexpConstants.ATOM,
115                                         "Atom");
116         alt = new ProductionPatternAlternative();
117         alt.addToken(RegexpConstants.CHAR, 1, 1);
118         pattern.addAlternative(alt);
119         alt = new ProductionPatternAlternative();
120         alt.addToken(RegexpConstants.NUMBER, 1, 1);
121         pattern.addAlternative(alt);
122         alt = new ProductionPatternAlternative();
123         alt.addToken(RegexpConstants.COMMA, 1, 1);
124         pattern.addAlternative(alt);
125         alt = new ProductionPatternAlternative();
126         alt.addToken(RegexpConstants.DOT, 1, 1);
127         pattern.addAlternative(alt);
128         alt = new ProductionPatternAlternative();
129         alt.addToken(RegexpConstants.LEFT_PAREN, 1, 1);
130         alt.addProduction(RegexpConstants.EXPR, 1, 1);
131         alt.addToken(RegexpConstants.RIGHT_PAREN, 1, 1);
132         pattern.addAlternative(alt);
133         alt = new ProductionPatternAlternative();
134         alt.addToken(RegexpConstants.LEFT_BRACKET, 1, 1);
135         alt.addProduction(RegexpConstants.CHARACTER_SET, 1, 1);
136         alt.addToken(RegexpConstants.RIGHT_BRACKET, 1, 1);
137         pattern.addAlternative(alt);
138         addPattern(pattern);
139
140         pattern = new ProductionPattern(RegexpConstants.ATOM_MODIFIER,
141                                         "AtomModifier");
142         alt = new ProductionPatternAlternative();
143         alt.addToken(RegexpConstants.QUESTION, 1, 1);
144         alt.addToken(RegexpConstants.QUESTION, 0, 1);
145         pattern.addAlternative(alt);
146         alt = new ProductionPatternAlternative();
147         alt.addToken(RegexpConstants.ASTERISK, 1, 1);
148         alt.addToken(RegexpConstants.QUESTION, 0, 1);
149         pattern.addAlternative(alt);
150         alt = new ProductionPatternAlternative();
151         alt.addToken(RegexpConstants.PLUS, 1, 1);
152         alt.addToken(RegexpConstants.QUESTION, 0, 1);
153         pattern.addAlternative(alt);
154         alt = new ProductionPatternAlternative();
155         alt.addToken(RegexpConstants.LEFT_BRACE, 1, 1);
156         alt.addToken(RegexpConstants.NUMBER, 1, 1);
157         alt.addProduction(SUBPRODUCTION_2, 0, 1);
158         alt.addToken(RegexpConstants.RIGHT_BRACE, 1, 1);
159         alt.addToken(RegexpConstants.QUESTION, 0, 1);
160         pattern.addAlternative(alt);
161         addPattern(pattern);
162
163         pattern = new ProductionPattern(RegexpConstants.CHARACTER_SET,
164                                         "CharacterSet");
165         alt = new ProductionPatternAlternative();
166         alt.addProduction(RegexpConstants.CHARACTER, 1, -1);
167         pattern.addAlternative(alt);
168         addPattern(pattern);
169
170         pattern = new ProductionPattern(RegexpConstants.CHARACTER,
171                                         "Character");
172         alt = new ProductionPatternAlternative();
173         alt.addToken(RegexpConstants.CHAR, 1, 1);
174         pattern.addAlternative(alt);
175         alt = new ProductionPatternAlternative();
176         alt.addToken(RegexpConstants.NUMBER, 1, 1);
177         pattern.addAlternative(alt);
178         alt = new ProductionPatternAlternative();
179         alt.addToken(RegexpConstants.COMMA, 1, 1);
180         pattern.addAlternative(alt);
181         alt = new ProductionPatternAlternative();
182         alt.addToken(RegexpConstants.DOT, 1, 1);
183         pattern.addAlternative(alt);
184         alt = new ProductionPatternAlternative();
185         alt.addToken(RegexpConstants.VERTICAL_BAR, 1, 1);
186         pattern.addAlternative(alt);
187         alt = new ProductionPatternAlternative();
188         alt.addToken(RegexpConstants.PLUS, 1, 1);
189         pattern.addAlternative(alt);
190         alt = new ProductionPatternAlternative();
191         alt.addToken(RegexpConstants.ASTERISK, 1, 1);
192         pattern.addAlternative(alt);
193         alt = new ProductionPatternAlternative();
194         alt.addToken(RegexpConstants.QUESTION, 1, 1);
195         pattern.addAlternative(alt);
196         alt = new ProductionPatternAlternative();
197         alt.addToken(RegexpConstants.LEFT_BRACE, 1, 1);
198         pattern.addAlternative(alt);
199         alt = new ProductionPatternAlternative();
200         alt.addToken(RegexpConstants.RIGHT_BRACE, 1, 1);
201         pattern.addAlternative(alt);
202         alt = new ProductionPatternAlternative();
203         alt.addToken(RegexpConstants.LEFT_PAREN, 1, 1);
204         pattern.addAlternative(alt);
205         alt = new ProductionPatternAlternative();
206         alt.addToken(RegexpConstants.RIGHT_PAREN, 1, 1);
207         pattern.addAlternative(alt);
208         alt = new ProductionPatternAlternative();
209         alt.addToken(RegexpConstants.LEFT_BRACKET, 1, 1);
210         pattern.addAlternative(alt);
211         addPattern(pattern);
212
213         pattern = new ProductionPattern(SUBPRODUCTION_1,
214                                         "Subproduction1");
215         pattern.setSynthetic(true);
216         alt = new ProductionPatternAlternative();
217         alt.addToken(RegexpConstants.VERTICAL_BAR, 1, 1);
218         alt.addProduction(RegexpConstants.EXPR, 1, 1);
219         pattern.addAlternative(alt);
220         addPattern(pattern);
221
222         pattern = new ProductionPattern(SUBPRODUCTION_2,
223                                         "Subproduction2");
224         pattern.setSynthetic(true);
225         alt = new ProductionPatternAlternative();
226         alt.addToken(RegexpConstants.COMMA, 1, 1);
227         alt.addToken(RegexpConstants.NUMBER, 0, 1);
228         pattern.addAlternative(alt);
229         addPattern(pattern);
230     }
231 }
232
Popular Tags