amalthea.opp.exp 4.44 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
%{
  open Io_types ;;
  open Io_messages ;;
  open Io_parser_state ;;
  let unpos = snd
  let pos = fst
  let ct1 = fun c (cs, bs) -> (c::cs, bs)
  let ct2 = fun b (cs, bs) -> (cs, b::bs)
  let parse_error = function msg ->
    raise (Io_module_error (Io_parser_error !last_pos))

%}
%start parse_io_module
%token Lcolon
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
%token <Io_types.pos> Ldeclare
%token Lend
%token <Io_types.pos> Lexport
%token <Io_types.pos> Lgetvar
%token <Io_types.pos * string> Lident
%token <Io_types.pos> Limport
%token <Io_types.pos * int> Lint
%token <Io_types.pos> Llambda
%token Llpar
%token Lperiod
%token <Io_types.pos> Lprimitive
%token <Io_types.pos> Lputvar
%token Lrpar
%token Lsemi
%token <Io_types.pos * string> Lstring
%token <Io_types.pos> Lvariable
31
32
33
34
%type <Io_types.io_ast> parse_io_module
%%

parse_io_module:
35
  _1 = imports _2 = export _3 = decll _4 = expr _5 = Lend
36
    {                                               ( (_1,_2,_3,_4) )}
37
38

imports:
39
  _1 = Limport _2 = Lident _3 = importlist _4 = Lperiod _5 = imports
40
    {                                               ( last_pos := pos _2;(String.lowercase (unpos _2), _3)::_5 )}
41
| 
42
    {                                               ( [] )}
43
44

importlist:
45
  _1 = Lcolon _2 = idlist
46
    {                                               ( Some _2 )}
47
| 
48
    {                                               ( None )}
49
50

export:
51
  _1 = Lexport _2 = idlist _3 = Lperiod
52
    {                                               ( _2 )}
53
| 
54
    {                                               ( [] )}
55
56

decll:
57
  _1 = Ldeclare _2 = Lident _3 = Lcolon _4 = eatom _5 = Lperiod _6 = decll
58
59
60
61
62
    {                                                  ( last_pos := pos _2;ct1 (_1,unpos _2,_4) _6 )}
| _1 = Lprimitive _2 = Lident _3 = Lcolon _4 = Lident _5 = Lperiod _6 = decll
    {                                                  ( last_pos := pos _2;ct1 (_1,unpos _2,Eprimitive (unpos _4)) _6 )}
| _1 = Lvariable _2 = Lident _3 = Lcolon _4 = eatom _5 = Lperiod _6 = decll
    {                                                  ( last_pos := pos _2;ct2 (_1,unpos _2,_4) _6 )}
63
| 
64
    {                                                  ( ([], []) )}
65
66

expr:
67
  _1 = Lident _2 = paramlist
68
69
70
71
72
73
74
75
76
    {                                               ( Eappl (pos _1, unpos _1, _2, EFall) )}
| _1 = Lident
    {                                               ( Eid (pos _1, unpos _1) )}
| _1 = Lident _2 = Lputvar _3 = patom _4 = stmttail
    {                                               ( Eputvar (pos _1, unpos _1, _3, _4, EFall) )}
| _1 = Lident _2 = Lgetvar _3 = Lident _4 = stmttail
    {                                               ( Egetvar (pos _1, unpos _1, unpos _3, _4, EFall) )}
| _1 = stmt
    {                                               ( _1 )}
77
78

paramlist:
79
  _1 = patom _2 = paramlisttail
80
81
82
83
84
    {                                               ( _1::_2 )}
| _1 = Lsemi _2 = eatom
    {                                               ( [_2]   )}
| _1 = stmt
    {                                               ( [_1] )}
85
86

paramlisttail:
87
  _1 = patom _2 = paramlisttail
88
89
90
91
92
    {                                               ( _1::_2 )}
| _1 = Lsemi _2 = eatom
    {                                               ( [_2]   )}
| _1 = stmt
    {                                               ( [_1] )}
93
| 
94
    {                                               ( [] )}
95
96

stmt:
97
  _1 = Llambda _2 = idlist _3 = stmttail
98
    {                                               ( Elambda (_1,_2,_3,EFall) )}
99
100

stmttail:
101
  _1 = Lsemi _2 = eatom
102
103
104
    {                                               ( _2 )}
| _1 = atom
    {                                               ( _1 )}
105
106

idlist:
107
  _1 = Lident _2 = idlist
108
    {                                               ( last_pos := pos _1;(unpos _1)::_2 )}
109
| 
110
    {                                               ( [] )}
111
112

eatom:
113
  _1 = expr
114
115
116
    {                                               ( _1 )}
| _1 = atom
    {                                               ( _1 )}
117
118

patom:
119
  _1 = Lident
120
121
122
    {                                               ( last_pos := pos _1; Eid (pos _1,unpos _1) )}
| _1 = atom
    {                                               ( _1 )}
123
124

atom:
125
  _1 = Lint
126
127
128
129
130
    {                                               ( last_pos := pos _1; Eint (pos _1,unpos _1) )}
| _1 = Lstring
    {                                               ( last_pos := pos _1; Estring (pos _1,unpos _1) )}
| _1 = Llpar _2 = expr _3 = Lrpar
    {                                               ( _2 )}
131
132
133
134

%%


135