/* This file defines a parser for the propositional calculus */ import java_cup.runtime.*; import truthtable.*; // truth table abstract syntax and semantic classes action code {: /* things you want to use in the bottom portion goes here */ :} parser code {: /* these variables must be declared here: */ String intext; // concrete syntax typed in by user Yylex scanner; // scanner object :}; init with {: try { /* Get Input, form lexer: */ java.io.InputStreamReader lr = new java.io.InputStreamReader(System.in); java.io.BufferedReader lineinput = new java.io.BufferedReader(lr); /* didn't figure out how to pass in input from the main program: */ System.out.print("Enter Propositional Sentence: "); intext = lineinput.readLine(); } catch (Exception ee) {} /* scanner needs an input stream */ scanner = new Yylex(new java.io.StringBufferInputStream(intext)); :}; scan with {: return scanner.next_token(); :}; /* grammer symbols: */ /* types are defined in truthtable.java */ /* (abstract) type 'proposition' is type of syntax tree node */ /* "0" is false, "1" is true. */ terminal String LETTER; /* String is the real type of the "Object" stored in the "value" field of a LETTER "Symbol". */ /* define reset of grammar symbols here... */ /* don't forget the precedence relations here... */ /* the grammer and actions to build abstract syntax tree goes here: */ /* remember that in an "CONST:e1", e1 is the "Object" associated with symbol CONST, which is in fact a "String". This argument is stored in the "value" field of the "Symbol" class. */ EXP ::= CONST:s1 {: RESULT = new constantProp(s1); :} ....