- /*
- * parser.cup -- SPL parser specification
- */
- package parse;
- import java_cup.runtime.*;
- parser code {:
- public void syntax_error(Symbol currToken) {
- System.out.println(
- "**** Error: syntax error" +
- " in line " + currToken.left +
- ", column " + currToken.right
- );
- System.exit(0);
- }
- :}
- /* Terminals (tokens returned by lexer). */
- terminal LPAREN, RPAREN, LBRACK, RBRACK, LCURL, RCURL;
- terminal EQ, NE, LT, LE, GT, GE;
- terminal ASGN, COLON, COMMA, SEMIC;
- terminal PLUS, MINUS, STAR, SLASH;
- terminal String IDENT;
- terminal Integer INTLIT;
- terminal WHILE, ELSE, OF, IF, ARRAY, PROC, REF, TYPE, VAR;
- /*non terminals*/
- non terminal program;
- non terminal anweisungen, anweisung, kommando;
- non terminal zuweisung, ausdruck, deklaration, deklarationen, typdef;
- non terminal schleife, elif, funkaufruf, funkkopf, feld, funksignatur, funkdef, feldtyp;
- non terminal bedingung, parameterliste, parameter, verglop;
- non terminal mulop1, addop1;
- /* Startzeichen*/
- start with program;
- /*Regeln*/
- program ::= deklarationen anweisungen funkdef;
- anweisungen ::= anweisung anweisungen |;
- anweisung ::= kommando SEMIC | schleife | elif;
- zuweisung ::= IDENT ASGN ausdruck;
- ausdruck ::= INTLIT | IDENT | mulop1 | addop1;
- kommando ::= zuweisung | funkaufruf | typdef;
- funkdef ::= PROC funksignatur LCURL deklarationen anweisungen RCURL |;
- funksignatur ::= IDENT LPAREN funkkopf RPAREN;
- funkkopf ::= | parameterliste;
- deklarationen ::= deklaration deklarationen |;
- deklaration ::= VAR IDENT COLON IDENT SEMIC;
- parameterliste ::= parameter | parameter COMMA parameterliste;
- parameter ::= IDENT COLON IDENT|REF IDENT COLON IDENT;
- mulop1 ::= LPAREN ausdruck STAR ausdruck RPAREN
- | LPAREN ausdruck SLASH ausdruck RPAREN;
- addop1 ::= LPAREN ausdruck PLUS ausdruck RPAREN
- | LPAREN ausdruck MINUS ausdruck RPAREN;
- typdef ::= TYPE IDENT EQ IDENT | feld;
- feld ::= ARRAY LBRACK ausdruck RBRACK OF feldtyp;
- feldtyp ::= IDENT | feld ;
- elif ::= IF LPAREN bedingung RPAREN LCURL anweisungen RCURL ELSE LCURL anweisungen RCURL;
- elif ::= IF LPAREN bedingung RPAREN LCURL anweisungen RCURL;
- bedingung ::= IDENT verglop ausdruck;
- verglop ::= EQ | NE | LT | LE | GT | GE;
- schleife ::= WHILE LPAREN bedingung RPAREN LCURL anweisungen RCURL;