-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathInterpretVCDHeader.g
44 lines (35 loc) · 978 Bytes
/
InterpretVCDHeader.g
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
tree grammar InterpretVCDHeader;
options {
language=Python;
tokenVocab=ValueChangeDump;
ASTLabelType=CommonTree;
}
@init {
self.vars={};
self.empty=[];
}
vcd_header returns [result]: ^(HEADER decl_command_list[stack=self.empty])
{$result=self.vars}
;
decl_command_list [stack]
: ^(DECLS decl_command[stack=stack]+)
;
decl_command [stack]
: ^(TIMESCALE DEC_NUM TIME_UNIT)
| ^(NEWVAR type=. size=DEC_NUM id_code=IDENTIFIER ref=IDENTIFIER)
{
myvar={'code':$id_code.text,'ref':$ref.text,'scope':$stack,'size':int($size.text)};
self.vars[$id_code.text]=myvar;
}
| vcd_scope[stack=stack]
;
vcd_decl_timescale
: ^(TIMESCALE DEC_NUM TIME_UNIT)
;
vcd_scope [stack]
: ^(NEWSCOPE vcd_decl_scope decl_command_list[stack=stack+list(($vcd_decl_scope.label,))])
;
vcd_decl_scope returns [label]
: ^(DECLSCOPE type=. IDENTIFIER)
{$label=$IDENTIFIER.text}
;