-
Notifications
You must be signed in to change notification settings - Fork 0
/
com2.lark
65 lines (52 loc) · 1.92 KB
/
com2.lark
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
%import common.WS
%import common.SH_COMMENT
%ignore WS
%ignore SH_COMMENT
start: section+
// identifiers
ID: /[a-z_][a-z0-9_]*/i
PREPROC_ID : "$" ID
// types
array_dim : "[" [INT] "]"
type : ID array_dim*
// expressions
INT: /[0-9]+/
ARITH_OP : "+" | "-" | "*" | "/" | "%" | "|" | "^" | "&" | "==" | "!="
UNARY_OP : "!" | "~"
expr : l_value | INT | "(" expr ")" | expr ARITH_OP expr | UNARY_OP expr | PREPROC_ID
l_value : ID ("[" expr "]")*
// sections
?section: parameters | variables | states | functions
parameters: "parameters" "{" (param_declaration ";")* "}"
variables: "variables" "{" (var_declaration ";")* "}"
states: "states" "{" state_list "}"
state_list : state_block* -> state_list
?state_block : state | for_loop
for_loop : "for" PREPROC_ID "from" INT "to" INT "{" state_list "}"
functions : "left" "{" function* "}" -> left_functions
| "right" "{" function* "}" -> right_functions
| "shared" "{" function* "}" -> shared_functions
param_declaration : type ID ["=" expr]
var_declaration : type ID
TIME_UNIT.1 : "s" | "ms" | "us" | "ns"
duration : expr TIME_UNIT
?condition : duration | ID
condition_list : (condition ("," condition)*)?
LABEL : ID (ID | PREPROC_ID)*
state : [LABEL ":"] "(" condition_list ")" "{" state_actions "}" [transitions]
state_actions : (state_action ";")*
?state_action : wire_write | wire_read_write | variable_assignment
wire_read_write : ID "==>" l_value -> transfer_to_right
| l_value "<==" ID -> transfer_to_left
wire_write : ID "-->" expr -> send_to_right
| expr "<--" ID -> send_to_left
variable_assignment : l_value "=" expr
transitions : "[" transition ("," transition)* "]"
transition : [expr] "=>" LABEL
function : "fn" ID "(" arg_list ")" "{" stmt_list "}"
arg_list : (argument ("," argument)*)?
argument : IO_TYPE type ID
IO_TYPE.1 : "input" | "output"
stmt_list : (stmt ";")*
?stmt: variable_assignment | state_path
state_path : [ID] "..." ID