hoc.1 (2356B)
1 .TH HOC 1 2 .SH NAME 3 hoc \- interactive floating point language 4 .SH SYNOPSIS 5 .B hoc 6 [ 7 .I file ... 8 ] 9 [ 10 .B -e 11 .I expression 12 ] 13 .SH DESCRIPTION 14 .I Hoc 15 interprets a simple language for floating point arithmetic, 16 at about the level of BASIC, with C-like syntax and 17 functions. 18 .PP 19 The named 20 .I files 21 are read and interpreted in order. 22 If no 23 .I file 24 is given or if 25 .I file 26 is 27 .L - 28 .I hoc 29 interprets the standard input. 30 The 31 .B -e 32 option allows input to 33 .I hoc 34 to be specified on the command line, to be treated as if it appeared in a file. 35 .PP 36 .I Hoc 37 input consists of 38 .I expressions 39 and 40 .IR statements . 41 Expressions are evaluated and their results printed. 42 Statements, typically assignments and function or procedure 43 definitions, produce no output unless they explicitly call 44 .IR print . 45 .PP 46 Variable names have the usual syntax, including 47 .LR _ ; 48 the name 49 .L _ 50 by itself contains the value of the last expression evaluated. 51 The variables 52 .BR E , 53 .BR PI , 54 .BR PHI , 55 .BR GAMMA 56 and 57 .B DEG 58 are predefined; the last is 59.25..., degrees per radian. 59 .PP 60 Expressions are formed with these C-like operators, listed by 61 decreasing precedence. 62 .TP 63 .B ^ 64 exponentiation 65 .TP 66 .B ! - ++ -- 67 .TP 68 .B * / % 69 .TP 70 .B + - 71 .TP 72 .B > >= < <= == != 73 .TP 74 .B && 75 .TP 76 .B || 77 .TP 78 .B = += -= *= /= %= 79 .PP 80 Built in functions are 81 .BR abs , 82 .BR acos , 83 .BR asin , 84 .B atan 85 (one argument), 86 .BR cos , 87 .BR cosh , 88 .BR exp , 89 .BR int , 90 .BR log , 91 .BR log10 , 92 .BR sin , 93 .BR sinh , 94 .BR sqrt , 95 .BR tan , 96 and 97 .BR tanh . 98 The function 99 .B read(x) 100 reads a value into the variable 101 .B x 102 and returns 0 at EOF; 103 the statement 104 .B print 105 prints a list of expressions that may include 106 string constants such as 107 \fL"hello\en"\f1.\fP 108 .PP 109 Control flow statements are 110 .BR if - else , 111 .BR while , 112 and 113 .BR for , 114 with braces for grouping. 115 Newline ends a statement. 116 Backslash-newline is equivalent to a space. 117 .PP 118 Functions and procedures are introduced by the words 119 .B func 120 and 121 .BR proc ; 122 .B return 123 is used to return with a value from a function. 124 .SH EXAMPLES 125 .EX 126 func gcd(a, b) { 127 temp = abs(a) % abs(b) 128 if(temp == 0) return abs(b) 129 return gcd(b, temp) 130 } 131 for(i=1; i<12; i++) print gcd(i,12) 132 .EE 133 .SH SOURCE 134 .B \*9/src/cmd/hoc 135 .SH "SEE ALSO" 136 .IR bc (1), 137 .IR dc (1) 138 .br 139 B. W. Kernighan and R. Pike, 140 .I 141 The Unix Programming Environment, 142 Prentice-Hall, 1984 143 .SH BUGS 144 Error recovery is imperfect within function and procedure definitions.