Spaces:
Running
Running
root ::= (declaration)* | |
declaration ::= dataType identifier "(" parameter? ")" "{" statement* "}" | |
dataType ::= "int" ws | "float" ws | "char" ws | |
identifier ::= [a-zA-Z_] [a-zA-Z_0-9]* | |
parameter ::= dataType identifier | |
statement ::= | |
( dataType identifier ws "=" ws expression ";" ) | | |
( identifier ws "=" ws expression ";" ) | | |
( identifier ws "(" argList? ")" ";" ) | | |
( "return" ws expression ";" ) | | |
( "while" "(" condition ")" "{" statement* "}" ) | | |
( "for" "(" forInit ";" ws condition ";" ws forUpdate ")" "{" statement* "}" ) | | |
( "if" "(" condition ")" "{" statement* "}" ("else" "{" statement* "}")? ) | | |
( singleLineComment ) | | |
( multiLineComment ) | |
forInit ::= dataType identifier ws "=" ws expression | identifier ws "=" ws expression | |
forUpdate ::= identifier ws "=" ws expression | |
condition ::= expression relationOperator expression | |
relationOperator ::= ("<=" | "<" | "==" | "!=" | ">=" | ">") | |
expression ::= term (("+" | "-") term)* | |
term ::= factor(("*" | "/") factor)* | |
factor ::= identifier | number | unaryTerm | funcCall | parenExpression | |
unaryTerm ::= "-" factor | |
funcCall ::= identifier "(" argList? ")" | |
parenExpression ::= "(" ws expression ws ")" | |
argList ::= expression ("," ws expression)* | |
number ::= [0-9]+ | |
singleLineComment ::= "//" [^\n]* "\n" | |
multiLineComment ::= "/*" ( [^*] | ("*" [^/]) )* "*/" | |
ws ::= ([ \t\n]+) | |