Skip to content
Browse files

Big refactor. Sections require 'section' reserved word to be a separa…

…ted function
  • Loading branch information...
1 parent 636728b commit 3e435a3f7156bb14174d2d1527c122a76649fc05 @ajlopez committed Dec 30, 2012
View
4 README.md
@@ -90,6 +90,10 @@ npm test
[COBOL Tutorial](http://www.mainframegurukul.com/tutorials/programming/cobol/cobol-tutorial.html)
+[COBOL Tutorials](http://www.mainframetutorials.com/programming/programming.cobol.html)
+
+[COBOL Programming Standards](http://www.tonymarston.net/cobol/cobolstandards.html)
+
## Contribution
Feel free to [file issues](https://github.com/ajlopez/CobolScript) and submit
View
19 lib/cobolscript.js
@@ -905,6 +905,12 @@ var cobolscript = (function () {
var func = new Function("runtime", "program", "var ws = (program && program.data) ? program.data.working_storage : null;\r\n" + text);
return func;
};
+
+ function Parser(text) {
+ var lexer = new Lexer(text);
+ var self = this;
+
+ this.parseProgram = function() {
var program = new Program();
program.identification = parseIdentificationDivision();
@@ -1694,10 +1700,17 @@ var cobolscript = (function () {
function isReserved(name) {
name = normalizeName(name);
return reserved.indexOf(name) >= 0 || verbs.indexOf(name) >= 0;
+ };
+
function isVerb(name) {
-
- function isVerb(name) {
- name = normalizeName(name);
+ name = normalizeName(name);
+ return verbs.indexOf(name) >= 0;
+ };
+
+ function compileTemplateText(text) {
+ if (!text)
+ return '';
+
text = text.replace(/\"/g, '\\"');
text = text.replace(/\n/g, '\\n');
text = text.replace(/\r/g, '\\r');
View
4 samples/factorial/factorial.cob
@@ -5,12 +5,12 @@ working-storage section.
procedure division.
perform show-factorial varying n from 1 to 10.
-show-factorial.
+show-factorial section.
local result.
perform factorial using n giving result.
display n "! = " result.
-factorial using n.
+factorial section using n.
local m.
if n = 1 then return n.
subtract 1 from n giving m.
View
4 samples/factorialweb/factorial.cob
@@ -11,12 +11,12 @@ perform show-factorial varying n from 1 to 10.
display "</table>".
stop run.
-show-factorial.
+show-factorial section.
local result.
perform factorial using n giving result.
display "<tr><td align='right'>" n "</td><td align='right'>" result "</td></tr>".
-factorial using n.
+factorial section using n.
local m.
if n = 1 then return n.
subtract 1 from n giving m.
View
4 samples/helloasync/hello.cob
@@ -4,8 +4,8 @@ local name.
perform getname async giving name.
display name.
-sayhello async.
+sayhello section async.
display "Hello, " with no advancing.
-getname asynchronous.
+getname section asynchronous.
return "World".
View
4 samples/local/factorial.cob
@@ -4,12 +4,12 @@
local n.
perform show-factorial using n varying n from 1 to 10.
-show-factorial using n.
+show-factorial section using n.
local result.
perform factorial using n giving result.
display n "! = " result.
-factorial using n.
+factorial section using n.
local m.
if n = 1 then return n.
subtract 1 from n giving m.
View
2 samples/mysql/run.js
@@ -1 +1 @@
-
+
View
2 samples/mysql/showdb.cob
@@ -1 +1 @@
-data division.
+data division.
View
1 samples/mysqlweb/database.cobp
@@ -3,6 +3,7 @@ data division.
linkage section.
01 request.
02 response.
+03 require.
procedure division.
#>
View
9 samples/mysqlweb/databases.cobp
@@ -1,7 +1,12 @@
+<#
+data division.
+linkage section.
+01 require.
+procedure division.
+#>
<h1>MySQL Databases</h1>
<p>List of databases at localhost</p>
<#
-global require.
local mysql.
perform require using "mysql" giving mysql.
@@ -18,7 +23,7 @@ perform createConnection in mysql using options giving connection.
perform query in connection using "show databases" showdbs.
-showdbs using err, rows, fields.
+showdbs section using err, rows, fields.
if err then
display "<h2>" err "</h2>"
stop run
View
2 samples/mysqlweb/server.js
@@ -1 +1 @@
-
+
View
4 samples/template/factorial.cobt
@@ -11,14 +11,14 @@ Factorial
<#
perform show-factorial varying n from 1 to 10.
-show-factorial.
+show-factorial section.
local result.
perform factorial using n giving result.
#>
${n}!= ${result}
<#
.
-factorial using n.
+factorial section using n.
local m.
if n = 1 then return n.
subtract 1 from n giving m.
View
4 samples/templateweb/factorial.cobp
@@ -11,15 +11,15 @@ perform show-factorial using n varying n from 1 to 10.
.
stop run.
-show-factorial using n.
+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 using n.
+factorial section using n.
local m.
if n = 1 then return n.
subtract 1 from n giving m.
View
2 samples/webserver/run.js
@@ -1 +1 @@
-
+
View
7 samples/webserver/webserver.cob
@@ -1,5 +1,8 @@
+data division.
+linkage section.
+01 require.
-global require.
+procedure division.
local http.
local server.
@@ -8,6 +11,6 @@ perform createServer in http using doget giving server.
perform listen in server using 8000.
display "listening on port 8000".
-doget using request, response.
+doget section using request, response.
perform write in response using "<h1>Hello, world</h1>".
perform end in response.
View
22 test/compile.js
@@ -131,20 +131,20 @@ assert.ok(text.indexOf('ws.a_1 = ws.a_2 = 1;') >= 0);
// simple function
-var text = compile('procedure1.');
+var text = compile('procedure1 section.');
assert.ok(text.indexOf('function procedure1()') >= 0);
// function with moves
-var text = compile('procedure1. move 1 to a. move 2 to b.', { a: null, b: null });
+var text = compile('procedure1 section. move 1 to a. move 2 to b.', { a: null, b: null });
assert.ok(text.indexOf('function procedure1() {') >= 0);
assert.ok(text.indexOf('ws.a = 1;') >= 0);
assert.ok(text.indexOf('ws.b = 2;') >= 0);
assert.ok(text.indexOf('}') >= 0);
// function with parameters
-var text = compile('procedure1 using x, y. move x to a. move y to b.', { a: null, b: null });
+var text = compile('procedure1 section using x, y. move x to a. move y to b.', { a: null, b: null });
assert.ok(text.indexOf('function procedure1(x, y) {') >= 0);
assert.ok(text.indexOf('ws.a = x;') >= 0);
assert.ok(text.indexOf('ws.b = y;') >= 0);
@@ -162,7 +162,7 @@ assert.ok(text.indexOf('procedure1();') >= 0);
// perform procedure with procedure
-var text = compile('perform procedure1. procedure1. move 1 to a. move 2 to b.', { a: null, b: null });
+var text = compile('perform procedure1. procedure1 section. move 1 to a. move 2 to b.', { a: null, b: null });
assert.ok(text.indexOf('procedure1();') >= 0);
assert.ok(text.indexOf('function procedure1() {') >= 0);
assert.ok(text.indexOf('ws.a = 1;') >= 0);
@@ -171,7 +171,7 @@ assert.ok(text.indexOf('}') >= 0);
// perform procedure with varying
-var text = compile('perform procedure1 varying k from 1 to 10 by 1. procedure1. move 1 to a. move 2 to b.', { k: null, a: null, b: null });
+var text = compile('perform procedure1 varying k from 1 to 10 by 1. procedure1 section. move 1 to a. move 2 to b.', { k: null, a: null, b: null });
assert.ok(text.indexOf('for (ws.k = 1; ws.k <= 10; ws.k++)') >= 0);
assert.ok(text.indexOf('procedure1();') >= 0);
assert.ok(text.indexOf('function procedure1() {') >= 0);
@@ -181,15 +181,15 @@ assert.ok(text.indexOf('}') >= 0);
// perform procedure with giving
-var text = compile('perform procedure1 giving k. procedure1. return 1.', { k: null });
+var text = compile('perform procedure1 giving k. procedure1 section. return 1.', { k: null });
assert.ok(text.indexOf('ws.k = procedure1();') >= 0);
assert.ok(text.indexOf('function procedure1() {') >= 0);
assert.ok(text.indexOf('return 1;') >= 0);
assert.ok(text.indexOf('}') >= 0);
// perform procedure with giving many variables
-var text = compile('perform procedure-1 giving k, j. procedure-1. return 1.', { k: null, j: null });
+var text = compile('perform procedure-1 giving k, j. procedure-1 section. return 1.', { k: null, j: null });
assert.ok(text.indexOf('var $aux = procedure_1();') >= 0);
assert.ok(text.indexOf('ws.k = $aux;') >= 0);
assert.ok(text.indexOf('ws.j = $aux;') >= 0);
@@ -204,11 +204,11 @@ procedure division.\r\n\
perform procedure-1.\r\n\
perform procedure-2.\r\n\
\r\n\
-procedure-1. local a.\r\n\
+procedure-1 section. local a.\r\n\
move 1 to a.\r\n\
return a.\r\n\
\r\n\
-procedure-2. local a.\r\n\
+procedure-2 section. local a.\r\n\
move 2 to a.\r\n\
return a.'
, { k: null, j: null });
@@ -289,7 +289,7 @@ assert.ok(text.indexOf('obj.func()') >= 0);
// use a procedure as parameter
-var text = compile('perform proc1 using proc2. proc1. return 1. proc2. return 2.');
+var text = compile('perform proc1 using proc2. proc1 section. return 1. proc2 section. return 2.');
assert.ok(text.indexOf('proc1(proc2)') >= 0);
// a linkage item is visible as a runtime field
@@ -330,7 +330,7 @@ assert.equal(text, 'proc1($cb1); function $cb1(err) { proc2($cb2); function $cb2
// procedure with async
-var text = compile('procedure division. local name. perform proc1 async giving name. display "hello " name. proc1 async. return "world"');
+var text = compile('procedure division. local name. perform proc1 async giving name. display "hello " name. proc1 section async. return "world"');
assert.equal(text, 'var name; proc1($cb1); function $cb1(name) { runtime.display("hello ", name); } function proc1($cb) { $cb("world"); return; }');
// perform inline
View
16 test/perform.js
@@ -16,54 +16,54 @@ function run(text, ws) {
// perform procedure
var ws = { a: 1 };
-run('perform procedure1. procedure1. add 1 to a.', ws);
+run('perform procedure1. procedure1 section. add 1 to a.', ws);
assert.equal(ws.a, 2);
// perform procedure with two commands
var ws = { a: 1, b: 3 };
-run('perform procedure1. procedure1. add 1 to a. add 2 to b.', ws);
+run('perform procedure1. procedure1 section. add 1 to a. add 2 to b.', ws);
assert.equal(ws.a, 2);
assert.equal(ws.b, 5);
// perform two procedures
var ws = { a: 1, b: 3 };
-run('perform procedure1. perform procedure2. procedure1. add 1 to a. procedure2. add 2 to b.', ws);
+run('perform procedure1. perform procedure2. procedure1 section. add 1 to a. procedure2 section. add 2 to b.', ws);
assert.equal(ws.a, 2);
assert.equal(ws.b, 5);
// perform procedure 10 times
var ws = { k: null, a: 0 };
-run('perform procedure1 varying k from 1 to 4. procedure1. add k to a.', ws);
+run('perform procedure1 varying k from 1 to 4. procedure1 section. add k to a.', ws);
assert.equal(ws.a, 10);
assert.equal(ws.k, 5);
// perform procedure passing argument
var ws = { a: 1, b: 3 };
-run('perform procedure1 using 3. procedure1 using x. add x to a. add x to b.', ws);
+run('perform procedure1 using 3. procedure1 section using x. add x to a. add x to b.', ws);
assert.equal(ws.a, 4);
assert.equal(ws.b, 6);
// perform procedure 10 times passing argument
var ws = { k: null, a: 0 };
-run('perform procedure1 using k varying k from 1 to 4. procedure1 using x. add x to a.', ws);
+run('perform procedure1 using k varying k from 1 to 4. procedure1 section using x. add x to a.', ws);
assert.equal(ws.a, 10);
assert.equal(ws.k, 5);
// perform with giving and return
var ws = { result: 0 };
-run('perform procedure1 using 3 giving result. procedure1 using n. add 1 to n. return n.', ws);
+run('perform procedure1 using 3 giving result. procedure1 section using n. add 1 to n. return n.', ws);
assert.equal(ws.result, 4);
// perform factorial with auxiliary parameters
var ws = { result: 0 };
-run('perform factorial using 3 giving 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.', ws);
+run('perform factorial using 3 giving result. 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.', ws);
assert.equal(ws.result, 6);
// perform global function
View
6 test/runtime.js
@@ -20,9 +20,9 @@ assert.ok(runtime.flush);
assert.equal(typeof(runtime.flush), 'function');
assert.ok(runtime.global);
-// getRuntime with response, request
+// getRuntime with response, request, require
-var runtime = cobs.getRuntime( { response: {}, request: {} });
+var runtime = cobs.getRuntime( { response: {}, request: {}, require: require });
assert.ok(runtime);
assert.ok(runtime.display);
@@ -34,4 +34,4 @@ assert.equal(typeof(runtime.flush), 'function');
assert.ok(runtime.response);
assert.ok(runtime.request);
assert.ok(runtime.global);
-
+assert.ok(runtime.require);

0 comments on commit 3e435a3

Please sign in to comment.
Something went wrong with that request. Please try again.