Angel \”Java\” Lopez on Blog

January 19, 2013

CobolScript (4) Web Pages with Templates

Filed under: COBOL, CobolScript, JavaScript, NodeJs, Open Source Projects — ajlopez @ 3:47 pm

Previous Post

In the previous post I presented CobolScript generating output using templates. It can be used to generate web page output, too. The sample is at:

https://github.com/ajlopez/CobolScript/tree/master/samples/templateweb

The launch program in JavaScript is simple:

var cobs = require('../..'),
    http = require('http'),
    fs = require('fs');

var program = cobs.compileTemplateFile('./factorial.cobp');

http.createServer(function(req, res) {
    program.run(cobs.getRuntime({ request: req, response: res }));
}).listen(8000);

console.log('Server started, listening at port 8000');

The key part is the call to compile the file template. It produce a compiled JavaScript function to be invoked. The call of program.run executes the template, with a giving runtime context. The runtime context is build giving the request and response objects of the current incoming request. That runtime derives all the output of the CobolScript program to the response output. So, the template doesn’t know about web request and response. You can see the runtime object as a service provider to the compiled CobolScript program. Its properties can be accessed if you define a LINKAGE SECTION as in classic COBOL. But this feature was not used in this simple sample.

The template file

<h1>Factorial</h1>
<p>Page generated by CobolScript, using templates</p>
<table>
<tr><th align='right'>n</th><th align='right'>n!
</th>
</tr>
<#
local n.
perform show-factorial using n varying n from 1 to 10.
#>
</table>
<#
.
stop run.

show-factorial section using n.
local result.
perform factorial using n giving result.
#>
<tr>
<td align='right'>${n}</td><td align='right'>${result}
</td>
</tr>
<#
.

factorial section 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.
#>

Launch the server with

node server

Navigate to localhost:8000, the result:

Next post: a dynamic web site accessing MySQL database, using CobolScript.

Keep tuned!

Angel “Java” Lopez

http://www.ajlopez.com

http://twitter.com/ajlopez

January 12, 2013

Code Katas in JavaScript/Node.js using TDD

These past weeks, I was working in JavaScript/Node.js modules, using TDD at each step. Practice, practice, practice, the journey to mastery.

You can see my progress, reviewing the commits I did at each new test. This is a summary of that work:

CobolScript: See my posts, an implementation of COBOL as a compiler to JavaScript, having console program samples, dynamic web pages and access to Node.js modules. See web sample, using MySQL, and SimpleWeb.

SimplePipes: A way to define message-passing using ‘pipes’ to connect different defined nodes/functions. I want to extend it to have distributed process.

SimpleBoggle: Boggle solver, it is better than me! See console sample.

SimpleMemolap: Multidimensional OLAP-like processing, with in-memory model, and SimpleWeb site see sample:

SimpleChess: Work in progress, define a board using SimpleBoard, and make moves. I’m working on SimpleGo, too, to have a board, game, and evaluators.

SimpleRules: forward-chaing rule engine. I should add rule compilation to JavaScript. The engine works a la Rete-2, detecting the changes in the current state, and triggering actions.

SimpleScript: see post, my simple language, compiled to JavaScript. See posts. WIP.

Py2Script: Python language compiler to JavaScript, first step. WIP.

SimpleWeb: web middleware, a la Connect, with web sample.

BasicScript: My first steps to compile Basic to JavaScript. I want to use it to program and compile a game.

SimplePermissions: Today code kata. It implements subjects, roles, and permissions, granted by context.

SimpleFunc: Serialization of functions.

SimpleMapReduce: Exploring the implementation of a Map-Reduce algorithm.

SimpleTuring: Turing machine implentation.

Cellular: Cellular automata implementation, including a Game of Life console sample.

I will work on:

NodeDelicious: To retrieve my links from my Delicious account, now the site was revamped and no more pagination.

SimpleDatabase: In-memory database, maybe I will add file persistence.

SimpleSudoku: Rewrite of my AjSudoku solver, from scratch.

I’m having a lot of fun, as usual 😉

Keep tuned!

Angel “Java” Lopez
http://www.ajlopez.com
http://twitter.com/ajlopez

December 29, 2012

CobolScript (3) Templates

Previous Post
Next Post

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

http://www.ajlopez.com

http://twitter.com/ajlopez

December 24, 2012

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:

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:

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

http://www.ajlopez.com

http://twitter.com/ajlopez

December 22, 2012

CobolScript (1) COBOL compiler to JavaScript/Node.js

Filed under: COBOL, JavaScript, NodeJs, Open Source Projects, Programming Languages — ajlopez @ 5:38 pm

Next Post

Today, I started a new project at my Github account:

https://github.com/ajlopez/CobolScript

It’s a compiler from COBOL to JavaScript. It’s work in progress, but the Hello, world is running:

https://github.com/ajlopez/CobolScript/blob/master/samples/hello/hello.cobs

DISPLAY "HELLO, WORLD".

You can run it, executing:

node run hello.cobs

A more complete code:

https://github.com/ajlopez/CobolScript/blob/master/samples/hellopgm/hello.cob

IDENTIFICATION DIVISION.
    PROGRAM-ID. HELLO.
    AUTHOR. A.J.LOPEZ.
    INSTALLATION. TEST.
    DATE-WRITTEN. 2012-12-22.
    DATE-COMPILED. 2012-12-22.
ENVIRONMENT DIVISION.
    CONFIGURATION SECTION.
        SOURCE-COMPUTER. NODE.
        OBJECT-COMPUTER. NODE.
DATA DIVISION.
PROCEDURE DIVISION.
    DISPLAY "HELLO, WORLD".

Let’s run it executing:

node run hello.cob

My work was written using TDD (Test-Driven Development). I shoudl add a lot of things: picture support, working storage section, file section, and maybe, SQL execute commands. But it’s a good starting point. It can run on browser and on Node.js.

Keep tuned!

Angel “Java” Lopez

http://www.ajlopez.com

http://twitter.com/ajlopez

December 20, 2012

COBOL: Links, News And Resources (2)

Filed under: COBOL, Links, Programming Languages — ajlopez @ 4:14 pm

Previous Post

COBOL on Cogs
http://www.coboloncogs.org/INDEX.HTM

Java is becoming the new Cobol
http://www.infoworld.com/d/developer-world/java-becoming-new-cobol-204

IBM Mainframes
http://ibmmainframes.com/manuals.php
Online IBM Reference Manuals

MicroFocus
http://www.microfocus.com/

COBOL
http://en.wikipedia.org/wiki/COBOL

COBOl Tutorials
http://www.mainframetutorials.com/programming/programming.cobol.html

zingCOBOL
http://cobol.404i.com/
The aim of this COBOL tutorial site is to give the basics of the COBOL programming language for anyone who knows a little bit about computers (not much) and preferably will at least have come across another procedural progamming language such as C, QBASIC or Pascal.

COBOL Programming Tutorial
http://www.mainframegurukul.com/tutorials/programming/cobol/cobol-tutorial.html

COBOL programming – tutorials, lectures, exercises, examples
http://www.csis.ul.ie/cobol/

Compile Online
http://www.compileonline.com/index.php

The SOUL program query language
http://soft.vub.ac.be/SOUL/
Query and inspect your Java, Smalltalk, C and Cobol programs.

When Did That Happen?
http://pragprog.com/magazines/2012-02/when-did-that-happen
Grace Murray Hopper and Automatic Coding

COBOL Reborn
http://it.toolbox.com/blogs/oracle-guide/cobol-reborn-25896
(2005) "COBOL is like an invisible giant. There’s reported to be 180 billion-200 billion lines of code out there, processing 75% of commercial business. Few companies are keen to throw away the hundreds or thousands of man-years that have been invested in mature, high-performance COBOL code. Instead, they are integrating and building bridges between COBOL, .NET and J2EE [Java 2 Platform, Enterprise Edition], using service-oriented architectures to preserve the strengths of the legacy code while benefiting from Web-oriented development tools,"

Universal Cobol Compiler
http://sourceforge.net/projects/universalcobol/
The Universal COBOL Compiler (UCC) is a Java-based COBOL to Java bytecode cross-compiler. It’s made up of a COBOL compiler, a Java-based COBOL runtime, and a package for manipulating Java class files.

COB2J
http://www.mpsinc.com/cob2j.html
The COB2J® translator is a family of Microsoft Windows cross compiler programming tools that accepts many COBOL source code dialects and translates them to JAVA or J#. The translation process is a simple turn key process with minimal user intervention. The translator output is JAVA or J# code that is ready to be tested with the target compiler. Simply run your COBOL code through the translator and start debugging JAVA code with your target compiler.

isCOBOL Evolve
http://www.veryant.com/products/iscobol/
By compiling COBOL code into Java, isCOBOL software allows your organization to retain and enhance valuable COBOL application and development assets, while taking full advantage of the Java technology platform in deployment.

My Links
http://delicious.com/ajlopez/cobol

December 27, 2011

COBOL: Links, News and Resources (1)

Filed under: COBOL, Links, Programming Languages — ajlopez @ 9:43 am

Next Post

More than 30 years ago, I wrote programs in COBOL, for IBM mainframes and other machines. Now, the language is alive and still in use. Some of my links:

http://en.wikipedia.org/wiki/COBOL

COBOL (play /ˈkbɒl/) is one of the oldest programming languages. Its name is an acronym forCOmmon Business-Oriented Language, defining its primary domain in business, finance, and administrative systems for companies and governments.

The COBOL 2002 standard includes support for object-oriented programming and other modern language features.[1]

 

Visual COBOL integration with Visual Studio 2010
http://www.youtube.com/watch?v=-1Pi0rxjk3Y

Java apps have most flaws, Cobol apps the least, study finds
http://www.computerworld.com/s/article/9222503/Java_apps_have_most_flaws_Cobol_apps_the_least_study_finds

RES – An Open Cobol To Java Translator
http://sourceforge.net/projects/opencobol2java/

Koopa Cobol Parser
http://sourceforge.net/projects/koopa/

Why Cobol Modernization Is Relevant Today
http://cloudcomputing.sys-con.com/node/1723532

Grace Hopper: Programming Pioneer
http://www.crn.com/news/channel-programs/18836964/grace-hopper-programming-pioneer.htm

COBOL
http://www.csee.umbc.edu/courses/graduate/631/Fall2002/COBOL.pdf

COBOL’s Not Dead. Make it Play Nice with the Modern Enterprise
http://www.readwriteweb.com/enterprise/2011/01/cobols-not-dead-in-the-enterprise.php

COBOL – The New Age Programming Language
http://www.shlomifish.org/humour/bits/COBOL-the-New-Age-Programming-Language/

Micro Focus Announces CICS® for .NET
http://www.microfocus.com/aboutmicrofocus/pressroom/releases/pr20100712268224.asp

Net Express with .NET
http://download.cnet.com/Net-Express-with-NET/3000-2069_4-10866201.html

Geriatric Java struggles to stay relevant
http://www.infoworld.com/d/developer-world/geriatric-java-struggles-stay-relevant-700

A Comparison Of .net COBOL, Visual Basic and C#
http://www.codeproject.com/KB/net-languages/COBOLvsVBvsCSharp.aspx

Ideone
http://ideone.com/
Ideone is something more than a pastebin; it’s an online compiler and debugging tool which allows
to compile and run code online in more than 40 programming languages.

The Future of the Mainframe
http://lips.informatik.uni-leipzig.de/files/Spruth2007TheFutureoftheMainframeEUROcmgNrnberg.pdf

Enterprise Applications: 20 Things You Might Not Know About COBOL (as the Language Turns 50)
http://www.eweek.com/c/a/Enterprise-Applications/20-Things-You-Might-Not-Know-About-COBOL-As-the-Language-Turns-50-103943/

Cobol-IT
http://www.cobol-it.com/
Open Source COBOL Compiler

COBOL to Java Automatic Migration with GPL’ed Tools
http://www.infoq.com/news/2009/07/cobol-to-java

APL, COBOL, & Dijkstra
http://www.zdnet.com/blog/murphy/apl-cobol-dijkstra/568

Free Cobol
Programming
http://www.freebyte.com/programming/cobol/

The COBOL Programming Language
http://groups.engin.umd.umich.edu/CIS/course.des/cis400/cobol/cobol.html

Cobol hits 50 and keeps counting
http://www.guardian.co.uk/technology/2009/apr/09/cobol-internet-programming

COBOL
http://www.microfocus.com/mcro/cobol/

My Links
http://delicious.com/ajlopez/cobol

More links about programming languages are coming.

Keep tuned!

Angel “Java” Lopez
http://www.ajlopez.com
http://twitter.com/ajlopez

Blog at WordPress.com.