Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
E-language compiler
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sellami Youssef
E-language compiler
Commits
ec4bd438
Commit
ec4bd438
authored
2 weeks ago
by
Sellami Youssef
Browse files
Options
Downloads
Patches
Plain Diff
Types : mutual recursive functions
parent
9510950f
No related branches found
Branches containing commit
No related tags found
1 merge request
!3
Master
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
expr_grammar_action.g
+5
-2
5 additions, 2 deletions
expr_grammar_action.g
src/elang_gen.ml
+8
-2
8 additions, 2 deletions
src/elang_gen.ml
src/elang_print.ml
+4
-3
4 additions, 3 deletions
src/elang_print.ml
tests/Makefile
+1
-1
1 addition, 1 deletion
tests/Makefile
with
18 additions
and
8 deletions
expr_grammar_action.g
+
5
−
2
View file @
ec4bd438
...
...
@@ -13,7 +13,7 @@ non-terminals CMP_EXPRS CMP_EXPR
non-terminals EQ_EXPRS EQ_EXPR
non-terminals AFTER_IDENTIFIER_INSTR AFTER_IDENTIFIER_FACTOR LARGS REST_ARGS
non-terminals TYPE AFTER_IDENTIFIER_DEC CHARACTER
non-terminals TYPE AFTER_IDENTIFIER_DEC CHARACTER
FUN_INSTR
axiom S
{
...
...
@@ -42,7 +42,7 @@ rules
S -> FUNDEFS SYM_EOF { Node(Tlistglobdef, $1) }
FUNDEFS -> FUNDEF FUNDEFS { $1::$2 }
FUNDEFS -> { [] }
FUNDEF -> TYPE IDENTIFIER SYM_LPARENTHESIS LPARAMS SYM_RPARENTHESIS INSTR { Node(Tfundef, [Node(Tfuntype, [$1]); Node(Tfunname, [$2]); Node(Tfunargs, $4); Node(Tfunbody, [$6])]) }
FUNDEF -> TYPE IDENTIFIER SYM_LPARENTHESIS LPARAMS SYM_RPARENTHESIS
FUN_
INSTR { Node(Tfundef, [Node(Tfuntype, [$1]); Node(Tfunname, [$2]); Node(Tfunargs, $4); Node(Tfunbody, [$6])]) }
TYPE -> SYM_INT { TypeLeaf Tint }
TYPE -> SYM_CHAR { TypeLeaf Tchar }
...
...
@@ -58,6 +58,9 @@ LARGS -> { [] }
REST_ARGS -> SYM_COMMA EXPR REST_ARGS { $2::$3 }
REST_ARGS -> { [] }
FUN_INSTR -> SYM_LBRACE LINSTRS SYM_RBRACE { $2 }
FUN_INSTR -> SYM_SEMICOLON { NullLeaf }
LINSTRS -> INSTR INSTRS { Node(Tblock, $1::$2) }
LINSTRS -> { NullLeaf }
INSTRS -> INSTR INSTRS { $1::$2 }
...
...
This diff is collapsed.
Click to expand it.
src/elang_gen.ml
+
8
−
2
View file @
ec4bd438
...
...
@@ -48,7 +48,7 @@ let rec type_expr (typ_var : (string,typ) Hashtbl.t) (typ_fun : (string, typ lis
type_expr
typ_var
typ_fun
e1
>>=
fun
t1
->
type_expr
typ_var
typ_fun
e2
>>=
fun
t2
->
if
t1
!=
Tvoid
&&
t2
!=
Tvoid
then
OK
Tint
then
OK
Tint
(* à vérifier *)
else
Error
"E: Binop is not defined on void type."
|
Eunop
(
u
,
e
)
->
type_expr
typ_var
typ_fun
e
>>=
fun
t
->
...
...
@@ -195,7 +195,13 @@ let make_eprog_of_ast (a: tree) : eprog res =
Hashtbl
.
replace
fun_typ
"print"
([
Tint
]
,
Tvoid
);
Hashtbl
.
replace
fun_typ
"print_int"
([
Tint
]
,
Tvoid
);
Hashtbl
.
replace
fun_typ
"print_char"
([
Tchar
]
,
Tvoid
);
list_map_res
(
fun
a
->
make_fundef_of_ast
fun_typ
a
>>=
fun
(
fname
,
efun
)
->
OK
(
fname
,
Gfun
efun
))
l
List
.
fold_left
(
fun
acc
a
->
acc
>>=
fun
f_list
->
make_fundef_of_ast
fun_typ
a
>>=
fun
(
fname
,
efun
)
->
match
List
.
assoc_opt
fname
f_list
with
|
None
->
OK
(
f_list
@
[
fname
,
Gfun
efun
])
|
Some
(
Gfun
dec
)
when
dec
.
funbody
=
Iblock
[]
->
OK
(
List
.
remove_assoc
fname
f_list
@
[
fname
,
Gfun
efun
])
|
_
->
Error
(
Format
.
sprintf
"E: Multiple definitions of function %s."
fname
))
(
OK
[]
)
l
|
_
->
Error
(
Printf
.
sprintf
"make_fundef_of_ast: Expected a Tlistglobdef, got %s."
(
string_of_ast
a
))
...
...
This diff is collapsed.
Click to expand it.
src/elang_print.ml
+
4
−
3
View file @
ec4bd438
...
...
@@ -27,7 +27,7 @@ let rec dump_eexpr = function
|
Eint
i
->
Printf
.
sprintf
"%d"
i
|
Evar
s
->
Printf
.
sprintf
"%s"
s
|
Ecall
(
f
,
args
)
->
Printf
.
sprintf
"%s(%s)"
f
(
String
.
concat
", "
(
List
.
map
dump_eexpr
args
))
|
Echar
c
->
Printf
.
sprintf
"%c"
c
|
Echar
c
->
Printf
.
sprintf
"
'
%c
'
"
c
let
indent_size
=
2
let
spaces
n
=
range
(
indent_size
*
n
)
|>
List
.
map
(
fun
_
->
'
'
)
|>
String
.
of_list
...
...
@@ -66,8 +66,9 @@ let rec dump_einstr_rec indent oc i =
let
dump_einstr
oc
i
=
dump_einstr_rec
0
oc
i
let
dump_efun
oc
funname
{
funargs
;
funbody
}
=
Format
.
fprintf
oc
"%s(%s) {
\n
%a
\n
}
\n
"
let
dump_efun
oc
funname
{
funargs
;
funbody
;
funrettype
}
=
Format
.
fprintf
oc
"%s %s(%s) %a
\n
"
(
string_of_typ
funrettype
)
funname
(
String
.
concat
","
(
List
.
map
(
fun
(
s
,
t
)
->
Printf
.
sprintf
"%s %s"
(
string_of_typ
t
)
s
)
funargs
))
dump_einstr
funbody
...
...
This diff is collapsed.
Click to expand it.
tests/Makefile
+
1
−
1
View file @
ec4bd438
# if make is launched with a DIR variable, pass it as the -f option to test.py
# 'make DIR=basic/mul*.e' launches all the files starting with mul in the basic directory
# otherwise, use basic/*.e as a default
FILES
:=
$(
if
$(
DIR
)
,
$(
DIR
)
,type_
basic
/
*
.e
)
FILES
:=
$(
if
$(
DIR
)
,
$(
DIR
)
,type_
funcall
/
*
.e
)
OPTS
:=
$(
if
$(
OPTS
)
,
$(
OPTS
)
,
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment