Skip to content

JavaScript Runtime bug #3270

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Gravity-I-Pull-You-Down opened this issue Sep 8, 2021 · 4 comments
Closed

JavaScript Runtime bug #3270

Gravity-I-Pull-You-Down opened this issue Sep 8, 2021 · 4 comments
Milestone

Comments

@Gravity-I-Pull-You-Down
Copy link

Gravity-I-Pull-You-Down commented Sep 8, 2021

I already posted the complete issue on StackOverflow and someone pointed out that this should be posted here.

This is the code for NodeJS file

import {createServer} from 'http';
import antlr4 from 'antlr4';
import fs from 'fs'
import HelloLexer from "./gen/CobolLexer.js";
import HelloParser from "./gen/CobolParser.js";
import CustomCobolListener from "./CustomCobolListener.js"

const {CommonTokenStream, InputStream} = antlr4;
let Filename = './COBOLCodes/AROMA96.CBL'
createServer((req, res) => {
    res.writeHead(200, {"Content-Type": "text/json"});
   var InputFromFile = '';
    try {
        let data = fs.readFileSync(Filename, 'utf8');
        InputFromFile = data;
    } catch (e) {
        console.log(e);
    }
    console.log("server running");
    try {
        var chars = new InputStream(InputFromFile, true);
        var lexer = new HelloLexer(chars);
        var tokens = new CommonTokenStream(lexer);
        var parser = new HelloParser(tokens);
        parser.buildParseTrees = true;
        var tree = parser.startRule();
        var htmlChat = new CustomCobolListener(res,Filename.substr(Filename.lastIndexOf('/') + 1,Filename.length - Filename.lastIndexOf('/') - 5));
        antlr4.tree.ParseTreeWalker.DEFAULT.walk(htmlChat, tree);
    }catch (e) {
        console.log(e)
    }
    // res.write("</body></html>");
    res.end();
}).listen(1337);

Please click this Link for COBOL grammar

The COBOL code I am trying to parse is as follows

IDENTIFICATION DIVISION.
PROGRAM-ID.  Aroma96exam.

ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
   SELECT Oil-Details-File ASSIGN TO "ODF.DAT"
          ORGANIZATION IS INDEXED   
          ACCESS MODE IS DYNAMIC
          RECORD KEY IS Oil-Num-ODF
          ALTERNATE RECORD KEY IS Oil-Name-ODF
                      WITH DUPLICATES
          FILE STATUS IS ODF-Status.

   SELECT Oil-Stock-File ASSIGN TO "OSF.DAT"
          ORGANIZATION IS RELATIVE   
          ACCESS MODE IS DYNAMIC
          RELATIVE KEY IS Rel-Rec-Num 
          FILE STATUS IS OSF-Status.

   SELECT Trans-File ASSIGN TO "TRANS.DAT"
        ORGANIZATION IS LINE SEQUENTIAL.   

   SELECT Report-File ASSIGN TO "OILSTOCK.RPT".

   SELECT Error-File ASSIGN TO "ERROR.DAT"
        ORGANIZATION IS LINE SEQUENTIAL. 

  

DATA DIVISION.
FILE SECTION.
FD Oil-Details-File.
01 ODF-Rec.
   88 End-Of-ODF		VALUE HIGH-VALUES.
   02 Oil-Num-ODF               PIC 9(4).
   02 Oil-Name-ODF              PIC X(20).
   02 Unit-Size-ODF		PIC 9(2).
   02 Unit-Cost-ODF		PIC 99V99.

FD Oil-Stock-File.
01 OSF-Rec.
   02 Oil-Num-OSF		PIC 9(4).
   02 Qty-In-Stock-OSF		PIC 9(5).

FD Trans-File.
01 Trans-Rec.
   88 End-Of-Trans		VALUE HIGH-VALUES.
   02 Type-Code			PIC 9.
      88 Add-To-Stock		VALUE 1.
      88 Remove-From-Stock      VALUE 2.
   02 Oil-Num.
      03  Rel-Rec-Num		PIC 9(3).
      03  FILLER		PIC 9.
   02 Qty			PIC 9(5).

FD Error-File.
01 Error-Rec			PIC X(10).

FD Report-File REPORT IS Oil-Stock-Report.


WORKING-STORAGE SECTION.
01 Status-Codes.
   02 ODF-Status                PIC X(2).
   02 OSF-Status                PIC X(2).
      88 No-Error-Found		VALUE "00".
      88 Rec-Not-Found		VALUE "23".


01 Stock-Value			PIC 9(5)V99.

REPORT SECTION.
RD Oil-Stock-Report
   CONTROLS ARE FINAL
                Oil-Name-ODF
   PAGE LIMIT IS 66
   HEADING 2
   FIRST DETAIL 8
   LAST DETAIL 50
   FOOTING 55.

01 TYPE IS REPORT HEADING.
   02 LINE 2.
      03 COLUMN 15		PIC X(18) VALUE "OIL  STOCK  REPORT".
   02 LINE 3.
      03 COLUMN 13		PIC X(22) VALUE ALL "-".
   
01 TYPE IS PAGE HEADING.
   02 LINE 6.
      03 COLUMN 03		PIC X(9)  VALUE "OIL  NAME".
      03 COLUMN 23		PIC X(4)  VALUE "OIL#".
      03 COLUMN 29		PIC X(4)  VALUE "SIZE".
      03 COLUMN 36		PIC X(3)  VALUE "QTY".
      03 COLUMN 44		PIC X(11) VALUE "STOCK VALUE".

01 Stock-Detail-Line TYPE IS DETAIL.
   02 LINE IS PLUS 2.
      03 COLUMN 01		PIC X(20) SOURCE Oil-Name-ODF GROUP INDICATE.
      03 COLUMN 23		PIC 9(4)  SOURCE Oil-Num-ODF.
      03 COLUMN 30		PIC 99    SOURCE Unit-Size-ODF.
      03 COLUMN 35              PIC ZZ,ZZ9 SOURCE Qty-In-Stock-OSF.
      03 COLUMN 44              PIC $$$,$$9.99 SOURCE Stock-Value.

01 TYPE IS CONTROL FOOTING Oil-Name-ODF NEXT GROUP PLUS 1.
   02 LINE IS PLUS 2.
      03 COLUMN 27		PIC X(15) VALUE "TOTAL OIL VALUE".
      03 Oil-Val COLUMN 44      PIC $$$$,$$9.99 SUM Stock-Value.

01 TYPE IS CONTROL FOOTING FINAL.
   02 LINE IS PLUS 3.
      03 COLUMN 27              PIC X(17) VALUE "TOTAL STOCK VALUE".
      03 COLUMN 46              PIC $$,$$$,$$9.99 SUM Oil-Val.
 

PROCEDURE DIVISION.
Begin.
   OPEN I-O Oil-Details-File.
   OPEN I-O Oil-Stock-File.
   OPEN OUTPUT Error-File.
   OPEN INPUT Trans-File.
   READ Trans-File 
      AT END SET End-Of-Trans TO TRUE
      END-READ.
   PERFORM Process-Transactions UNTIL End-Of-Trans.

   CLOSE Error-File.
   CLOSE Trans-File.  
   OPEN OUTPUT Report-File.
   INITIATE Oil-Stock-Report.

   MOVE SPACES TO Oil-Name-ODF.
   START Oil-Details-File 
      KEY IS GREATER THAN Oil-Name-ODF
      INVALID KEY DISPLAY "Start Error FS = " ODF-Status
   END-START.
   READ Oil-Details-File NEXT RECORD
      AT END SET End-Of-ODF TO TRUE
   END-READ.
   PERFORM Print-Stock-Report UNTIL End-Of-ODF.
   TERMINATE Oil-Stock-Report.
   CLOSE Oil-Details-File.
   CLOSE Oil-Stock-File.
   STOP RUN.

Process-Transactions.
   READ Oil-Stock-File
       INVALID KEY DISPLAY "OSF rec not found FS = " OSF-Status
   END-READ.
   IF No-Error-Found 
      EVALUATE TRUE
        WHEN Add-To-Stock ADD Qty TO Qty-In-Stock-OSF
        WHEN Remove-From-Stock SUBTRACT Qty FROM Qty-In-Stock-OSF
        WHEN OTHER DISPLAY "Type code not 1 or 2 Rec = " Trans-Rec
      END-EVALUATE
      REWRITE OSF-Rec
         INVALID KEY DISPLAY "Problem on REWRITE FS= " OSF-Status
      END-REWRITE
    ELSE IF Rec-Not-Found 
                WRITE Error-Rec FROM Trans-Rec
         END-IF
   END-IF.  
   READ Trans-File 
      AT END SET End-Of-Trans TO TRUE
   END-READ. 

Print-Stock-Report.
   MOVE Oil-Num-ODF TO Oil-Num
   READ Oil-Stock-File
      INVALID KEY DISPLAY "Error on reading OSF SF= " OSF-Status
   END-READ.
   COMPUTE Stock-Value = Unit-Cost-ODF * Qty-In-Stock-OSF.
   GENERATE Stock-Detail-Line. 
   READ Oil-Details-File NEXT RECORD
      AT END SET End-Of-ODF TO TRUE
   END-READ.

Here is an image of a tree formed after parsing the above COBOL code through the given grammar, which clearly shows that TRUE is identified as a booleanliteral which is as expected
antlr error

but after I run the code on my local nodejs it gives a runtime error as follows

/bin/node /mnt/sdb3/antlr/antlr.js
server running
line 125:33 missing {ABORT, AS, ASCII, ASSOCIATED_DATA, ASSOCIATED_DATA_LENGTH, ATTRIBUTE, AUTO, AUTO_SKIP, BACKGROUND_COLOR, BACKGROUND_COLOUR, BEEP, BELL, BINARY, BIT, BLINK, BOUNDS, CAPABLE, CCSVERSION, CHANGED, CHANNEL, CLOSE_DISPOSITION, COBOL, COMMITMENT, CONTROL_POINT, CONVENTION, CRUNCH, CURSOR, DEFAULT, DEFAULT_DISPLAY, DEFINITION, DFHRESP, DFHVALUE, DISK, DONTCARE, DOUBLE, EBCDIC, EMPTY_CHECK, ENTER, ENTRY_PROCEDURE, ERASE, EOL, EOS, ESCAPE, EVENT, EXCLUSIVE, EXPORT, EXTENDED, FOREGROUND_COLOR, FOREGROUND_COLOUR, FULL, FUNCTIONNAME, FUNCTION_POINTER, GRID, HIGHLIGHT, IMPLICIT, IMPORT, INTEGER, IS, JUST, JUSTIFIED, KANJI, KEPT, KEYBOARD, LANGUAGE, LB, LD, LEFTLINE, LENGTH_CHECK, LIBACCESS, LIBPARAMETER, LIBRARY, LIST, LOCAL, LOCK, LONG_DATE, LONG_TIME, LOWER, LOWLIGHT, MMDDYYYY, NAMED, NATIONAL, NATIONAL_EDITED, NETWORK, NO_ECHO, NUMERIC_DATE, NUMERIC_TIME, OCCURS, ODT, ORDERLY, OVERLINE, OWN, PASSWORD, PORT, PRINTER, PRIVATE, PROCESS, PROGRAM, PROMPT, READER, REMOTE, REAL, RECEIVED, RECURSIVE, REF, REMOVE, REQUIRED, REVERSE_VIDEO, SAVE, SECURE, SHARED, SHAREDBYALL, SHAREDBYRUNUNIT, SHARING, SHORT_DATE, SYMBOL, TASK, THREAD, THREAD_LOCAL, TIMER, TODAYS_DATE, TODAYS_NAME, TRUE, TRUNCATED, TYPEDEF, UNDERLINE, VIRTUAL, WAIT, YEAR, YYYYMMDD, YYYYDDD, ZERO_FILL, '66', '77', '88', INTEGERLITERAL, NUMERICLITERAL, IDENTIFIER} at 'TRUE'

and as a StackOverflow user pointed out that the code runs fine in java.

File Attachment to reproduce the code.
Git.zip

@ericvergnaud
Copy link
Contributor

Please attach all files required to run your code and reproduce the bug

@Gravity-I-Pull-You-Down
Copy link
Author

Git.zip
I think these should be enough to reproduce the error.

@ericvergnaud
Copy link
Contributor

Hi,
I am able to reproduce the error and it is indeed a JS runtime bug.
It might take a couple of weeks to get it fixed.

@Gravity-I-Pull-You-Down
Copy link
Author

This is for anyone who is facing the same problem as me and doesn't want to / can't wait for the next release to get their problem solved.
open node_modules folder inside your project and navigate to antlr4 folder and take a look at the pull request made by @ericvergnaud above, you will find both the files in your antlr4 folder you can change them manually to get your project up and running, although I would recommend compiling from the source but currently the ANTLR4 project is uncompilable on Linux systems.

@parrt parrt added this to the 4.9.3 milestone Oct 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants