home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Interactive Guide
/
c-cplusplus-interactive-guide.iso
/
c_ref
/
csource4
/
224_01
/
hoc.hlp
< prev
next >
Wrap
Text File
|
1987-01-04
|
5KB
|
123 lines
NAME
hoc - an interactive language for floating point arithmetic
SYNTAX
hoc [file_list]
DESCRIPTION
Hoc is a simple interpreter for floating point arithmetic. It has
C-style control flow, function definitions, expressions, and the standard
built-in functions like sin() and log(). Hoc will read and execute the
statements in the specified files, where the '-' can be used to imply the
standard input. If no files are specified, hoc will take its input from
the standard input. The output from the "print" statement and any results
from expressions are printed on the standard output.
Hoc, being a simple interpreter, is slow for complicated calculations; but
provides an excellent interface for doing quick calculations. It is also
easy to use since it does not require reverse-Polish notation and accepts
C-style expressions.
All expressions are considered floating point expressions. Valid
expressions "expr" include a number, variable, ( expr ), expr binop expr,
unop expr, or function ( arguments ).
Variables can be created in an assignment statement by:
variable_name = expression
Note that statements are terminated by the carriage return (unlike C where
the statements are terminated by the semicolon). A variable name is a
letter followed by a string of letters and numbers.
The following binary operators, "binop", and the unary operators,,"unop",
are in order of precedence:
^ exponentiation
! - unary negation: logical and arithmetic
* / multiplication and division
+ - addition and subtraction
> >= < <= relational operators: greater than, greater or equal,
== != less than, less than or equal, equal, not equal
&& logical AND
|| logical OR
= assignment
Functions can be defined by the user in the following format:
func function_name() statement_list
The arguments can be accessed inside a function by $1, $2, ... . The
following is an example function. Note that semicolons are not used
to terminate a statement as in a C program.
func max() {
if ($1 > $2) return $2 else return $1
}
The built-in functions are (with all angles specified in degrees):
abs(x) absolute value of x
int(x) integer part of x, truncated towards zero
sqrt(x) square root of x
cos(x) Cosine of x
sin(x) sine of x
tan(x) tangent of x
acos(x) arc cosine of x
asin(x) arc sine of x
atan(x) arc tangent of x
exp(x) exponential base e of x: E ^ x
exp10(x) exponential base 10 of x: 10 ^ x
log(x) logarithm base e of x
log10(x) logarithm base 10 of x
The built-in constants are:
DEG 57.29577951308232087680 180 / PI, degrees per radian
E 2.71828182845904523536 base e of natural logarithm
GAMMA 0.57721566490153286060 Euler-Mascheroni constant
PHI 1.61803398874989484820 the golden ratio, (sqrt(5)+1)/2
PI 3.14159265358979323846 180 degrees in radians
The valid statements for hoc are expr, variable = expr, print expr_list,
procedure (arguments), return, return expr, while (expr) statement,
if (expr) statement, if (expr) statement else statement, or
{ statement_list }. Because newlines are mandatory for statements, use
brackets, { and }, to put statements on separate lines; for example:
if (x < 0)
print -x,"\n"
else
print x,"\n"
is an invalid statement, but :
if (x < 0) {
print -x,"\n"
} else {
print x,"\n"
}
is a valid statement!
The only input and output interface are the "read" function and the
"print" statement. The input function, read(x), will read the standard
input, which must be a number, and store in the variable x. The return
value of read() is 1 if a value was read, else 0 if an error occurred or
end of file found. The "print" statement can have a list of expressions and
strings following "print" separated by commas. Print will not add a
newline at the end, so it must be done explicitly with a string with the
last character being '\n'. Examples:
if (read(x)) print "x = ", x, "\n"
print "This is an example only", sin(45 / DEG), PI * E / 4.5E20
REFERENCE
Hoc is a modified version of the hoc listed in appendix 3 of :
Kernighan, B.W. and Pike, R., 1984. "The UNIX Programming Environment".
Englewood Cliffs: Prentice-Hall, Inc..
The version of hoc in UTILIX is a freeware software.