prince-ao/dipole
Folders and files
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Repository files navigation
The Dipole Programming Language
---
Grammar:
<program>_S ::= <statement>* EOT ;
<statement> ::=
<printStmt> |
<ifStmt> |
<declStmt> |
<assignStmt> |
<whileLoop> |
<forLoop>;
<printStmt> ::= 'print' <expression> ( 'new_line' | ';' ) ;
<ifStmt> ::= <ifHead> | <ifHead> 'else' <block> ;
<ifHead> ::= 'if' '(' <expression> ')' <block> ;
<block> ::= '{' <statement>* '}' ;
<declStmt> ::= 'let' 'identifier' ( '=' <expression> )? ( 'new_line' | ';' ) ;
<assignStmt> ::= 'identifier' '=' <expression> ( 'new_line' | ';' ) ;
<whileLoop> ::= 'while' '(' <expression> ')' <block> ;
<forLoop> ::= 'for' '(' ( <declStmt> | <assignStmt> )? ( <expression> )? ';' ( <assignStmt> )? ')' <block> ;
<expression> ::= <logic_op> ;
<logic_op> ::= <equality> (('or' | 'and') <equality>)* ;
<equality> ::= <comparison> (('!=' | '==') <comparison>)* ;
<comparison> ::= <term> (('>' | '>=' | '<' | '<=') <term>)* ;
<term> ::= <factor> (('+' | '-') <factor>)* ;
<factor> ::= <unary> (('*' | '/') <unary>)* ;
<unary> ::= ('-' | '!') <unary> | <primary> ;
<primary> ::=
'int' |
'true' |
'false' |
'none' |
'identifier' |
'string' |
(' <expression> ')' ;