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