I like to have a template engine in my languages, so, I added one in my open source CobolScript, COBOL compiler to JavaScript. The first sample:
https://github.com/ajlopez/CobolScript/tree/master/samples/template
The code:
<# data division. working-storage section. 01 n. procedure division. #> Factorial --------- <# perform show-factorial varying n from 1 to 10. show-factorial. local result. perform factorial using n giving result. #> ${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 template file is compiled to COBOL transforming every text to DISPLAY … WITH NO ADVANCING (the new lines are already in the text). The code between <# and #> is copy as is to the COBOL program. Every expression between ${ and } is expanded as another parameter to a DISPLAY command. Then, after compiling all the texto to COBOL, CobolScript compile it to JavaScript. The template syntax is a kind of syntax-sugar.
The output of the program:
Factorial --------- 1!= 1 2!= 2 3!= 6 4!= 24 5!= 120 6!= 720 7!= 5040 8!= 40320 9!= 362880 10!= 3628800
I could use the template support to generate text files, that is, to implement code generation in CobolScript, as I did in AjGenesis (classic, Ruby, Node.js). I already have a dynamic web page implementation based on this template engine (yes, dynamic web pages in CobolScript
. But that is a topic for another post.
Keep tuned!
Angel “Java” Lopez
[...] Previous Post Next Post [...]
Pingback by CobolScript (2) First Factorial Function « Angel ”Java” Lopez on Blog — December 29, 2012 @ 2:48 pm
[...] Previous Post [...]
Pingback by CobolScript (4) Web Pages with Templates « Angel ”Java” Lopez on Blog — January 19, 2013 @ 3:47 pm