Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,32 @@
|
|||
Calculator: procedure options (main); /* 14 Sept. 2012 */
|
||||
declare expression character (100) varying initial ('');
|
||||
declare ch character (1);
|
||||
declare (stack controlled, operand) float (18);
|
||||
declare in file input;
|
||||
|
||||
open file (in) title ('/CALCULAT.DAT,type(text),recsize(100)');
|
||||
on endfile (in) go to done;
|
||||
|
||||
put ('Stack contents:');
|
||||
main_loop:
|
||||
do forever;
|
||||
get file (in) edit (ch) (a(1));
|
||||
expression = expression || ch;
|
||||
if ch = ' ' then iterate;
|
||||
select (ch);
|
||||
when ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')
|
||||
do; allocate stack; stack = ch; iterate main_loop; end;
|
||||
when ('+') do; operand = stack; free stack; stack = stack + operand; end;
|
||||
when ('-') do; operand = stack; free stack; stack = stack - operand; end;
|
||||
when ('*') do; operand = stack; free stack; stack = stack * operand; end;
|
||||
when ('/') do; operand = stack; free stack; stack = stack / operand; end;
|
||||
when ('^') do; operand = stack; free stack; stack = stack ** operand; end;
|
||||
end;
|
||||
call show_stack;
|
||||
end;
|
||||
|
||||
done:
|
||||
put skip list ('The reverse polish expression = ' || expression);
|
||||
put skip list ('The evaluated expression = ' || stack);
|
||||
|
||||
end Calculator;
|
||||
Loading…
Add table
Add a link
Reference in a new issue