Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Raphaël Cauderlier
Sigmaid
Commits
441e5bb7
Commit
441e5bb7
authored
Jun 27, 2014
by
Raphaël Cauderlier
Browse files
Declare labels before using them.
parent
8fe77fdf
Changes
3
Hide whitespace changes
Inline
Side-by-side
parser.mly
View file @
441e5bb7
...
...
@@ -9,6 +9,15 @@
let
parse_error
s
=
print_endline
s
let
rec
insert1
k
=
function
|
[]
->
[
k
]
|
k'
::
l
when
k
<
k'
->
k
::
k'
::
l
|
k'
::
l
when
k
=
k'
->
k
::
l
|
k'
::
l
->
k'
::
k
::
l
let
label
l
=
let
l'
=
Label
l
in
Base
.
labels
:=
insert1
l'
!
Base
.
labels
;
l'
%
}
%
token
<
string
>
ID
CID
SELECT
UPDATE
...
...
printer.ml
View file @
441e5bb7
...
...
@@ -4,7 +4,20 @@ open Typer
let
print_id
out_fmter
(
Id
i
)
=
Format
.
fprintf
out_fmter
"%s"
i
let
print_cid
out_fmter
(
Cid
c
)
=
Format
.
fprintf
out_fmter
"%s"
c
let
print_label
out_fmter
(
Label
l
)
=
Format
.
fprintf
out_fmter
"%s"
l
let
print_label
out_fmter
(
Label
l
)
=
Format
.
fprintf
out_fmter
"lab_%s"
l
let
compile_string
out_fmter
s
=
let
n
=
String
.
length
s
in
String
.
iter
(
Format
.
fprintf
out_fmter
"dk_string.cons@ dk_char.%c@ ("
)
s
;
Format
.
fprintf
out_fmter
"dk_string.nil"
;
Format
.
fprintf
out_fmter
"%s"
(
String
.
make
n
'
)
'
)
let
declare_label
out_fmter
(
Label
l
)
=
Format
.
fprintf
out_fmter
"lab_%s :@ dk_string.String :=@ @[%a@]."
l
compile_string
l
let
declare_labels
out_fmter
=
List
.
iter
(
declare_label
out_fmter
)
let
rec
print_ty
out_fmter
=
function
|
Stcid
(
c
,
_
)
->
print_cid
out_fmter
c
...
...
sigmaid.ml
View file @
441e5bb7
...
...
@@ -18,6 +18,7 @@ let rec lex_prog lb =
let
main
()
=
Arg
.
parse
[]
(
fun
file
->
Base
.
labels
:=
[]
;
let
input
=
open_in
file
in
let
lexbuf
=
Lexing
.
from_channel
input
in
let
out_fmter
=
Format
.
std_formatter
in
...
...
@@ -25,6 +26,7 @@ let main () =
let
scoped_prog
=
Scoper
.
scope
prog
in
let
typed_prog
=
Typer
.
type_check
scoped_prog
in
Format
.
fprintf
out_fmter
"#NAME %s.@
\n
"
(
Filename
.
chop_extension
file
);
Printer
.
declare_labels
out_fmter
!
Base
.
labels
;
Printer
.
print
out_fmter
typed_prog
;
Format
.
fprintf
out_fmter
"@."
)
"Please provide a file name."
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment