/* * * RPC grammar for JavaCC * * Contributed by Adelene Ng (awln@asia1.com> * * Date: 06/26/01 * Version: 01 * * References: * 1. XDR: External Data Representation Standard, rfc1832, R. Srinivasan, * Aug 1995 * 2. RPC: Remote Procedure Call Specification Version 2, rfc1831, * R. Srinivasan, Aug 1995 * 3. Power Programming with RPC, John Bloomer, O'Reilly * */ options { LOOKAHEAD = 2; } PARSER_BEGIN(rpc) public class rpc { public static void main(String args[]) { rpc rpcparser; if(args.length == 0) { System.out.println("RPC Parser Version 0.1 Alpha: Reading from standard input . . ."); rpcparser = new rpc(System.in); } else if(args.length == 1) { System.out.println("RPC Parser Version 0.1 Alpha: Reading from file " + args[0] + " . . ." ); try { rpcparser = new rpc(new java.io.FileInputStream(args[0])); } catch(java.io.FileNotFoundException e) { System.out.println("RPC Parser Version 0.1: File " + args[0] + " not found."); return ; } } else { System.out.println("RPC Parser Version 0.1Alpha: Usage is one of:"); System.out.println(" java rpc < inputfile"); System.out.println("OR"); System.out.println(" java rpc inputfile"); return ; } try { rpcparser.TranslationUnit(); System.out.println("RPC Parser Version 0.1 Alpha: RPC program parsed successfully."); } catch(ParseException e){ System.out.println("RPC Parser Version 0.1 Alpha: Encountered errors during parse."); } } } PARSER_END(rpc) SKIP : { " " | "\t" | "\n" | "\r" | <"//" (~["\n","\r"])* ("\n" | "\r" | "\r\n")> | <"/*" (~["*"])* "*" ("*" | ~["*","/"] (~["*"])* "*")* "/"> } TOKEN : { | | | | | | | | | | | | | | | | | | | } TOKEN : { ( | )*> | <#LETTER: ["$","A"-"Z","_","a"-"z"]> | <#DIGIT: ["0"-"9"]> } TOKEN : { )+> } void TranslationUnit() : { } { //specification() [program_def()] specification() specification() } void declaration() : { } { (type_specifier() ( "*" )* [ ("[" value() "]") ] [ ("<" [ value() ] ">") ]) | ( (("[" value() "]") | ("<" (value())* ">")) ) | ( "<" (value())* ">" ) | } void value() : { } { | } void type_specifier() : { } { (()* ) | (()* ) | | | | | | | enum_type_spec() | struct_type_spec() | union_type_spec() } void enum_type_spec() : { } { enum_body() } void enum_body() : { } { "{" ( "=" value()) ( "," "=" value())* "}" } void struct_type_spec() : { } { struct_body() } void struct_body() : { } { "{" (declaration() ";") (declaration() ";")* "}" } void union_type_spec() : { } { union_body() } void union_body() : { } { "(" declaration() ")" "{" ( value() ":" declaration() ";") ( value() ":" declaration() ";")* ( ":" declaration() ";")* "}" } void constant_def() : { } { "=" ";" } void type_def() : { } { ( declaration() ";") | ( enum_body() ";") | ( struct_body() ";") | ( union_body() ";") } void definition() : { } { type_def() | constant_def() | program_def() } void specification() : { } { (definition())+ } void program_def() : { } { "{" version_def() [ version_def() ] "}" "=" ";" } void version_def() : { } { "{" procedure_def() [ procedure_def() ] "}" "=" ";" } void procedure_def() : { } { type_specifier() "(" type_specifier() ( "," type_specifier() )* ")" "=" ";" }