-
Notifications
You must be signed in to change notification settings - Fork 4
/
hoc.1
167 lines (167 loc) · 2.79 KB
/
hoc.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
.TH HOC 1
.CT 1 numbers
.SH NAME
hoc \(mi interactive floating point language
.SH SYNOPSIS
.B hoc
[
.I file ...
]
.SH DESCRIPTION
.I Hoc
interprets a simple language for floating point arithmetic,
at about the level of Basic, with C-like syntax and
functions.
.PP
The named
.IR file s
are read and interpreted in order.
If no
.I file
is given or if
.I file
is
.L -
.I hoc
interprets the standard input.
.PP
.I Hoc
input consists of
.I expressions
and
.IR statements .
Expressions are evaluated and their results printed.
Statements, typically assignments and function or procedure
definitions, produce no output unless they explicitly call
.IR print .
.PP
Variable names have the usual syntax, including
.LR _ ;
the name
.L _
by itself contains the value of the last expression evaluated.
Certain variables are already initialized:
.TP
.B E
base of natural logs
.PD0
.TP
.B PI
.TP
.B PHI
golden ratio
.TP
.B GAMMA
Euler's constant
.TP
.B DEG
180/PI, degrees per radian
.TP
.B PREC
maximum number of significant digits in output, initially 15;
.B PREC=0
gives shortest `exact' values.
.PD
.PP
Expressions are formed with these C-like operators, listed by
decreasing precedence.
.TP
.B ^
exponentiation
.TP
.B ! - ++ --
.TP
.B * / %
.TP
.B + -
.TP
.B > >= < <= == !=
.TP
.B &&
.TP
.B ||
.TP
.B = += -= *= /= %=
.PP
Built in functions include
.BR abs ,
.BR acos ,
.B atan
(one argument),
.BR cos ,
.BR cosh ,
.BR erf ,
.BR erfc ,
.BR exp ,
.BR gamma ,
.BR int ,
.BR log ,
.BR log10 ,
.BR sin ,
.BR sinh ,
.BR sqrt ,
.BR tan ,
and
.BR tanh .
The function
.B read(x)
reads a value into the variable
.BR x ;
the statement
.B print
prints a list of expressions that may include
string constants such as
.B \&\&\&"hello\en".
.PP
Control flow statements are
.BR if - else ,
.BR while ,
and
.BR for ,
with braces for grouping.
Newline ends a statement.
Backslash-newline is equivalent to a space.
.PP
Functions and procedures are introduced by the words
.B func
and
.BR proc ;
.B return
is used to return with a value from a function.
Within a function or procedure,
arguments are referred to as
.BR $1 ,
.BR $2 ,
etc.; all other variables are global.
.SH EXAMPLES
.EX
func gcd() {
temp = abs($1) % abs($2)
if(temp == 0) return abs($2)
return gcd($2, temp)
}
for(i=1; i<12; i++) print gcd(i,12)
.EE
.SH "SEE ALSO"
.IR bc (1),
.IR dc (1)
.br
B. W. Kernighan and R. Pike,
.I
The Unix Programming Environment,
Prentice-Hall, 1984
.SH BUGS
.br
All components of a
.B for
statement must be non-empty.
.br
Error recovery is imperfect within function and procedure definitions.
.br
The treatment of newlines is not exactly user-friendly.
.br
Functions and procedures typically have to be declared
before use, which makes mutual recursion a bit impossible.
.br
Arguments $1, etc., are not really variables and thus won't work
in constructs like, for instance, $1++.