grammar Pcl_P1 ; @header { package intermediate.antlr4; import intermediate.symtab.SymtabEntry; import intermediate.type.Typespec_P1; } program : programHeader block '.' ; programHeader : PROGRAM identifier programParameters? ';' ; programParameters : '(' identifier ( ',' identifier )* ')' ; identifier locals [ SymtabEntry entry = null, Typespec_P1 typespec = null, Object value = null ] : IDENTIFIER ; block : declarations compoundStatement ; compoundStatement : BEGIN END ; declarations : ( constantsPart ';' )? ( typesPart ';' )? ( variablesPart ';' )? ( procedureAndFunctionsPart ';')? ; constantsPart : CONST constantDefinitionsList ; constantDefinitionsList : constantDefinition ( ';' constantDefinition )* ; typesPart : /* empty */ ; variablesPart : VAR variableDeclarationsList ; variableDeclarationsList : variableDeclarations ( ';' variableDeclarations )* ; procedureAndFunctionsPart : /* empty */ ; constantDefinition : identifier '=' constant ; constant locals [ Typespec_P1 typespec = null, Object value = null ] : sign? ( constantIdentifier | unsignedConstant ) | characterConstant | stringConstant | booleanConstant ; sign : '-' | '+' ; constantIdentifier locals [ Typespec_P1 typespec = null, Object value = null ] : identifier ; unsignedConstant locals [ Typespec_P1 typespec = null, Object value = null ] : integerConstant | realConstant ; integerConstant locals [ Typespec_P1 typespec = null, Object value = null ] : INTEGER ; realConstant locals [ Typespec_P1 typespec = null, Object value = null ] : REAL; characterConstant locals [ Typespec_P1 typespec = null, Object value = null ] : CHARACTER ; stringConstant locals [ Typespec_P1 typespec = null, Object value = null ] : STRING ; booleanConstant locals [ Typespec_P1 typespec = null, Object value = null ] : TRUE | FALSE ; typeSpecification locals [ Typespec_P1 typespec = null ] : typeIdentifier | ordinalType | structuredType ; typeIdentifier : identifier ; ordinalType locals [ Typespec_P1 typespec = null ] : enumeratedType | subrangeType ; structuredType locals [ Typespec_P1 typespec = null ] : arrayType | recordType ; enumeratedType : /* empty */ ; subrangeType : /* empty */ ; arrayType : /* empty */ ; recordType : /* empty */ ; variableDeclarations : variableIdentifierList ':' typeSpecification ; variableIdentifierList : identifier ( ',' identifier )* ; PROGRAM : P R O G R A M ; CONST : C O N S T ; TYPE : T Y P E ; PACKED : P A C K E D ; ARRAY : A R R A Y ; OF : O F ; RECORD : R E C O R D ; VAR : V A R ; BEGIN : B E G I N ; END : E N D ; TRUE : T R U E ; FALSE : F A L S E ; IDENTIFIER : LETTER ( LETTER | DIGIT )*; INTEGER : DIGITS ; REAL : DIGITS '.' DIGITS | DIGITS ('e' | 'E') ('+' | '-')? DIGITS | DIGITS '.' DIGITS ('e' | 'E') ('+' | '-')? DIGITS ; LETTER : [a-zA-Z] ; DIGIT : [0-9]; DIGITS : DIGIT+ ; CHARACTER : QUOTE STRING_CHAR QUOTE ; STRING : QUOTE STRING_CHAR* QUOTE ; WHITESPACE : [ \n\r\t]+ -> skip ; COMMENT : '{' COMMENT_CHAR* '}' -> skip ; fragment A : ('a' | 'A') ; fragment B : ('b' | 'B') ; fragment C : ('c' | 'C') ; fragment D : ('d' | 'D') ; fragment E : ('e' | 'E') ; fragment F : ('f' | 'F') ; fragment G : ('g' | 'G') ; fragment H : ('h' | 'H') ; fragment I : ('i' | 'I') ; fragment J : ('j' | 'J') ; fragment K : ('k' | 'K') ; fragment L : ('l' | 'L') ; fragment M : ('m' | 'M') ; fragment N : ('n' | 'N') ; fragment O : ('o' | 'O') ; fragment P : ('p' | 'P') ; fragment Q : ('q' | 'Q') ; fragment R : ('r' | 'R') ; fragment S : ('s' | 'S') ; fragment T : ('t' | 'T') ; fragment U : ('u' | 'U') ; fragment V : ('v' | 'V') ; fragment W : ('w' | 'W') ; fragment X : ('x' | 'X') ; fragment Y : ('y' | 'Y') ; fragment Z : ('z' | 'Z') ; fragment QUOTE : '\'' ; fragment CHARACTER_CHAR : ~'\'' ; fragment STRING_CHAR : QUOTE QUOTE | CHARACTER_CHAR ; fragment COMMENT_CHAR : ~'}' ;