1: #line 3296 "./lpsrc/flx_tutorial.pak"
2:
3:
4:
5: data := "1+2+3$";
6:
7:
8: union token_t =
9: | TOK_EOF
10: | TOK_PLUS
11: | TOK_INT of int
12: ;
13:
14:
15: var i = 0;
16: fun get_token():token_t =
17: {
18: ch := data.[i to i+1];
19: ++i;
20: tok :=
21: match ch with
22: | "$" => TOK_EOF
23: | "+" => TOK_PLUS
24: | "1" => TOK_INT 1
25: | "2" => TOK_INT 2
26: | "3" => TOK_INT 3
27: endmatch
28: ;
29: return tok;
30: }
31:
32:
33: union expr_t =
34: | Integer of int
35: ;
36:
37:
38: nonterm eexpr : expr_t =
39: | xx:eexpr TOK_PLUS y:TOK_INT =>
40: match xx with
41: | Integer ?i => Integer (i+y)
42: endmatch
43:
44: | y:TOK_INT => Integer y
45: ;
46:
47:
48: var z : 1 + int =
49: parse (the get_token) with
50: | e: eexpr => match e with | Integer ?i => i endmatch
51: endmatch
52: ;
53:
54:
55: match z with
56: | case 0 => { print "Error"; }
57: | case 1 (?i) => { print i; }
58: endmatch;
59: endl;
60: