Commit c781e458 authored by Yann Régis-Gianas's avatar Yann Régis-Gianas

Syntax: Every producer must be named.

   If the programmer did not provide a name [_i] is used (where [i] is
   the producer's position in the right hand side).

   This syntax modification actually simplifies the code:
   - There is no more on-the-fly naming of unnamed arguments.
   - Inlining is no more restricted to semantic actions that do not use $i.

   The patch is large because:
   - This change has an impact on many modules.
   - The expected results of the bench had to be updated.
parent 943020b3
......@@ -15,18 +15,18 @@ open Syntax.Raw
%%
expr:
| VAR
{ EVar $1 }
| CONST
{ EConst $1 }
| expr PLUS expr
{ EAdd ($1, $3) }
| FAIL
{ EFail }
| _1 = VAR
{ ( EVar _1 )}
| _1 = CONST
{ ( EConst _1 )}
| _1 = expr _2 = PLUS _3 = expr
{ ( EAdd (_1, _3) )}
| _1 = FAIL
{ ( EFail )}
declarations:
| VAR EQUAL expr EOF
{ D ($1, $3, Suspension.create (fun () -> !ParserFix.declarations())) }
| _1 = VAR _2 = EQUAL _3 = expr _4 = EOF
{ ( D (_1, _3, Suspension.create (fun () -> !ParserFix.declarations())) )}
%%
......
......@@ -35,101 +35,101 @@ open Mm.Raw
%%
atomic_expression:
| LIDENT
{ EVar $1 }
| LCURLY record_fields RCURLY
{ ERecord $2 }
| atomic_expression DOT LIDENT
{ ERecordSelection ($1, $3) }
| MIXIN components END
{ let _, input, output = $2 in
EStructure (input, output) }
| LPAREN expression RPAREN
{ $2 }
| _1 = LIDENT
{ ( 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 )}
unary_expression:
| atomic_expression
{ $1 }
| CLOSE unary_expression
{ EClose $2 }
| DELETE fields IN unary_expression
{ EDeletion ($4, $2) }
| FAKE LIDENT DEPENDS ON LIDENT IN unary_expression
{ EFakeDependency ($7, $2, $5) }
| _1 = atomic_expression
{ ( _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) )}
summand_expression:
| unary_expression
{ $1 }
| summand_expression PLUS unary_expression
{ EComposition ($1, $3) }
| _1 = unary_expression
{ ( _1 )}
| _1 = summand_expression _2 = PLUS _3 = unary_expression
{ ( EComposition (_1, _3) )}
expression:
| summand_expression
{ $1 }
| LET REC bindings IN expression
{ ELetRec (List.rev $3, $5) }
| _1 = summand_expression
{ ( _1 )}
| _1 = LET _2 = REC _3 = bindings _4 = IN _5 = expression
{ ( ELetRec (List.rev _3, _5) )}
bindings:
| binding
{ [ $1 ] }
| bindings AND binding
{ $3 :: $1 }
| _1 = binding
{ ( [ _1 ] )}
| _1 = bindings _2 = AND _3 = binding
{ ( _3 :: _1 )}
binding:
| LIDENT EQUAL expression
{ ($1, $3) }
| _1 = LIDENT _2 = EQUAL _3 = expression
{ ( (_1, _3) )}
toplevel:
| expression EOF
{ $1 }
| _1 = expression _2 = EOF
{ ( _1 )}
record_fields:
|
{ StringMap.empty }
| record_fields VAL LIDENT EQUAL expression
{ StringMap.add $3 $5 $1 }
{ ( StringMap.empty )}
| _1 = record_fields _2 = VAL _3 = LIDENT _4 = EQUAL _5 = expression
{ ( StringMap.add _3 _5 _1 )}
components:
|
{ 0, StringMap.empty, (StringMap.empty, []) }
| components VAL lident_pun dependencies EQUAL 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) }
| components VAL WILDCARD AS LIDENT dependencies EQUAL expression
{ let i, input, (fields, anonymous) = $1 in
let anonymous = ($6, $5, $8, Mm.KStructMember i) :: anonymous in
i+1, input, (fields, anonymous) }
| components VAL lident_pun
{ let xname, iname = $3 in
let i, input, output = $1 in
{ ( 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
let input = StringMap.add xname iname input in
i+1, input, output }
i+1, input, output )}
lident_pun:
| LIDENT AS LIDENT
{ $1, $3 }
| LIDENT
{ $1, $1 }
| _1 = LIDENT _2 = AS _3 = LIDENT
{ ( _1, _3 )}
| _1 = LIDENT
{ ( _1, _1 )}
fields:
|
{ StringSet.empty }
| fields LIDENT
{ StringSet.add $2 $1 }
{ ( StringSet.empty )}
| _1 = fields _2 = LIDENT
{ ( StringSet.add _2 _1 )}
dependencies:
|
{ [] }
| LSQUARE variables RSQUARE
{ $2 }
{ ( [] )}
| _1 = LSQUARE _2 = variables _3 = RSQUARE
{ ( _2 )}
variables:
|
{ [] }
| variables LIDENT
{ $2 :: $1 }
{ ( [] )}
| _1 = variables _2 = LIDENT
{ ( _2 :: _1 )}
%%
......
......@@ -32,134 +32,134 @@ open Fsub.Raw
%%
toplevel:
| EOF
{ TopEOF }
| Term SEMI toplevel
{ TopEval ($1, $3) }
| UCID TyBinder SEMI toplevel
{ TopTypeBind ($1, $2, $4) }
| LCID Binder SEMI toplevel
{ TopTermBind ($1, $2, $4) }
| _1 = EOF
{ ( TopEOF )}
| _1 = Term _2 = SEMI _3 = toplevel
{ ( TopEval (_1, _3) )}
| _1 = UCID _2 = TyBinder _3 = SEMI _4 = toplevel
{ ( TopTypeBind (_1, _2, _4) )}
| _1 = LCID _2 = Binder _3 = SEMI _4 = toplevel
{ ( TopTermBind (_1, _2, _4) )}
Binder:
| COLON Type
{ $2 }
| _1 = COLON _2 = Type
{ ( _2 )}
Type:
| ArrowType
{ $1 }
| ALL UCID OType DOT Type
{ TForall ($2, $3, $5) }
| _1 = ArrowType
{ ( _1 )}
| _1 = ALL _2 = UCID _3 = OType _4 = DOT _5 = Type
{ ( TForall (_2, _3, _5) )}
AType:
| LPAREN Type RPAREN
{ $2 }
| UCID
{ TVar $1 }
| TTOP
{ TTop }
| LCURLY FieldTypes RCURLY
{ TRecord $2 }
| _1 = LPAREN _2 = Type _3 = RPAREN
{ ( _2 )}
| _1 = UCID
{ ( TVar _1 )}
| _1 = TTOP
{ ( TTop )}
| _1 = LCURLY _2 = FieldTypes _3 = RCURLY
{ ( TRecord _2 )}
TyBinder:
|
{ TTop }
| LEQ Type
{ $2 }
{ ( TTop )}
| _1 = LEQ _2 = Type
{ ( _2 )}
ArrowType:
| AType ARROW ArrowType
{ TArrow ($1, $3) }
| AType
{ $1 }
| _1 = AType _2 = ARROW _3 = ArrowType
{ ( TArrow (_1, _3) )}
| _1 = AType
{ ( _1 )}
Term:
| AppTerm
{ $1 }
| LAMBDA LCID COLON Type DOT Term
{ EAbs ($2, $4, $6) }
| LET Pattern EQ Term IN Term
{ ELet ($2, $4, $6) }
| LAMBDA UCID OType DOT Term
{ ETyAbs ($2, $3, $5) }
| _1 = AppTerm
{ ( _1 )}
| _1 = LAMBDA _2 = LCID _3 = COLON _4 = Type _5 = DOT _6 = Term
{ ( EAbs (_2, _4, _6) )}
| _1 = LET _2 = Pattern _3 = EQ _4 = Term _5 = IN _6 = Term
{ ( ELet (_2, _4, _6) )}
| _1 = LAMBDA _2 = UCID _3 = OType _4 = DOT _5 = Term
{ ( ETyAbs (_2, _3, _5) )}
AppTerm:
| PathTerm
{ $1 }
| AppTerm PathTerm
{ EApp ($1, $2) }
| AppTerm LSQUARE Type RSQUARE
{ ETyApp ($1, $3) }
| _1 = PathTerm
{ ( _1 )}
| _1 = AppTerm _2 = PathTerm
{ ( EApp (_1, _2) )}
| _1 = AppTerm _2 = LSQUARE _3 = Type _4 = RSQUARE
{ ( ETyApp (_1, _3) )}
PathTerm:
| PathTerm DOT LCID
{ EProj ($1, $3) }
| ATerm
{ $1 }
| _1 = PathTerm _2 = DOT _3 = LCID
{ ( EProj (_1, _3) )}
| _1 = ATerm
{ ( _1 )}
FieldTypes:
|
{ StringMap.empty }
| NEFieldTypes
{ $1 }
{ ( StringMap.empty )}
| _1 = NEFieldTypes
{ ( _1 )}
NEFieldTypes:
| LCID COLON Type
{ StringMap.singleton $1 $3 }
| LCID COLON Type COMMA NEFieldTypes
{ StringMap.add $1 $3 $5 }
| _1 = LCID _2 = COLON _3 = Type
{ ( StringMap.singleton _1 _3 )}
| _1 = LCID _2 = COLON _3 = Type _4 = COMMA _5 = NEFieldTypes
{ ( StringMap.add _1 _3 _5 )}
TermSeq:
| Term
{ $1 }
| Term SEMI TermSeq
{ ELet (PWildcard, $1, $3) }
| _1 = Term
{ ( _1 )}
| _1 = Term _2 = SEMI _3 = TermSeq
{ ( ELet (PWildcard, _1, _3) )}
ATerm:
| LPAREN TermSeq RPAREN
{ $2 }
| LCID
{ EVar $1 }
| LCURLY Fields RCURLY
{ ERecord $2 }
| _1 = LPAREN _2 = TermSeq _3 = RPAREN
{ ( _2 )}
| _1 = LCID
{ ( EVar _1 )}
| _1 = LCURLY _2 = Fields _3 = RCURLY
{ ( ERecord _2 )}
Fields:
|
{ StringMap.empty }
| NEFields
{ $1 }
{ ( StringMap.empty )}
| _1 = NEFields
{ ( _1 )}
NEFields:
| LCID EQ Term
{ StringMap.singleton $1 $3 }
| LCID EQ Term COMMA NEFields
{ StringMap.add $1 $3 $5 }
| _1 = LCID _2 = EQ _3 = Term
{ ( StringMap.singleton _1 _3 )}
| _1 = LCID _2 = EQ _3 = Term _4 = COMMA _5 = NEFields
{ ( StringMap.add _1 _3 _5 )}
OType:
|
{ TTop}
| LEQ Type
{ $2 }
{ ( TTop)}
| _1 = LEQ _2 = Type
{ ( _2 )}
Pattern:
| USCORE
{ PWildcard }
| LCID COLON Type
{ PVar ($1, $3) }
| LCURLY PatFields RCURLY
{ PRecord $2 }
| _1 = USCORE
{ ( PWildcard )}
| _1 = LCID _2 = COLON _3 = Type
{ ( PVar (_1, _3) )}
| _1 = LCURLY _2 = PatFields _3 = RCURLY
{ ( PRecord _2 )}
PatFields:
|
{ StringMap.empty }
| NEPatFields
{ $1 }
{ ( StringMap.empty )}
| _1 = NEPatFields
{ ( _1 )}
NEPatFields:
| LCID EQ Pattern
{ StringMap.singleton $1 $3 }
| LCID EQ Pattern COMMA NEPatFields
{ StringMap.add $1 $3 $5 }
| _1 = LCID _2 = EQ _3 = Pattern
{ ( StringMap.singleton _1 _3 )}
| _1 = LCID _2 = EQ _3 = Pattern _4 = COMMA _5 = NEPatFields
{ ( StringMap.add _1 _3 _5 )}
%%
......
This diff is collapsed.
This diff is collapsed.
......@@ -33,102 +33,102 @@
%%
parse_io_module:
| imports export decll expr Lend
{ ($1,$2,$3,$4) }
| _1 = imports _2 = export _3 = decll _4 = expr _5 = Lend
{ ( (_1,_2,_3,_4) )}
imports:
| Limport Lident importlist Lperiod imports
{ last_pos := pos $2;(String.lowercase (unpos $2), $3)::$5 }
| _1 = Limport _2 = Lident _3 = importlist _4 = Lperiod _5 = imports
{ ( last_pos := pos _2;(String.lowercase (unpos _2), _3)::_5 )}
|
{ [] }
{ ( [] )}
importlist:
| Lcolon idlist
{ Some $2 }
| _1 = Lcolon _2 = idlist
{ ( Some _2 )}
|
{ None }
{ ( None )}
export:
| Lexport idlist Lperiod
{ $2 }
| _1 = Lexport _2 = idlist _3 = Lperiod
{ ( _2 )}
|
{ [] }
{ ( [] )}
decll:
| Ldeclare Lident Lcolon eatom Lperiod decll
{ last_pos := pos $2;ct1 ($1,unpos $2,$4) $6 }
| Lprimitive Lident Lcolon Lident Lperiod decll
{ last_pos := pos $2;ct1 ($1,unpos $2,Eprimitive (unpos $4)) $6 }
| Lvariable Lident Lcolon eatom Lperiod decll
{ last_pos := pos $2;ct2 ($1,unpos $2,$4) $6 }
| _1 = Ldeclare _2 = Lident _3 = Lcolon _4 = eatom _5 = Lperiod _6 = decll
{ ( 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 )}
|
{ ([], []) }
{ ( ([], []) )}
expr:
| Lident paramlist
{ Eappl (pos $1, unpos $1, $2, EFall) }
| Lident
{ Eid (pos $1, unpos $1) }
| Lident Lputvar patom stmttail
{ Eputvar (pos $1, unpos $1, $3, $4, EFall) }
| Lident Lgetvar Lident stmttail
{ Egetvar (pos $1, unpos $1, unpos $3, $4, EFall) }
| stmt
{ $1 }
| _1 = Lident _2 = paramlist
{ ( 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 )}
paramlist:
| patom paramlisttail
{ $1::$2 }
| Lsemi eatom
{ [$2] }
| stmt
{ [$1] }
| _1 = patom _2 = paramlisttail
{ ( _1::_2 )}
| _1 = Lsemi _2 = eatom
{ ( [_2] )}
| _1 = stmt
{ ( [_1] )}
paramlisttail:
| patom paramlisttail
{ $1::$2 }
| Lsemi eatom
{ [$2] }
| stmt
{ [$1] }
| _1 = patom _2 = paramlisttail
{ ( _1::_2 )}
| _1 = Lsemi _2 = eatom
{ ( [_2] )}
| _1 = stmt
{ ( [_1] )}
|
{ [] }
{ ( [] )}
stmt:
| Llambda idlist stmttail
{ Elambda ($1,$2,$3,EFall) }
| _1 = Llambda _2 = idlist _3 = stmttail
{ ( Elambda (_1,_2,_3,EFall) )}
stmttail:
| Lsemi eatom
{ $2 }
| atom
{ $1 }
| _1 = Lsemi _2 = eatom
{ ( _2 )}
| _1 = atom
{ ( _1 )}
idlist:
| Lident idlist
{ last_pos := pos $1;(unpos $1)::$2 }
| _1 = Lident _2 = idlist
{ ( last_pos := pos _1;(unpos _1)::_2 )}
|
{ [] }
{ ( [] )}
eatom:
| expr
{ $1 }
| atom
{ $1 }
| _1 = expr
{ ( _1 )}
| _1 = atom
{ ( _1 )}
patom:
| Lident
{ last_pos := pos $1; Eid (pos $1,unpos $1) }
| atom
{ $1 }
| _1 = Lident
{ ( last_pos := pos _1; Eid (pos _1,unpos _1) )}
| _1 = atom
{ ( _1 )}
atom:
| Lint
{ last_pos := pos $1; Eint (pos $1,unpos $1) }
| Lstring
{ last_pos := pos $1; Estring (pos $1,unpos $1) }
| Llpar expr Lrpar
{ $2 }
| _1 = Lint
{ ( 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 )}
%%
......
......@@ -11,41 +11,41 @@ recommend switching on --infer in order to avoid obscure type error messages.
%%
phrase:
| xs = list___anonymous_0_ ys = list___anonymous_1_ EOF
{ xs @ ys }
| xs = list___anonymous_0_ ys = list___anonymous_1_ _3 = EOF
{ ( xs @ ys )}
list___anonymous_1_:
|
{ [] }
{ ( [] )}
| x0 = D y0 = D xs = list___anonymous_1_
{let x =
let y = y0 in
let x = x0 in
( x + y )
( ( x + y ))
in
x :: xs }
( x :: xs )}
list___anonymous_0_:
|
{ [] }
{ ( [] )}
| x0 = A xs = list___anonymous_0_
{let x =
let x = x0 in
( x )
( ( x ))
in
x :: xs }
( x :: xs )}
| x0 = B xs = list___anonymous_0_
{let x =
let x = x0 in
( x )
( ( x ))
in
x :: xs }
( x :: xs )}
| x0 = C xs = list___anonymous_0_
{let x =
let x = x0 in
( x )
( ( x ))
in
x :: xs }
( x :: xs )}
%%
......
......@@ -114,145 +114,145 @@ let rec addbinders tyT l = match l with
%%
toplevel:
| EOF
{ fun ctx -> [],ctx }
| Command SEMI toplevel
{ fun ctx ->
let cmd,ctx = $1 ctx in
let cmds,ctx = $3 ctx in
cmd::cmds,ctx }
| _1 = EOF
{ ( fun ctx -> [],ctx )}
| _1 = Command _2 = SEMI _3 = toplevel
{ ( fun ctx ->
let cmd,ctx = _1 ctx in
let cmds,ctx = _3 ctx in
cmd::cmds,ctx )}
Command:
| IMPORT STRINGV
{ fun ctx -> (Import($2.v)),ctx }
| Term
{ fun ctx -> (let t = $1 ctx in Whred(tmInfo t,t)),ctx }
| LPAREN NORMAL Term RPAREN
{ fun ctx -> (let t = $3 ctx in Eval(tmInfo t,t)),ctx }
| UCID TyBinder
{ fun ctx -> ((Bind($1.i, $1.v, $2 ctx)), addname ctx $1.v) }
| LCID Binder
{ fun ctx -> ((Bind($1.i,$1.v,$2 ctx)), addname ctx $1.v) }
| _1 = IMPORT _2 = STRINGV
{ ( fun ctx -> (Import(_2.v)),ctx )}