1 /*@bgen(jjtree) Generated By:JJTree: Do not edit this line. ExprParser.jj */
9 PARSER_BEGIN(ExprParser)
10 import java.io.FileReader;
11 import java.io.Reader;
13 public class ExprParser/*@bgen(jjtree)*/implements ExprParserTreeConstants/*@egen*/ {/*@bgen(jjtree)*/
14 protected static JJTExprParserState jjtree = new JJTExprParserState();
18 public static void main(String[] args) throws Exception {
19 /* Check the command-line arguments. */
20 if (args.length < 1) {
21 throw new Exception("No source file specified on command-line.");
24 /* Open the input file to be processed. */
25 Reader input = new FileReader(args[0]);
27 /* Create an instance of the parser. */
28 ExprParser p = new ExprParser(input);
30 /* Perform the parse with 'infix' as the initial production. */
32 SimpleNode root = p.infix();
37 /* Let the PostfixVisitor run. */
38 PostfixVisitor pfv= new PostfixVisitor();
39 root.jjtAccept(pfv,null);
40 } catch (Exception e) {
41 e.printStackTrace(System.out);
45 PARSER_END(ExprParser)
53 <integer : ["1"-"9"](["0"-"9"])* >
62 SimpleNode infix() : {/*@bgen(jjtree) infix */
63 ASTinfix jjtn000 = new ASTinfix(JJTINFIX);
64 boolean jjtc000 = true;
65 jjtree.openNodeScope(jjtn000);
66 /*@egen*/} {/*@bgen(jjtree) infix */
69 expression()/*@bgen(jjtree)*/
71 jjtree.closeNodeScope(jjtn000, true);
75 {return jjtn000;}/*@bgen(jjtree)*/
76 } catch (Throwable jjte000) {
78 jjtree.clearNodeScope(jjtn000);
83 if (jjte000 instanceof RuntimeException) {
84 throw (RuntimeException)jjte000;
86 if (jjte000 instanceof ParseException) {
87 throw (ParseException)jjte000;
92 jjtree.closeNodeScope(jjtn000, true);
98 void expression() : {/*@bgen(jjtree) expression */
99 ASTexpression jjtn000 = new ASTexpression(JJTEXPRESSION);
100 boolean jjtc000 = true;
101 jjtree.openNodeScope(jjtn000);
102 /*@egen*/} {/*@bgen(jjtree) expression */
105 term() (expressionPrime())*/*@bgen(jjtree)*/
106 } catch (Throwable jjte000) {
108 jjtree.clearNodeScope(jjtn000);
113 if (jjte000 instanceof RuntimeException) {
114 throw (RuntimeException)jjte000;
116 if (jjte000 instanceof ParseException) {
117 throw (ParseException)jjte000;
119 throw (Error)jjte000;
122 jjtree.closeNodeScope(jjtn000, true);
128 void addop() : {/*@bgen(jjtree) addop */
129 ASTaddop jjtn000 = new ASTaddop(JJTADDOP);
130 boolean jjtc000 = true;
131 jjtree.openNodeScope(jjtn000);
132 /*@egen*/} {/*@bgen(jjtree) addop */
135 <plus>/*@bgen(jjtree)*/
137 jjtree.closeNodeScope(jjtn000, true);
140 /*@egen*/ {jjtn000.value = token;} | <minus>/*@bgen(jjtree)*/
142 jjtree.closeNodeScope(jjtn000, true);
145 /*@egen*/ {jjtn000.value = token;}/*@bgen(jjtree)*/
148 jjtree.closeNodeScope(jjtn000, true);
154 void expressionPrime() : {/*@bgen(jjtree) expressionPrime */
155 ASTexpressionPrime jjtn000 = new ASTexpressionPrime(JJTEXPRESSIONPRIME);
156 boolean jjtc000 = true;
157 jjtree.openNodeScope(jjtn000);
158 /*@egen*/} {/*@bgen(jjtree) expressionPrime */
161 addop() term()/*@bgen(jjtree)*/
162 } catch (Throwable jjte000) {
164 jjtree.clearNodeScope(jjtn000);
169 if (jjte000 instanceof RuntimeException) {
170 throw (RuntimeException)jjte000;
172 if (jjte000 instanceof ParseException) {
173 throw (ParseException)jjte000;
175 throw (Error)jjte000;
178 jjtree.closeNodeScope(jjtn000, true);
184 void term() : {/*@bgen(jjtree) term */
185 ASTterm jjtn000 = new ASTterm(JJTTERM);
186 boolean jjtc000 = true;
187 jjtree.openNodeScope(jjtn000);
188 /*@egen*/} {/*@bgen(jjtree) term */
191 factor() (termPrime())*/*@bgen(jjtree)*/
192 } catch (Throwable jjte000) {
194 jjtree.clearNodeScope(jjtn000);
199 if (jjte000 instanceof RuntimeException) {
200 throw (RuntimeException)jjte000;
202 if (jjte000 instanceof ParseException) {
203 throw (ParseException)jjte000;
205 throw (Error)jjte000;
208 jjtree.closeNodeScope(jjtn000, true);
214 void termPrime() : {/*@bgen(jjtree) termPrime */
215 ASTtermPrime jjtn000 = new ASTtermPrime(JJTTERMPRIME);
216 boolean jjtc000 = true;
217 jjtree.openNodeScope(jjtn000);
218 /*@egen*/} {/*@bgen(jjtree) termPrime */
221 multop() factor()/*@bgen(jjtree)*/
222 } catch (Throwable jjte000) {
224 jjtree.clearNodeScope(jjtn000);
229 if (jjte000 instanceof RuntimeException) {
230 throw (RuntimeException)jjte000;
232 if (jjte000 instanceof ParseException) {
233 throw (ParseException)jjte000;
235 throw (Error)jjte000;
238 jjtree.closeNodeScope(jjtn000, true);
244 void multop() : {/*@bgen(jjtree) multop */
245 ASTmultop jjtn000 = new ASTmultop(JJTMULTOP);
246 boolean jjtc000 = true;
247 jjtree.openNodeScope(jjtn000);
248 /*@egen*/} {/*@bgen(jjtree) multop */
251 <mult>/*@bgen(jjtree)*/
253 jjtree.closeNodeScope(jjtn000, true);
256 /*@egen*/ {jjtn000.value = token;} | <div>/*@bgen(jjtree)*/
258 jjtree.closeNodeScope(jjtn000, true);
261 /*@egen*/ {jjtn000.value = token;}/*@bgen(jjtree)*/
264 jjtree.closeNodeScope(jjtn000, true);
270 void factor() : {/*@bgen(jjtree) factor */
271 ASTfactor jjtn000 = new ASTfactor(JJTFACTOR);
272 boolean jjtc000 = true;
273 jjtree.openNodeScope(jjtn000);
274 /*@egen*/} {/*@bgen(jjtree) factor */
277 <left_paren> infix() <right_paren> | <integer>/*@bgen(jjtree)*/
279 jjtree.closeNodeScope(jjtn000, true);
283 {jjtn000.value = token;}/*@bgen(jjtree)*/
284 } catch (Throwable jjte000) {
286 jjtree.clearNodeScope(jjtn000);
291 if (jjte000 instanceof RuntimeException) {
292 throw (RuntimeException)jjte000;
294 if (jjte000 instanceof ParseException) {
295 throw (ParseException)jjte000;
297 throw (Error)jjte000;
300 jjtree.closeNodeScope(jjtn000, true);