Parsing/RPN calculator algorithm: Difference between revisions
→{{header|ANSI Standard BASIC}}: Simplifications: 1. In get_number, buffer for conversion is not necessary. 2. In is_digit, used the parameter ch$ instead of a global variable. Added result in Decimal BASIC.
(Dialects of BASIC moved to the BASIC section.) |
(→{{header|ANSI Standard BASIC}}: Simplifications: 1. In get_number, buffer for conversion is not necessary. 2. In is_digit, used the parameter ch$ instead of a global variable. Added result in Decimal BASIC.) |
||
Line 681:
=={{header|BASIC}}==
==={{header|ANSI Standard BASIC}}===
{{works with|Decimal BASIC}}
<syntaxhighlight lang="
1010 PUBLIC NUMERIC R(64) ! stack
1020 PUBLIC STRING expn$ ! for keyboard input
Line 766 ⟶ 767:
1830 EXTERNAL FUNCTION get_number
1840 DECLARE EXTERNAL FUNCTION is_digit
1850 LET
1860
1880
1890
1900 LET
1910
1920
1930 LOOP
1940 END
1950 EXIT
1960 END IF
1980
▲1990 LET j = j + 1
2000
2010 ! check for digit
2030 IF "0" <=
2040 LET is_digit = true
▲2040 LOOP
2060 LET is_digit = false
▲2060 END FUNCTION
2070
2080 END FUNCTION
2090 !
▲2090 EXTERNAL FUNCTION is_digit( ch$ )
2110 PRINT expn$(i:i);"
▲2120 ELSE
2130
2140
2150
{{out}}
▲2170 EXTERNAL SUB print_stack
<pre>
enter an RPN expression:
▲2190 FOR ptr=n TO 2 STEP -1
? 3 4 2 * 1 5 - 2 3 ^ ^ / +
expn: 3 4 2 * 1 5 - 2 3 ^ ^ / +
3.0000
4.0000 3.0000
▲2230 END SUB</syntaxhighlight>
2.0000 4.0000 3.0000
* 8.0000 3.0000
1.0000 8.0000 3.0000
5.0000 1.0000 8.0000 3.0000
- -4.0000 8.0000 3.0000
2.0000 -4.0000 8.0000 3.0000
3.0000 2.0000 -4.0000 8.0000 3.0000
^ 8.0000 -4.0000 8.0000 3.0000
^ 65536.0000 8.0000 3.0000
/ 0.0001 3.0000
+ 3.0001
result: 3.0001220703125
enter an RPN expression:
?
</pre>
==={{header|BBC BASIC}}===
|