-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnoncyclicrd.blt
executable file
·49 lines (44 loc) · 1.38 KB
/
noncyclicrd.blt
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
import stack;
// from http://plus.kaist.ac.kr/~shoh/ocaml/ocamllex-ocamlyacc/ocamlyacc-tutorial/sec-multi-function-calculator.html
//input: /* empty */ { }
// | input line { }
//;
//line: NEWLINE { }
// | exp NEWLINE { printf "\t%.10g\n" $1; flush stdout }
// | error NEWLINE { }
//;
//exp: NUM { $1 }
// | VAR { try Hashtbl.find var_table $1
// with Not_found ->
// printf "no such variable '%s'\n" $1;
// 0.0
// }
// | VAR EQ exp { Hashtbl.replace var_table $1 $3;
// $3
// }
// | FNCT LPAREN exp RPAREN { $1 $3 }
// | exp PLUS exp { $1 +. $3 }
// | exp MINUS exp { $1 -. $3 }
// | exp MULTIPLY exp { $1 *. $3 }
// | exp DIVIDE exp { $1 /. $3 }
// | MINUS exp %prec NEG { -. $2 }
// | exp CARET exp { $1 ** $3 }
// | LPAREN exp RPAREN { $2 }
//;
class token {
int id;
gen_code => (Code* code);
}
typedef vector<token> token_vector;
unordered_multimap< key=token, value=token_vector > grammar;
main
{
grammar = {
"block": ["const","ident","equals","number",{,"comma","ident","equals","number",},"semicolon"],
"block": ["var","ident",{,"comma","ident",},"semicolon"],
"block": ["procedure","ident","semicolon","block","semicolon","statement"]
}
}
class handler
{
}