# BNF for lex.jj

## TOKENS

    <DEFAULT> SKIP : {
    <SPACE: " " | "\t" | "\r" | "\n">
    }
    <DEFAULT> SKIP : {
    "/*" : WithinComment
    }
    <WithinComment> SKIP : {
    "*/" : DEFAULT
    }
    <WithinComment> MORE : {
    <~[]>
    }
    <DEFAULT> SKIP : {
    "//" : AfterComment
    }
    <AfterComment> SKIP : {
    "\n" : DEFAULT
    }
    <AfterComment> MORE : {
    <~[]>
    }
    <DEFAULT> TOKEN : {
    <DIJKSTRA: "#dijk">
    | <COROUTINDETACH: "#detach">
    | <COROUTINCALL: "#call">
    | <COROUTINRESUME: "#resume">
    | <HOARE: "hoa" (" ")* "(">
    | <HOARECASE: "*:">
    | <REFERENCE: "ref">
    | <NEW: "new">
    | <THIS: "this">
    | <SELECT: "*.">
    | <LPAREN: "{">
    | <RPAREN: "}">
    | <ARROW: "->">
    | <WHILE: "while" (" ")* "(">
    | <GOTO: "goto">
    | <RETURN: "return:">
    | <RETURNVOID: "return;">
    | <FOR: "for" (" ")* "(">
    | <EMPTYSTATEMENT: ";">
    | <PRINT: "printf">
    | <MAIN: "main:">
    }
    <DEFAULT> TOKEN : {
    <UNDEFINEDID: <IDENTIFIER> ":">
    | <PROCEDUREID: <IDENTIFIER> "(">
    | <SELECTTHIS: "this.">
    | <SELECTID: <IDENTIFIER> ".">
    | <ARRAYID: <IDENTIFIER> "[">
    | <DEFINEDID: <IDENTIFIER>>
    | <NUM: (<DIGIT>)+>
    | <REALNUM: (<DIGIT>)* "." (<DIGIT>)+ (["e","E"] ["+","-"] <DIGIT>)?>
    | <#LETTER: ["a"-"z","A"-"Z"]>
    | <#DIGIT: ["0"-"9"]>
    | <#IDENTIFIER: <LETTER> (<LETTER> | <DIGIT>)*>
    }
    <DEFAULT> MORE : {
    "\"" : STR
    }
    <STR> TOKEN : {
    <STRING: "\"" | "\r\n"> : DEFAULT
    }
    <STR> MORE : {
    "\\\"" : {
    }
    <STR> MORE : {
    "\\n" : {
    }
    <STR> MORE : {
    <~[]>
    }
    <DEFAULT> TOKEN : {
    <ID: "deadbeef">
    | <IF: "if">
    | <ELSE: "else">
    }

## NON-TERMINALS

program | ::= | ( block )+ <EOF>
block | ::= | ( dahlObjectClass | <MAIN> <LPAREN> stetementList <RPAREN> )
dahlObjectClass | ::= | <UNDEFINEDID> <LPAREN> stetementList <RPAREN>
stetementList | ::= | ( <EMPTYSTATEMENT> | variableDeclaration | hoareCase | procedureCall | variableAssignment | selectiveDeclaration | selectiveUpdate | whileStatement | forStatement | jump | returnStatement | dijkstraCocatnation | printf | <COROUTINDETACH> "(" ")" | <COROUTINCALL> "(" <DEFINEDID> ")" | <COROUTINRESUME> "(" <DEFINEDID> ")" | <MAIN> <LPAREN> stetementList <RPAREN> )*
printf | ::= | <PRINT> "(" <STRING> ")"
dijkstraCocatnation | ::= | <DIJKSTRA> "(" ( <DEFINEDID> | <STRING> ) ")"
variableDeclaration | ::= | <UNDEFINEDID> typeOperation
typeOperation | ::= | ( containElementSet | procedureDeclaration | "[" <NUM> "]" "=" typeId | <NEW> <DEFINEDID> | <REFERENCE> <DEFINEDID> assignment | <LPAREN> block <RPAREN> )
containElementSet | ::= | typeId assignment
typeId | ::= | <DEFINEDID>
procedureDeclaration | ::= | "(" parameterList <LPAREN> stetementList <RPAREN>
parameterList | ::= | ( <UNDEFINEDID> ( ( <REFERENCE> )? <DEFINEDID> | procedureDeclaration ) )? ( "," <UNDEFINEDID> ( ( <REFERENCE> )? <DEFINEDID> | procedureDeclaration ) )* ")"
hoareCase | ::= | <HOARE> <UNDEFINEDID> "?" assignment ")" <LPAREN> ( <HOARECASE> <DEFINEDID> <LPAREN> stetementList <RPAREN> )+ <RPAREN>
selectiveDeclaration | ::= | <SELECT> ( variableDeclaration | <PROCEDUREID> parameterList <LPAREN> stetementList <RPAREN> )
selectiveUpdate | ::= | arrayAssignment
| | | ( ( <SELECTTHIS> | <SELECTID> ) ( procedureCall | variableAssignment | selectiveUpdate ) )
variableAssignment | ::= | <DEFINEDID> assignment
arrayAssignment | ::= | <ARRAYID> expression "]" assignment
assignment | ::= | "=" expression
procedureCall | ::= | <PROCEDUREID> ( expression ( "," expression )* )? ")"
whileStatement | ::= | <WHILE> conditionalExpression ")" <LPAREN> stetementList <RPAREN>
forStatement | ::= | <FOR> ")" <LPAREN> stetementList <RPAREN>
jump | ::= | <GOTO> <DEFINEDID>
returnStatement | ::= | ( <RETURN> <DEFINEDID> expression | <RETURNVOID> )
externalDecl | ::= | variableDecl
| | | subpDeclarator ( ";" | "{" ( variableDecl )* ( stmt )* "}" )
variableDecl | ::= | <UNDEFINEDID> typeId varDecl ( "," varDecl )* ";"
varDecl | ::= | <ID> ( "[" <NUM> "]" | )
subpDeclarator | ::= | typeId <ID> "(" ( paramDecl ( "," paramDecl )* )? ")"
paramDecl | ::= | typeId <ID> ( "[" "]" | )
stmt | ::= | ( variable "=" expression ";" | <IF> "(" conditionalExpression ")" stmt ( <ELSE> stmt | ) | <WHILE> "(" conditionalExpression ")" stmt | "{" ( stmt )* "}" | callExpr ";" | <RETURN> ( expression | ) ";" )
conditionalExpression | ::= | expression comparisonOperator expression
comparisonOperator | ::= | "=="
| | | "!="
| | | ">"
| | | ">="
| | | "<"
| | | "<="
expression | ::= | term ( "+" term | "-" term )*
term | ::= | factor ( "*" factor | "/" factor )*
factor | ::= | "+" factor
| | | "-" factor
| | | variable
| | | <THIS>
| | | <NUM>
| | | <REALNUM>
| | | <STRING>
variable | ::= | ( procedureCall | ( <SELECTTHIS> | <SELECTID> ) variable | <DEFINEDID> ( "[" expression "]" | ) )
callExpr | ::= | <DEFINEDID> "(" ( expression ( "," expression )* )? ")"
recoveredError | ::= | java code