alphaCaml-demos-mixins.opp.exp 2.99 KB
Newer Older
1
2
3
4
5
6
7
8
%{

open Strings
open Mm.Raw

%}
%start toplevel
%token AND
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
%token AS
%token CLOSE
%token DELETE
%token DEPENDS
%token DOT
%token END
%token EOF
%token EQUAL
%token FAKE
%token IN
%token LCURLY
%token LET
%token <string> LIDENT
%token LPAREN
%token LSQUARE
%token MIXIN
%token ON
%token PLUS
%token RCURLY
%token REC
%token RPAREN
%token RSQUARE
%token VAL
%token WILDCARD
33
34
35
36
%type <Mm.Raw.expression> toplevel
%%

atomic_expression:
37
  _1 = LIDENT
38
39
40
41
42
43
44
45
46
47
    {    ( EVar _1 )}
| _1 = LCURLY _2 = record_fields _3 = RCURLY
    {    ( ERecord _2 )}
| _1 = atomic_expression _2 = DOT _3 = LIDENT
    {    ( ERecordSelection (_1, _3) )}
| _1 = MIXIN _2 = components _3 = END
    {    ( let _, input, output = _2 in
      EStructure (input, output) )}
| _1 = LPAREN _2 = expression _3 = RPAREN
    {    ( _2 )}
48
49

unary_expression:
50
  _1 = atomic_expression
51
52
53
54
55
56
57
    {    ( _1 )}
| _1 = CLOSE _2 = unary_expression
    {    ( EClose _2 )}
| _1 = DELETE _2 = fields _3 = IN _4 = unary_expression
    {    ( EDeletion (_4, _2) )}
| _1 = FAKE _2 = LIDENT _3 = DEPENDS _4 = ON _5 = LIDENT _6 = IN _7 = unary_expression
    {    ( EFakeDependency (_7, _2, _5) )}
58
59

summand_expression:
60
  _1 = unary_expression
61
62
63
    {    ( _1 )}
| _1 = summand_expression _2 = PLUS _3 = unary_expression
    {    ( EComposition (_1, _3) )}
64
65

expression:
66
  _1 = summand_expression
67
68
69
    {    ( _1 )}
| _1 = LET _2 = REC _3 = bindings _4 = IN _5 = expression
    {    ( ELetRec (List.rev _3, _5) )}
70
71

bindings:
72
  _1 = binding
73
74
75
    {    ( [ _1 ] )}
| _1 = bindings _2 = AND _3 = binding
    {    ( _3 :: _1 )}
76
77

binding:
78
  _1 = LIDENT _2 = EQUAL _3 = expression
79
    {    ( (_1, _3) )}
80
81

toplevel:
82
  _1 = expression _2 = EOF
83
    {    ( _1 )}
84
85

record_fields:
86
  
87
88
89
    {    ( StringMap.empty )}
| _1 = record_fields _2 = VAL _3 = LIDENT _4 = EQUAL _5 = expression
    {    ( StringMap.add _3 _5 _1 )}
90
91

components:
92
  
93
94
95
96
97
98
99
100
101
102
103
104
105
    {    ( 0, StringMap.empty, (StringMap.empty, []) )}
| _1 = components _2 = VAL _3 = lident_pun _4 = dependencies _5 = EQUAL _6 = expression
    {    ( let xname, iname = _3 in
      let i, input, (fields, anonymous) = _1 in
      let fields = StringMap.add xname (_4, iname, _6, Mm.KStructMember i) fields in
      i+1, input, (fields, anonymous) )}
| _1 = components _2 = VAL _3 = WILDCARD _4 = AS _5 = LIDENT _6 = dependencies _7 = EQUAL _8 = expression
    {    ( let i, input, (fields, anonymous) = _1 in
      let anonymous = (_6, _5, _8, Mm.KStructMember i) :: anonymous in
      i+1, input, (fields, anonymous) )}
| _1 = components _2 = VAL _3 = lident_pun
    {    ( let xname, iname = _3 in
      let i, input, output = _1 in
106
      let input = StringMap.add xname iname input in
107
      i+1, input, output )}
108
109

lident_pun:
110
  _1 = LIDENT _2 = AS _3 = LIDENT
111
112
113
    {    ( _1, _3 )}
| _1 = LIDENT
    {    ( _1, _1 )}
114
115

fields:
116
  
117
118
119
    {    ( StringSet.empty )}
| _1 = fields _2 = LIDENT
    {    ( StringSet.add _2 _1 )}
120
121

dependencies:
122
  
123
124
125
    {    ( [] )}
| _1 = LSQUARE _2 = variables _3 = RSQUARE
    {    ( _2 )}
126
127

variables:
128
  
129
130
131
    {    ( [] )}
| _1 = variables _2 = LIDENT
    {    ( _2 :: _1 )}
132
133
134
135

%%


136