001// $ANTLR 2.7.5 (20050128): "../src/csheets/ext/assertion/AssertionParser.g" -> "AssertionParser.java"$
002package csheets.ext.assertion;
003import antlr.TokenBuffer;
004import antlr.TokenStreamException;
005import antlr.TokenStreamIOException;
006import antlr.ANTLRException;
007import antlr.LLkParser;
008import antlr.Token;
009import antlr.TokenStream;
010import antlr.RecognitionException;
011import antlr.NoViableAltException;
012import antlr.MismatchedTokenException;
013import antlr.SemanticException;
014import antlr.ParserSharedInputState;
015import antlr.collections.impl.BitSet;
016import java.util.List;
017public class AssertionParser extends antlr.LLkParser       implements AssertionParserTokenTypes
018 {
019
020
021protected AssertionParser(TokenBuffer tokenBuf, int k) {
022  super(tokenBuf,k);
023  tokenNames = _tokenNames;
024}
025
026public AssertionParser(TokenBuffer tokenBuf) {
027  this(tokenBuf,1);
028}
029
030protected AssertionParser(TokenStream lexer, int k) {
031  super(lexer,k);
032  tokenNames = _tokenNames;
033}
034
035public AssertionParser(TokenStream lexer) {
036  this(lexer,1);
037}
038
039public AssertionParser(ParserSharedInputState state) {
040  super(state,1);
041  tokenNames = _tokenNames;
042}
043
044        public final void assertion(
045                USAssertion ass, List<Interval> orIntervals, List<Interval> exceptIntervals
046        ) throws RecognitionException, TokenStreamException, AssertionException {
047                
048                
049                                ass.isInteger = false;
050                        
051                
052                {
053                switch ( LA(1)) {
054                case LBRACK:
055                case RBRACK:
056                case NUMBER:
057                case GT:
058                case LT:
059                case GTEQ:
060                case LTEQ:
061                {
062                        or_expr(orIntervals);
063                        break;
064                }
065                case EOF:
066                case EXCEPT:
067                case INTEGER:
068                {
069                        break;
070                }
071                default:
072                {
073                        throw new NoViableAltException(LT(1), getFilename());
074                }
075                }
076                }
077                {
078                switch ( LA(1)) {
079                case EXCEPT:
080                {
081                        except_clause(exceptIntervals);
082                        break;
083                }
084                case EOF:
085                case INTEGER:
086                {
087                        break;
088                }
089                default:
090                {
091                        throw new NoViableAltException(LT(1), getFilename());
092                }
093                }
094                }
095                {
096                switch ( LA(1)) {
097                case INTEGER:
098                {
099                        is_integer(ass);
100                        break;
101                }
102                case EOF:
103                {
104                        break;
105                }
106                default:
107                {
108                        throw new NoViableAltException(LT(1), getFilename());
109                }
110                }
111                }
112                match(Token.EOF_TYPE);
113        }
114        
115        public final void or_expr(
116                List<Interval> lst
117        ) throws RecognitionException, TokenStreamException, AssertionException {
118                
119                
120                term(lst);
121                {
122                _loop10:
123                do {
124                        if ((LA(1)==OR)) {
125                                match(OR);
126                                term(lst);
127                        }
128                        else {
129                                break _loop10;
130                        }
131                        
132                } while (true);
133                }
134        }
135        
136        public final void except_clause(
137                List<Interval> lst
138        ) throws RecognitionException, TokenStreamException, AssertionException {
139                
140                
141                match(EXCEPT);
142                term(lst);
143                {
144                _loop7:
145                do {
146                        if ((LA(1)==COMMA)) {
147                                match(COMMA);
148                                term(lst);
149                        }
150                        else {
151                                break _loop7;
152                        }
153                        
154                } while (true);
155                }
156        }
157        
158        public final void is_integer(
159                USAssertion ass
160        ) throws RecognitionException, TokenStreamException {
161                
162                
163                match(INTEGER);
164                
165                                ass.isInteger = true;
166                        
167        }
168        
169        public final void term(
170                List<Interval> lst
171        ) throws RecognitionException, TokenStreamException, AssertionException {
172                
173                
174                                double c; 
175                        
176                
177                switch ( LA(1)) {
178                case LBRACK:
179                case RBRACK:
180                {
181                        interval(lst);
182                        break;
183                }
184                case NUMBER:
185                {
186                        c=constant();
187                        
188                                                try {
189                                                        lst.add(new Interval(c));
190                                                } catch (IllegalArgumentException iae) {
191                                                        // This should never happen since c should be a good value.
192                                                        throw new AssertionException("Invalid constant specified in assertion");
193                                                }
194                                        
195                        break;
196                }
197                case GT:
198                case LT:
199                case GTEQ:
200                case LTEQ:
201                {
202                        os_interval(lst);
203                        break;
204                }
205                default:
206                {
207                        throw new NoViableAltException(LT(1), getFilename());
208                }
209                }
210        }
211        
212        public final void interval(
213                List<Interval> lst
214        ) throws RecognitionException, TokenStreamException, AssertionException {
215                
216                Token  ltok = null;
217                Token  rtok = null;
218                
219                                double lower = 0.0, upper = 0.0;
220                                boolean lclosed = false, rclosed = false;
221                        
222                
223                {
224                switch ( LA(1)) {
225                case LBRACK:
226                {
227                        ltok = LT(1);
228                        match(LBRACK);
229                        lclosed = true;
230                        break;
231                }
232                case RBRACK:
233                {
234                        rtok = LT(1);
235                        match(RBRACK);
236                        break;
237                }
238                default:
239                {
240                        throw new NoViableAltException(LT(1), getFilename());
241                }
242                }
243                }
244                lower=constant();
245                match(TO);
246                upper=constant();
247                {
248                switch ( LA(1)) {
249                case LBRACK:
250                {
251                        match(LBRACK);
252                        break;
253                }
254                case RBRACK:
255                {
256                        match(RBRACK);
257                        rclosed=true;
258                        break;
259                }
260                default:
261                {
262                        throw new NoViableAltException(LT(1), getFilename());
263                }
264                }
265                }
266                
267                                        Token tok;
268                                        if (lclosed)
269                                                tok = ltok;
270                                        else    
271                                                tok = rtok;
272                                        try {
273                                                lst.add(new Interval(lower, upper, lclosed, rclosed));
274                                        }
275                                        catch (IllegalArgumentException iae) {
276                                                
277                                                throw new AssertionException(tok.getLine(), tok.getColumn(), iae.getMessage());
278                                        }
279                                                
280                                
281        }
282        
283        public final double  constant() throws RecognitionException, TokenStreamException {
284                double value;
285                
286                Token  r = null;
287                
288                                value = 0;
289                        
290                
291                r = LT(1);
292                match(NUMBER);
293                
294                                        value = Double.parseDouble(r.getText());
295                                
296                return value;
297        }
298        
299        public final void os_interval(
300                List<Interval> lst
301        ) throws RecognitionException, TokenStreamException, AssertionException {
302                
303                Token  gttok = null;
304                Token  lttok = null;
305                Token  gteqtok = null;
306                Token  lteqtok = null;
307                
308                                double c = 0.0;
309                                boolean eq = false, gt = true;
310                        
311                
312                {
313                switch ( LA(1)) {
314                case GT:
315                {
316                        gttok = LT(1);
317                        match(GT);
318                        break;
319                }
320                case LT:
321                {
322                        lttok = LT(1);
323                        match(LT);
324                        gt = false;
325                        break;
326                }
327                case GTEQ:
328                {
329                        gteqtok = LT(1);
330                        match(GTEQ);
331                        eq = true;
332                        break;
333                }
334                case LTEQ:
335                {
336                        lteqtok = LT(1);
337                        match(LTEQ);
338                        eq=true;gt=false;
339                        break;
340                }
341                default:
342                {
343                        throw new NoViableAltException(LT(1), getFilename());
344                }
345                }
346                }
347                c=constant();
348                
349                                Token tok = (gt ? (eq ? gteqtok : gttok) : (eq ? lteqtok : lttok));
350                                try {
351                                        if (gt) {
352                                                lst.add(new Interval(c, Double.POSITIVE_INFINITY, eq, false));
353                                        } else {
354                                                lst.add(new Interval(Double.NEGATIVE_INFINITY, c, false, eq));
355                                        }
356                                } catch (IllegalArgumentException iae) {
357                                        throw new AssertionException(tok.getLine(), tok.getColumn(), iae.toString());
358                                }
359                        
360        }
361        
362        
363        public static final String[] _tokenNames = {
364                "<0>",
365                "EOF",
366                "<2>",
367                "NULL_TREE_LOOKAHEAD",
368                "EXCEPT",
369                "','",
370                "OR",
371                "'['",
372                "']'",
373                "TO",
374                "a numeric constant",
375                "'>'",
376                "'<'",
377                "'>='",
378                "'<='",
379                "INTEGER",
380                "end of line",
381                "whitespace",
382                "DIGIT",
383                "'+'",
384                "'-'",
385                "EXPONENT"
386        };
387        
388        
389        }