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