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

Too many changes to show.

To preserve performance only 104 of 104+ files are displayed.

......@@ -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 )}
%%
......
......@@ -56,234 +56,234 @@ open Syntax
%%
typevar:
| QUOTE LID
{ $2 }
| _1 = QUOTE _2 = LID
{ ( _2 )}
typevars:
| typevar
{ [ $1 ] }
| typevars COMMA typevar
{ $3 :: $1 }
| _1 = typevar
{ ( [ _1 ] )}
| _1 = typevars _2 = COMMA _3 = typevar
{ ( _3 :: _1 )}
params:
|
{ [] }
| typevar
{ [ $1 ] }
| LPAREN typevars RPAREN
{ List.rev $2 }
{ ( [] )}
| _1 = typevar
{ ( [ _1 ] )}
| _1 = LPAREN _2 = typevars _3 = RPAREN
{ ( List.rev _2 )}
params_and_set_current:
| params
{ let params = $1 in
| _1 = params
{ ( let params = _1 in
current_params := params;
params }
params )}
identifier:
| LID
{ $1 }
| UID DOT identifier
{ let (pos1, _, id1) = $1
and (_, pos2, id2) = $3 in
(pos1, pos2, id1 ^ "." ^ id2) }
| _1 = LID
{ ( _1 )}
| _1 = UID _2 = DOT _3 = identifier
{ ( let (pos1, _, id1) = _1
and (_, pos2, id2) = _3 in
(pos1, pos2, id1 ^ "." ^ id2) )}
container:
|
{ None }
| identifier
{ Some $1 }
{ ( None )}
| _1 = identifier
{ ( Some _1 )}
expfactor:
| ATOM LID
{ EAtom $2 }
| OCAML
{ EEscape $1 }
| params LID container
{ ETypRef ($3, $1, $2) }
| LANGLE params LID RANGLE
{ EAbstraction ($2, $3) }
| LANGLE LPAREN LID BINDS sorts RPAREN patrhs RANGLE
{ inline_defs := DeclPatType (!current_params, $3, $5, $7) :: !inline_defs;
EAbstraction (!current_params, $3) }
| ATOM error
{ error 2 "\"atom\" should be followed by a sort (a lowercase identifier)" }
| LANGLE error
{ error 2 "The contents of an abstraction should be either\n\
| _1 = ATOM _2 = LID
{ ( EAtom _2 )}
| _1 = OCAML
{ ( EEscape _1 )}
| _1 = params _2 = LID _3 = container
{ ( ETypRef (_3, _1, _2) )}
| _1 = LANGLE _2 = params _3 = LID _4 = RANGLE
{ ( EAbstraction (_2, _3) )}
| _1 = LANGLE _2 = LPAREN _3 = LID _4 = BINDS _5 = sorts _6 = RPAREN _7 = patrhs _8 = RANGLE
{ ( inline_defs := DeclPatType (!current_params, _3, _5, _7) :: !inline_defs;
EAbstraction (!current_params, _3) )}
| _1 = ATOM _2 = error
{ ( error 2 "\"atom\" should be followed by a sort (a lowercase identifier)" )}
| _1 = LANGLE _2 = error
{ ( error 2 "The contents of an abstraction should be either\n\
a (possibly parameterized) pattern type identifier or\n\
an inline pattern type definition." }
| INNER
{ error 1 "\"inner\" does not make sense in an expression type." }
| OUTER
{ error 1 "\"outer\" does not make sense in an expression type." }
| NEUTRAL
{ error 1 "\"neutral\" does not make sense in an expression type." }
| error
{ error 1 "Invalid expression factor." }
an inline pattern type definition." )}
| _1 = INNER
{ ( error 1 "\"inner\" does not make sense in an expression type." )}
| _1 = OUTER
{ ( error 1 "\"outer\" does not make sense in an expression type." )}
| _1 = NEUTRAL
{ ( error 1 "\"neutral\" does not make sense in an expression type." )}
| _1 = error
{ ( error 1 "Invalid expression factor." )}
patfactor:
| ATOM LID
{ PAtom $2 }
| OCAML
{ PEscape $1 }
| params LID container
{ PTypRef (MRef, $3, $1, $2) }
| patmodifier params LID container
{ PTypRef ($1, $4, $2, $3) }
| ATOM error
{ error 2 "\"atom\" should be followed by a sort (a lowercase identifier)" }
| patmodifier error
{ error 2 "\"inner\", \"outer\", and \"neutral\" should be followed by a\n(possibly parameterized) type identifier." }
| LANGLE
{ error 1 "An abstraction does not make sense in a pattern type." }
| error
{ error 1 "Invalid pattern factor." }
| _1 = ATOM _2 = LID
{ ( PAtom _2 )}
| _1 = OCAML
{ ( PEscape _1 )}
| _1 = params _2 = LID _3 = container
{ ( PTypRef (MRef, _3, _1, _2) )}
| _1 = patmodifier _2 = params _3 = LID _4 = container
{ ( PTypRef (_1, _4, _2, _3) )}
| _1 = ATOM _2 = error
{ ( error 2 "\"atom\" should be followed by a sort (a lowercase identifier)" )}
| _1 = patmodifier _2 = error
{ ( error 2 "\"inner\", \"outer\", and \"neutral\" should be followed by a\n(possibly parameterized) type identifier." )}
| _1 = LANGLE
{ ( error 1 "An abstraction does not make sense in a pattern type." )}
| _1 = error
{ ( error 1 "Invalid pattern factor." )}
patmodifier:
| INNER
{ MInner }
| OUTER
{ MOuter }
| NEUTRAL
{ MNeutral }
| _1 = INNER
{ ( MInner )}
| _1 = OUTER
{ ( MOuter )}
| _1 = NEUTRAL
{ ( MNeutral )}
expfactors:
| expfactor
{ [ (None, $1) ] }
| expfactors STAR expfactor
{ (None, $3) :: $1 }
| expfactors error
{ error 2 "Undetermined syntax error." }
| _1 = expfactor
{ ( [ (None, _1) ] )}
| _1 = expfactors _2 = STAR _3 = expfactor
{ ( (None, _3) :: _1 )}
| _1 = expfactors _2 = error
{ ( error 2 "Undetermined syntax error." )}
patfactors:
| patfactor
{ [ (None, $1) ] }
| patfactors STAR patfactor
{ (None, $3) :: $1 }
| patfactors error
{ error 2 "Undetermined syntax error." }
| _1 = patfactor
{ ( [ (None, _1) ] )}
| _1 = patfactors _2 = STAR _3 = patfactor
{ ( (None, _3) :: _1 )}
| _1 = patfactors _2 = error
{ ( error 2 "Undetermined syntax error." )}
explfactor:
| LID COLON expfactor
{ (Some $1, $3) }
| error
{ error 1 "\"<label> : <expression factor>\" expected." }
| _1 = LID _2 = COLON _3 = expfactor
{ ( (Some _1, _3) )}
| _1 = error
{ ( error 1 "\"<label> : <expression factor>\" expected." )}
explfactors:
| explfactor
{ [ $1 ] }
| explfactors SEMICOLON explfactor
{ $3 :: $1 }
| explfactors error
{ error 2 "\";\" or \"}\" expected." }
| _1 = explfactor
{ ( [ _1 ] )}
| _1 = explfactors _2 = SEMICOLON _3 = explfactor
{ ( _3 :: _1 )}
| _1 = explfactors _2 = error
{ ( error 2 "\";\" or \"}\" expected." )}
patlfactor:
| LID COLON patfactor
{ (Some $1, $3) }
| error
{ error 1 "\"<label> : <pattern factor>\" expected." }
| _1 = LID _2 = COLON _3 = patfactor
{ ( (Some _1, _3) )}
| _1 = error
{ ( error 1 "\"<label> : <pattern factor>\" expected." )}
patlfactors:
| patlfactor
{ [ $1 ] }
| patlfactors SEMICOLON patlfactor
{ $3 :: $1 }
| patlfactors error
{ error 2 "\";\" or \"}\" expected." }
| _1 = patlfactor
{ ( [ _1 ] )}
| _1 = patlfactors _2 = SEMICOLON _3 = patlfactor
{ ( _3 :: _1 )}
| _1 = patlfactors _2 = error
{ ( error 2 "\";\" or \"}\" expected." )}
expsummand:
| BAR UID
{ Summand (Some $2, []) }
| BAR UID OF expfactors
{ Summand (Some $2, List.rev $4) }
| BAR error
{ error 2 "\"| <uppercase identifier> [ of <expression factors> ]\" expected." }
| _1 = BAR _2 = UID
{ ( Summand (Some _2, []) )}
| _1 = BAR _2 = UID _3 = OF _4 = expfactors
{ ( Summand (Some _2, List.rev _4) )}
| _1 = BAR _2 = error
{ ( error 2 "\"| <uppercase identifier> [ of <expression factors> ]\" expected." )}
patsummand:
| BAR UID
{ Summand (Some $2, []) }
| BAR UID OF patfactors
{ Summand (Some $2, List.rev $4) }
| BAR error
{ error 2 "\"| <uppercase identifier> [ of <pattern factors> ]\" expected." }
| _1 = BAR _2 = UID
{ ( Summand (Some _2, []) )}
| _1 = BAR _2 = UID _3 = OF _4 = patfactors
{ ( Summand (Some _2, List.rev _4) )}
| _1 = BAR _2 = error
{ ( error 2 "\"| <uppercase identifier> [ of <pattern factors> ]\" expected." )}
expsummands:
| expsummand
{ [ $1 ] }
| expsummands expsummand
{ $2 :: $1 }
| _1 = expsummand
{ ( [ _1 ] )}
| _1 = expsummands _2 = expsummand
{ ( _2 :: _1 )}
patsummands:
| patsummand
{ [ $1 ] }
| patsummands patsummand
{ $2 :: $1 }
| _1 = patsummand
{ ( [ _1 ] )}
| _1 = patsummands _2 = patsummand
{ ( _2 :: _1 )}
sorts:
| LID
{ [ $1 ] }