-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathlang.y
66 lines (57 loc) · 1.1 KB
/
lang.y
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
66
%{
package gohaml
import "fmt"
var Output inode
%}
%union {
n inode
s string
i interface{}
c icodenode
}
%type<n> statement
%type<c> rhs
%type<s> complex_ident
%token<s> IDENT
%token<i> ATOM FOR RANGE
%%
statement : FOR IDENT ',' IDENT ':' '=' RANGE IDENT
{
rn := new(rangenode)
rn._lhs1 = $2
rn._lhs2 = $4
rn._rhs = res{$8, true}
$$ = rn
Output = $$
}
| IDENT ':' '=' rhs
{
$4.setLHS($1)
$$ = $4
Output = $$
}
;
rhs : ATOM
{
dan := new(declassnode)
dan._rhs = $1
$$ = dan
}
| IDENT complex_ident
{
dan := new(vdeclassnode)
dan._rhs.value = $1 + $2
dan._rhs.needsResolution = true
$$ = dan
}
;
complex_ident : '.' IDENT complex_ident
{
$$ = fmt.Sprintf(".%s%s", $2, $3)
}
|
{
$$ = ""
}
;
%%