import java_cup.runtime.*; import java.io.*; /* regular languages parser for CUP. * Copyright (C) 2006 Silvano Rivoira * This program is released under the terms of the GPL; see the file * COPYING for more details. There is NO WARRANTY on this code. */ parser code {: public static void main(String argv[]) { for (int i = 0; i < argv.length; i++) { try { System.out.println("Parsing ["+argv[i]+"]"); Scanner s = new Scanner(new FileReader(argv[i])); rlac p = new rlac(s); p.parse(); System.out.println("No errors."); } catch (Exception e) { e.printStackTrace(System.out); System.exit(1); } } } public void report_error(String message, Object info) { StringBuffer m = new StringBuffer("Error "); if (info instanceof java_cup.runtime.Symbol) m.append( "("+info.toString()+")" ); m.append(" : "+message); System.err.println(m); } public void report_fatal_error(String message, Object info) { report_error(message, info); throw new RuntimeException("Fatal Syntax Error"); } :}; terminal LALPHA, RALPHA, LDEF, RDEF, LPAREN, RPAREN, LBRACK, RBRACK, COMMA; terminal EMPTY; terminal NOT, PROD, PLUS, MINUS, UNION, STAR; terminal EQ, EQUESTION, INQUESTION; terminal ILLEGAL_CHARACTER; terminal java.lang.String IDENTIFIER, INPUTSYMBOL; non terminal goal; non terminal alphabet_declaration, expression_declaration, input_symbols, regular_definitions, regular_definition; non terminal evaluations, evaluation, string, expression, prod_expression, unary_expression, symbol; non terminal regular_expression, conc_expression, closure_expression, paren_expression; start with goal; goal ::= alphabet_declaration expression_declaration evaluations ; alphabet_declaration ::= LALPHA input_symbols RALPHA ; input_symbols ::= INPUTSYMBOL | input_symbols COMMA INPUTSYMBOL ; expression_declaration ::= | LDEF regular_definitions RDEF ; regular_definitions ::= | regular_definitions regular_definition ; regular_definition ::= IDENTIFIER EQ expression ; evaluations ::= | evaluations evaluation ; evaluation ::= IDENTIFIER EQUESTION IDENTIFIER | IDENTIFIER INQUESTION IDENTIFIER | LPAREN string RPAREN INQUESTION IDENTIFIER | LPAREN RPAREN INQUESTION IDENTIFIER ; string ::= INPUTSYMBOL | string INPUTSYMBOL | EMPTY ; expression ::= prod_expression | expression PLUS prod_expression | expression MINUS prod_expression ; prod_expression ::= unary_expression | prod_expression PROD unary_expression ; unary_expression ::= LBRACK regular_expression RBRACK | LBRACK expression RBRACK | NOT unary_expression ; regular_expression ::= conc_expression | EMPTY UNION conc_expression | regular_expression UNION conc_expression ; conc_expression ::= closure_expression | conc_expression closure_expression ; closure_expression ::= symbol | paren_expression | symbol STAR | paren_expression STAR ; symbol ::= INPUTSYMBOL | IDENTIFIER ; paren_expression ::= LPAREN regular_expression RPAREN ;