-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrammar.txt
54 lines (48 loc) · 1.02 KB
/
grammar.txt
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
lexid Spaces
//
// Output Options
//
%CONTEXT [[std::ostream &]]
%ON_ERROR [[
$c <<"COL#" <<$pos.m_Col <<": " <<$message <<'\n';
]]
%EXTRA_TOKENS [[dec_num|oct_num|hex_num|spaces]]
%SHOW_UNDEFINED
//
// Operator Precedence
//
left + -
left * / %
right ( )
//
// Grammar with Reduction Code
//
<@> ::= <Expr> [[
$r = $1;
]]
<Expr> ::= <Expr> + <Expr> [[
bux::unlex<int>($1) += bux::unlex<int>($3);
$r = $1;
]]
<Expr> ::= <Expr> - <Expr> [[
bux::unlex<int>($1) -= bux::unlex<int>($3);
$r = $1;
]]
<Expr> ::= <Expr> * <Expr> [[
bux::unlex<int>($1) *= bux::unlex<int>($3);
$r = $1;
]]
<Expr> ::= <Expr> / <Expr> [[
bux::unlex<int>($1) /= bux::unlex<int>($3);
$r = $1;
]]
<Expr> ::= <Expr> % <Expr> [[
bux::unlex<int>($1) %= bux::unlex<int>($3);
$r = $1;
]]
<Expr> ::= ( <Expr> ) [[
$r = $2;
]]
<Expr> ::= $Num [[
$r = bux::createLex(dynamic_cast<bux::C_IntegerLex&>(*$1).value<int>());
]]