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