JavaScript is butter in my hands
. I was working on CobolScript, my COBOL compiler to JavaScript.
I added the support for user-defined functions, parameters, arguments and local variables. The first example, factorial:
https://github.com/ajlopez/CobolScript/blob/master/samples/factorial/factorial.cob
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
Keep tuned!
Angel “Java” Lopez
[...] Next Post [...]
Pingback by CobolScript (1) COBOL compiler to JavaScript/Node.js « Angel ”Java” Lopez on Blog — December 24, 2012 @ 5:04 pm
[...] Previous Post [...]
Pingback by CobolScript (3) Templates « Angel ”Java” Lopez on Blog — December 29, 2012 @ 2:46 pm