summaryrefslogtreecommitdiff
path: root/ecomp-c/minie.ebnf
blob: be68ba82d8018fa87673607b43f734d26585b227 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# scanner/lexer
Digit				= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" .
Letter				= "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" | "J" | "K" | "L" | "M" | "N" | "O" | "P" | "Q" | "R" | "S" | "T" | "U" | "V" | "W" | "X" | "Y" | "Z" |
				  "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | "y" | "z" .
Special				= "_" | " " .
Identifier			= Letter { Letter | Digit | "_" } .
Number				= Digit { Digit } .
Character			= "'" Digit | Letter | Special |  "'" .
String				= """" { Character } """" .

# parser
Factor				= Number | Character | String | Identifier [ "[" Expression "]" ] | "(" Expression ")" | "not" Factor .
Term				= Factor { ( "*" | "/" | "mod" | "and" ) Factor } .
SimpleExpression		= Term { ( "+" | "-" | "or" ) Term } .
RelationalOperator		= "=" | "<>" | "<" | ">" | "<=" | ">=" .
Expression			= SimpleExpression [ RelationalOperator SimpleExpression ] .
Assignment			= Identifier [ "[" Expression "]" ] ":=" Expression .
IfStatement			= "if" Expression "do" StatementSequence "else" StatementSequence "end" .
WhileStatement			= "while" Expression "do" StatementSequence "end" .
ParameterList			= "(" Expression { "," Expression } ")" .
ProcedureCall			= Identifier [ ParameterList ] .
Statement			= Assignment | IfStatement | WhileStatement | ProcedureCall .
StatementSequence		= Statement { ";" Statement } .
StatementBlock			= "begin" StatementSequence "end" .
SimpleType			= Identifier .
ArrayType			= "array" [ ConstExpression ] "of" Type .
Type				= SimpleType | ArrayType .
ConstExpression			= ( Number | Identifier ) .
ConstDeclaration		= Identifier { "," Identifier } ":" Type "=" ConstExpression .
ConstBlock			= "const" { ConstDeclaration ";" } .
VariableDeclaration		= Identifier { "," Identifier } ":" Type [ ":=" ConstExpression ] .
VariableBlock			= "var" { VariableDeclaration ";" } .
ParameterDeclaration		= Identifier ":" Type .
ParamaterDeclarationList	= "(" ParameterDeclaration { "," ParameterDeclaration } ")" .
ProcedureDeclaration		= "procedure" Identifier [ ParamaterDeclarationList ] ";" ProcedureDeclarationBlock StatementBlock .
ProcedureDeclarationBlock 	= [ ConstBlock ] [ VariableBlock ] .
ProcedureBlock			= { ProcedureDeclaration } .
DeclarationBlock		= [ ConstBlock ] [ VariableBlock ] [ ProcedureBlock ] .
Module				= "module" Identifier ";" DeclarationBlock StatementBlock .