Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pga
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
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
Taddeüs Kroes
pga
Commits
a974ecee
Commit
a974ecee
authored
10 years ago
by
Taddeüs Kroes
Browse files
Options
Downloads
Patches
Plain Diff
Added finite repeat instruction and utf8/latex stringification commands
parent
739a8a89
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
parser.mly
+8
-7
8 additions, 7 deletions
parser.mly
pga.ml
+8
-2
8 additions, 2 deletions
pga.ml
stringify.ml
+44
-22
44 additions, 22 deletions
stringify.ml
types.ml
+11
-10
11 additions, 10 deletions
types.ml
with
71 additions
and
41 deletions
parser.mly
+
8
−
7
View file @
a974ecee
...
...
@@ -20,11 +20,12 @@ program:
{
instrs
}
instruction
:
|
c
=
LOWER
{
Basic
c
}
|
EXCLAM
{
Terminate
}
|
PLUS
c
=
LOWER
{
Ptest
c
}
|
MINUS
c
=
LOWER
{
Ntest
c
}
|
HASH
n
=
NUMBER
{
Jump
n
}
|
i
=
instruction
OMEGA
{
Repeat
i
}
|
c
=
UPPER
{
Program
c
}
|
c
=
LOWER
{
Basic
c
}
|
EXCLAM
{
Terminate
}
|
PLUS
c
=
LOWER
{
Ptest
c
}
|
MINUS
c
=
LOWER
{
Ntest
c
}
|
HASH
n
=
NUMBER
{
Jump
n
}
|
i
=
instruction
n
=
NUMBER
{
Repeat
(
i
,
n
)
}
|
i
=
instruction
OMEGA
{
Loop
i
}
|
c
=
UPPER
{
Program
c
}
|
LPAREN
i
=
separated_list
(
SEMICOL
,
instruction
)
RPAREN
{
Concat
i
}
This diff is collapsed.
Click to expand it.
pga.ml
+
8
−
2
View file @
a974ecee
...
...
@@ -7,8 +7,10 @@ let main () =
prerr_endline
"command:"
;
prerr_endline
" help show this help page"
;
prerr_endline
" echo TERM pretty-print a program"
;
prerr_endline
" utf8 TERM print a program in UTF-8 format"
;
prerr_endline
" latex TERM print latex source for a program"
;
prerr_endline
" norm TERM get the norm of a program"
;
prerr_endline
" i TERM
get the
i
th instruction of a program"
;
prerr_endline
" i
I
TERM get the
I
th instruction of a program"
;
prerr_endline
" dot TERM generate Dot code for a flow graph"
;
prerr_endline
"input program syntax:"
;
prerr_endline
" - write star (*) instead of omega sign"
;
...
...
@@ -38,7 +40,11 @@ let main () =
|
"help"
->
usage
0
|
"echo"
->
print_endline
(
string_of_program
(
input_term
2
))
print_endline
(
string_of_program_ascii
(
input_term
2
))
|
"utf8"
->
print_endline
(
string_of_program_utf8
(
input_term
2
))
|
"latex"
->
print_endline
(
string_of_program_latex
(
input_term
2
))
|
"norm"
|
"i"
|
"dot"
->
raise
(
Failure
"not implemented"
)
|
_
->
...
...
This diff is collapsed.
Click to expand it.
stringify.ml
+
44
−
22
View file @
a974ecee
open
Types
(*
let omega = "\xcf\x89"
let pound = "\xc2\xa3"
*)
let
omega
=
"*"
let
pound
=
"$"
let
rec
string_of_instruction
=
function
|
Basic
c
->
Char
.
escaped
c
|
Terminate
->
"!"
|
Ptest
c
->
"+"
^
Char
.
escaped
c
|
Ntest
c
->
"-"
^
Char
.
escaped
c
|
Jump
len
->
"#"
^
string_of_int
len
|
Concat
l
->
"("
^
String
.
concat
";"
(
List
.
map
string_of_instruction
l
)
^
")"
|
Repeat
i
->
string_of_instruction
i
^
omega
|
Program
c
->
Char
.
escaped
c
|
Empty
->
""
let
rec
string_of_program
instrs
=
String
.
concat
";"
(
List
.
map
string_of_instruction
instrs
)
let
utf8_omega
=
"
\xcf\x89
"
let
utf8_pound
=
"
\xc2\xa3
"
let
utf8_super
=
[
|
"
\xe2\x81\xb0
"
;
"
\xc2\xb9
"
;
"
\xc2\xb2
"
;
"
\xc2\xb3
"
;
"
\xe2\x81\xb4
"
;
"
\xe2\x81\xb5
"
;
"
\xe2\x81\xb6
"
;
"
\xe2\x81\xb7
"
;
"
\xe2\x81\xb8
"
;
"
\xe2\x81\xb9
"
|
]
let
cat
string_of_ins
instrs
=
"("
^
String
.
concat
";"
(
List
.
map
string_of_ins
instrs
)
^
")"
let
rec
string_of_ins_ascii
=
function
|
Basic
c
->
Char
.
escaped
c
|
Terminate
->
"!"
|
Ptest
c
->
"+"
^
Char
.
escaped
c
|
Ntest
c
->
"-"
^
Char
.
escaped
c
|
Jump
len
->
"#"
^
string_of_int
len
|
Concat
l
->
cat
string_of_ins_ascii
l
|
Repeat
(
i
,
n
)
->
string_of_ins_ascii
i
^
string_of_int
n
|
Loop
i
->
string_of_ins_ascii
i
^
"*"
|
Program
c
->
Char
.
escaped
c
|
Empty
->
""
let
rec
string_of_ins_utf8
=
function
|
Concat
l
->
cat
string_of_ins_utf8
l
|
Repeat
(
i
,
n
)
when
n
<=
9
->
string_of_ins_utf8
i
^
utf8_super
.
(
n
)
|
Loop
i
->
string_of_ins_utf8
i
^
utf8_omega
|
i
->
string_of_ins_ascii
i
let
rec
string_of_ins_latex
=
function
|
Concat
l
->
cat
string_of_ins_latex
l
|
Repeat
(
i
,
n
)
->
string_of_ins_latex
i
^
"^{"
^
string_of_int
n
^
"}"
|
Loop
i
->
string_of_ins_latex
i
^
"^
\\
omega"
|
i
->
string_of_ins_ascii
i
let
string_of_program_ascii
instrs
=
String
.
concat
";"
(
List
.
map
string_of_ins_ascii
instrs
)
let
string_of_program_utf8
instrs
=
String
.
concat
";"
(
List
.
map
string_of_ins_utf8
instrs
)
let
string_of_program_latex
instrs
=
"$"
^
String
.
concat
";"
(
List
.
map
string_of_ins_latex
instrs
)
^
"$"
This diff is collapsed.
Click to expand it.
types.ml
+
11
−
10
View file @
a974ecee
type
ins
truction
=
|
Basic
of
char
|
Terminate
|
Ptest
of
char
|
Ntest
of
char
|
Jump
of
int
type
ins
=
|
Basic
of
char
(* a *)
|
Terminate
(* ! *)
|
Ptest
of
char
(* +a *)
|
Ntest
of
char
(* -a *)
|
Jump
of
int
(* #1 *)
|
Concat
of
instruction
list
|
Repeat
of
instruction
|
Concat
of
ins
list
(* a;b *)
|
Repeat
of
ins
*
int
(* a2 : execute a twice *)
|
Loop
of
ins
(* a* : repeat a infinitely *)
|
Program
of
char
|
Program
of
char
(* X *)
|
Empty
type
program
=
ins
truction
list
type
program
=
ins
list
exception
FatalError
of
string
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