dilaria/grammar.txt
2021-11-02 20:37:43 +01:00

88 lines
No EOL
1.8 KiB
Text

# todo: calls (property access and function calls)
<program> ::= <statement-list>
<statement-list> ::= { <statement> }
<block> ::= "{" <statement-list> "}"
<statement> ::= <declaration>
| <assignment>
| <fn-decl>
| <if-stmt>
| <loop-stmt>
| <while-stmt>
| <break-stmt>
| <return-stmt>
| <block>
| <expression-statement>
<declaration> ::= "let" <IDENT> "=" <expression> ";"
<assignment> ::= { call "." } <IDENT> "=" <expression> ";"
<fn-decl> ::= "fn" <IDENT> <fn-args> <block>
<fn-args> ::= "(" <ident-list> ")"
<if-stmt> ::= "if" <expression> <block> { <else-part> }
<else-part> ::= "else" ( <if-stmt> | <block> )
<loop-stmt> ::= "loop" <block>
<while-stmt> ::= "while" <expression> <block>
<break-stmt> ::= "break" ";"
<return-stmt> ::= "return" { <expression> } ";"
<expression-statement> ::= <expression> ";"
<expression> ::= <logical-or>
<logical-or> ::= <logical-and> { "or" <logical-or> }
<logical-and> ::= <equality> { "and" <logical-and> }
<equality> ::= <comparison> { ("!=" | "==") <comparison> }
<comparison> ::= <term> { (">" | "<" | ">=" | "<=") <term> }
<term> ::= <factor> { ("-" | "+") <term> }
<factor> ::= <unary> { ( "*" | "/" | "%" ) <factor> }
<unary> ::= { ( "not" | "-" ) } <call>
<call> ::= <primary> { ( "(" <expr-list> ")" | "." <IDENT> ) }
<primary> ::= <IDENT>
| <NUMBER>
| <STRING>
| <object-literal>
| <array-literal>
| "false"
| "true"
| "null"
| "(" <expression> ")"
<object-literal> ::= "{}"
<array-literal> ::= "[" <expr-list> "]"
<expr-list> ::= { <expression> { "," <expression> } { "," } }
<ident-list> ::= { <IDENT> { "," <IDENT> } { "," } }