Menu

Commit [r13018]  Maximize  Restore  History

P-code: clear the remaining C-generation syntax errors

Nine tests in the aubit4gltest corpus failed to get through c2pcode with a
syntax error, and four more were rejected for "excess elements". All but two
of the compile failures are now gone: 15 down to 2, and 27 of the comparable
tests pass (was 21).

Most of this is on the code generation side rather than the grammar, since we
control what is emitted:

* _dtype_hint was declared just before its use in the PROMPT block, after
statements had already been emitted. The p-code grammar is C89, where a
declaration cannot follow a statement, so it is now declared in the block
prologue with the other locals.

* "a4gl_sqlca.sqlcode = a4gl_status = _fetcherr" is a chained assignment, and
the grammar's assign rule is "variable '=' expr". Split into two statements -
exactly equivalent, and clearer C.

* The generated event list declared aclfgl_event_list _sio_evt[n+1] where n
counts EVENTS, but the loop emits one entry per key code, so an event listing
several keys overflowed the array. C only warns about that; p-code rejected
it. Both backends now emit the unsized form and let the initialiser fix the
extent, so the count cannot drift.

* The ERR_CHK_* names are macros, and p-code skips every '#' line, so it saw
them as undefined variables. The generator emits the expansion when doing
p-code. There is no way to reach the preprocessor from the generator, so
expand_err_chk() in err_hand.c has to be kept in step with
incl/a4gl_incl_4gldef.h by hand.

Two additions to the grammar itself, both of which leave the conflict count
exactly where it was (64 shift/reduce, 1 reduce/reduce):

* "struct BINDING *reread" - dtype folds pointers into the type for CHAR, INT,
LONG, SHORT and VOID but had no form for a pointer to a named struct.

* sizeof of a TYPE rather than an expression, as in
"sizeof(_ordbind)/sizeof(struct BINDING)". The size is known at that point,
so it folds to a constant.

* A trailing comma in a brace initialiser list, which C allows and every
generated bind array uses.

Still failing to compile: one module using a typedef (the grammar's TYPEDEF
rule reads its dtype through the wrong union member, so it needs fixing before
it can help), and one 22,000 line module that exhausts the parser.

Verified: full aubit4gltest run unchanged against the r13015 baseline - the
generator changes are all behind A4GL_doing_pcode() except the chained
assignment split, which is equivalent C. Multi-module p-code still links and
runs, and the OO suite passes.

mikeaubury 2026-08-31

changed /aubit4glsrc/trunk/compilers/pcode/simple.yacc
changed /aubit4glsrc/trunk/lib/liblex/lex_esqlc/cmds_funcs.c
changed /aubit4glsrc/trunk/lib/liblex/lex_esqlc/compile_c.c
changed /aubit4glsrc/trunk/lib/liblex/lex_esqlc/compile_c_esql.c
changed /aubit4glsrc/trunk/lib/liblex/lex_esqlc/compile_c_sql.c
changed /aubit4glsrc/trunk/lib/liblex/lex_esqlc/err_hand.c
/aubit4glsrc/trunk/compilers/pcode/simple.yacc Diff Switch to side-by-side view
Loading...
/aubit4glsrc/trunk/lib/liblex/lex_esqlc/cmds_funcs.c Diff Switch to side-by-side view
Loading...
/aubit4glsrc/trunk/lib/liblex/lex_esqlc/compile_c.c Diff Switch to side-by-side view
Loading...
/aubit4glsrc/trunk/lib/liblex/lex_esqlc/compile_c_esql.c Diff Switch to side-by-side view
Loading...
/aubit4glsrc/trunk/lib/liblex/lex_esqlc/compile_c_sql.c Diff Switch to side-by-side view
Loading...
/aubit4glsrc/trunk/lib/liblex/lex_esqlc/err_hand.c Diff Switch to side-by-side view
Loading...