/
simple.pir
53 lines (40 loc) · 1.56 KB
/
simple.pir
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
.namespace [ "Simple" ]
.sub "__onload"
.local pmc optable
.local pmc term
.local pmc p6rule
.local string op
$I0 = find_type "PGE::OPTable"
optable = new $I0
store_global "Simple", "$optable", optable
p6rule = compreg "PGE::P6Rule"
term = p6rule("\\d+ | <ident>", 'grammar' => "Simple", 'name' => "term")
optable.'newtok'("infix:+", 'precedence' => '=')
optable.'newtok'("infix:-", 'equiv' => 'infix:+')
optable.'newtok'("infix:*", 'tighter' => 'infix:+')
optable.'newtok'("infix:/", 'equiv' => 'infix:*')
optable.'newtok'("infix:%", 'equiv' => 'infix:*')
optable.'newtok'("prefix:+", 'tighter' => 'infix:*')
optable.'newtok'("prefix:-", 'equiv' => 'prefix:+')
optable.'newtok'("prefix:!", 'equiv' => 'prefix:+')
optable.'newtok'("infix:**", 'tighter' => '>prefix:+')
optable.'newtok'("postcircumfix:( )", 'tighter' => "infix:**", 'nullterm' => 1)
optable.'newtok'("term:", 'tighter' => 'postcircumfix:( )', 'parsed' => term)
optable.'newtok'("circumfix:( )", 'equiv' => 'term:')
optable.'newtok'("infix:==", 'looser' => 'infix:+')
optable.'newtok'("infix:!=", 'equiv' => 'infix:==')
optable.'newtok'("ternary:? :", 'looser' => 'infix:==', 'assoc' => 'right')
optable.'newtok'("infix:=", 'looser' => 'ternary:? :', 'assoc' => 'right')
.end
.sub "expr"
.param pmc mob
.local pmc optable
optable = find_global "Simple", "$optable"
$P0 = optable."parse"(mob)
.return ($P0)
.end
# Local Variables:
# mode: pir
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4: