Skip to content

Formal Grammar of Sircle

Value Expression

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
value_expr ::= func_app binary_op func_app | unary_op func_app
func_app = value_term func_app | value_term
value_term ::= lexeme 
             | symbol_name 
             | [ value_expr ( ',' value_expr )* ]
             | '{' ( string_lexeme '->' value_expr )+ '}'
             | '{' [ effect ( ';' effect )* ] '}'
             | '(' value_expr ( ',' value_expr )* ')'
             | '(' value_expr ')'
             | if_expr
             | for_expr
effect ::= 'def' symbol_name [ ':' type_expr ] '=' value_expr
         | symbol_name '=' value_expr
         | value_expr
if_expr ::= 'if' value_expr 'then' value_expr [ 'else' value_expr ]
for_expr ::= 'for' for_comb ( ',' for_comb )* 'do' value_expr
for_comb ::= symbol_name '<-' value_expr
           | value_expr

Type Expression

1
2
3
4
5
6
type_expr ::= type_term ( '->' type_term )*
type_term ::= primitive_type
            | symbol_name
            | '(' type_expr ')'
            | '(' type_expr ( ',' type_expr )* ')'
            | '{' [ string_lexeme ':' type_expr ( string_lexeme ':' type_expr )* ] '}'

Top-level Value Binding

1
top_value_binding ::= 'def' symbol_name [ ':' type_expr ] '=' value_expr

Top-level Type Binding

1
top_type_binding ::= 'type' symbol_name '=' type_expr