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