mridoni / gixsql

GixSQL is an ESQL preprocessor and a series of runtime libraries to enable GnuCOBOL to access PostgreSQL, ODBC, MySQL, Oracle and SQLite databases.
GNU General Public License v3.0
16 stars 8 forks source link

Unexpected WORD "SD" parsing cobol program #175

Open sergiosa61 opened 8 months ago

sergiosa61 commented 8 months ago

In trying to process a cobol program for our Oracle migration project, I get the following error.

--accepting rule at line 1388("SD") Next token is token WORD (1.1-2546: SD) Error: popping nterm sqlvariantstate_list (1.2204-2542: ) Stack now 0 1 6 44 Error: popping nterm $@3 (1.2204: ) Stack now 0 1 6 Error: popping token Begin of FILE SECTION (1.1-2203: ) Stack now 0 1 Error: popping nterm sqlstate_list (MU057R.PCO:1.1: ) Stack now 0 Cleanup: discarding lookahead token WORD (1.1-2546: SD) Stack now 0 /dati/HDS/home/parsbt/SC3/WORK/MU057R.PCO(99): error: syntax error, unexpected WORD

These are the Cobol lines that generate the error.

000086 DATA DIVISION.
000087 FILE SECTION.
000088 FD  F-XSET
000089     LABEL RECORD STANDARD.
000090 01  A-XSET.
000091     03 RECXSET        PIC X(80).
000092     03 FILLER  REDEFINES  RECXSET.
000093      05 XSET-TIP       PIC X(04).
000094      05 XSET-NOMEINT   PIC X(10).
000095      05 XSET-NOMEEXT   PIC X(66).
000096      05  FILLER REDEFINES XSET-NOMEEXT.
000097       07 FILLER        PIC X(59).
000098       07 XSET-MAXREL   PIC X(07).
000099 SD  F-FSORT
000100     DATA RECORD A-FSORT  .
000101 01  A-FSORT.
000102       06 SORT-KEY                     PIC  9(007).
000103       06 SORT-CONTO                   PIC  9(015).

This is the syntax from the GnuCobol manual

GnuCOBOL 2.2 Final [7Sept2017] Programmer’s Guide
95
5.2.1. File/Sort-Description
�
File/Sort-Description Syntax
�
FD|SD file-name-1 [ IS EXTERNAL|GLOBAL ]
~~ ~~
~~~~~~~~ ~~~~~~
[ BLOCK CONTAINS [ integer-1 TO ] integer-2 CHARACTERS|RECORDS ]

The gixpp version

gixpp -V
gixpp - the ESQL preprocessor for Gix-IDE/GixSQL
Version: 1.0.20b
libgixpp version: 1.0.20b

The cobc version

>cobc -V
cobc (OpenCOBOL) 2.0.0
Copyright (C) 2001,2002,2003,2004,2005,2006,2007 Keisuke Nishida
Copyright (C) 2006-2012 Roger While
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Built     Nov 30 2023 11:35:35
Packaged  Feb 11 2012 12:36:31 UTC
C version "8.3.0"
GitMensch commented 8 months ago

I haven't checked the result (maybe it doesn't even build) - but can you please recheck after applying #176 ?

sergiosa61 commented 8 months ago

Hi, I applied the changes to libgixpp/gix_esql_parser.yy 117 %token LOCALSTORAGEEND "End of LOCAL-STORAGE SECTION" 118 %token FD "FILE description (FD)" 119 %token SD "SORT description (SD)" 830 ; 831 832 file_def: 833 FD token_list PERIOD {} 834 |SD token_list PERIOD {} 835 ; 836 837 838 sqlvariantstate_list: 839 %empty 840 |sqlvariantstate_list file_def 841 |sqlvariantstate_list incfile 842 |sqlvariantstate_list includesql I ran the commands make clean ./configure --prefix=/opt/install --enable-pgsql --disable-mysql --disable-odbc --disable-oracle make sudo make install But the error persists 16:16:33 /dati/HDS/home/parsbt/SC3/WORK/MU057R.PCO(99): error: syntax error, unexpected WORD

Il 20/03/24 13:57, Simon Sobisch ha scritto:

I haven't checked the result (maybe it doesn't even build) - but can you please recheck after applying #176 https://github.com/mridoni/gixsql/pull/176 ?

GitMensch commented 8 months ago

Adjusting the code, then make && sudo make install is enough. Nice to see that it compiles. But I've forgot to adjust the scanner (which creates the token for the parser).

It just occurred to me that the parser does not need to differ between FD and SD, so you can revert the change, then only adjust the scanner as follows:

--- a/libgixpp/gix_esql_scanner.ll
+++ b/libgixpp/gix_esql_scanner.ll
@@ -1245,7 +1245,7 @@ SUBSYSTEM "SQL"|"CICS"|"DLI"
        return yy::gix_esql_parser::make_WORKINGEND(loc);
     }

-   "FD" {
+   ("FD"|"SD") {
        if (driver->data_division_section == DD_SECTION_FS) {
            __yy_push_state(FD_STATE);
        }
sergiosa61 commented 8 months ago

Hi, i revert the change to libgixpp/gix_esql_parser.yy. I applied the new changes to libgixpp/gix_esql_scanner.ll

1206     "SCREEN"[ ]+"SECTION"[ ]*"." {
1207                 driver->startlineno = yylineno - 1;
1208                 driver->endlineno = yylineno - 1;
1209                 driver->host_reference_list->clear();
1210                 driver->res_host_reference_list->clear();
1211
1212                 driver->commandname = "WORKING_END";
1213                 driver->cursorname = "";
1214                 driver->sqlname = "";
1215                 driver->incfilename = "";
1216                 driver->data_division_section = DD_SECTION_INITIAL;
1217
1218                 driver->hostreferenceCount = 0;
1219                 driver->command_putother = 0;
1220                 driver->sql_list->clear();
1221
1222                 __yy_pop_state();
1223                 return yy::gix_esql_parser::make_WORKINGEND(loc);
1224     }
1225         ("FD"|"SD") {
1226                 if (driver->data_division_section == DD_SECTION_FS) {
1227                         __yy_push_state(FD_STATE);
1228                 }
1229                 return yy::gix_esql_parser::make_FD(loc);
1230         }
1231
1232     "PIC" |
1233     "PICTURE" {
1234                 __yy_push_state(PICTURE_STATE);
1235     }

gixpp still throws error

00086 : 000086 DATA DIVISION.
00087 : 000087 FILE SECTION.
00088 : 000088 FD  F-XSET
00089 : 000089     LABEL RECORD STANDARD.
00090 : 000090 01  A-XSET.
00091 : 000091     03 RECXSET        PIC X(80).
00092 : 000092     03 FILLER  REDEFINES  RECXSET.
00093 : 000093      05 XSET-TIP       PIC X(04).
00094 : 000094      05 XSET-NOMEINT   PIC X(10).
00095 : 000095      05 XSET-NOMEEXT   PIC X(66).
00096 : 000096      05  FILLER REDEFINES XSET-NOMEEXT.
00097 : 000097       07 FILLER        PIC X(59).
00098 : 000098       07 XSET-MAXREL   PIC X(07).
00099 : 000099 SD  F-FSORT
/dati/HDS/home/parsbt/SC3/WORK/MU057R.PCO(99): error: syntax error, unexpected WORD

I added the --parser-scanner-debug parameter

00099 : 000099 SD F-FSORT --accepting rule at line 1396(" ") --accepting rule at line 1388("SD") Next token is token WORD (1.1-2546: SD) Error: popping nterm sqlvariantstate_list (1.2204-2542: ) Stack now 0 1 6 44 Error: popping nterm $@3 (1.2204: ) Stack now 0 1 6 Error: popping token Begin of FILE SECTION (1.1-2203: ) Stack now 0 1 Error: popping nterm sqlstate_list (MU057R.PCO:1.1: ) Stack now 0 Cleanup: discarding lookahead token WORD (1.1-2546: SD) Stack now 0 /dati/HDS/home/parsbt/SC3/WORK/MU057R.PCO(99): error: syntax error, unexpected WORD