-
Notifications
You must be signed in to change notification settings - Fork 14
/
pl0c.1
92 lines (92 loc) · 2.46 KB
/
pl0c.1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
.\"
.\" pl0c - PL/0 compiler
.\"
.\" Copyright (c) 2021 Brian Callahan <bcallah@openbsd.org>
.\"
.\" Permission to use, copy, modify, and distribute this software for any
.\" purpose with or without fee is hereby granted, provided that the above
.\" copyright notice and this permission notice appear in all copies.
.\"
.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
.Dd August 26, 2021
.Dt PL0C 1
.Os
.Sh NAME
.Nm pl0c
.Nd PL/0 compiler
.Sh SYNOPSIS
.Nm
.Sh DESCRIPTION
.Nm
is a PL/0 compiler.
.Nm
reads input from
.Ar stdin
and outputs to
.Ar stdout .
.Sh GRAMMAR
The PL/0 grammar is as follows:
.Bd -literal
program = block "." .
block = [ "const" id "=" number { "," id "=" number } ";" ]
[ "var" id [ array ] { "," id [ array ] } ";" ]
{ "forward" id ";" }
{ "procedure" id ";" block ";" } statement .
statement = [ id ":=" expression
| "call" id
| "begin" statement { ";" statement } "end"
| "if" condition "then" statement
| "while" condition "do" statement
| "readInt" [ "into" ] id
| "readChar" [ "into" ] id
| "writeInt" expression
| "writeChar" expression
| "writeStr" ( id | string )
| "exit" expression ] .
condition = "odd" expression
| expression ( comparator ) expression .
expression = [ "+" | "-" | "not" ] term { ( "+" | "-" | "or" ) term } .
term = factor { ( "*" | "/" | "mod" | "and" ) factor } .
factor = id
| number
| "(" expression ")" .
comparator = "=" | "#" | "<" | ">" | "<=" | ">=" | "<>" .
array = "size" number .
.Ed
.Sh EXIT STATUS
The
.Nm
utility exits 0 on success, and >0 if an error occurs.
.Sh EXAMPLES
The following program prints the first 16 factorials:
.Bd -literal -offset indent
var n, f;
begin
n := 0;
f := 1;
while n # 16 do
begin
n := n + 1;
f := f * n;
writeInt f;
writeChar '\\n'
end;
end.
.Ed
.Pp
The output of
.Nm
can be piped into a C compiler to produce an executable, like so:
.Pp
.Dl pl0c < file.pl0 | cc -O -o file -x c -
.Sh AUTHORS
.Nm
was written by
.An Brian Callahan Aq Mt bcallah@openbsd.org .