Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
pga
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
pga
Commits
ddcf4560
Commit
ddcf4560
authored
Jul 03, 2014
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added some congruence functions and empty commands
parent
a974ecee
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
68 additions
and
19 deletions
+68
-19
Makefile
Makefile
+1
-1
congruence.ml
congruence.ml
+19
-0
lexer.mll
lexer.mll
+2
-2
parse.ml
parse.ml
+3
-3
pga.ml
pga.ml
+23
-12
stringify.ml
stringify.ml
+4
-0
types.ml
types.ml
+16
-1
No files found.
Makefile
View file @
ddcf4560
RESULT
:=
pga
BASENAMES
:=
types stringify parser lexer parse pga
BASENAMES
:=
types stringify parser lexer parse
congruence
pga
OFILES
:=
$(
addsuffix
.cmx,
$(BASENAMES)
)
...
...
congruence.ml
0 → 100644
View file @
ddcf4560
open
Types
let
rec
unfold_repeat
=
function
|
Repeat
(
_
,
0
)
as
i
::
_
->
raise
(
Ins_error
(
i
,
"cannot repeat 0 times"
))
|
Repeat
(
i
,
1
)
::
tl
->
i
::
unfold_repeat
tl
|
Repeat
(
i
,
n
)
::
tl
->
i
::
unfold_repeat
(
Repeat
(
i
,
n
-
1
)
::
tl
)
|
hd
::
tl
->
hd
::
unfold_repeat
tl
|
[]
->
[]
let
rec
norm
=
function
|
[]
->
N
0
|
Repeat
(
i
,
t
)
::
tl
->
norm
[
i
]
**
(
N
t
)
++
norm
tl
|
Loop
_
::
tl
->
Infinity
|
Concat
l
::
tl
->
norm
l
++
norm
tl
|
hd
::
tl
->
N
1
++
norm
tl
lexer.mll
View file @
ddcf4560
...
...
@@ -2,7 +2,7 @@
open
Lexing
open
Parser
exception
Syntax
E
rror
of
string
exception
Syntax
_e
rror
of
string
let
next_line
lexbuf
=
let
pos
=
lexbuf
.
lex_curr_p
in
...
...
@@ -34,4 +34,4 @@ rule token = parse
|
[
'
'
'\t'
]
+
{
token
lexbuf
}
|
eof
|
'\000'
{
EOF
}
|
_
as
chr
{
raise
(
Syntax
E
rror
(
"unexpected '"
^
Char
.
escaped
chr
^
"'"
))
}
|
_
as
chr
{
raise
(
Syntax
_e
rror
(
"unexpected '"
^
Char
.
escaped
chr
^
"'"
))
}
parse.ml
View file @
ddcf4560
...
...
@@ -17,7 +17,7 @@ let loc_msg lexbuf msg =
let
parse_with_error
lexbuf
=
try
Parser
.
program
Lexer
.
token
lexbuf
with
|
Lexer
.
Syntax
E
rror
msg
->
raise
(
Fatal
E
rror
(
loc_msg
lexbuf
msg
))
|
Lexer
.
Syntax
_e
rror
msg
->
raise
(
Fatal
_e
rror
(
loc_msg
lexbuf
msg
))
|
Parser
.
Error
->
raise
(
Fatal
E
rror
(
loc_msg
lexbuf
"syntax error"
))
raise
(
Fatal
_e
rror
(
loc_msg
lexbuf
"syntax error"
))
pga.ml
View file @
ddcf4560
...
...
@@ -5,20 +5,23 @@ let main () =
let
usage
status
=
prerr_endline
(
"usage: "
^
Sys
.
argv
.
(
0
)
^
" command [args]"
);
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 I TERM get the Ith instruction of a program"
;
prerr_endline
" dot TERM generate Dot code for a flow graph"
;
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 I TERM get the Ith instruction of a program"
;
prerr_endline
" canon1 TERM transform to first canonical form"
;
prerr_endline
" canon2 TERM transform to second canonical form"
;
prerr_endline
" eq TERM TERM check for instruction-row equivalence"
;
prerr_endline
" dot TERM generate Dot code for a flow graph"
;
prerr_endline
"input program syntax:"
;
prerr_endline
" - write star (*) instead of omega sign"
;
prerr_endline
" - write dollar sign ($) instead of pound sign"
;
prerr_endline
""
;
prerr_endline
"A
TERM argument may also be omitted and passed on stdi
n"
;
prerr_endline
"instead for convenient use of UNIX pipes, e.g.:"
;
prerr_endline
"$ ./pga
echo 'a;b;(c)*
' | ./pga dot | dot -T png | display"
;
prerr_endline
"A
single TERM argument may also be omitted and passed o
n"
;
prerr_endline
"
stdin
instead for convenient use of UNIX pipes, e.g.:"
;
prerr_endline
"$ ./pga
canon1 '(a)*;!
' | ./pga dot | dot -T png | display"
;
exit
status
in
...
...
@@ -45,14 +48,22 @@ let main () =
print_endline
(
string_of_program_utf8
(
input_term
2
))
|
"latex"
->
print_endline
(
string_of_program_latex
(
input_term
2
))
|
"norm"
|
"i"
|
"dot"
->
|
"norm"
->
print_endline
(
string_of_natural
(
Congruence
.
norm
(
input_term
2
)))
|
"i"
|
"canon1"
|
"canon2"
|
"eq"
|
"dot"
->
raise
(
Failure
"not implemented"
)
|
_
->
usage
1
with
|
Fatal
E
rror
msg
->
|
Fatal
_e
rror
msg
->
prerr_endline
msg
;
exit
1
|
Ins_error
(
i
,
msg
)
->
prerr_endline
(
"error on "
^
string_of_ins_ascii
i
^
": "
^
msg
);
exit
1
|
Program_error
(
p
,
msg
)
->
prerr_endline
(
"error on "
^
string_of_program_ascii
p
^
": "
^
msg
);
exit
1
end
;
exit
0
...
...
stringify.ml
View file @
ddcf4560
...
...
@@ -44,3 +44,7 @@ let string_of_program_utf8 instrs =
let
string_of_program_latex
instrs
=
"$"
^
String
.
concat
";"
(
List
.
map
string_of_ins_latex
instrs
)
^
"$"
let
string_of_natural
=
function
|
N
i
->
string_of_int
i
|
Infinity
->
"oo"
types.ml
View file @
ddcf4560
...
...
@@ -14,4 +14,19 @@ type ins =
type
program
=
ins
list
exception
FatalError
of
string
(* Natural numbers *)
type
natural
=
Infinity
|
N
of
int
let
natural_binop
binop
a
b
=
match
(
a
,
b
)
with
|
N
i
,
N
j
->
N
(
binop
i
j
)
|
_
->
Infinity
let
(
++
)
=
natural_binop
(
+
)
let
(
--
)
=
natural_binop
(
-
)
let
(
**
)
=
natural_binop
(
*
)
let
(
//
)
=
natural_binop
(
/
)
exception
Fatal_error
of
string
exception
Ins_error
of
ins
*
string
exception
Program_error
of
program
*
string
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