use separated list
This commit is contained in:
parent
51150269cc
commit
1305a867f8
2 changed files with 13 additions and 50 deletions
3
Makefile
3
Makefile
|
@ -30,3 +30,6 @@ archive:
|
|||
|
||||
symlinks:
|
||||
ln -s _build/*.cmi .
|
||||
|
||||
menhir-debug:
|
||||
menhir parser.mly --explain --infer
|
||||
|
|
60
parser.mly
60
parser.mly
|
@ -18,17 +18,10 @@
|
|||
%left Ladd Lsub Lmul Ldiv Lrem Lseq Lsge Lsgt Lsle Lslt Lsne
|
||||
%left Land Lor
|
||||
|
||||
%left Lbracedeb Lparfin Lbracefin Lreturn
|
||||
%left Ltype Lbool Lint Lvar Lstr
|
||||
%left Lif Lwhile
|
||||
%type <Ast.Syntax.prog> prog
|
||||
|
||||
%start prog
|
||||
|
||||
%type <Ast.Syntax.block> block
|
||||
%type <Ast.Syntax.prog> prog
|
||||
%type <Ast.Syntax.args> args_ident
|
||||
%type <Ast.Syntax.expr list> args_expr
|
||||
|
||||
%%
|
||||
|
||||
prog:
|
||||
|
@ -38,42 +31,19 @@ prog:
|
|||
| Lend { [] }
|
||||
|
||||
def:
|
||||
/* Définition fonction : type fonction (args) block */
|
||||
/* Définition fonction : type fonction (...) block */
|
||||
| t = Ltype
|
||||
; f = Lvar
|
||||
; a = args_ident
|
||||
; Lpardeb
|
||||
; a = separated_list(Lcomma, arg)
|
||||
; Lparfin
|
||||
; b = block {
|
||||
[ Func { func = f ; type_t = t ; args = a ; code = b ; pos = $startpos(f) } ]
|
||||
}
|
||||
|
||||
/* Définition fonction : type fonction () block */
|
||||
| t = Ltype
|
||||
; f = Lvar
|
||||
; Lpardeb
|
||||
; Lparfin
|
||||
; b = block {
|
||||
[ Func { func = f ; type_t = t ; args = [] ; code = b ; pos = $startpos(f) } ]
|
||||
}
|
||||
|
||||
args_ident:
|
||||
/* ( */
|
||||
| Lpardeb ; s = args_ident { s }
|
||||
|
||||
/* type a, ... */
|
||||
| t = Ltype ; a = arg_ident ; Lcomma ; s = args_ident { Arg { type_t = t
|
||||
; name = a
|
||||
} :: s }
|
||||
|
||||
/* type c) */
|
||||
| t = Ltype ; a = arg_ident ; Lparfin { [ Arg { type_t = t
|
||||
; name = a } ] }
|
||||
|
||||
/* ) */
|
||||
| Lparfin { [] }
|
||||
|
||||
arg_ident:
|
||||
/* Argument */
|
||||
| a = Lvar { a }
|
||||
arg:
|
||||
/* type a */
|
||||
| t = Ltype ; a = Lvar { Arg { type_t = t ; name = a } }
|
||||
|
||||
block:
|
||||
/* { */
|
||||
|
@ -223,18 +193,8 @@ expr:
|
|||
Call { func = "%or" ; args = [ a ; b ] ; pos = $startpos($2) }
|
||||
}
|
||||
|
||||
/* function(a */
|
||||
| f = Lvar ; Lpardeb ; a = args_expr {
|
||||
/* function(...) */
|
||||
| f = Lvar ; Lpardeb ; a = separated_list(Lcomma, expr) ; Lparfin {
|
||||
Call { func = f ; args = a ; pos = $startpos(a) }
|
||||
}
|
||||
;
|
||||
|
||||
args_expr:
|
||||
/* a, ... */
|
||||
| a = expr ; Lcomma ; s = args_expr { a :: s }
|
||||
|
||||
/* c) */
|
||||
| a = expr ; Lparfin { [ a ] }
|
||||
|
||||
/* ) */
|
||||
| Lparfin { [] }
|
||||
|
|
Reference in a new issue