Merge remote-tracking branch 'origin/svn'
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / internal / parsing / parser / SCLParser.java
1 package org.simantics.scl.compiler.internal.parsing.parser;\r
2 \r
3 import java.io.DataInputStream;\r
4 import java.io.IOException;\r
5 import java.util.ArrayList;\r
6 import java.util.Arrays;\r
7 import java.util.Collections;\r
8 import org.simantics.scl.compiler.internal.parsing.exceptions.SCLSyntaxErrorException;\r
9 \r
10 import org.simantics.scl.compiler.internal.parsing.Token;\r
11 \r
12 public abstract class SCLParser {    \r
13     public static final boolean TRACE = false;\r
14 \r
15     private static final int INITIAL_CAPACITY = 16;\r
16     private static final int STATE_COUNT = 324;\r
17     private static final int TERMINAL_COUNT = 79;\r
18     private static final int NONTERMINAL_COUNT = 49;\r
19     private static final int PRODUCT_COUNT = 126;\r
20     \r
21     private static final int[] ACTION_ROW_ID = new int[STATE_COUNT];\r
22     private static final int[] ACTION_COLUMN_ID = new int[TERMINAL_COUNT];\r
23     private static final short[] ACTION_TABLE = new short[5508];\r
24     private static final int[] ERROR_TABLE = new int[800];\r
25     private static final int[] GOTO_ROW_ID = new int[STATE_COUNT];\r
26     private static final int[] GOTO_COLUMN_ID = new int[NONTERMINAL_COUNT];\r
27     private static final short[] GOTO_TABLE = new short[1620];\r
28     private static final int[] PRODUCT_LHS = new int[PRODUCT_COUNT];\r
29 \r
30     private static final short STATE_MASK = (short)0x0fff;\r
31     private static final short REDUCE_MASK = (short)0x8000;\r
32     private static final short POP_MASK = (short)0x4000;\r
33     private static final short PUSH_MASK = (short)0x2000;\r
34     private static final short ERROR_ACTION = (short)0xffff;\r
35     private static final short ACCEPT_ACTION = (short)0xfffe;\r
36     \r
37     public static final String[] TERMINAL_NAMES = new String[] {\r
38         "SEMICOLON",\r
39         "LBRACE",\r
40         "RBRACE",\r
41         "COMMA",\r
42         "HASTYPE",\r
43         "DATA",\r
44         "ID",\r
45         "EQUALS",\r
46         "BAR",\r
47         "TYPE",\r
48         "CLASS",\r
49         "WHERE",\r
50         "INSTANCE",\r
51         "DERIVING",\r
52         "BEGIN_STRING",\r
53         "END_STRING",\r
54         "ANNOTATION_ID",\r
55         "INFIX",\r
56         "INFIXL",\r
57         "INFIXR",\r
58         "INTEGER",\r
59         "IMPORTJAVA",\r
60         "EFFECT",\r
61         "RULE",\r
62         "ABSTRACT_RULE",\r
63         "EXTENDS",\r
64         "MAPPING_RELATION",\r
65         "FOLLOWS",\r
66         "IMPORT",\r
67         "INCLUDE",\r
68         "AS",\r
69         "LPAREN",\r
70         "RPAREN",\r
71         "HIDING",\r
72         "ARROW",\r
73         "COLON",\r
74         "WITH",\r
75         "MINUS",\r
76         "SYMBOL",\r
77         "LESS",\r
78         "GREATER",\r
79         "SEPARATED_DOT",\r
80         "ESCAPED_ID",\r
81         "LAMBDA",\r
82         "LET",\r
83         "IF",\r
84         "MATCH",\r
85         "DO",\r
86         "MDO",\r
87         "ENFORCE",\r
88         "BLANK",\r
89         "FLOAT",\r
90         "LBRACKET",\r
91         "ESCAPED_SYMBOL",\r
92         "CHAR",\r
93         "WHEN",\r
94         "ATTACHED_HASH",\r
95         "SELECT",\r
96         "SELECT_FIRST",\r
97         "SELECT_DISTINCT",\r
98         "TRANSFORMATION",\r
99         "EQ",\r
100         "ATTACHED_DOT",\r
101         "IN",\r
102         "THEN",\r
103         "ELSE",\r
104         "RBRACKET",\r
105         "DOTDOT",\r
106         "AT",\r
107         "SUSPEND_STRING",\r
108         "CONTINUE_STRING",\r
109         "BINDS",\r
110         "BY",\r
111         "QUERY_OP",\r
112         "IMPLIES",\r
113         "FORALL",\r
114         "COMMENT",\r
115         "EOL",\r
116         "EOF"\r
117     };\r
118 \r
119     public static final String[] NONTERMINAL_NAMES = new String[] {\r
120         "module",\r
121         "commands",\r
122         "import",\r
123         "type",\r
124         "exp",\r
125         "equationBlock",\r
126         "declaration",\r
127         "command",\r
128         "statement",\r
129         "declarations",\r
130         "var",\r
131         "bexp",\r
132         "rhs",\r
133         "constructor",\r
134         "context",\r
135         "fundeps",\r
136         "atype",\r
137         "aexp",\r
138         "ruleDeclarations",\r
139         "importSpec",\r
140         "importItem",\r
141         "fieldDeclaration",\r
142         "statements",\r
143         "guardedExpEq",\r
144         "fundep",\r
145         "ruleDeclaration",\r
146         "query",\r
147         "queryBlock",\r
148         "lexp",\r
149         "symbol",\r
150         "faexp",\r
151         "accessor",\r
152         "case",\r
153         "stringLiteral",\r
154         "symbolWithoutMinus",\r
155         "listQualifier",\r
156         "field",\r
157         "caseRhs",\r
158         "guardedExpArrow",\r
159         "equation",\r
160         "etype",\r
161         "btype",\r
162         "dummy",\r
163         "init$6",\r
164         "init$5",\r
165         "init$4",\r
166         "init$3",\r
167         "init$2",\r
168         "init$1"\r
169     };\r
170         \r
171     static {\r
172         try {\r
173             DataInputStream input = new DataInputStream(SCLParser.class.getResourceAsStream("SCLParser.dat"));\r
174             for(int i=0;i<ACTION_ROW_ID.length;++i)\r
175                 ACTION_ROW_ID[i] = input.readInt();\r
176             for(int i=0;i<ACTION_COLUMN_ID.length;++i)\r
177                 ACTION_COLUMN_ID[i] = input.readInt();    \r
178             for(int i=0;i<ACTION_TABLE.length;++i)\r
179                 ACTION_TABLE[i] = input.readShort();\r
180             for(int i=0;i<ERROR_TABLE.length;++i)\r
181                 ERROR_TABLE[i] = input.readInt();\r
182             for(int i=0;i<GOTO_ROW_ID.length;++i)\r
183                 GOTO_ROW_ID[i] = input.readInt();\r
184             for(int i=0;i<GOTO_COLUMN_ID.length;++i)\r
185                 GOTO_COLUMN_ID[i] = input.readInt();    \r
186             for(int i=0;i<GOTO_TABLE.length;++i)\r
187                 GOTO_TABLE[i] = input.readShort();\r
188             for(int i=0;i<PRODUCT_LHS.length;++i)\r
189                 PRODUCT_LHS[i] = input.readInt();\r
190             input.close();\r
191         } catch(IOException e) {\r
192             e.printStackTrace();\r
193         }\r
194     }\r
195     \r
196     private static short getAction(int state, int symbol) {\r
197         int id = TERMINAL_COUNT*state + symbol;\r
198         if( ((ERROR_TABLE[id>>5] >> (id&31))&1) != 0 )\r
199             return ERROR_ACTION;\r
200         return ACTION_TABLE[ACTION_ROW_ID[state] + ACTION_COLUMN_ID[symbol]];\r
201     }\r
202     \r
203     private static short getGoto(int state, int symbol) {\r
204         return GOTO_TABLE[GOTO_ROW_ID[state] + GOTO_COLUMN_ID[symbol]];\r
205     }\r
206     \r
207     protected abstract Token nextToken();\r
208     \r
209     private Object[] symbolStack = new Object[INITIAL_CAPACITY];\r
210     private int symbolStackLength = 0;\r
211     \r
212     private int[] stateStack = new int[INITIAL_CAPACITY];\r
213     private int[] symbolStackPositionStack = new int[INITIAL_CAPACITY];\r
214     private int stateStackLength = 0;\r
215     \r
216     // For reduce\r
217     private int reductionLength;\r
218     \r
219     protected int length() {\r
220         return reductionLength;\r
221     }\r
222     \r
223     protected Object get(int i) {\r
224         if(i < 0 || i >= reductionLength)\r
225             throw new IndexOutOfBoundsException();\r
226         return symbolStack[symbolStackLength+i];\r
227     }\r
228     \r
229     private String parseErrorDescription(int state, Token token, int tokenId) {\r
230         StringBuilder b = new StringBuilder();\r
231         b.append("Unexpected token '").append(token)\r
232          .append("' (").append(TERMINAL_NAMES[tokenId])\r
233          .append("). Expected one of ");\r
234         ArrayList<String> possibleTerminals = new ArrayList<String>();\r
235         for(int i=0;i<TERMINAL_COUNT;++i)\r
236             if(getAction(state, i) != ERROR_ACTION)\r
237                 possibleTerminals.add(TERMINAL_NAMES[i]);\r
238         Collections.sort(possibleTerminals);\r
239         for(int i=0;i<possibleTerminals.size();++i) {\r
240             if(i > 0)\r
241                 b.append(", ");\r
242             b.append(possibleTerminals.get(i));\r
243         }\r
244         b.append('.');\r
245         return b.toString();\r
246     }\r
247     \r
248     protected abstract RuntimeException syntaxError(Token token, String description);\r
249     \r
250     private static String describeAction(int action) {\r
251         if(action == ERROR_ACTION)\r
252             return "ERROR";\r
253         if(action == ACCEPT_ACTION)\r
254             return "ACCEPT";\r
255         StringBuilder b = new StringBuilder();\r
256         if((action & REDUCE_MASK) != 0) {\r
257             action ^= REDUCE_MASK;\r
258             b.append("REDUCE");\r
259         }\r
260         else\r
261             b.append("SHIFT");\r
262         if((action & POP_MASK) != 0) {\r
263             action ^= POP_MASK;\r
264             b.append(" POP");\r
265         }\r
266         if((action & PUSH_MASK) != 0) {\r
267             action ^= PUSH_MASK;\r
268             b.append(" PUSH");\r
269         }\r
270         b.append(' ').append(action);\r
271         return b.toString();\r
272     }\r
273     \r
274     private Object parse(int state) {\r
275         while(true) {\r
276             Token token = nextToken();\r
277             int tokenId = token.id;\r
278             while(true) {\r
279                 short action = getAction(state, tokenId);\r
280                 if(TRACE) {\r
281                     System.out.println("state=" + state + ", tokenId=" + TERMINAL_NAMES[tokenId] + \r
282                         ", action=" + describeAction(action));\r
283                     System.out.print("   ");\r
284                     for(int i=symbolStackLength-1,j=stateStackLength-1;i>=0;--i) {                    \r
285                         Object s = symbolStack[i];\r
286                         if(s instanceof Token)\r
287                             System.out.print(" " + TERMINAL_NAMES[((Token)s).id]);\r
288                         else\r
289                             System.out.print(" " + s.getClass().getSimpleName());                            \r
290                         while(j>=0 && symbolStackPositionStack[j]==i)\r
291                             System.out.print(" (" + stateStack[j--] + ")");\r
292                     }\r
293                     System.out.println();\r
294                 }\r
295                 //System.out.println(STATE_DESCRIPTIONS[state]);\r
296                 if((action & REDUCE_MASK) != 0) {\r
297                     if(action == ACCEPT_ACTION)\r
298                         return symbolStack[symbolStackLength-1];\r
299                     if(action == ERROR_ACTION)\r
300                         throw syntaxError(token, parseErrorDescription(state, token, tokenId));\r
301                     stateStackLength -= (action >>> 13)&3;\r
302                     action &= STATE_MASK;\r
303                     \r
304                     int reductionBegin = symbolStackPositionStack[--stateStackLength];\r
305                     \r
306                     reductionLength = symbolStackLength-reductionBegin;\r
307                     symbolStackLength = reductionBegin;\r
308                     \r
309                     if(symbolStackLength == symbolStack.length)\r
310                         symbolStack = Arrays.copyOf(symbolStack, symbolStackLength*2);\r
311                     Object symbol = reduce(action);\r
312                     postReduce(symbol);\r
313                     symbolStack[symbolStackLength] = symbol;\r
314                     \r
315                     state = stateStack[stateStackLength];\r
316                     action = getGoto(state, PRODUCT_LHS[action]);\r
317                     // Pop state\r
318                     if((action & POP_MASK) != 0) {\r
319                         --stateStackLength;\r
320                     }\r
321                     // Push state\r
322                     if((action & PUSH_MASK) != 0) {\r
323                         if(stateStackLength == stateStack.length) {\r
324                             stateStack = Arrays.copyOf(stateStack, stateStackLength*2);\r
325                             symbolStackPositionStack = Arrays.copyOf(symbolStackPositionStack, stateStackLength*2);\r
326                         }\r
327                         symbolStackPositionStack[stateStackLength] = symbolStackLength;\r
328                         stateStack[stateStackLength++] = state;\r
329                     }\r
330                     state = action & STATE_MASK;\r
331                     ++symbolStackLength;\r
332                 }\r
333                 else {\r
334                     // Pop state\r
335                     if((action & POP_MASK) != 0) {\r
336                         --stateStackLength;\r
337                     }\r
338                     // Push state\r
339                     if((action & PUSH_MASK) != 0) {\r
340                         if(stateStackLength == stateStack.length) {\r
341                             stateStack = Arrays.copyOf(stateStack, stateStackLength*2);\r
342                             symbolStackPositionStack = Arrays.copyOf(symbolStackPositionStack, stateStackLength*2);\r
343                         }\r
344                         symbolStackPositionStack[stateStackLength] = symbolStackLength;\r
345                         stateStack[stateStackLength++] = state;\r
346                     }\r
347                     \r
348                     // New state\r
349                     state = action & STATE_MASK;\r
350                     \r
351                     // Push symbol\r
352                     if(symbolStackLength == symbolStack.length)\r
353                         symbolStack = Arrays.copyOf(symbolStack, symbolStackLength*2);\r
354                     symbolStack[symbolStackLength++] = token;\r
355                     break;\r
356                 }\r
357             }\r
358         }\r
359     }\r
360     \r
361     public Object parseModule() {\r
362         return parse(0);\r
363     }\r
364     public Object parseCommands() {\r
365         return parse(309);\r
366     }\r
367     public Object parseImport() {\r
368         return parse(316);\r
369     }\r
370     public Object parseType() {\r
371         return parse(318);\r
372     }\r
373     public Object parseExp() {\r
374         return parse(320);\r
375     }\r
376     public Object parseEquationBlock() {\r
377         return parse(322);\r
378     }\r
379 \r
380 \r
381     protected Object reduce(int productionId) {\r
382         try {\r
383         switch(productionId) {\r
384         case 0:\r
385             return reduceModule();\r
386         case 1:\r
387             return reduceOneCommand();\r
388         case 2:\r
389             return reduceManyCommands();\r
390         case 3:\r
391             return reduceImport();\r
392         case 4:\r
393             return reduceArrow();\r
394         case 5:\r
395             return reduceLocalTypeAnnotation();\r
396         case 6:\r
397             return reduceEntityTypeAnnotation();\r
398         case 7:\r
399             return reduceEquationBlock();\r
400         case 8:\r
401             return reduceTypeAnnotation();\r
402         case 9:\r
403             return reduceValueDefinition();\r
404         case 10:\r
405             return reduceDataDefinition();\r
406         case 11:\r
407             return reduceTypeDefinition();\r
408         case 12:\r
409             return reduceClassDefinition();\r
410         case 13:\r
411             return reduceInstanceDefinition();\r
412         case 14:\r
413             return reduceDerivingInstanceDefinition();\r
414         case 15:\r
415             return reduceDocumentationString();\r
416         case 16:\r
417             return reduceAnnotation();\r
418         case 17:\r
419             return reducePrecedenceDefinition();\r
420         case 18:\r
421             return reduceJustImport();\r
422         case 19:\r
423             return reduceImportJava();\r
424         case 20:\r
425             return reduceEffectDefinition();\r
426         case 21:\r
427             return reduceRuleDefinition();\r
428         case 22:\r
429             return reduceMappingRelationDefinition();\r
430         case 23:\r
431             return reduceRelationDefinition();\r
432         case 24:\r
433             return reduceStatementCommand();\r
434         case 25:\r
435             return reduceImportCommand();\r
436         case 26:\r
437             return reduceGuardStatement();\r
438         case 27:\r
439             return reduceLetStatement();\r
440         case 28:\r
441             return reduceBindStatement();\r
442         case 29:\r
443             return reduceRuleStatement();\r
444         case 30:\r
445             return reduceDeclarations();\r
446         case 31:\r
447             return reduceVarId();\r
448         case 32:\r
449             return reduceEscapedSymbol();\r
450         case 33:\r
451             return reduceTupleConstructor();\r
452         case 34:\r
453             return reduceBinary();\r
454         case 35:\r
455             return reduceSimpleRhs();\r
456         case 36:\r
457             return reduceGuardedRhs();\r
458         case 37:\r
459             return reduceConstructor();\r
460         case 38:\r
461             return reduceRecordConstructor();\r
462         case 39:\r
463             return reduceContext();\r
464         case 40:\r
465             return reduceFundeps();\r
466         case 41:\r
467             return reduceTypeVar();\r
468         case 42:\r
469             return reduceTupleType();\r
470         case 43:\r
471             return reduceListType();\r
472         case 44:\r
473             return reduceListTypeConstructor();\r
474         case 45:\r
475             return reduceTupleTypeConstructor();\r
476         case 46:\r
477             return reduceLambda();\r
478         case 47:\r
479             return reduceLet();\r
480         case 48:\r
481             return reduceIf();\r
482         case 49:\r
483             return reduceMatch();\r
484         case 50:\r
485             return reduceDo();\r
486         case 51:\r
487             return reduceSelect();\r
488         case 52:\r
489             return reduceEnforce();\r
490         case 53:\r
491             return reduceWhen();\r
492         case 54:\r
493             return reduceVar();\r
494         case 55:\r
495             return reduceHashedId();\r
496         case 56:\r
497             return reduceBlank();\r
498         case 57:\r
499             return reduceInteger();\r
500         case 58:\r
501             return reduceFloat();\r
502         case 59:\r
503             return reduceString();\r
504         case 60:\r
505             return reduceChar();\r
506         case 61:\r
507             return reduceTuple();\r
508         case 62:\r
509             return reduceRightSection();\r
510         case 63:\r
511             return reduceLeftSection();\r
512         case 64:\r
513             return reduceListLiteral();\r
514         case 65:\r
515             return reduceRange();\r
516         case 66:\r
517             return reduceListComprehension();\r
518         case 67:\r
519             return reduceAs();\r
520         case 68:\r
521             return reduceRecord();\r
522         case 69:\r
523             return reduceTransformation();\r
524         case 70:\r
525             return reduceEq();\r
526         case 71:\r
527             return reduceRuleDeclarations();\r
528         case 72:\r
529             return reduceImportShowing();\r
530         case 73:\r
531             return reduceImportHiding();\r
532         case 74:\r
533             return reduceImportValueItem();\r
534         case 75:\r
535             return reduceFieldDescription();\r
536         case 76:\r
537             return reduceStatements();\r
538         case 77:\r
539             return reduceGuardedExpEq();\r
540         case 78:\r
541             return reduceFundep();\r
542         case 79:\r
543             return reduceQueryRuleDeclaration();\r
544         case 80:\r
545             return reduceAnnotation();\r
546         case 81:\r
547             return reduceGuardQuery();\r
548         case 82:\r
549             return reduceEqualsQuery();\r
550         case 83:\r
551             return reduceBindQuery();\r
552         case 84:\r
553             return reduceCompositeQuery();\r
554         case 85:\r
555             return reduceQueryBlock();\r
556         case 86:\r
557             return reduceApply();\r
558         case 87:\r
559             return reduceSymbol();\r
560         case 88:\r
561             return reduceEscapedId();\r
562         case 89:\r
563             return reduceMinus();\r
564         case 90:\r
565             return reduceLess();\r
566         case 91:\r
567             return reduceGreater();\r
568         case 92:\r
569             return reduceDot();\r
570         case 93:\r
571             return reduceFieldAccess();\r
572         case 94:\r
573             return reduceIdAccessor();\r
574         case 95:\r
575             return reduceStringAccessor();\r
576         case 96:\r
577             return reduceExpAccessor();\r
578         case 97:\r
579             return reduceCase();\r
580         case 98:\r
581             return reduceStringLiteral();\r
582         case 99:\r
583             return reduceSymbol();\r
584         case 100:\r
585             return reduceEscapedId();\r
586         case 101:\r
587             return reduceLess();\r
588         case 102:\r
589             return reduceGreater();\r
590         case 103:\r
591             return reduceDot();\r
592         case 104:\r
593             return reduceGuardQualifier();\r
594         case 105:\r
595             return reduceLetQualifier();\r
596         case 106:\r
597             return reduceBindQualifier();\r
598         case 107:\r
599             return reduceThenQualifier();\r
600         case 108:\r
601             return reduceField();\r
602         case 109:\r
603             return reduceFieldShorthand();\r
604         case 110:\r
605             return reduceSimpleCaseRhs();\r
606         case 111:\r
607             return reduceGuardedCaseRhs();\r
608         case 112:\r
609             return reduceGuardedExpArrow();\r
610         case 113:\r
611             return reduceGuardEquation();\r
612         case 114:\r
613             return reduceBasicEquation();\r
614         case 115:\r
615             return reduceEffect();\r
616         case 116:\r
617             return reduceJustEtype();\r
618         case 117:\r
619             return reduceForAll();\r
620         case 118:\r
621             return reduceApplyType();\r
622         case 119:\r
623             return reduceDummy1();\r
624 \r
625         default:\r
626             throw new RuntimeException("Internal parser error.");\r
627         }\r
628         } catch(SCLSyntaxErrorException e) {\r
629             StringBuilder b = new StringBuilder();\r
630             b.append("Failed to reduce");\r
631             for(int i=0;i<length();++i) {\r
632                 Object obj = get(i);\r
633                 b.append("\n    (").append(i).append(") \"").append(obj).append('\"');\r
634                 if(obj instanceof Token)\r
635                     b.append(" (").append(TERMINAL_NAMES[((Token)obj).id]).append(")");\r
636                 else\r
637                     b.append(" [").append(obj.getClass().getSimpleName()).append("]");\r
638             }\r
639             throw new RuntimeException(b.toString(), e);\r
640         } \r
641     }\r
642 \r
643     /**\r
644      * module ::= (declaration (SEMICOLON declaration)&#42;)?\r
645      */\r
646     protected abstract Object reduceModule();\r
647     /**\r
648      * commands ::= command?\r
649      */\r
650     protected abstract Object reduceOneCommand();\r
651     /**\r
652      * commands ::= commands SEMICOLON command\r
653      */\r
654     protected abstract Object reduceManyCommands();\r
655     /**\r
656      * import ::= (IMPORT | INCLUDE) BEGIN_STRING END_STRING (AS ID)? importSpec?\r
657      */\r
658     protected abstract Object reduceImport();\r
659     /**\r
660      * type ::= (etype (ARROW | IMPLIES))&#42; etype\r
661      */\r
662     protected abstract Object reduceArrow();\r
663     /**\r
664      * exp ::= bexp (HASTYPE type)?\r
665      */\r
666     protected abstract Object reduceLocalTypeAnnotation();\r
667     /**\r
668      * exp ::= bexp COLON ID (queryBlock | WITH queryBlock?)?\r
669      */\r
670     protected abstract Object reduceEntityTypeAnnotation();\r
671     /**\r
672      * equationBlock ::= (equation (SEMICOLON equation)&#42;)?\r
673      */\r
674     protected abstract Object reduceEquationBlock();\r
675     /**\r
676      * declaration ::= (var COMMA)&#42; var HASTYPE type\r
677      */\r
678     protected abstract Object reduceTypeAnnotation();\r
679     /**\r
680      * declaration ::= bexp rhs\r
681      */\r
682     protected abstract Object reduceValueDefinition();\r
683     /**\r
684      * declaration ::= DATA ID ID&#42; (EQUALS (constructor BAR)&#42; constructor)?\r
685      */\r
686     protected abstract Object reduceDataDefinition();\r
687     /**\r
688      * declaration ::= TYPE ID ID&#42; EQUALS type\r
689      */\r
690     protected abstract Object reduceTypeDefinition();\r
691     /**\r
692      * declaration ::= CLASS context? ID ID&#42; (BAR fundeps | (BAR fundeps)? WHERE declarations)?\r
693      */\r
694     protected abstract Object reduceClassDefinition();\r
695     /**\r
696      * declaration ::= INSTANCE context? ID atype atype&#42; (WHERE declarations)?\r
697      */\r
698     protected abstract Object reduceInstanceDefinition();\r
699     /**\r
700      * declaration ::= DERIVING INSTANCE context? ID atype atype&#42;\r
701      */\r
702     protected abstract Object reduceDerivingInstanceDefinition();\r
703     /**\r
704      * declaration ::= BEGIN_STRING END_STRING\r
705      */\r
706     protected abstract Object reduceDocumentationString();\r
707     /**\r
708      * declaration ::= ANNOTATION_ID aexp&#42;\r
709      */\r
710     protected abstract Object reduceAnnotation();\r
711     /**\r
712      * declaration ::= (INFIX | INFIXL | INFIXR) INTEGER (var COMMA)&#42; var\r
713      */\r
714     protected abstract Object reducePrecedenceDefinition();\r
715     /**\r
716      * declaration ::= import\r
717      */\r
718     protected abstract Object reduceJustImport();\r
719     /**\r
720      * declaration ::= IMPORTJAVA BEGIN_STRING END_STRING WHERE declarations\r
721      */\r
722     protected abstract Object reduceImportJava();\r
723     /**\r
724      * declaration ::= EFFECT ID BEGIN_STRING END_STRING BEGIN_STRING END_STRING\r
725      */\r
726     protected abstract Object reduceEffectDefinition();\r
727     /**\r
728      * declaration ::= (RULE | ABSTRACT_RULE) ID (EXTENDS (ID COMMA)&#42; ID)? WHERE ruleDeclarations\r
729      */\r
730     protected abstract Object reduceRuleDefinition();\r
731     /**\r
732      * declaration ::= MAPPING_RELATION ID atype&#42;\r
733      */\r
734     protected abstract Object reduceMappingRelationDefinition();\r
735     /**\r
736      * declaration ::= bexp FOLLOWS ruleDeclarations\r
737      */\r
738     protected abstract Object reduceRelationDefinition();\r
739     /**\r
740      * command ::= statement\r
741      */\r
742     protected abstract Object reduceStatementCommand();\r
743     /**\r
744      * command ::= import\r
745      */\r
746     protected abstract Object reduceImportCommand();\r
747     /**\r
748      * statement ::= exp\r
749      */\r
750     protected abstract Object reduceGuardStatement();\r
751     /**\r
752      * statement ::= exp rhs\r
753      */\r
754     protected abstract Object reduceLetStatement();\r
755     /**\r
756      * statement ::= exp BINDS exp\r
757      */\r
758     protected abstract Object reduceBindStatement();\r
759     /**\r
760      * statement ::= exp FOLLOWS queryBlock\r
761      */\r
762     protected abstract Object reduceRuleStatement();\r
763     /**\r
764      * declarations ::= LBRACE (declaration (SEMICOLON (declaration SEMICOLON)&#42; declaration)?)? RBRACE\r
765      */\r
766     protected abstract Object reduceDeclarations();\r
767     /**\r
768      * var ::= ID\r
769      */\r
770     protected abstract Object reduceVarId();\r
771     /**\r
772      * var ::= ESCAPED_SYMBOL\r
773      */\r
774     protected abstract Object reduceEscapedSymbol();\r
775     /**\r
776      * var ::= LPAREN COMMA COMMA&#42; RPAREN\r
777      */\r
778     protected abstract Object reduceTupleConstructor();\r
779     /**\r
780      * bexp ::= MINUS? lexp (symbol lexp)&#42;\r
781      */\r
782     protected abstract Object reduceBinary();\r
783     /**\r
784      * rhs ::= EQUALS exp (WHERE statements)?\r
785      */\r
786     protected abstract Object reduceSimpleRhs();\r
787     /**\r
788      * rhs ::= guardedExpEq guardedExpEq&#42; (WHERE statements)?\r
789      */\r
790     protected abstract Object reduceGuardedRhs();\r
791     /**\r
792      * constructor ::= (ANNOTATION_ID aexp)&#42; ID atype&#42;\r
793      */\r
794     protected abstract Object reduceConstructor();\r
795     /**\r
796      * constructor ::= (ANNOTATION_ID aexp)&#42; ID LBRACE fieldDeclaration (COMMA fieldDeclaration)&#42; RBRACE\r
797      */\r
798     protected abstract Object reduceRecordConstructor();\r
799     /**\r
800      * context ::= LPAREN type (COMMA type)&#42; RPAREN IMPLIES\r
801      */\r
802     protected abstract Object reduceContext();\r
803     /**\r
804      * fundeps ::= (fundep COMMA)&#42; fundep\r
805      */\r
806     protected abstract Object reduceFundeps();\r
807     /**\r
808      * atype ::= ID\r
809      */\r
810     protected abstract Object reduceTypeVar();\r
811     /**\r
812      * atype ::= LPAREN (type (COMMA (type COMMA)&#42; type)?)? RPAREN\r
813      */\r
814     protected abstract Object reduceTupleType();\r
815     /**\r
816      * atype ::= LBRACKET type RBRACKET\r
817      */\r
818     protected abstract Object reduceListType();\r
819     /**\r
820      * atype ::= LBRACKET RBRACKET\r
821      */\r
822     protected abstract Object reduceListTypeConstructor();\r
823     /**\r
824      * atype ::= LPAREN COMMA COMMA&#42; RPAREN\r
825      */\r
826     protected abstract Object reduceTupleTypeConstructor();\r
827     /**\r
828      * aexp ::= LAMBDA aexp aexp&#42; ARROW exp\r
829      */\r
830     protected abstract Object reduceLambda();\r
831     /**\r
832      * aexp ::= LET statements IN exp\r
833      */\r
834     protected abstract Object reduceLet();\r
835     /**\r
836      * aexp ::= IF exp THEN exp ELSE exp\r
837      */\r
838     protected abstract Object reduceIf();\r
839     /**\r
840      * aexp ::= MATCH exp WITH LBRACE case (SEMICOLON case)&#42; RBRACE\r
841      */\r
842     protected abstract Object reduceMatch();\r
843     /**\r
844      * aexp ::= (DO | MDO) statements\r
845      */\r
846     protected abstract Object reduceDo();\r
847     /**\r
848      * aexp ::= (SELECT | SELECT_FIRST | SELECT_DISTINCT) exp WHERE queryBlock\r
849      */\r
850     protected abstract Object reduceSelect();\r
851     /**\r
852      * aexp ::= ENFORCE queryBlock\r
853      */\r
854     protected abstract Object reduceEnforce();\r
855     /**\r
856      * aexp ::= WHEN queryBlock SEMICOLON exp\r
857      */\r
858     protected abstract Object reduceWhen();\r
859     /**\r
860      * aexp ::= var\r
861      */\r
862     protected abstract Object reduceVar();\r
863     /**\r
864      * aexp ::= ATTACHED_HASH ID\r
865      */\r
866     protected abstract Object reduceHashedId();\r
867     /**\r
868      * aexp ::= BLANK\r
869      */\r
870     protected abstract Object reduceBlank();\r
871     /**\r
872      * aexp ::= INTEGER\r
873      */\r
874     protected abstract Object reduceInteger();\r
875     /**\r
876      * aexp ::= FLOAT\r
877      */\r
878     protected abstract Object reduceFloat();\r
879     /**\r
880      * aexp ::= stringLiteral\r
881      */\r
882     protected abstract Object reduceString();\r
883     /**\r
884      * aexp ::= CHAR\r
885      */\r
886     protected abstract Object reduceChar();\r
887     /**\r
888      * aexp ::= LPAREN (exp (COMMA (exp COMMA)&#42; exp)?)? RPAREN\r
889      */\r
890     protected abstract Object reduceTuple();\r
891     /**\r
892      * aexp ::= LPAREN symbolWithoutMinus lexp RPAREN\r
893      */\r
894     protected abstract Object reduceRightSection();\r
895     /**\r
896      * aexp ::= LPAREN lexp symbol RPAREN\r
897      */\r
898     protected abstract Object reduceLeftSection();\r
899     /**\r
900      * aexp ::= LBRACKET (exp (COMMA (exp COMMA)&#42; exp)?)? RBRACKET\r
901      */\r
902     protected abstract Object reduceListLiteral();\r
903     /**\r
904      * aexp ::= LBRACKET exp DOTDOT exp RBRACKET\r
905      */\r
906     protected abstract Object reduceRange();\r
907     /**\r
908      * aexp ::= LBRACKET exp BAR listQualifier (COMMA listQualifier)&#42; RBRACKET\r
909      */\r
910     protected abstract Object reduceListComprehension();\r
911     /**\r
912      * aexp ::= ID AT aexp\r
913      */\r
914     protected abstract Object reduceAs();\r
915     /**\r
916      * aexp ::= ID LBRACE (field (COMMA field)&#42;)? RBRACE\r
917      */\r
918     protected abstract Object reduceRecord();\r
919     /**\r
920      * aexp ::= TRANSFORMATION ID WHERE queryBlock\r
921      */\r
922     protected abstract Object reduceTransformation();\r
923     /**\r
924      * aexp ::= EQ LBRACE equationBlock RBRACE\r
925      */\r
926     protected abstract Object reduceEq();\r
927     /**\r
928      * ruleDeclarations ::= LBRACE (ruleDeclaration (SEMICOLON (ruleDeclaration SEMICOLON)&#42; ruleDeclaration)?)? RBRACE\r
929      */\r
930     protected abstract Object reduceRuleDeclarations();\r
931     /**\r
932      * importSpec ::= LPAREN (importItem (COMMA (importItem COMMA)&#42; importItem)?)? RPAREN\r
933      */\r
934     protected abstract Object reduceImportShowing();\r
935     /**\r
936      * importSpec ::= HIDING LPAREN (importItem (COMMA importItem)&#42;)? RPAREN\r
937      */\r
938     protected abstract Object reduceImportHiding();\r
939     /**\r
940      * importItem ::= ID\r
941      */\r
942     protected abstract Object reduceImportValueItem();\r
943     /**\r
944      * fieldDeclaration ::= ID HASTYPE type\r
945      */\r
946     protected abstract Object reduceFieldDescription();\r
947     /**\r
948      * statements ::= LBRACE (statement (SEMICOLON (statement SEMICOLON)&#42; statement)?)? RBRACE\r
949      */\r
950     protected abstract Object reduceStatements();\r
951     /**\r
952      * guardedExpEq ::= BAR exp (COMMA exp)&#42; EQUALS exp\r
953      */\r
954     protected abstract Object reduceGuardedExpEq();\r
955     /**\r
956      * fundep ::= ID ID&#42; ARROW ID\r
957      */\r
958     protected abstract Object reduceFundep();\r
959     /**\r
960      * ruleDeclaration ::= query\r
961      */\r
962     protected abstract Object reduceQueryRuleDeclaration();\r
963     /**\r
964      * query ::= exp\r
965      */\r
966     protected abstract Object reduceGuardQuery();\r
967     /**\r
968      * query ::= exp EQUALS exp\r
969      */\r
970     protected abstract Object reduceEqualsQuery();\r
971     /**\r
972      * query ::= exp BINDS exp\r
973      */\r
974     protected abstract Object reduceBindQuery();\r
975     /**\r
976      * query ::= QUERY_OP queryBlock\r
977      */\r
978     protected abstract Object reduceCompositeQuery();\r
979     /**\r
980      * queryBlock ::= LBRACE (query (SEMICOLON (query SEMICOLON)&#42; query)?)? RBRACE\r
981      */\r
982     protected abstract Object reduceQueryBlock();\r
983     /**\r
984      * lexp ::= faexp faexp&#42;\r
985      */\r
986     protected abstract Object reduceApply();\r
987     /**\r
988      * symbol ::= SYMBOL\r
989      */\r
990     protected abstract Object reduceSymbol();\r
991     /**\r
992      * symbol ::= ESCAPED_ID\r
993      */\r
994     protected abstract Object reduceEscapedId();\r
995     /**\r
996      * symbol ::= MINUS\r
997      */\r
998     protected abstract Object reduceMinus();\r
999     /**\r
1000      * symbol ::= LESS\r
1001      */\r
1002     protected abstract Object reduceLess();\r
1003     /**\r
1004      * symbol ::= GREATER\r
1005      */\r
1006     protected abstract Object reduceGreater();\r
1007     /**\r
1008      * symbol ::= SEPARATED_DOT\r
1009      */\r
1010     protected abstract Object reduceDot();\r
1011     /**\r
1012      * faexp ::= aexp ((ATTACHED_HASH | ATTACHED_DOT) accessor)&#42;\r
1013      */\r
1014     protected abstract Object reduceFieldAccess();\r
1015     /**\r
1016      * accessor ::= ID\r
1017      */\r
1018     protected abstract Object reduceIdAccessor();\r
1019     /**\r
1020      * accessor ::= BEGIN_STRING END_STRING\r
1021      */\r
1022     protected abstract Object reduceStringAccessor();\r
1023     /**\r
1024      * accessor ::= LPAREN exp RPAREN\r
1025      */\r
1026     protected abstract Object reduceExpAccessor();\r
1027     /**\r
1028      * case ::= exp caseRhs\r
1029      */\r
1030     protected abstract Object reduceCase();\r
1031     /**\r
1032      * stringLiteral ::= BEGIN_STRING (SUSPEND_STRING exp CONTINUE_STRING)&#42; END_STRING\r
1033      */\r
1034     protected abstract Object reduceStringLiteral();\r
1035     /**\r
1036      * listQualifier ::= exp\r
1037      */\r
1038     protected abstract Object reduceGuardQualifier();\r
1039     /**\r
1040      * listQualifier ::= exp EQUALS exp\r
1041      */\r
1042     protected abstract Object reduceLetQualifier();\r
1043     /**\r
1044      * listQualifier ::= exp BINDS exp\r
1045      */\r
1046     protected abstract Object reduceBindQualifier();\r
1047     /**\r
1048      * listQualifier ::= THEN exp (BY exp)?\r
1049      */\r
1050     protected abstract Object reduceThenQualifier();\r
1051     /**\r
1052      * field ::= ID EQUALS exp\r
1053      */\r
1054     protected abstract Object reduceField();\r
1055     /**\r
1056      * field ::= ID\r
1057      */\r
1058     protected abstract Object reduceFieldShorthand();\r
1059     /**\r
1060      * caseRhs ::= ARROW exp (WHERE statements)?\r
1061      */\r
1062     protected abstract Object reduceSimpleCaseRhs();\r
1063     /**\r
1064      * caseRhs ::= guardedExpArrow guardedExpArrow&#42; (WHERE statements)?\r
1065      */\r
1066     protected abstract Object reduceGuardedCaseRhs();\r
1067     /**\r
1068      * guardedExpArrow ::= BAR exp (COMMA exp)&#42; ARROW exp\r
1069      */\r
1070     protected abstract Object reduceGuardedExpArrow();\r
1071     /**\r
1072      * equation ::= exp\r
1073      */\r
1074     protected abstract Object reduceGuardEquation();\r
1075     /**\r
1076      * equation ::= exp EQUALS exp\r
1077      */\r
1078     protected abstract Object reduceBasicEquation();\r
1079     /**\r
1080      * etype ::= LESS ID (COMMA ID)&#42; GREATER btype\r
1081      */\r
1082     protected abstract Object reduceEffect();\r
1083     /**\r
1084      * etype ::= btype\r
1085      */\r
1086     protected abstract Object reduceJustEtype();\r
1087     /**\r
1088      * etype ::= FORALL ID ID&#42; (SEPARATED_DOT | ATTACHED_DOT) type\r
1089      */\r
1090     protected abstract Object reduceForAll();\r
1091     /**\r
1092      * btype ::= atype atype&#42;\r
1093      */\r
1094     protected abstract Object reduceApplyType();\r
1095     /**\r
1096      * dummy ::= COMMENT EOL\r
1097      */\r
1098     protected abstract Object reduceDummy1();\r
1099 \r
1100     protected void postReduce(Object reduced) {\r
1101     }\r
1102 \r
1103 }\r