options { UNICODE_INPUT = true; ERROR_REPORTING = true; USER_CHAR_STREAM = true; STATIC = false; JDK_VERSION = "1.5"; FORCE_LA_CHECK = true; } PARSER_BEGIN(XampilParser) package org.codecover.instrumentation.xampil.parser; public class XampilParser { } PARSER_END(XampilParser) /* * TOKENS */ SPECIAL_TOKEN : { < SPACE_CHAR: " " | "\t" | "\f" > } SPECIAL_TOKEN : { < SINGLE_LINE_COMMENT: "//" (~["\n", "\r"])* ("\n" | "\r" | "\n\r")? > } TOKEN : { < EOL: ("\n" | "\r" | "\n\r") ("\n" | "\r" | "\n\r" | " " | "\t" | "\f")* > } TOKEN : { < DECLARATION: "DECLARATION" > | < PROGRAM: "PROGRAM" > | < ENDPROGRAM: "ENDPROGRAM" > | < BOOLEAN: "BOOLEAN" > | < INTEGER: "INTEGER" > | < STRING: "STRING" > | < IF: "IF" > | < THEN: "THEN" > | < ELSE: "ELSE" > | < ENDIF: "ENDIF" > | < WHILE: "WHILE" > | < DO: "DO" > | < ENDWHILE: "ENDWHILE" > | < SWITCH: "SWITCH" > | < CASE: "CASE" > | < CASE_DEFAULT: "DEFAULT" > | < ENDCASE: "ENDCASE" > | < ENDSWITCH: "ENDSWITCH" > | < FILE: "FILE" > | < OVERWRITE: "OVERWRITE" > | < APPEND: "APPEND" > | < AND: "AND" > | < OR: "OR" > | < NOT: "NOT" > | < TRUE: "TRUE" > | < FALSE: "FALSE" > } TOKEN : { < LPAREN: "(" > | < RPAREN: ")" > | < COLON: ":" > | < ASSIGN: ":=" > | < EQ: "=" > | < NEQ: "<>" > | < LT: "<" > | < GT: ">" > | < LE: "<=" > | < GE: ">=" > | < PLUS: "+" > | < MINUS: "-" > | < STAR: "*" > | < SLASH: "/" > } TOKEN : { < IDENTIFIER: ( ["a"-"z"] | ["A"-"Z"] ) ( ["a"-"z"] | ["A"-"Z"] | ["0"-"9"] | "_" )* > } TOKEN : { < INTEGER_LITERAL: ( ( )? ["1"-"9"] (["0"-"9"])* ) | "0" > | < STRING_LITERAL: "\"" ( ( ~["\"","\\","\n","\r"] ) | ( "\\" ["n", "t", "b", "r", "f", "\\", "'", "\""] ) )* "\"" > } /* * SYNTAX */ void CompilationUnit(): {} { Declaration() Program() ( )? } void Declaration(): {} { ( SimpleDeclaration() )* } void SimpleDeclaration(): {} { ( | | ) ( ( | | | ) ) ? } void Program(): {} { ( Statement() )* ( )? } void Statement(): {} { AssignmentStatement() | IfStatement() | WhileStatement() | SwitchStatement() | FileStatement() } void AssignmentStatement(): {} { Expression() } void IfStatement(): {} { Expression() ( Statement() )* ( ( Statement() )* )? } void WhileStatement(): {} { Expression() ( Statement() )* } void SwitchStatement(): {} { ( Expression() ( )? ( Statement() )* )+ ( ( )? ( Statement() )* )? } void FileStatement(): {} { ( | ) ( | ) Expression() } void Expression(): {} { OrExpression() } void OrExpression(): {} { AndExpression() ( AndExpression() )* } void AndExpression(): {} { NotExpression() ( NotExpression() )* } void NotExpression(): {} { ( )? EqualityExpression() } void EqualityExpression(): {} { RelationalExpression() ( ( | ) RelationalExpression() ) ? } void RelationalExpression(): {} { AdditiveExpression() ( ( | | | ) AdditiveExpression() )? } void AdditiveExpression(): {} { MultiplicativeExpression() ( ( | ) MultiplicativeExpression() )* } void MultiplicativeExpression(): {} { BasicExpression() ( ( | ) BasicExpression() )* } void BasicExpression(): {} { | | | | | Expression() }