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