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