]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/parsing/parser/SCLParser.java
735974868ec8d4ae851d4490661b95eccf93bdd1
[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 = 345;
17     private static final int TERMINAL_COUNT = 83;
18     private static final int NONTERMINAL_COUNT = 51;
19     private static final int PRODUCT_COUNT = 132;
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[6360];
24     private static final int[] ERROR_TABLE = new int[895];
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[1711];
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         "MINUS",
76         "SYMBOL",
77         "LESS",
78         "GREATER",
79         "SEPARATED_DOT",
80         "ESCAPED_ID",
81         "LAMBDA",
82         "LAMBDA_MATCH",
83         "LET",
84         "IF",
85         "MATCH",
86         "DO",
87         "MDO",
88         "ENFORCE",
89         "BLANK",
90         "FLOAT",
91         "LBRACKET",
92         "ESCAPED_SYMBOL",
93         "CHAR",
94         "WHEN",
95         "ATTACHED_HASH",
96         "SELECT",
97         "SELECT_FIRST",
98         "SELECT_DISTINCT",
99         "TRANSFORMATION",
100         "EQ",
101         "ATTACHED_DOT",
102         "IN",
103         "THEN",
104         "ELSE",
105         "WITH",
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         "lexp",
153         "symbol",
154         "faexp",
155         "accessor",
156         "case",
157         "queryBlock",
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(330);
397     }
398     public Object parseImport() {
399         return parse(337);
400     }
401     public Object parseType() {
402         return parse(339);
403     }
404     public Object parseExp() {
405         return parse(341);
406     }
407     public Object parseEquationBlock() {
408         return parse(343);
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 reduceEquationBlock();
429         case 7:
430             return reduceModuleHeader();
431         case 8:
432             return reduceTypeAnnotation();
433         case 9:
434             return reduceValueDefinition();
435         case 10:
436             return reduceDataDefinition();
437         case 11:
438             return reduceTypeDefinition();
439         case 12:
440             return reduceClassDefinition();
441         case 13:
442             return reduceInstanceDefinition();
443         case 14:
444             return reduceDerivingInstanceDefinition();
445         case 15:
446             return reduceDocumentationString();
447         case 16:
448             return reduceAnnotation();
449         case 17:
450             return reducePrecedenceDefinition();
451         case 18:
452             return reduceJustImport();
453         case 19:
454             return reduceImportJava();
455         case 20:
456             return reduceEffectDefinition();
457         case 21:
458             return reduceRuleDefinition();
459         case 22:
460             return reduceMappingRelationDefinition();
461         case 23:
462             return reduceRelationDefinition();
463         case 24:
464             return reduceStatementCommand();
465         case 25:
466             return reduceImportCommand();
467         case 26:
468             return reduceGuardStatement();
469         case 27:
470             return reduceLetStatement();
471         case 28:
472             return reduceBindStatement();
473         case 29:
474             return reduceRuleStatement();
475         case 30:
476             return reduceCHRStatement();
477         case 31:
478             return reduceVerboseCHRStatement();
479         case 32:
480             return reduceConstraintStatement();
481         case 33:
482             return reduceDeclarations();
483         case 34:
484             return reduceField();
485         case 35:
486             return reduceFieldShorthand();
487         case 36:
488             return reduceVarId();
489         case 37:
490             return reduceEscapedSymbol();
491         case 38:
492             return reduceTupleConstructor();
493         case 39:
494             return reduceBinary();
495         case 40:
496             return reduceSimpleRhs();
497         case 41:
498             return reduceGuardedRhs();
499         case 42:
500             return reduceConstructor();
501         case 43:
502             return reduceRecordConstructor();
503         case 44:
504             return reduceContext();
505         case 45:
506             return reduceFundeps();
507         case 46:
508             return reduceTypeVar();
509         case 47:
510             return reduceTupleType();
511         case 48:
512             return reduceListType();
513         case 49:
514             return reduceListTypeConstructor();
515         case 50:
516             return reduceTupleTypeConstructor();
517         case 51:
518             return reduceLambda();
519         case 52:
520             return reduceLambdaMatch();
521         case 53:
522             return reduceLet();
523         case 54:
524             return reduceIf();
525         case 55:
526             return reduceMatch();
527         case 56:
528             return reduceDo();
529         case 57:
530             return reduceSelect();
531         case 58:
532             return reduceEnforce();
533         case 59:
534             return reduceVar();
535         case 60:
536             return reduceHashedId();
537         case 61:
538             return reduceBlank();
539         case 62:
540             return reduceInteger();
541         case 63:
542             return reduceFloat();
543         case 64:
544             return reduceString();
545         case 65:
546             return reduceChar();
547         case 66:
548             return reduceTuple();
549         case 67:
550             return reduceViewPattern();
551         case 68:
552             return reduceRightSection();
553         case 69:
554             return reduceLeftSection();
555         case 70:
556             return reduceListLiteral();
557         case 71:
558             return reduceRange();
559         case 72:
560             return reduceListComprehension();
561         case 73:
562             return reduceAs();
563         case 74:
564             return reduceRecord();
565         case 75:
566             return reduceTransformation();
567         case 76:
568             return reduceEq();
569         case 77:
570             return reduceRuleDeclarations();
571         case 78:
572             return reduceImportShowing();
573         case 79:
574             return reduceImportHiding();
575         case 80:
576             return reduceImportValueItem();
577         case 81:
578             return reduceFieldDescription();
579         case 82:
580             return reduceStatements();
581         case 83:
582             return reduceGuardedExpEq();
583         case 84:
584             return reduceFundep();
585         case 85:
586             return reduceQueryRuleDeclaration();
587         case 86:
588             return reduceAnnotation();
589         case 87:
590             return reduceGuardQuery();
591         case 88:
592             return reduceEqualsQuery();
593         case 89:
594             return reduceBindQuery();
595         case 90:
596             return reduceCompositeQuery();
597         case 91:
598             return reduceApply();
599         case 92:
600             return reduceSymbol();
601         case 93:
602             return reduceEscapedId();
603         case 94:
604             return reduceMinus();
605         case 95:
606             return reduceLess();
607         case 96:
608             return reduceGreater();
609         case 97:
610             return reduceDot();
611         case 98:
612             return reduceFieldAccess();
613         case 99:
614             return reduceIdAccessor();
615         case 100:
616             return reduceStringAccessor();
617         case 101:
618             return reduceExpAccessor();
619         case 102:
620             return reduceCase();
621         case 103:
622             return reduceQueryBlock();
623         case 104:
624             return reduceStringLiteral();
625         case 105:
626             return reduceSymbol();
627         case 106:
628             return reduceEscapedId();
629         case 107:
630             return reduceLess();
631         case 108:
632             return reduceGreater();
633         case 109:
634             return reduceDot();
635         case 110:
636             return reduceGuardQualifier();
637         case 111:
638             return reduceLetQualifier();
639         case 112:
640             return reduceBindQualifier();
641         case 113:
642             return reduceThenQualifier();
643         case 114:
644             return reduceCHRQuery();
645         case 115:
646             return reduceVerboseCHRQuery();
647         case 116:
648             return reduceSimpleCaseRhs();
649         case 117:
650             return reduceGuardedCaseRhs();
651         case 118:
652             return reduceGuardedExpArrow();
653         case 119:
654             return reduceGuardEquation();
655         case 120:
656             return reduceBasicEquation();
657         case 121:
658             return reduceEffect();
659         case 122:
660             return reduceJustEtype();
661         case 123:
662             return reduceForAll();
663         case 124:
664             return reduceApplyType();
665         case 125:
666             return reduceDummy();
667
668         default:
669             throw new RuntimeException("Internal parser error.");
670         }
671         } catch(SCLSyntaxErrorException e) {
672             StringBuilder b = new StringBuilder();
673             b.append("Failed to reduce");
674             for(int i=0;i<length();++i) {
675                 Object obj = get(i);
676                 b.append("\n    (").append(i).append(") \"").append(obj).append('\"');
677                 if(obj instanceof Token)
678                     b.append(" (").append(TERMINAL_NAMES[((Token)obj).id]).append(")");
679                 else
680                     b.append(" [").append(obj.getClass().getSimpleName()).append("]");
681             }
682             throw new RuntimeException(b.toString(), e);
683         } 
684     }
685
686     /**
687      * module ::= (declaration (SEMICOLON declaration)&#42;)?
688      */
689     protected abstract Object reduceModule();
690     /**
691      * commands ::= command?
692      */
693     protected abstract Object reduceOneCommand();
694     /**
695      * commands ::= commands SEMICOLON command
696      */
697     protected abstract Object reduceManyCommands();
698     /**
699      * import ::= (IMPORT | INCLUDE) BEGIN_STRING END_STRING (AS ID)? importSpec?
700      */
701     protected abstract Object reduceImport();
702     /**
703      * type ::= (etype (ARROW | IMPLIES))&#42; etype
704      */
705     protected abstract Object reduceArrow();
706     /**
707      * exp ::= bexp (HASTYPE type)?
708      */
709     protected abstract Object reduceLocalTypeAnnotation();
710     /**
711      * equationBlock ::= (equation (SEMICOLON equation)&#42;)?
712      */
713     protected abstract Object reduceEquationBlock();
714     /**
715      * declaration ::= MODULE LBRACE (field (COMMA field)&#42;)? RBRACE
716      */
717     protected abstract Object reduceModuleHeader();
718     /**
719      * declaration ::= (var COMMA)&#42; var HASTYPE type
720      */
721     protected abstract Object reduceTypeAnnotation();
722     /**
723      * declaration ::= bexp rhs
724      */
725     protected abstract Object reduceValueDefinition();
726     /**
727      * declaration ::= DATA ID ID&#42; (EQUALS (constructor BAR)&#42; constructor)?
728      */
729     protected abstract Object reduceDataDefinition();
730     /**
731      * declaration ::= TYPE ID ID&#42; EQUALS type
732      */
733     protected abstract Object reduceTypeDefinition();
734     /**
735      * declaration ::= CLASS context? ID ID&#42; (BAR fundeps | (BAR fundeps)? WHERE declarations)?
736      */
737     protected abstract Object reduceClassDefinition();
738     /**
739      * declaration ::= INSTANCE context? ID atype atype&#42; (WHERE declarations)?
740      */
741     protected abstract Object reduceInstanceDefinition();
742     /**
743      * declaration ::= DERIVING INSTANCE context? ID atype atype&#42;
744      */
745     protected abstract Object reduceDerivingInstanceDefinition();
746     /**
747      * declaration ::= BEGIN_STRING END_STRING
748      */
749     protected abstract Object reduceDocumentationString();
750     /**
751      * declaration ::= ANNOTATION_ID aexp&#42;
752      */
753     protected abstract Object reduceAnnotation();
754     /**
755      * declaration ::= (INFIX | INFIXL | INFIXR) INTEGER (var COMMA)&#42; var
756      */
757     protected abstract Object reducePrecedenceDefinition();
758     /**
759      * declaration ::= import
760      */
761     protected abstract Object reduceJustImport();
762     /**
763      * declaration ::= IMPORTJAVA BEGIN_STRING END_STRING WHERE declarations
764      */
765     protected abstract Object reduceImportJava();
766     /**
767      * declaration ::= EFFECT ID BEGIN_STRING END_STRING BEGIN_STRING END_STRING
768      */
769     protected abstract Object reduceEffectDefinition();
770     /**
771      * declaration ::= (RULE | ABSTRACT_RULE) ID (EXTENDS (ID COMMA)&#42; ID)? WHERE ruleDeclarations
772      */
773     protected abstract Object reduceRuleDefinition();
774     /**
775      * declaration ::= MAPPING_RELATION ID atype&#42;
776      */
777     protected abstract Object reduceMappingRelationDefinition();
778     /**
779      * declaration ::= bexp FOLLOWS ruleDeclarations
780      */
781     protected abstract Object reduceRelationDefinition();
782     /**
783      * command ::= statement
784      */
785     protected abstract Object reduceStatementCommand();
786     /**
787      * command ::= import
788      */
789     protected abstract Object reduceImportCommand();
790     /**
791      * statement ::= exp
792      */
793     protected abstract Object reduceGuardStatement();
794     /**
795      * statement ::= exp rhs
796      */
797     protected abstract Object reduceLetStatement();
798     /**
799      * statement ::= exp BINDS exp
800      */
801     protected abstract Object reduceBindStatement();
802     /**
803      * statement ::= exp FOLLOWS queryBlock
804      */
805     protected abstract Object reduceRuleStatement();
806     /**
807      * statement ::= chrQuery IMPLIES chrQuery
808      */
809     protected abstract Object reduceCHRStatement();
810     /**
811      * statement ::= WHEN verboseChrQuery THEN_AFTER_WHEN verboseChrQuery
812      */
813     protected abstract Object reduceVerboseCHRStatement();
814     /**
815      * statement ::= CONSTRAINT ID atype&#42;
816      */
817     protected abstract Object reduceConstraintStatement();
818     /**
819      * declarations ::= LBRACE (declaration (SEMICOLON (declaration SEMICOLON)&#42; declaration)?)? RBRACE
820      */
821     protected abstract Object reduceDeclarations();
822     /**
823      * field ::= ID EQUALS exp
824      */
825     protected abstract Object reduceField();
826     /**
827      * field ::= ID
828      */
829     protected abstract Object reduceFieldShorthand();
830     /**
831      * var ::= ID
832      */
833     protected abstract Object reduceVarId();
834     /**
835      * var ::= ESCAPED_SYMBOL
836      */
837     protected abstract Object reduceEscapedSymbol();
838     /**
839      * var ::= LPAREN COMMA COMMA&#42; RPAREN
840      */
841     protected abstract Object reduceTupleConstructor();
842     /**
843      * bexp ::= MINUS? lexp (symbol lexp)&#42;
844      */
845     protected abstract Object reduceBinary();
846     /**
847      * rhs ::= EQUALS exp (WHERE statements)?
848      */
849     protected abstract Object reduceSimpleRhs();
850     /**
851      * rhs ::= guardedExpEq guardedExpEq&#42; (WHERE statements)?
852      */
853     protected abstract Object reduceGuardedRhs();
854     /**
855      * constructor ::= (ANNOTATION_ID aexp)&#42; ID atype&#42;
856      */
857     protected abstract Object reduceConstructor();
858     /**
859      * constructor ::= (ANNOTATION_ID aexp)&#42; ID LBRACE fieldDeclaration (COMMA fieldDeclaration)&#42; RBRACE
860      */
861     protected abstract Object reduceRecordConstructor();
862     /**
863      * context ::= LPAREN type (COMMA type)&#42; RPAREN IMPLIES
864      */
865     protected abstract Object reduceContext();
866     /**
867      * fundeps ::= (fundep COMMA)&#42; fundep
868      */
869     protected abstract Object reduceFundeps();
870     /**
871      * atype ::= ID
872      */
873     protected abstract Object reduceTypeVar();
874     /**
875      * atype ::= LPAREN (type (COMMA (type COMMA)&#42; type)?)? RPAREN
876      */
877     protected abstract Object reduceTupleType();
878     /**
879      * atype ::= LBRACKET type RBRACKET
880      */
881     protected abstract Object reduceListType();
882     /**
883      * atype ::= LBRACKET RBRACKET
884      */
885     protected abstract Object reduceListTypeConstructor();
886     /**
887      * atype ::= LPAREN COMMA COMMA&#42; RPAREN
888      */
889     protected abstract Object reduceTupleTypeConstructor();
890     /**
891      * aexp ::= LAMBDA aexp aexp&#42; ARROW exp
892      */
893     protected abstract Object reduceLambda();
894     /**
895      * aexp ::= LAMBDA_MATCH LBRACE case (SEMICOLON case)&#42; RBRACE
896      */
897     protected abstract Object reduceLambdaMatch();
898     /**
899      * aexp ::= LET statements IN exp
900      */
901     protected abstract Object reduceLet();
902     /**
903      * aexp ::= IF exp THEN exp (ELSE exp)?
904      */
905     protected abstract Object reduceIf();
906     /**
907      * aexp ::= MATCH exp WITH LBRACE case (SEMICOLON case)&#42; RBRACE
908      */
909     protected abstract Object reduceMatch();
910     /**
911      * aexp ::= (DO | MDO) statements
912      */
913     protected abstract Object reduceDo();
914     /**
915      * aexp ::= (SELECT | SELECT_FIRST | SELECT_DISTINCT) exp WHERE queryBlock
916      */
917     protected abstract Object reduceSelect();
918     /**
919      * aexp ::= ENFORCE queryBlock
920      */
921     protected abstract Object reduceEnforce();
922     /**
923      * aexp ::= var
924      */
925     protected abstract Object reduceVar();
926     /**
927      * aexp ::= ATTACHED_HASH ID
928      */
929     protected abstract Object reduceHashedId();
930     /**
931      * aexp ::= BLANK
932      */
933     protected abstract Object reduceBlank();
934     /**
935      * aexp ::= INTEGER
936      */
937     protected abstract Object reduceInteger();
938     /**
939      * aexp ::= FLOAT
940      */
941     protected abstract Object reduceFloat();
942     /**
943      * aexp ::= stringLiteral
944      */
945     protected abstract Object reduceString();
946     /**
947      * aexp ::= CHAR
948      */
949     protected abstract Object reduceChar();
950     /**
951      * aexp ::= LPAREN (exp (COMMA (exp COMMA)&#42; exp)?)? RPAREN
952      */
953     protected abstract Object reduceTuple();
954     /**
955      * aexp ::= LPAREN exp ARROW exp RPAREN
956      */
957     protected abstract Object reduceViewPattern();
958     /**
959      * aexp ::= LPAREN symbolWithoutMinus lexp RPAREN
960      */
961     protected abstract Object reduceRightSection();
962     /**
963      * aexp ::= LPAREN lexp symbol RPAREN
964      */
965     protected abstract Object reduceLeftSection();
966     /**
967      * aexp ::= LBRACKET (exp (COMMA (exp COMMA)&#42; exp)?)? RBRACKET
968      */
969     protected abstract Object reduceListLiteral();
970     /**
971      * aexp ::= LBRACKET exp DOTDOT exp RBRACKET
972      */
973     protected abstract Object reduceRange();
974     /**
975      * aexp ::= LBRACKET exp BAR listQualifier (COMMA listQualifier)&#42; RBRACKET
976      */
977     protected abstract Object reduceListComprehension();
978     /**
979      * aexp ::= ID AT aexp
980      */
981     protected abstract Object reduceAs();
982     /**
983      * aexp ::= ID LBRACE (field (COMMA field)&#42;)? RBRACE
984      */
985     protected abstract Object reduceRecord();
986     /**
987      * aexp ::= TRANSFORMATION ID WHERE queryBlock
988      */
989     protected abstract Object reduceTransformation();
990     /**
991      * aexp ::= EQ LBRACE equationBlock RBRACE
992      */
993     protected abstract Object reduceEq();
994     /**
995      * ruleDeclarations ::= LBRACE (ruleDeclaration (SEMICOLON (ruleDeclaration SEMICOLON)&#42; ruleDeclaration)?)? RBRACE
996      */
997     protected abstract Object reduceRuleDeclarations();
998     /**
999      * importSpec ::= LPAREN (importItem (COMMA (importItem COMMA)&#42; importItem)?)? RPAREN
1000      */
1001     protected abstract Object reduceImportShowing();
1002     /**
1003      * importSpec ::= HIDING LPAREN (importItem (COMMA importItem)&#42;)? RPAREN
1004      */
1005     protected abstract Object reduceImportHiding();
1006     /**
1007      * importItem ::= ID
1008      */
1009     protected abstract Object reduceImportValueItem();
1010     /**
1011      * fieldDeclaration ::= ID HASTYPE type
1012      */
1013     protected abstract Object reduceFieldDescription();
1014     /**
1015      * statements ::= LBRACE (statement (SEMICOLON (statement SEMICOLON)&#42; statement)?)? RBRACE
1016      */
1017     protected abstract Object reduceStatements();
1018     /**
1019      * guardedExpEq ::= BAR exp (COMMA exp)&#42; EQUALS exp
1020      */
1021     protected abstract Object reduceGuardedExpEq();
1022     /**
1023      * fundep ::= ID ID&#42; ARROW ID
1024      */
1025     protected abstract Object reduceFundep();
1026     /**
1027      * ruleDeclaration ::= query
1028      */
1029     protected abstract Object reduceQueryRuleDeclaration();
1030     /**
1031      * query ::= exp
1032      */
1033     protected abstract Object reduceGuardQuery();
1034     /**
1035      * query ::= exp EQUALS exp
1036      */
1037     protected abstract Object reduceEqualsQuery();
1038     /**
1039      * query ::= exp BINDS exp
1040      */
1041     protected abstract Object reduceBindQuery();
1042     /**
1043      * query ::= QUERY_OP queryBlock
1044      */
1045     protected abstract Object reduceCompositeQuery();
1046     /**
1047      * lexp ::= faexp faexp&#42;
1048      */
1049     protected abstract Object reduceApply();
1050     /**
1051      * symbol ::= SYMBOL
1052      */
1053     protected abstract Object reduceSymbol();
1054     /**
1055      * symbol ::= ESCAPED_ID
1056      */
1057     protected abstract Object reduceEscapedId();
1058     /**
1059      * symbol ::= MINUS
1060      */
1061     protected abstract Object reduceMinus();
1062     /**
1063      * symbol ::= LESS
1064      */
1065     protected abstract Object reduceLess();
1066     /**
1067      * symbol ::= GREATER
1068      */
1069     protected abstract Object reduceGreater();
1070     /**
1071      * symbol ::= SEPARATED_DOT
1072      */
1073     protected abstract Object reduceDot();
1074     /**
1075      * faexp ::= aexp ((ATTACHED_HASH | ATTACHED_DOT) accessor)&#42;
1076      */
1077     protected abstract Object reduceFieldAccess();
1078     /**
1079      * accessor ::= ID
1080      */
1081     protected abstract Object reduceIdAccessor();
1082     /**
1083      * accessor ::= BEGIN_STRING END_STRING
1084      */
1085     protected abstract Object reduceStringAccessor();
1086     /**
1087      * accessor ::= LPAREN exp RPAREN
1088      */
1089     protected abstract Object reduceExpAccessor();
1090     /**
1091      * case ::= exp caseRhs
1092      */
1093     protected abstract Object reduceCase();
1094     /**
1095      * queryBlock ::= LBRACE (query (SEMICOLON (query SEMICOLON)&#42; query)?)? RBRACE
1096      */
1097     protected abstract Object reduceQueryBlock();
1098     /**
1099      * stringLiteral ::= BEGIN_STRING (SUSPEND_STRING exp CONTINUE_STRING)&#42; END_STRING
1100      */
1101     protected abstract Object reduceStringLiteral();
1102     /**
1103      * listQualifier ::= exp
1104      */
1105     protected abstract Object reduceGuardQualifier();
1106     /**
1107      * listQualifier ::= exp EQUALS exp
1108      */
1109     protected abstract Object reduceLetQualifier();
1110     /**
1111      * listQualifier ::= exp BINDS exp
1112      */
1113     protected abstract Object reduceBindQualifier();
1114     /**
1115      * listQualifier ::= THEN exp (BY exp)?
1116      */
1117     protected abstract Object reduceThenQualifier();
1118     /**
1119      * chrQuery ::= (listQualifier COMMA)&#42; listQualifier
1120      */
1121     protected abstract Object reduceCHRQuery();
1122     /**
1123      * verboseChrQuery ::= LBRACE listQualifier (SEMICOLON listQualifier)&#42; RBRACE
1124      */
1125     protected abstract Object reduceVerboseCHRQuery();
1126     /**
1127      * caseRhs ::= ARROW exp (WHERE statements)?
1128      */
1129     protected abstract Object reduceSimpleCaseRhs();
1130     /**
1131      * caseRhs ::= guardedExpArrow guardedExpArrow&#42; (WHERE statements)?
1132      */
1133     protected abstract Object reduceGuardedCaseRhs();
1134     /**
1135      * guardedExpArrow ::= BAR exp (COMMA exp)&#42; ARROW exp
1136      */
1137     protected abstract Object reduceGuardedExpArrow();
1138     /**
1139      * equation ::= exp
1140      */
1141     protected abstract Object reduceGuardEquation();
1142     /**
1143      * equation ::= exp EQUALS exp
1144      */
1145     protected abstract Object reduceBasicEquation();
1146     /**
1147      * etype ::= LESS ID (COMMA ID)&#42; GREATER btype
1148      */
1149     protected abstract Object reduceEffect();
1150     /**
1151      * etype ::= btype
1152      */
1153     protected abstract Object reduceJustEtype();
1154     /**
1155      * etype ::= FORALL ID ID&#42; (SEPARATED_DOT | ATTACHED_DOT) type
1156      */
1157     protected abstract Object reduceForAll();
1158     /**
1159      * btype ::= atype atype&#42;
1160      */
1161     protected abstract Object reduceApplyType();
1162     /**
1163      * dummy ::= COMMENT EOL
1164      */
1165     protected abstract Object reduceDummy();
1166
1167     protected void postReduce(Object reduced) {
1168     }
1169
1170 }