I added the support for user-defined functions, parameters, arguments and local variables. The first example, factorial:
You can run it, executing command line in that folder:
node run factorial.cob
data division. working-storage section. 01 n. procedure division. perform show-factorial varying n from 1 to 10. show-factorial local result. perform factorial using n giving result. display n "! = " result. factorial using n local m. if n = 1 then return n. subtract 1 from n giving m. perform factorial using m giving m. multiply n by m. return m.
The new syntax features:
– perform … using … You can call a local procedure passing arguments.
– <proc> using … The procedure declares its arguments.
– <proc> local(s) … The procedure declares its local variables.
– perform … giving <var>… You can specify that a perform has a return value, to be saved in one or more variables.
– return (expr) The procedure can return at any point. A return value could be specified.
I just added web page support, but that is a topic for another post 😉
Angel “Java” Lopez