CobolScript (2) First Factorial Function

Previous Post
Next Post

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:

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:

performusing … You can call a local procedure passing arguments.

– <proc> using …  The procedure declares its arguments.

– <proc> local(s) … The procedure declares its local variables.

performgiving <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

2 thoughts on “CobolScript (2) First Factorial Function

  1. Pingback: CobolScript (1) COBOL compiler to JavaScript/Node.js « Angel ”Java” Lopez on Blog

  2. Pingback: CobolScript (3) Templates « Angel ”Java” Lopez on Blog

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s