~tapaal-contributor/tapaal/disappearing-tokens-1940098

« back to all changes in this revision

Viewing changes to src/dk/aau/cs/TCTL/Parsing/TAPAALQueryParser.java

  • Committer: Kenneth Yrke Jørgensen
  • Date: 2011-04-12 09:50:16 UTC
  • mfrom: (329.1.188 tapaal-1.5)
  • Revision ID: mail@yrke.dk-20110412095016-e4hqdgab5596ja09
Merged with branch addning support for new 1.5 features

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
 * Licensed Material - Property of Matthew Hawkins (hawkini@4email.net) 
28
28
 */
29
29
 
30
 
public class TAPAALQueryParser implements GPMessageConstants
31
 
{       
32
 
        
33
 
        public interface SymbolConstants 
34
 
        {
35
 
                   final int SYMBOL_EOF               =  0;  // (EOF)
36
 
                   final int SYMBOL_ERROR             =  1;  // (Error)
37
 
                   final int SYMBOL_WHITESPACE        =  2;  // (Whitespace)
38
 
                   final int SYMBOL_EXCLAM            =  3;  // '!'
39
 
                   final int SYMBOL_AMPAMP            =  4;  // '&&'
40
 
                   final int SYMBOL_LPARAN            =  5;  // '('
41
 
                   final int SYMBOL_RPARAN            =  6;  // ')'
42
 
                   final int SYMBOL_PIPEPIPE          =  7;  // '||'
43
 
                   final int SYMBOL_LT                =  8;  // '<'
44
 
                   final int SYMBOL_LTEQ              =  9;  // '<='
45
 
                   final int SYMBOL_EQ                = 10;  // '='
46
 
                   final int SYMBOL_EQEQ              = 11;  // '=='
47
 
                   final int SYMBOL_GT                = 12;  // '>'
48
 
                   final int SYMBOL_GTEQ              = 13;  // '>='
49
 
                   final int SYMBOL_ALBRACKETRBRACKET = 14;  // 'A[]'
50
 
                   final int SYMBOL_ALTGT             = 15;  // 'A<>'
51
 
                   final int SYMBOL_AF                = 16;  // AF
52
 
                   final int SYMBOL_AG                = 17;  // AG
53
 
                   final int SYMBOL_AND               = 18;  // and
54
 
                   final int SYMBOL_ELBRACKETRBRACKET = 19;  // 'E[]'
55
 
                   final int SYMBOL_ELTGT             = 20;  // 'E<>'
56
 
                   final int SYMBOL_EF                = 21;  // EF
57
 
                   final int SYMBOL_EG                = 22;  // EG
58
 
                   final int SYMBOL_IDENTIFIER        = 23;  // Identifier
59
 
                   final int SYMBOL_NOT               = 24;  // not
60
 
                   final int SYMBOL_NUM               = 25;  // Num
61
 
                   final int SYMBOL_OR                = 26;  // or
62
 
                   final int SYMBOL_ABSTRACTPROPERTY  = 27;  // <AbstractProperty>
63
 
                   final int SYMBOL_AND2              = 28;  // <And>
64
 
                   final int SYMBOL_ATOMICPROPOSITION = 29;  // <AtomicProposition>
65
 
                   final int SYMBOL_EXPR              = 30;  // <Expr>
66
 
                   final int SYMBOL_FACTOR            = 31;  // <Factor>
67
 
                   final int SYMBOL_NOT2              = 32;  // <Not>
68
 
                   final int SYMBOL_OR2               = 33;  // <Or>
69
 
                };
70
 
        
71
 
 
72
 
                public interface RuleConstants
73
 
                {
74
 
                   final int RULE_ABSTRACTPROPERTY_EF                   =  0;  // <AbstractProperty> ::= EF <Expr>
75
 
                   final int RULE_ABSTRACTPROPERTY_ELTGT                =  1;  // <AbstractProperty> ::= 'E<>' <Expr>
76
 
                   final int RULE_ABSTRACTPROPERTY_EG                   =  2;  // <AbstractProperty> ::= EG <Expr>
77
 
                   final int RULE_ABSTRACTPROPERTY_ELBRACKETRBRACKET    =  3;  // <AbstractProperty> ::= 'E[]' <Expr>
78
 
                   final int RULE_ABSTRACTPROPERTY_AF                   =  4;  // <AbstractProperty> ::= AF <Expr>
79
 
                   final int RULE_ABSTRACTPROPERTY_ALTGT                =  5;  // <AbstractProperty> ::= 'A<>' <Expr>
80
 
                   final int RULE_ABSTRACTPROPERTY_AG                   =  6;  // <AbstractProperty> ::= AG <Expr>
81
 
                   final int RULE_ABSTRACTPROPERTY_ALBRACKETRBRACKET    =  7;  // <AbstractProperty> ::= 'A[]' <Expr>
82
 
                   final int RULE_EXPR                                  =  8;  // <Expr> ::= <Or>
83
 
                   final int RULE_OR_OR                                 =  9;  // <Or> ::= <Or> or <And>
84
 
                   final int RULE_OR_PIPEPIPE                           = 10;  // <Or> ::= <Or> '||' <And>
85
 
                   final int RULE_OR                                    = 11;  // <Or> ::= <And>
86
 
                   final int RULE_AND_AND                               = 12;  // <And> ::= <And> and <Not>
87
 
                   final int RULE_AND_AMPAMP                            = 13;  // <And> ::= <And> '&&' <Not>
88
 
                   final int RULE_AND                                   = 14;  // <And> ::= <Not>
89
 
                   final int RULE_NOT_NOT_LPARAN_RPARAN                 = 15;  // <Not> ::= not '(' <Expr> ')'
90
 
                   final int RULE_NOT_EXCLAM_LPARAN_RPARAN              = 16;  // <Not> ::= '!' '(' <Expr> ')'
91
 
                   final int RULE_NOT                                   = 17;  // <Not> ::= <Factor>
92
 
                   final int RULE_FACTOR                                = 18;  // <Factor> ::= <AtomicProposition>
93
 
                   final int RULE_FACTOR_LPARAN_RPARAN                  = 19;  // <Factor> ::= '(' <Expr> ')'
94
 
                   final int RULE_ATOMICPROPOSITION_IDENTIFIER_LT_NUM   = 20;  // <AtomicProposition> ::= Identifier '<' Num
95
 
                   final int RULE_ATOMICPROPOSITION_IDENTIFIER_LTEQ_NUM = 21;  // <AtomicProposition> ::= Identifier '<=' Num
96
 
                   final int RULE_ATOMICPROPOSITION_IDENTIFIER_EQ_NUM   = 22;  // <AtomicProposition> ::= Identifier '=' Num
97
 
                   final int RULE_ATOMICPROPOSITION_IDENTIFIER_EQEQ_NUM = 23;  // <AtomicProposition> ::= Identifier '==' Num
98
 
                   final int RULE_ATOMICPROPOSITION_IDENTIFIER_GTEQ_NUM = 24;  // <AtomicProposition> ::= Identifier '>=' Num
99
 
                   final int RULE_ATOMICPROPOSITION_IDENTIFIER_GT_NUM   = 25;  // <AtomicProposition> ::= Identifier '>' Num
100
 
                };
101
 
 
 
30
public class TAPAALQueryParser implements GPMessageConstants {
 
31
 
 
32
        private static final String ERROR_PARSING_QUERY_MESSAGE = "TAPAAL countered an error trying to parse the query";
 
33
 
 
34
        public interface SymbolConstants {
 
35
                final int SYMBOL_EOF = 0; // (EOF)
 
36
                final int SYMBOL_ERROR = 1; // (Error)
 
37
                final int SYMBOL_WHITESPACE = 2; // (Whitespace)
 
38
                final int SYMBOL_EXCLAM = 3; // '!'
 
39
                final int SYMBOL_AMPAMP = 4; // '&&'
 
40
                final int SYMBOL_LPARAN = 5; // '('
 
41
                final int SYMBOL_RPARAN = 6; // ')'
 
42
                final int SYMBOL_DOT = 7; // '.'
 
43
                final int SYMBOL_PIPEPIPE = 8; // '||'
 
44
                final int SYMBOL_LT = 9; // '<'
 
45
                final int SYMBOL_LTEQ = 10; // '<='
 
46
                final int SYMBOL_EQ = 11; // '='
 
47
                final int SYMBOL_EQEQ = 12; // '=='
 
48
                final int SYMBOL_GT = 13; // '>'
 
49
                final int SYMBOL_GTEQ = 14; // '>='
 
50
                final int SYMBOL_ALBRACKETRBRACKET = 15; // 'A[]'
 
51
                final int SYMBOL_ALTGT = 16; // 'A<>'
 
52
                final int SYMBOL_AF = 17; // AF
 
53
                final int SYMBOL_AG = 18; // AG
 
54
                final int SYMBOL_AND = 19; // and
 
55
                final int SYMBOL_ELBRACKETRBRACKET = 20; // 'E[]'
 
56
                final int SYMBOL_ELTGT = 21; // 'E<>'
 
57
                final int SYMBOL_EF = 22; // EF
 
58
                final int SYMBOL_EG = 23; // EG
 
59
                final int SYMBOL_IDENTIFIER = 24; // Identifier
 
60
                final int SYMBOL_NOT = 25; // not
 
61
                final int SYMBOL_NUM = 26; // Num
 
62
                final int SYMBOL_OR = 27; // or
 
63
                final int SYMBOL_ABSTRACTPROPERTY = 28; // <AbstractProperty>
 
64
                final int SYMBOL_AND2 = 29; // <And>
 
65
                final int SYMBOL_ATOMICPROPOSITION1 = 30; // <AtomicProposition1>
 
66
                final int SYMBOL_ATOMICPROPOSITION2 = 31; // <AtomicProposition2>
 
67
                final int SYMBOL_EXPR = 32; // <Expr>
 
68
                final int SYMBOL_FACTOR = 33; // <Factor>
 
69
                final int SYMBOL_NOT2 = 34; // <Not>
 
70
                final int SYMBOL_OR2 = 35; // <Or>
 
71
        };
 
72
 
 
73
        public interface RuleConstants {
 
74
                final int RULE_ABSTRACTPROPERTY_EF = 0; // <AbstractProperty> ::= EF <Expr>
 
75
                final int RULE_ABSTRACTPROPERTY_ELTGT = 1; // <AbstractProperty> ::= 'E<>' <Expr>
 
76
                final int RULE_ABSTRACTPROPERTY_EG = 2; // <AbstractProperty> ::= EG <Expr>
 
77
                final int RULE_ABSTRACTPROPERTY_ELBRACKETRBRACKET = 3; // <AbstractProperty> ::= 'E[]' <Expr>
 
78
                final int RULE_ABSTRACTPROPERTY_AF = 4; // <AbstractProperty> ::= AF <Expr>
 
79
                final int RULE_ABSTRACTPROPERTY_ALTGT = 5; // <AbstractProperty> ::= 'A<>' <Expr>
 
80
                final int RULE_ABSTRACTPROPERTY_AG = 6; // <AbstractProperty> ::= AG <Expr>
 
81
                final int RULE_ABSTRACTPROPERTY_ALBRACKETRBRACKET = 7; // <AbstractProperty> ::= 'A[]' <Expr>
 
82
                final int RULE_EXPR = 8; // <Expr> ::= <Or>
 
83
                final int RULE_OR_OR = 9; // <Or> ::= <Or> or <And>
 
84
                final int RULE_OR_PIPEPIPE = 10; // <Or> ::= <Or> '||' <And>
 
85
                final int RULE_OR = 11; // <Or> ::= <And>
 
86
                final int RULE_AND_AND = 12; // <And> ::= <And> and <Not>
 
87
                final int RULE_AND_AMPAMP = 13; // <And> ::= <And> '&&' <Not>
 
88
                final int RULE_AND = 14; // <And> ::= <Not>
 
89
                final int RULE_NOT_NOT_LPARAN_RPARAN = 15; // <Not> ::= not '(' <Expr>
 
90
                                                                                                        // ')'
 
91
                final int RULE_NOT_EXCLAM_LPARAN_RPARAN = 16; // <Not> ::= '!' '(' <Expr> ')'
 
92
                final int RULE_NOT = 17; // <Not> ::= <Factor>
 
93
                final int RULE_FACTOR = 18; // <Factor> ::= <AtomicProposition1>
 
94
                final int RULE_FACTOR2 = 19; // <Factor> ::= <AtomicProposition2>
 
95
                final int RULE_FACTOR_LPARAN_RPARAN = 20; // <Factor> ::= '(' <Expr> ')'
 
96
                final int RULE_ATOMICPROPOSITION1_IDENTIFIER_LT_NUM = 21; // <AtomicProposition1> ::= Identifier '<' Num
 
97
                final int RULE_ATOMICPROPOSITION1_IDENTIFIER_LTEQ_NUM = 22; // <AtomicProposition1> ::= Identifier '<=' Num
 
98
                final int RULE_ATOMICPROPOSITION1_IDENTIFIER_EQ_NUM = 23; // <AtomicProposition1> ::= Identifier '=' Num
 
99
                final int RULE_ATOMICPROPOSITION1_IDENTIFIER_EQEQ_NUM = 24; // <AtomicProposition1> ::= Identifier '==' Num
 
100
                final int RULE_ATOMICPROPOSITION1_IDENTIFIER_GTEQ_NUM = 25; // <AtomicProposition1> ::= Identifier '>=' Num
 
101
                final int RULE_ATOMICPROPOSITION1_IDENTIFIER_GT_NUM = 26; // <AtomicProposition1> ::= Identifier '>' Num
 
102
                final int RULE_ATOMICPROPOSITION2_IDENTIFIER_DOT = 27; // <AtomicProposition2> ::= Identifier '.' <AtomicProposition1>
 
103
        };
102
104
 
103
105
        private Stack<TCTLAbstractStateProperty> parseStack;
104
 
        
 
106
 
105
107
        /***************************************************************
106
 
         * This class will run the engine, and needs a file called config.dat
107
 
         * in the current directory. This file should contain two lines,
108
 
         * The first should be the absolute path name to the .cgt file, the second
109
 
         * should be the source file you wish to parse.
110
 
         * @param text Array of arguments.
 
108
         * This class will run the engine, and needs a file called config.dat in the
 
109
         * current directory. This file should contain two lines, The first should
 
110
         * be the absolute path name to the .cgt file, the second should be the
 
111
         * source file you wish to parse.
 
112
         * 
 
113
         * @param text
 
114
         *            Array of arguments.
111
115
         * @return TODO
112
 
         * @throws IOException 
 
116
         * @throws IOException
113
117
         ***************************************************************/
114
 
        public TCTLAbstractProperty parse(String query) throws ParseException
115
 
        {
 
118
        public TCTLAbstractProperty parse(String query) throws ParseException {
116
119
 
117
120
                String textToParse = query, compiledGrammar = this.getClass().getResource("/dk/aau/cs/TCTL/Parsing/TAPAALQuery.cgt").getFile();
118
121
 
119
122
                GOLDParser parser = new GOLDParser();
120
 
                
 
123
 
121
124
                parseStack = new Stack<TCTLAbstractStateProperty>();
122
 
                
 
125
 
123
126
                File temp;
124
127
 
125
 
                try
126
 
                {
127
 
                        
 
128
                try {
 
129
 
128
130
                        parser.loadCompiledGrammar(compiledGrammar);
129
131
 
130
 
                        // put the text to parse in a temp file since parser requires it to be in a file
 
132
                        // put the text to parse in a temp file since parser requires it to
 
133
                        // be in a file
131
134
                        temp = File.createTempFile("queryToParse", ".q");
132
135
                        temp.deleteOnExit();
133
 
                        PrintStream out = new PrintStream(temp); 
 
136
                        PrintStream out = new PrintStream(temp);
134
137
                        out.append(textToParse);
135
138
                        out.append("\n");
136
139
                        out.close();
137
140
 
138
141
                        // open temp file
139
142
                        parser.openFile(temp.getPath());
140
 
                        //          parser.openFile("/home/lassejac/Desktop/test_queries/test");
141
 
                }
142
 
                catch(ParserException parse)
143
 
                {
 
143
                        // parser.openFile("/home/lassejac/Desktop/test_queries/test");
 
144
                } catch (ParserException parse) {
144
145
                        System.out.println("**PARSER ERROR**\n" + parse.toString());
145
146
                        System.exit(1);
146
147
                } catch (IOException e) {
153
154
                int response = -1;
154
155
                TCTLAbstractProperty root = null;
155
156
 
156
 
 
157
 
                while(!done)
158
 
                {
159
 
                        try
160
 
                        {
 
157
                while (!done) {
 
158
                        try {
161
159
                                response = parser.parse();
162
 
                        }
163
 
                        catch(ParserException parse)
164
 
                        {
 
160
                        } catch (ParserException parse) {
165
161
                                System.out.println("**PARSER ERROR**\n" + parse.toString());
166
162
                                System.exit(1);
167
163
                        }
168
164
 
169
 
                        switch(response)
170
 
                        {
 
165
                        switch (response) {
171
166
                        case gpMsgTokenRead:
172
 
                                /* A token was read by the parser. The Token Object can be accessed
173
 
                      through the CurrentToken() property:  Parser.CurrentToken */
 
167
                                /*
 
168
                                 * A token was read by the parser. The Token Object can be
 
169
                                 * accessed through the CurrentToken() property:
 
170
                                 * Parser.CurrentToken
 
171
                                 */
174
172
                                break;
175
173
 
176
174
                        case gpMsgReduction:
177
 
                                /* This message is returned when a rule was reduced by the parse engine.
178
 
                      The CurrentReduction property is assigned a Reduction object
179
 
                      containing the rule and its related tokens. You can reassign this
180
 
                      property to your own customized class. If this is not the case,
181
 
                      this message can be ignored and the Reduction object will be used
182
 
                      to store the parse tree.  */
183
 
                                
184
 
                                switch(parser.currentReduction().getParentRule().getTableIndex())
185
 
                                {
186
 
                                
 
175
                                /*
 
176
                                 * This message is returned when a rule was reduced by the parse
 
177
                                 * engine. The CurrentReduction property is assigned a Reduction
 
178
                                 * object containing the rule and its related tokens. You can
 
179
                                 * reassign this property to your own customized class. If this
 
180
                                 * is not the case, this message can be ignored and the
 
181
                                 * Reduction object will be used to store the parse tree.
 
182
                                 */
 
183
 
 
184
                                switch (parser.currentReduction().getParentRule()
 
185
                                                .getTableIndex()) {
 
186
 
187
187
                                case RuleConstants.RULE_ABSTRACTPROPERTY_EF: // <AbstractProperty> ::= EF <Expr>
188
 
                                case RuleConstants.RULE_ABSTRACTPROPERTY_ELTGT:                          // <AbstractProperty> ::= 'E<>' <Expr>
 
188
                                case RuleConstants.RULE_ABSTRACTPROPERTY_ELTGT: // <AbstractProperty> ::= 'E<>' <Expr>
189
189
                                        root = new TCTLEFNode(parseStack.pop());
190
190
                                        break;
191
 
                                case RuleConstants.RULE_ABSTRACTPROPERTY_EG:                                    // <AbstractProperty> ::= EG <Expr>
192
 
                                case RuleConstants.RULE_ABSTRACTPROPERTY_ELBRACKETRBRACKET:   // <AbstractProperty> ::= 'E[]' <Expr>
 
191
                                case RuleConstants.RULE_ABSTRACTPROPERTY_EG: // <AbstractProperty> ::= EG <Expr>
 
192
                                case RuleConstants.RULE_ABSTRACTPROPERTY_ELBRACKETRBRACKET: // <AbstractProperty> ::= 'E[]' <Expr>
193
193
                                        root = new TCTLEGNode(parseStack.pop());
194
194
                                        break;
195
 
                                case RuleConstants.RULE_ABSTRACTPROPERTY_AF:            // <AbstractProperty> ::= AF <Expr>
196
 
                                case RuleConstants.RULE_ABSTRACTPROPERTY_ALTGT:         // <AbstractProperty> ::= 'A<>' <Expr>
 
195
                                case RuleConstants.RULE_ABSTRACTPROPERTY_AF: // <AbstractProperty> ::= AF <Expr>
 
196
                                case RuleConstants.RULE_ABSTRACTPROPERTY_ALTGT: // <AbstractProperty> ::= 'A<>' <Expr>
197
197
                                        root = new TCTLAFNode(parseStack.pop());
198
198
                                        break;
199
 
                                case RuleConstants.RULE_ABSTRACTPROPERTY_AG: // <AbstractProperty> ::= AG <Expr>
 
199
                                case RuleConstants.RULE_ABSTRACTPROPERTY_AG: // <AbstractProperty>::= AG <Expr>
200
200
                                case RuleConstants.RULE_ABSTRACTPROPERTY_ALBRACKETRBRACKET: // <AbstractProperty> ::= 'A[]' <Expr>
201
201
                                        root = new TCTLAGNode(parseStack.pop());
202
202
                                        break;
203
 
                                
 
203
 
204
204
                                case RuleConstants.RULE_OR_OR: // <Or> ::= <Or> or <And>
205
 
                                case RuleConstants.RULE_OR_PIPEPIPE: // <Or> ::= <Or> '||' <And>                        
 
205
                                case RuleConstants.RULE_OR_PIPEPIPE: // <Or> ::= <Or> '||' <And>
206
206
                                        TCTLAbstractStateProperty orProp2 = parseStack.pop();
207
207
                                        TCTLAbstractStateProperty orProp1 = parseStack.pop();
208
208
                                        ArrayList<TCTLAbstractStateProperty> disjunctions = new ArrayList<TCTLAbstractStateProperty>();
209
 
                                        if(orProp1 instanceof TCTLOrListNode) {
210
 
                                                TCTLOrListNode node1 = (TCTLOrListNode)orProp1;
211
 
                                                
 
209
                                        if (orProp1 instanceof TCTLOrListNode) {
 
210
                                                TCTLOrListNode node1 = (TCTLOrListNode) orProp1;
 
211
 
212
212
                                                for (TCTLAbstractStateProperty p : node1.getProperties()) {
213
213
                                                        disjunctions.add(p);
214
214
                                                }
215
 
                                        }
216
 
                                        else {
 
215
                                        } else {
217
216
                                                disjunctions.add(orProp1);
218
217
                                        }
219
 
                                        
220
 
                                        if(orProp2 instanceof TCTLOrListNode) {
221
 
                                                TCTLOrListNode node2 = (TCTLOrListNode)orProp2;
222
 
                                                
 
218
 
 
219
                                        if (orProp2 instanceof TCTLOrListNode) {
 
220
                                                TCTLOrListNode node2 = (TCTLOrListNode) orProp2;
 
221
 
223
222
                                                for (TCTLAbstractStateProperty p : node2.getProperties()) {
224
223
                                                        disjunctions.add(p);
225
224
                                                }
226
 
                                        }
227
 
                                        else {
 
225
                                        } else {
228
226
                                                disjunctions.add(orProp2);
229
227
                                        }
230
228
                                        TCTLOrListNode orListNode = new TCTLOrListNode(disjunctions);
231
229
                                        parseStack.push(orListNode);
232
230
                                        break;
233
 
                                
 
231
 
234
232
                                case RuleConstants.RULE_AND_AND: // <And> ::= <And> and <Not>
235
 
                                case RuleConstants.RULE_AND_AMPAMP: // <And> ::= <And> '&&' <Not>
 
233
                                case RuleConstants.RULE_AND_AMPAMP: // <And> ::= <And> '&&'
 
234
                                                                                                        // <Not>
236
235
                                        TCTLAbstractStateProperty andProp2 = parseStack.pop();
237
236
                                        TCTLAbstractStateProperty andProp1 = parseStack.pop();
238
237
                                        ArrayList<TCTLAbstractStateProperty> conjunctions = new ArrayList<TCTLAbstractStateProperty>();
239
 
                                        if(andProp1 instanceof TCTLAndListNode) {
240
 
                                                TCTLAndListNode node1 = (TCTLAndListNode)andProp1;
241
 
                                                
 
238
                                        if (andProp1 instanceof TCTLAndListNode) {
 
239
                                                TCTLAndListNode node1 = (TCTLAndListNode) andProp1;
 
240
 
242
241
                                                for (TCTLAbstractStateProperty p : node1.getProperties()) {
243
242
                                                        conjunctions.add(p);
244
243
                                                }
245
 
                                        }
246
 
                                        else {
 
244
                                        } else {
247
245
                                                conjunctions.add(andProp1);
248
246
                                        }
249
 
                                        
250
 
                                        if(andProp2 instanceof TCTLAndListNode) {
251
 
                                                TCTLAndListNode node2 = (TCTLAndListNode)andProp2;
252
 
                                                
 
247
 
 
248
                                        if (andProp2 instanceof TCTLAndListNode) {
 
249
                                                TCTLAndListNode node2 = (TCTLAndListNode) andProp2;
 
250
 
253
251
                                                for (TCTLAbstractStateProperty p : node2.getProperties()) {
254
252
                                                        conjunctions.add(p);
255
253
                                                }
256
 
                                        }
257
 
                                        else {
 
254
                                        } else {
258
255
                                                conjunctions.add(andProp2);
259
256
                                        }
260
257
                                        TCTLAndListNode andListNode = new TCTLAndListNode(conjunctions);
266
263
                                        TCTLNotNode notNode = new TCTLNotNode(parseStack.pop());
267
264
                                        parseStack.push(notNode);
268
265
                                        break;
269
 
                                        
 
266
 
270
267
                                case RuleConstants.RULE_EXPR: // <Expr> ::= <Or>
271
268
                                case RuleConstants.RULE_OR: // <Or> ::= <And>
272
269
                                case RuleConstants.RULE_AND: // <And> ::= <Not>
273
270
                                case RuleConstants.RULE_NOT: // <Not> ::= <Factor>
274
271
                                case RuleConstants.RULE_FACTOR: // <Factor> ::= <AtomicProposition>
275
 
                                case RuleConstants.RULE_FACTOR_LPARAN_RPARAN: // <Factor> ::= '(' <Expr> ')'
 
272
                                case RuleConstants.RULE_FACTOR2:
 
273
                                case RuleConstants.RULE_FACTOR_LPARAN_RPARAN: // <Factor> ::= '(' <Expr>')'
276
274
                                        break;
277
 
                                case RuleConstants.RULE_ATOMICPROPOSITION_IDENTIFIER_LT_NUM: // <AtomicProposition> ::= Identifier '<' Num
278
 
                                case RuleConstants.RULE_ATOMICPROPOSITION_IDENTIFIER_LTEQ_NUM: // <AtomicProposition> ::= Identifier '<=' Num
279
 
                                case RuleConstants.RULE_ATOMICPROPOSITION_IDENTIFIER_EQ_NUM: // <AtomicProposition> ::= Identifier '=' Num
280
 
                                case RuleConstants.RULE_ATOMICPROPOSITION_IDENTIFIER_EQEQ_NUM: // <AtomicProposition> ::= Identifier '==' Num
281
 
                                case RuleConstants.RULE_ATOMICPROPOSITION_IDENTIFIER_GTEQ_NUM: // <AtomicProposition> ::= Identifier '>=' Num
282
 
                                case RuleConstants.RULE_ATOMICPROPOSITION_IDENTIFIER_GT_NUM: // <AtomicProposition> ::= Identifier '>' Num
283
 
                                        String place = (String)createObjectFromTerminal(parser.currentReduction().getToken(0));
284
 
                                        String op = (String)createObjectFromTerminal(parser.currentReduction().getToken(1));
285
 
                                        Integer n = (Integer)createObjectFromTerminal(parser.currentReduction().getToken(2));
 
275
 
 
276
                                case RuleConstants.RULE_ATOMICPROPOSITION1_IDENTIFIER_LT_NUM: // <AtomicProposition> ::= Identifier '<' Num
 
277
                                case RuleConstants.RULE_ATOMICPROPOSITION1_IDENTIFIER_LTEQ_NUM: // <AtomicProposition> ::= Identifier '<=' Num
 
278
                                case RuleConstants.RULE_ATOMICPROPOSITION1_IDENTIFIER_EQ_NUM: // <AtomicProposition> ::= Identifier '=' Num
 
279
                                case RuleConstants.RULE_ATOMICPROPOSITION1_IDENTIFIER_EQEQ_NUM: // <AtomicProposition> ::= Identifier '==' Num
 
280
                                case RuleConstants.RULE_ATOMICPROPOSITION1_IDENTIFIER_GTEQ_NUM: // <AtomicProposition> ::= Identifier '>=' Num
 
281
                                case RuleConstants.RULE_ATOMICPROPOSITION1_IDENTIFIER_GT_NUM: // <AtomicProposition> ::= Identifier '>' Num
 
282
                                        String place = (String) createObjectFromTerminal(parser.currentReduction().getToken(0));
 
283
                                        String op = (String) createObjectFromTerminal(parser.currentReduction().getToken(1));
 
284
                                        Integer n = (Integer) createObjectFromTerminal(parser.currentReduction().getToken(2));
286
285
                                        parseStack.push(new TCTLAtomicPropositionNode(place, op, n));
287
286
                                        break;
 
287
                                case RuleConstants.RULE_ATOMICPROPOSITION2_IDENTIFIER_DOT: // <AtomicProposition> ::= Identifier '.' <AtomicProposition1>
 
288
                                        TCTLAtomicPropositionNode node = (TCTLAtomicPropositionNode) parseStack.pop();
 
289
                                        String template = (String) createObjectFromTerminal(parser.currentReduction().getToken(0));
 
290
                                        node.setTemplate(template);
 
291
                                        parseStack.push(node);
 
292
                                        break;
288
293
                                }
289
 
                                
290
294
 
291
 
//                              // ************************************** log file
292
 
//                              System.out.println("gpMsgReduction");
293
 
//                              Reduction myRed = parser.currentReduction();
294
 
//                              System.out.println(myRed.getParentRule().getText());
295
 
//                              // ************************************** end log
 
295
                                // // ************************************** log file
 
296
                                // System.out.println("gpMsgReduction");
 
297
                                // Reduction myRed = parser.currentReduction();
 
298
                                // System.out.println(myRed.getParentRule().getText());
 
299
                                // // ************************************** end log
296
300
 
297
301
                                break;
298
302
 
299
303
                        case gpMsgAccept:
300
304
                                /* The program was accepted by the parsing engine */
301
305
 
302
 
//                              // ************************************** log file
303
 
//                              System.out.println("gpMsgAccept");
304
 
//                              // ************************************** end log
 
306
                                // // ************************************** log file
 
307
                                // System.out.println("gpMsgAccept");
 
308
                                // // ************************************** end log
305
309
 
306
310
                                done = true;
307
311
 
308
312
                                break;
309
313
 
310
 
                        case gpMsgLexicalError:
311
 
                                /* Place code here to handle a illegal or unrecognized token
312
 
                           To recover, pop the token from the stack: Parser.PopInputToken */
313
 
 
314
 
//                              // ************************************** log file
315
 
//                              System.out.println("gpMsgLexicalError");
316
 
//                              // ************************************** end log
317
 
 
318
 
                                parser.popInputToken();
319
 
 
320
 
                                break;
321
 
 
322
314
                        case gpMsgNotLoadedError:
323
315
                                /* Load the Compiled Grammar Table file first. */
324
316
 
325
 
//                              // ************************************** log file
326
 
//                              System.out.println("gpMsgNotLoadedError");
327
 
//                              // ************************************** end log
 
317
                                // // ************************************** log file
 
318
                                // System.out.println("gpMsgNotLoadedError");
 
319
                                // // ************************************** end log
328
320
                                done = true;
329
 
                                throw new ParseException("TAPAAL countered an error trying to parse the query", 0);
330
 
 
 
321
                                throw new ParseException(ERROR_PARSING_QUERY_MESSAGE,0);
 
322
                        case gpMsgLexicalError: /* Place code here to handle a illegal or unrecognized token To recover, pop the token from the stack: Parser.PopInputToken */
331
323
                        case gpMsgSyntaxError:
332
 
                                /* This is a syntax error: the source has produced a token that was
333
 
                           not expected by the LALR State Machine. The expected tokens are stored
334
 
                           into the Tokens() list. To recover, push one of the
335
 
                              expected tokens onto the parser's input queue (the first in this case):
336
 
                           You should limit the number of times this type of recovery can take
337
 
                           place. */
 
324
                                /*
 
325
                                 * This is a syntax error: the source has produced a token that
 
326
                                 * was not expected by the LALR State Machine. The expected
 
327
                                 * tokens are stored into the Tokens() list. To recover, push
 
328
                                 * one of the expected tokens onto the parser's input queue (the
 
329
                                 * first in this case): You should limit the number of times
 
330
                                 * this type of recovery can take place.
 
331
                                 */
338
332
                                done = true;
339
333
                                Token theTok = parser.currentToken();
340
 
                                System.out.println("Token not expected: " + (String)theTok.getData());
341
 
                                throw new ParseException("TAPAAL countered an error trying to parse the query", 0);
342
 
                                
343
 
//                              // ************************************** log file
344
 
//                              System.out.println("gpMsgSyntaxError");
345
 
//                              // ************************************** end log
 
334
                                System.out.println("Token not expected: "+ (String) theTok.getData());
 
335
                                throw new ParseException(ERROR_PARSING_QUERY_MESSAGE,0);
 
336
 
 
337
                                // // ************************************** log file
 
338
                                // System.out.println("gpMsgSyntaxError");
 
339
                                // // ************************************** end log
346
340
 
347
341
                        case gpMsgCommentError:
348
 
                                /* The end of the input was reached while reading a comment.
349
 
                             This is caused by a comment that was not terminated */
 
342
                                /*
 
343
                                 * The end of the input was reached while reading a comment.
 
344
                                 * This is caused by a comment that was not terminated
 
345
                                 */
350
346
 
351
 
//                              // ************************************** log file
352
 
//                              System.out.println("gpMsgCommentError");
353
 
//                              // ************************************** end log
 
347
                                // // ************************************** log file
 
348
                                // System.out.println("gpMsgCommentError");
 
349
                                // // ************************************** end log
354
350
 
355
351
                                done = true;
356
352
 
357
353
                                break;
358
354
 
359
355
                        case gpMsgInternalError:
360
 
                                /* Something horrid happened inside the parser. You cannot recover */
 
356
                                /*
 
357
                                 * Something horrid happened inside the parser. You cannot
 
358
                                 * recover
 
359
                                 */
361
360
 
362
 
//                              // ************************************** log file
363
 
//                              System.out.println("gpMsgInternalError");
364
 
//                              // ************************************** end log
 
361
                                // // ************************************** log file
 
362
                                // System.out.println("gpMsgInternalError");
 
363
                                // // ************************************** end log
365
364
                                done = true;
366
 
                                throw new ParseException("TAPAAL countered an error trying to parse the query", 0);
 
365
                                throw new ParseException(ERROR_PARSING_QUERY_MESSAGE,0);
367
366
 
368
 
                
369
367
                        }
370
368
                }
371
 
                try
372
 
                {
 
369
                try {
373
370
                        parser.closeFile();
374
 
                }
375
 
                catch(ParserException parse)
376
 
                {
 
371
                } catch (ParserException parse) {
377
372
                        System.out.println("**PARSER ERROR**\n" + parse.toString());
378
373
                        System.exit(1);
379
374
                }
381
376
                return root;
382
377
        }
383
378
 
384
 
        
385
379
        private Object createObjectFromTerminal(Token token) {
386
380
                Object retObj = null;
387
381
 
388
 
                switch(token.getTableIndex())
389
 
                {
 
382
                switch (token.getTableIndex()) {
390
383
 
391
 
                case SymbolConstants.SYMBOL_LT:  // '<'
 
384
                case SymbolConstants.SYMBOL_LT: // '<'
392
385
                case SymbolConstants.SYMBOL_LTEQ: // '<='
393
386
                case SymbolConstants.SYMBOL_EQ: // '='
394
387
                case SymbolConstants.SYMBOL_GT: // '>'
395
 
                case SymbolConstants.SYMBOL_GTEQ: // '>='                       
396
 
                        String op = (String)token.getData();
 
388
                case SymbolConstants.SYMBOL_GTEQ: // '>='
 
389
                        String op = (String) token.getData();
397
390
                        retObj = op;
398
391
                        break;
399
392
                case SymbolConstants.SYMBOL_EQEQ: // '=='
400
393
                        retObj = "=";
401
394
                        break;
402
395
                case SymbolConstants.SYMBOL_IDENTIFIER: // Identifier
403
 
                        String id = (String)token.getData();
 
396
                        String id = (String) token.getData();
404
397
                        retObj = id;
405
398
                        break;
406
399
                case SymbolConstants.SYMBOL_NUM: // Num
407
 
                        Integer n = Integer.parseInt((String)token.getData());
 
400
                        Integer n = Integer.parseInt((String) token.getData());
408
401
                        retObj = n;
409
402
                default:
410
403
                        break; // should not happen