View Javadoc
1   /**
2    * Copyright 2010 The Kuali Foundation Licensed under the
3    * Educational Community License, Version 2.0 (the "License"); you may
4    * not use this file except in compliance with the License. You may
5    * obtain a copy of the License at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing,
10   * software distributed under the License is distributed on an "AS IS"
11   * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12   * or implied. See the License for the specific language governing
13   * permissions and limitations under the License.
14   */
15  
16  // $ANTLR 3.1.1 BooleanFunction.g 2009-06-03 01:05:39
17   package org.kuali.student.common.messagebuilder.booleanmessage.ast.parsers;
18  
19  import java.util.List;
20  
21  import org.antlr.runtime.BitSet;
22  import org.antlr.runtime.NoViableAltException;
23  import org.antlr.runtime.Parser;
24  import org.antlr.runtime.ParserRuleReturnScope;
25  import org.antlr.runtime.RecognitionException;
26  import org.antlr.runtime.RecognizerSharedState;
27  import org.antlr.runtime.Token;
28  import org.antlr.runtime.TokenStream;
29  import org.antlr.runtime.tree.CommonTreeAdaptor;
30  import org.antlr.runtime.tree.TreeAdaptor;
31  
32  public class BooleanFunctionParser extends Parser {
33      public static final String[] tokenNames = new String[] {
34          "<invalid>", "<EOR>", "<DOWN>", "<UP>", "OR", "AND", "LP", "RP", "ALPHA", "UPPERCASE", "NUMBER", "WHITESPACE", "LOWERCASE"
35      };
36      public static final int UPPERCASE=9;
37      public static final int LOWERCASE=12;
38      public static final int RP=7;
39      public static final int OR=4;
40      public static final int NUMBER=10;
41      public static final int LP=6;
42      public static final int WHITESPACE=11;
43      public static final int AND=5;
44      public static final int EOF=-1;
45      public static final int ALPHA=8;
46  
47      // delegates
48      // delegators
49  
50  
51          public BooleanFunctionParser(TokenStream input) {
52              this(input, new RecognizerSharedState());
53          }
54          public BooleanFunctionParser(TokenStream input, RecognizerSharedState state) {
55              super(input, state);
56  
57          }
58  
59      protected TreeAdaptor adaptor = new CommonTreeAdaptor();
60  
61      public void setTreeAdaptor(TreeAdaptor adaptor) {
62          this.adaptor = adaptor;
63      }
64      public TreeAdaptor getTreeAdaptor() {
65          return adaptor;
66      }
67  
68      public String[] getTokenNames() { return BooleanFunctionParser.tokenNames; }
69      public String getGrammarFileName() { return "BooleanFunction.g"; }
70  
71  
72      @Override
73      public String getErrorMessage(RecognitionException e, String[] tokenNames) {
74          List<?> stack = getRuleInvocationStack(e, this.getClass().getName());
75          String msg = null;
76          if ( e instanceof NoViableAltException ) {
77             NoViableAltException nvae = (NoViableAltException)e;
78             msg = " No viable alternatives; token=" + e.token
79                + " (decision=" + nvae.decisionNumber
80                + " state " + nvae.stateNumber+")"
81                + " decision=<<" + nvae.grammarDecisionDescription + ">>";
82          }
83          else {
84             msg = super.getErrorMessage(e, tokenNames);
85          }
86          return stack + " " + msg;
87      }
88  
89      @Override
90      public String getTokenErrorDisplay(Token t) {
91          return t.toString();
92      }
93  
94      private boolean isTokenParenthesis(String paren){
95          if (paren != null) {
96              if ( paren.equals("(") || paren.equals(")") )
97                  return true;
98          }
99          return false;
100     }
101 
102 
103     public static class booleanExpression_return extends ParserRuleReturnScope {
104         Object tree;
105         public Object getTree() { return tree; }
106     };
107 
108     // $ANTLR start "booleanExpression"
109     // BooleanFunction.g:60:1: booleanExpression : orTerm ;
110     public final BooleanFunctionParser.booleanExpression_return booleanExpression() throws RecognitionException {
111         BooleanFunctionParser.booleanExpression_return retval = new BooleanFunctionParser.booleanExpression_return();
112         retval.start = input.LT(1);
113 
114         Object root_0 = null;
115 
116         BooleanFunctionParser.orTerm_return orTerm1 = null;
117 
118 
119 
120         try {
121             // BooleanFunction.g:60:18: ( orTerm )
122             // BooleanFunction.g:60:22: orTerm
123             {
124             root_0 = (Object)adaptor.nil();
125 
126             pushFollow(FOLLOW_orTerm_in_booleanExpression111);
127             orTerm1=orTerm();
128 
129             state._fsp--;
130 
131             adaptor.addChild(root_0, orTerm1.getTree());
132             if ( isTokenParenthesis(input.LT(1).getText()) ) throw new RecognitionException();
133 
134             }
135 
136             retval.stop = input.LT(-1);
137 
138             retval.tree = (Object)adaptor.rulePostProcessing(root_0);
139             adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);
140 
141         }
142 
143         catch (RecognitionException e) {
144             throw e;
145         }
146         finally {
147             root_0 = null;
148             orTerm1 = null;
149         }
150         return retval;
151     }
152     // $ANTLR end "booleanExpression"
153 
154     public static class orTerm_return extends ParserRuleReturnScope {
155         Object tree;
156         public Object getTree() { return tree; }
157     };
158 
159     // $ANTLR start "orTerm"
160     // BooleanFunction.g:61:1: orTerm : andTerm ( OR andTerm )* ;
161     public final BooleanFunctionParser.orTerm_return orTerm() throws RecognitionException {
162         BooleanFunctionParser.orTerm_return retval = new BooleanFunctionParser.orTerm_return();
163         retval.start = input.LT(1);
164 
165         Object root_0 = null;
166 
167         Token OR3=null;
168         BooleanFunctionParser.andTerm_return andTerm2 = null;
169 
170         BooleanFunctionParser.andTerm_return andTerm4 = null;
171 
172 
173         Object OR3_tree=null;
174 
175         try {
176             // BooleanFunction.g:61:9: ( andTerm ( OR andTerm )* )
177             // BooleanFunction.g:61:13: andTerm ( OR andTerm )*
178             {
179             root_0 = (Object)adaptor.nil();
180 
181             pushFollow(FOLLOW_andTerm_in_orTerm123);
182             andTerm2=andTerm();
183 
184             state._fsp--;
185 
186             adaptor.addChild(root_0, andTerm2.getTree());
187             // BooleanFunction.g:61:21: ( OR andTerm )*
188             loop1:
189             do {
190                 int alt1=2;
191                 int LA1_0 = input.LA(1);
192 
193                 if ( (LA1_0==OR) ) {
194                     alt1=1;
195                 }
196 
197 
198                 switch (alt1) {
199             	case 1 :
200             	    // BooleanFunction.g:61:22: OR andTerm
201             	    {
202             	    OR3=(Token)match(input,OR,FOLLOW_OR_in_orTerm126);
203             	    OR3_tree = (Object)adaptor.create(OR3);
204             	    root_0 = (Object)adaptor.becomeRoot(OR3_tree, root_0);
205 
206             	    pushFollow(FOLLOW_andTerm_in_orTerm129);
207             	    andTerm4=andTerm();
208 
209             	    state._fsp--;
210 
211             	    adaptor.addChild(root_0, andTerm4.getTree());
212 
213             	    }
214             	    break;
215 
216             	default :
217             	    break loop1;
218                 }
219             } while (true);
220 
221 
222             }
223 
224             retval.stop = input.LT(-1);
225 
226             retval.tree = (Object)adaptor.rulePostProcessing(root_0);
227             adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);
228 
229         }
230 
231         catch (RecognitionException e) {
232             throw e;
233         }
234         finally {
235             root_0 = null;
236             OR3 = null;
237             andTerm2 = null;
238             andTerm4 = null;
239             OR3_tree = null;
240         }
241         return retval;
242     }
243     // $ANTLR end "orTerm"
244 
245     public static class andTerm_return extends ParserRuleReturnScope {
246         Object tree;
247         public Object getTree() { return tree; }
248     };
249 
250     // $ANTLR start "andTerm"
251     // BooleanFunction.g:62:1: andTerm : atom ( AND atom )* ;
252     public final BooleanFunctionParser.andTerm_return andTerm() throws RecognitionException {
253         BooleanFunctionParser.andTerm_return retval = new BooleanFunctionParser.andTerm_return();
254         retval.start = input.LT(1);
255 
256         Object root_0 = null;
257 
258         Token AND6=null;
259         BooleanFunctionParser.atom_return atom5 = null;
260 
261         BooleanFunctionParser.atom_return atom7 = null;
262 
263 
264         Object AND6_tree=null;
265 
266         try {
267             // BooleanFunction.g:62:9: ( atom ( AND atom )* )
268             // BooleanFunction.g:62:13: atom ( AND atom )*
269             {
270             root_0 = (Object)adaptor.nil();
271 
272             pushFollow(FOLLOW_atom_in_andTerm140);
273             atom5=atom();
274 
275             state._fsp--;
276 
277             adaptor.addChild(root_0, atom5.getTree());
278             // BooleanFunction.g:62:18: ( AND atom )*
279             loop2:
280             do {
281                 int alt2=2;
282                 int LA2_0 = input.LA(1);
283 
284                 if ( (LA2_0==AND) ) {
285                     alt2=1;
286                 }
287 
288 
289                 switch (alt2) {
290             	case 1 :
291             	    // BooleanFunction.g:62:19: AND atom
292             	    {
293             	    AND6=(Token)match(input,AND,FOLLOW_AND_in_andTerm143);
294             	    AND6_tree = (Object)adaptor.create(AND6);
295             	    root_0 = (Object)adaptor.becomeRoot(AND6_tree, root_0);
296 
297             	    pushFollow(FOLLOW_atom_in_andTerm146);
298             	    atom7=atom();
299 
300             	    state._fsp--;
301 
302             	    adaptor.addChild(root_0, atom7.getTree());
303 
304             	    }
305             	    break;
306 
307             	default :
308             	    break loop2;
309                 }
310             } while (true);
311 
312 
313             }
314 
315             retval.stop = input.LT(-1);
316 
317             retval.tree = (Object)adaptor.rulePostProcessing(root_0);
318             adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);
319 
320         }
321 
322         catch (RecognitionException e) {
323             throw e;
324         }
325         finally {
326             root_0 = null;
327             AND6 = null;
328             atom5 = null;
329             atom7 = null;
330             AND6_tree = null;
331         }
332         return retval;
333     }
334     // $ANTLR end "andTerm"
335 
336     public static class atom_return extends ParserRuleReturnScope {
337         Object tree;
338         public Object getTree() { return tree; }
339     };
340 
341     // $ANTLR start "atom"
342     // BooleanFunction.g:63:1: atom : ( ALPHA | ( LP orTerm RP ) );
343     public final BooleanFunctionParser.atom_return atom() throws RecognitionException {
344         BooleanFunctionParser.atom_return retval = new BooleanFunctionParser.atom_return();
345         retval.start = input.LT(1);
346 
347         Object root_0 = null;
348 
349         Token ALPHA8=null;
350         Token LP9=null;
351         Token RP11=null;
352         BooleanFunctionParser.orTerm_return orTerm10 = null;
353 
354 
355         Object ALPHA8_tree=null;
356         Object LP9_tree=null;
357         Object RP11_tree=null;
358 
359         try {
360             // BooleanFunction.g:63:9: ( ALPHA | ( LP orTerm RP ) )
361             int alt3=2;
362             int LA3_0 = input.LA(1);
363 
364             if ( (LA3_0==ALPHA) ) {
365                 alt3=1;
366             }
367             else if ( (LA3_0==LP) ) {
368                 alt3=2;
369             }
370             else {
371                 NoViableAltException nvae =
372                     new NoViableAltException("", 3, 0, input);
373 
374                 throw nvae;
375             }
376             switch (alt3) {
377                 case 1 :
378                     // BooleanFunction.g:63:13: ALPHA
379                     {
380                     root_0 = (Object)adaptor.nil();
381 
382                     ALPHA8=(Token)match(input,ALPHA,FOLLOW_ALPHA_in_atom160);
383                     ALPHA8_tree = (Object)adaptor.create(ALPHA8);
384                     adaptor.addChild(root_0, ALPHA8_tree);
385 
386 
387                     }
388                     break;
389                 case 2 :
390                     // BooleanFunction.g:63:21: ( LP orTerm RP )
391                     {
392                     root_0 = (Object)adaptor.nil();
393 
394                     // BooleanFunction.g:63:21: ( LP orTerm RP )
395                     // BooleanFunction.g:63:22: LP orTerm RP
396                     {
397                     LP9=(Token)match(input,LP,FOLLOW_LP_in_atom165);
398                     pushFollow(FOLLOW_orTerm_in_atom168);
399                     orTerm10=orTerm();
400 
401                     state._fsp--;
402 
403                     adaptor.addChild(root_0, orTerm10.getTree());
404                     RP11=(Token)match(input,RP,FOLLOW_RP_in_atom170);
405 
406                     }
407 
408 
409                     }
410                     break;
411 
412             }
413             retval.stop = input.LT(-1);
414 
415             retval.tree = (Object)adaptor.rulePostProcessing(root_0);
416             adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);
417 
418         }
419 
420         catch (RecognitionException e) {
421             throw e;
422         }
423         finally {
424             root_0 = null;
425             ALPHA8=null;
426             LP9=null;
427             RP11=null;
428             orTerm10 = null;
429             ALPHA8_tree=null;
430             LP9_tree=null;
431             RP11_tree=null;
432         }
433         return retval;
434     }
435     // $ANTLR end "atom"
436 
437     // Delegated rules
438 
439 
440 
441 
442     public static final BitSet FOLLOW_orTerm_in_booleanExpression111 = new BitSet(new long[]{0x0000000000000002L});
443     public static final BitSet FOLLOW_andTerm_in_orTerm123 = new BitSet(new long[]{0x0000000000000012L});
444     public static final BitSet FOLLOW_OR_in_orTerm126 = new BitSet(new long[]{0x0000000000000140L});
445     public static final BitSet FOLLOW_andTerm_in_orTerm129 = new BitSet(new long[]{0x0000000000000012L});
446     public static final BitSet FOLLOW_atom_in_andTerm140 = new BitSet(new long[]{0x0000000000000022L});
447     public static final BitSet FOLLOW_AND_in_andTerm143 = new BitSet(new long[]{0x0000000000000140L});
448     public static final BitSet FOLLOW_atom_in_andTerm146 = new BitSet(new long[]{0x0000000000000022L});
449     public static final BitSet FOLLOW_ALPHA_in_atom160 = new BitSet(new long[]{0x0000000000000002L});
450     public static final BitSet FOLLOW_LP_in_atom165 = new BitSet(new long[]{0x0000000000000140L});
451     public static final BitSet FOLLOW_orTerm_in_atom168 = new BitSet(new long[]{0x0000000000000080L});
452     public static final BitSet FOLLOW_RP_in_atom170 = new BitSet(new long[]{0x0000000000000002L});
453 
454 }