-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProgramLanguageGrammar.txt
23 lines (22 loc) · 1.12 KB
/
ProgramLanguageGrammar.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Program ::= FunctionDeclaration+
FunctionDeclaration ::= "function" FunctionImplementation
FunctionImplementation ::= Identifier'(' FunctionImplementationParameters ')' Block
Identifier ::= ['a'-'z' 'A'-'Z' '_'] ['a'-'z' 'A'-'Z' '0'-'9' '_']+
FunctionImplementationParameters ::= {Variable (?=',')}* Variable?
Variable ::= Identifier
Block ::= '{' BlockBody '}'
BlockBody ::= Statement+
Statement ::= If | While | Operator
If ::= "if" '(' Condition ')' Block
While := "while" '( Condition ')' Block
Condition ::= Expression
Operator ::= (AssignmentOperator | FunctionСallOperator | Return) ';'
AssignmentOperator ::= Variable '=' Expression
FunctionCallOperator ::= Identifier '(' FunctionCallParameters ')'
FunctionCallParameters ::= {Expression (?=',')}* Expression?
Return ::= "return" Expression
Expression ::= TertiaryExpression {['+' '-' '<' "<=" "==" '>' ">=" "||"] Expression}?
TertiaryExpression ::= SecondaryExpression {['*' '/' "&&"] TertiaryExpression}?
SecondaryExpression ::= PrimaryExpression {['^'] SecondaryExpression}?
PrimaryExpression ::= '(' Expression ')' | FunctionCallOperator | Variable | Number
Number ::= ['0'-'9']+