-
Notifications
You must be signed in to change notification settings - Fork 0
/
readme.txt
34 lines (34 loc) · 1.12 KB
/
readme.txt
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
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> ')' ;