options { JAVA_UNICODE_ESCAPE = true; } PARSER_BEGIN(InterfaceParser) public class InterfaceParser {} PARSER_END(InterfaceParser) SKIP : /* WHITE SPACE */ { " " | "\t" | "\n" | "\r" | "\f" } SPECIAL_TOKEN : /* COMMENTS */ { | | } TOKEN : { < LPAREN: "(" > | < RPAREN: ")" > | < LBRACE: "{" > | < RBRACE: "}" > | < SEMICOLON: ";" > | < LTE: "<=" > | < QUESTION: "?" > | < BOOLEAN: "boolean" > | < INTERFACE: "interface" > | < INTEGER: "int" > | < VOID: "void" > } TOKEN : /* LITERALS */ { < INTEGER_LITERAL: ( ["1"-"9"] (["0"-"9"])* | "0" ) > } TOKEN : /* IDENTIFIERS */ { < IDENTIFIER: (|)* > | < #LETTER: [ "\u0024", "\u0041"-"\u005a", "\u005f", "\u0061"-"\u007a", "\u00c0"-"\u00d6", "\u00d8"-"\u00f6", "\u00f8"-"\u00ff", "\u0100"-"\u1fff", "\u3040"-"\u318f", "\u3300"-"\u337f", "\u3400"-"\u3d2d", "\u4e00"-"\u9fff", "\uf900"-"\ufaff" ] > | < #DIGIT: [ "\u0030"-"\u0039", "\u0660"-"\u0669", "\u06f0"-"\u06f9", "\u0966"-"\u096f", "\u09e6"-"\u09ef", "\u0a66"-"\u0a6f", "\u0ae6"-"\u0aef", "\u0b66"-"\u0b6f", "\u0be7"-"\u0bef", "\u0c66"-"\u0c6f", "\u0ce6"-"\u0cef", "\u0d66"-"\u0d6f", "\u0e50"-"\u0e59", "\u0ed0"-"\u0ed9", "\u1040"-"\u1049" ] > } /************************************* * The Interface Grammar Starts Here * *************************************/ void Goal() : {} { ( Query() )* ( InterfaceDeclaration() )* } void Query() : {} { Identifier() "<=" Identifier() "?" } void InterfaceDeclaration() : {} { "interface" Identifier() InterfaceBody() } void InterfaceBody() : {} { "{" ( InterfaceMember() )* "}" } void InterfaceMember() : {} { ResultType() Identifier() "(" Type() Identifier() ")" ";" } void Type() : {} { BooleanType() | IntegerType() | Identifier() // the name of an interface } void BooleanType() : {} { "boolean" } void IntegerType() : {} { "int" } void ResultType() : {} { VoidType() | Type() } void VoidType() : {} { "void" } void Identifier() : {} { }