Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
infosec-ecomp
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
Putegnat Theo
infosec-ecomp
Commits
d9659a6a
Commit
d9659a6a
authored
2 years ago
by
Putegnat Theo
Browse files
Options
Downloads
Patches
Plain Diff
TP3 premiere partie
parent
b23ce229
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
expr_grammar_action.g
+2
-2
2 additions, 2 deletions
expr_grammar_action.g
opts.mk
+2
-2
2 additions, 2 deletions
opts.mk
src/elang_gen.ml
+37
-4
37 additions, 4 deletions
src/elang_gen.ml
with
41 additions
and
8 deletions
expr_grammar_action.g
+
2
−
2
View file @
d9659a6a
...
@@ -77,7 +77,7 @@ ADD_EXPRS -> SYM_MINUS ADD_EXPR ADD_EXPRS { (Tsub,$2) :: $3 }
...
@@ -77,7 +77,7 @@ ADD_EXPRS -> SYM_MINUS ADD_EXPR ADD_EXPRS { (Tsub,$2) :: $3 }
ADD_EXPRS-> {[]}
ADD_EXPRS-> {[]}
EQ_EXPRS -> SYM_EQUALITY MUL_EXPR MUL_EXPRS { (Tceq,$2) :: $3 }
EQ_EXPRS -> SYM_EQUALITY MUL_EXPR MUL_EXPRS { (Tceq,$2) :: $3 }
EQ_EXPRS -> SYM_NOTEQ MUL_EXPR MUL_EXPRS { (Tne
g
,$2) :: $3 }
EQ_EXPRS -> SYM_NOTEQ MUL_EXPR MUL_EXPRS { (Tne,$2) :: $3 }
EQ_EXPRS -> {[]}
EQ_EXPRS -> {[]}
CMP_EXPRS -> SYM_GEQ MUL_EXPR MUL_EXPRS { (Tcge,$2) :: $3 }
CMP_EXPRS -> SYM_GEQ MUL_EXPR MUL_EXPRS { (Tcge,$2) :: $3 }
...
@@ -87,7 +87,7 @@ CMP_EXPRS -> SYM_LEQ MUL_EXPR MUL_EXPRS { (Tcle,$2) :: $3 }
...
@@ -87,7 +87,7 @@ CMP_EXPRS -> SYM_LEQ MUL_EXPR MUL_EXPRS { (Tcle,$2) :: $3 }
CMP_EXPRS -> {[]}
CMP_EXPRS -> {[]}
INTEGER -> SYM_INTEGER {IntLeaf
($1)}
INTEGER -> SYM_INTEGER {
Node (Tint, [
IntLeaf($1)
])
}
IDENTIFIER -> SYM_IDENTIFIER {StringLeaf ($1)}
IDENTIFIER -> SYM_IDENTIFIER {StringLeaf ($1)}
...
...
This diff is collapsed.
Click to expand it.
opts.mk
+
2
−
2
View file @
d9659a6a
CONF_OPTS
=
CONF_OPTS
=
# Use handwritten lexer
# Use handwritten lexer
CONF_OPTS
+=
-l
#
CONF_OPTS+=-l
# Use ocamllex lexer
# Use ocamllex lexer
#
CONF_OPTS+=-L
CONF_OPTS
+=
-L
# Use alpaga parser
# Use alpaga parser
CONF_OPTS
+=
-a
CONF_OPTS
+=
-a
...
...
This diff is collapsed.
Click to expand it.
src/elang_gen.ml
+
37
−
4
View file @
d9659a6a
...
@@ -45,8 +45,13 @@ let rec make_eexpr_of_ast (a: tree) : expr res =
...
@@ -45,8 +45,13 @@ let rec make_eexpr_of_ast (a: tree) : expr res =
let
res
=
let
res
=
match
a
with
match
a
with
|
Node
(
t
,
[
e1
;
e2
])
when
tag_is_binop
t
->
|
Node
(
t
,
[
e1
;
e2
])
when
tag_is_binop
t
->
Error
(
Printf
.
sprintf
"Unacceptable ast in make_eexpr_of_ast %s"
make_eexpr_of_ast
e1
>>=
(
fun
expr1
->
(
string_of_ast
a
))
make_eexpr_of_ast
e2
>>=
(
fun
expr2
->
OK
(
Ebinop
(
binop_of_tag
t
,
expr1
,
expr2
))))
|
Node
(
t
,
[
e
])
->
make_eexpr_of_ast
e
>>=
fun
expr
->
OK
(
Eunop
(
Eneg
,
expr
))
|
IntLeaf
(
a
)
->
OK
(
Eint
a
)
|
StringLeaf
(
s
)
->
OK
(
Evar
s
)
|
_
->
Error
(
Printf
.
sprintf
"Unacceptable ast in make_eexpr_of_ast %s"
|
_
->
Error
(
Printf
.
sprintf
"Unacceptable ast in make_eexpr_of_ast %s"
(
string_of_ast
a
))
(
string_of_ast
a
))
in
in
...
@@ -58,6 +63,34 @@ let rec make_eexpr_of_ast (a: tree) : expr res =
...
@@ -58,6 +63,34 @@ let rec make_eexpr_of_ast (a: tree) : expr res =
let
rec
make_einstr_of_ast
(
a
:
tree
)
:
instr
res
=
let
rec
make_einstr_of_ast
(
a
:
tree
)
:
instr
res
=
let
res
=
let
res
=
match
a
with
match
a
with
|
Node
(
Tassign
,
tass
)
->
begin
match
tass
with
|
[
Node
(
Tassignvar
,
[
StringLeaf
(
s
);
e
])]
->
make_eexpr_of_ast
e
>>=
(
fun
expr
->
OK
(
Iassign
(
s
,
expr
)))
|
_
->
Error
(
Printf
.
sprintf
"Pas encore d'autres options"
)
end
|
Node
(
Tif
,
[
e
;
i1
;
i2
])
->
make_eexpr_of_ast
e
>>=
(
fun
expr
->
make_einstr_of_ast
i1
>>=
fun
instr1
->
make_einstr_of_ast
i2
>>=
fun
instr2
->
OK
(
Iif
(
expr
,
instr1
,
instr2
)))
|
Node
(
Twhile
,
[
e
;
i
])
->
make_eexpr_of_ast
e
>>=
(
fun
expr
->
make_einstr_of_ast
i
>>=
fun
instr
->
OK
(
Iwhile
(
expr
,
instr
)))
|
Node
(
Tblock
,
list_of_instr
)
->
OK
(
Iblock
(
List
.
map
(
fun
x
->
make_einstr_of_ast
x
>>!
fun
instr
->
instr
)
list_of_instr
))
|
Node
(
Treturn
,
[
e
])
->
make_eexpr_of_ast
e
>>=
fun
expr
->
OK
(
Ireturn
(
expr
)
)
|
Node
(
Tprint
,
[
e
])
->
make_eexpr_of_ast
e
>>=
fun
expr
->
OK
(
Iprint
(
expr
))
|
_
->
Error
(
Printf
.
sprintf
"Unacceptable ast in make_einstr_of_ast %s"
|
_
->
Error
(
Printf
.
sprintf
"Unacceptable ast in make_einstr_of_ast %s"
(
string_of_ast
a
))
(
string_of_ast
a
))
in
in
...
@@ -76,9 +109,9 @@ let make_ident (a: tree) : string res =
...
@@ -76,9 +109,9 @@ let make_ident (a: tree) : string res =
let
make_fundef_of_ast
(
a
:
tree
)
:
(
string
*
efun
)
res
=
let
make_fundef_of_ast
(
a
:
tree
)
:
(
string
*
efun
)
res
=
match
a
with
match
a
with
|
Node
(
Tfundef
,
[
StringLeaf
fname
;
Node
(
Tfunargs
,
fargs
);
fbody
])
->
|
Node
(
Tfundef
,
[
StringLeaf
fname
;
Node
(
Tfunargs
,
fargs
);
fbody
])
->
list_map_res
make_ident
fargs
>>=
fun
fargs
->
list_map_res
make_ident
fargs
>>=
(
fun
new
fargs
->
(* TODO *)
(* TODO *)
Error
"make_fundef_of_ast: Not implemented, yet."
OK
(
fname
,
{
funargs
=
newfargs
;
funbody
=
(
make_einstr_of_ast
fbody
>>!
(
fun
fonction_body
->
fonction_body
))}))
|
_
->
|
_
->
Error
(
Printf
.
sprintf
"make_fundef_of_ast: Expected a Tfundef, got %s."
Error
(
Printf
.
sprintf
"make_fundef_of_ast: Expected a Tfundef, got %s."
(
string_of_ast
a
))
(
string_of_ast
a
))
...
...
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