¿ªÔÆÌåÓý

Re: Possible bug in BREXX parse instruction


 

Hi Mike,
I am?not a bit mad, and I am sorry I gave that impression.

I agree that the literals should be identified first, because they must be
used to separate the string being parsed into smaller sections that
are processed separately. I think you have the right approach,
even if I don't understand?the details of the control flow.
Bob

On Mon, Oct 17, 2022 at 8:35 AM Mike Gro?mann <mike.grossmann.de@...> wrote:
Hey Bob,


as you know my English is not the best. :) So if I misunderstood something, please don't be angry with me.

I know relatively exactly where the problem lies. I just don't have a solution.

I'll try to outline the problem.

The internal compiler processes the template and puts the following statements on the stack:


trest = '() trial 1'
Stck:0 0 NEWCLAUSE
?Stck:0 8 CREATE "TREST"
?Stck:1 24 PUSH "() trial 1"
?Stck:2 48 COPY "() trial 1"

say 'test of () trial 1'
Stck:0 56 NEWCLAUSE
?Stck:0 64 PUSH "test of () trial 1"
?Stck:1 88 SAY "test of () trial 1"

s = dotell(trest)
Stck:0 96 NEWCLAUSE
?Stck:0 104 CREATE "S"
?Stck:1 120 LOAD "TREST"
?Stck:2 144 CALL DOTELL NoArgs=1, Exist=1 Type=other
?Stck:2 248 LOADARG "() trial 1"
?Stck:3 264 COPY2TMP "() trial 1"
?Stck:3 272 PARSE "() trial 1"
?Stck:3 280 PUSH "("
?Stck:4 304 TR_LIT "("

// TR_LIT is trying to set break_end to a reasonable value based on the literal position
DBG> tr_lit: ToParse='() trial 1' - Lit='('
DBG> tr_lit exit) data_start = 1
DBG> tr_lit exit) break_start = 1
DBG> tr_lit exit) break_end = 2

?Stck:3 312 CREATE "WITH"
?Stck:4 328 PVAR

// Here you can see, that the "WITH" keyword is handled as variable, not as keyword.
// "WITH" keyword is not allowed at this context.
DBG> OP_PVAR: BreakStart: 1
DBG> OP_PVAR: BreakEnd: 2
DBG> OP_PVAR: DataStart: 1
DBG> OP_PVAR: DataEnd: 1

?Stck:3 344 TR_SPACE

DBG> tr_space 1) data_start = 1
DBG> tr_space 1) break_start = 1
DBG> tr_space 1) break_end = 2
DBG> tr_space 2) data_start = 2
DBG> tr_space 2) break_start = 3
DBG> tr_space 2) break_end = 4

?Stck:3 352 CREATE "IN1"
?Stck:4 368 PVAR

// OP_PVAR operation will extract a value from the parse string into the in1 variable
DBG> OP_PVAR: BreakStart: 3
DBG> OP_PVAR: BreakEnd: 4
DBG> OP_PVAR: DataStart: 2
DBG> OP_PVAR: DataEnd: 3
DBG> OP_PVAR: extracting value from '() trial 1' ?(2 to 3)

?Stck:3 384 PUSH ")"
?Stck:4 408 TR_LIT ")"

// TR_LIT is trying to set break_end to a reasonable value based on the literal position
DBG> tr_lit: ToParse='() trial 1' - Lit=')'
DBG> tr_lit 1) pattern_pos = 0
DBG> tr_lit 2) data_start = 4
DBG> tr_lit 2) break_start = 11
DBG> tr_lit 2) break_end = 11

?Stck:3 416 CREATE "IN2"
?Stck:4 432 PVAR

// OP_PVAR operation will extract a value from the parse string into the in2 variablev
DBG> OP_PVAR: BreakStart: 11
DBG> OP_PVAR: BreakEnd: 11
DBG> OP_PVAR: DataStart: 4
DBG> OP_PVAR: DataEnd: 11
DBG> OP_PVAR: extracting value from '() trial 1' ?(4 to 11)

?Stck:3 448 TR_END
?Stck:3 456 CREATE "OUTER"
?Stck:4 472 PVAR

// OP_PVAR operation will extract a value from the parse string into the outer variable
DBG> OP_PVAR: BreakStart: 11
DBG> OP_PVAR: BreakEnd: 11
DBG> OP_PVAR: DataStart: 11
DBG> OP_PVAR: DataEnd: 11

?Stck:3 488 POP

Stck:2 504 NEWCLAUSE
?...
?...
?


So, the compiler puts the template on the stack with the information that there must be two variables between two literals.?
The interpreter knows now, which operations (TR_LIT and TR_SPACE and PVALUE) must be executed,?
in order to bring the values from the input string into the variables. Unfortunately, the parsing algorithm cannot handle?
this, if the number of expected variables does not match the "words" in the input string.


To bring it to the point. The compiler, which unfortunately also processes its instructions sequentially,?
would have to collect all literals first, and only then place the template on the stack.?
Then one would have the possibility in the interpreter to process the data, as you described it.


If this makes any sense to you. :)



Mike



Am 17.10.2022 um 13:19 schrieb Bob Bolch <Bob@...>:

Hi Mike,
I don't know where the bad code is, but I expect it is probably in the interpre.c piece.

There is no code that I could find to handle literals in the parse template.?

For example, if we have a string to parse like this one?defined in a variable 'x':

a b c ( d e f? g? h i? j? k?

And a parse template like:

Parse var x one '(' two three four five? ' g'? six?


REXX should:


1. Find the literals in the template. Here they are '(' and 'g'.

2. Separate the string into the literals and the parts that are not literals. Those are:

String:? a b c
Literal: (
String: d e f
Literal: g
String: h i j k

3. We should then assign the template variables, as follows:

Assign value 'a b c' to variable 'one'.
Assign value 'd' to variable 'two'.
Assign value 'e' to variable 'three'.
Assign value 'f' to variable 'four'.
Assign value '' to variable 'five'.
Assign value 'h i j k' to variable 'six'.

t test exec? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
/* */ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
address COMMAND ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
x = 'a b c ( d e f ?g ?h i ?j ?k' ? ? ? ? ? ? ? ? ?
Parse var x one '(' two three four five ?' g' ?six?
say one ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
say two ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
say three ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
say four ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??
say five ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??
say six ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
Ready; T=0.01/0.01 07:12:13?



? ? ? ? ? ? test? ? ? ? ? ? ? ? ? ? ? ??
a b c ? ? ? ? ? ? ? ? ? ? ??
d ? ? ? ? ? ? ? ? ? ? ? ? ??
e ? ? ? ? ? ? ? ? ? ? ? ? ??
f ? ? ? ? ? ? ? ? ? ? ? ? ??
? ? ? ? ? ? ? ? ? ? ? ? ? ??
? h i ?j ?k ? ? ? ? ? ? ? ??
Ready; T=0.01/0.01 07:12:34? ?

The key here is to parse subsections of the string by first separating?them,
using the literals found in the parse template.? ?

BREXX doesn't do that on VMCE, or MVS, or in the first implementation by the?
developer. BREXX produces:? ?

test ? ? ? ? ? ? ? ? ? ? ? ?
a b c ? ? ? ? ? ? ? ? ? ? ??
d ? ? ? ? ? ? ? ? ? ? ? ? ??
e ? ? ? ? ? ? ? ? ? ? ? ? ??
f ? ? ? ? ? ? ? ? ? ? ? ? ??
g ?h i ?j ?k ? ? ? ? ? ? ? ?
? ? ? ? ? ? ? ? ? ? ? ? ? ??
Ready; T=0.02/0.02 07:16:28

because it does not process the literals in the parse template correctly.

Bob Bolch?



On Sun, Oct 16, 2022, 1:25 PM Mike Gro?mann <mike.grossmann.de@...> wrote:
Bob,

did you came closer to a c file, where the problem may occur?
I just reviewed my old mail, but can¡¯t really remember. Something with
not finding the closing ?)¡°. Where do you think is the bug, I will
review the code.


Mike ?

Am 16.10.2022 um 19:18 schrieb Bob Bolch <Bob@...>:

Yes. The problem is that BREXX doesn't handle literals in the parse template!!
I just don't know enough C to find and fix it.
Bob Bolch

On Sun, Oct 16, 2022, 12:46 PM Martin Scheffler <San-Lorenzo@...> wrote:
Comparing with results from real iron (z/VM 6.4):

Ready; T=0.01/0.01 10:46:48?????????????????????????????????????? ?
?DAVEMTST???????????????????????????????????????????????????????? ?
z/VM Version 6 Release 4.0, service level 1701 (64-bit)?????????? ?
Generated at 04/24/17 16:30:42 EST??????????????????????????????? ?
IPL at 10/08/22 07:37:33 EST????????????????????????????????????? ?
CMS Level 28, Service Level 1701????????????????????????????????? ?
REXX370 4.02 01 Dec 1998????????????????????????????????????????? ?
test of () trial 1??????????????????????????????????????????????? ?
in1 = //????????????????????????????????????????????????????????? ?
in2 = //????????????????????????????????????????????????????????? ?
outer=/ trial 1/????????????????????????????????????????????????? ?
test of (1) trial 2?????????????????????????????????????????????? ?
in1 = /1/???????????????????????????????????????????????????????? ?
in2 = //????????????????????????????????????????????????????????? ?
outer=/ trial 2/????????????????????????????????????????????????? ?
test of (1 3) trial 3???????????????????????????????????????????? ?
in1 = /1/???????????????????????????????????????????????????????? ?
in2 = /3/???????????????????????????????????????????????????????? ?
outer=/ trial3/?????????????????????????????????????????????????? ?
Ready; T=0.01/0.01 10:46:51?????????????????????????????????????? ?
????????????????????????????????????????????????????????????????? ?
????????????????????????????????????????????????????????????????? ?
Written new file: DAVEMTST EXEC A1??????????????????????????????? ?
Ready; T=0.09/0.23 15:58:32?????????????????????????????????????? ?
DAVEMTST????????????????????????????????????????????????????????? ?
SYSTEM 4381-A???????????????????????????????????????????????????? ?
VM/370 Community Edition Version? 1 Release? 1.2 10/11/22 08:44:05?
VM/370 CMS Community Edition Version 1 Release 1.2??????????????? ?
CMS bREXX 1.0.1 Jul? 5 2022?????????????????????????????????????? ?
test of () trial 1??????????????????????????????????????????????? ?
in1 = /)/???????????????????????????????????????????????????????? ?
in2 = /trial 1/?????????????????????????????????????????????????? ?
outer=//????????????????????????????????????????????????????????? ?
test of (1) trial 2?????????????????????????????????????????????? ?
in1 = /1)/??????????????????????????????????????????????????????? ?
in2 = /trial 2/?????????????????????????????????????????????????? ?
outer=//????????????????????????????????????????????????????????? ?
test of (1 3) trial 3???????????????????????????????????????????? ?
in1 = /1/???????????????????????????????????????????????????????? ?
in2 = /3/???????????????????????????????????????????????????????? ?
outer=/ trial3/?????????????????????????????????????????????????? ?
Ready; T=0.08/0.12 15:58:38?????????????????????????????????????? ?
????????????????????????????????????????????????????????????????? ?
*** side by side:???????????????????????????????????????????????? ?
????????????????????????????????????????????????????????????????? ?
REXX370 4.02 01 Dec 1998? CMS bREXX 1.0.1 Jul? 5 2022???????????? ?
test of () trial 1??????? test of () trial 1????????????????????? ?
in1 = //????????????????? in1 = /)/?????????????????????????????? ?
in2 = //????????????????? in2 = /trial 1/???????????????????????? ?
outer=/?trial 1/????????? outer=//??????????????????????????????? ?
test of (1) trial 2?????? test of (1) trial 2???????????????????? ?
in1 = /1/???????????????? in1 = /1)/????????????????????????????? ?
in2 = //????????????????? in2 = /trial 2/???????????????????????? ?
outer=/?trial 2/????????? outer=//??????????????????????????????? ?
test of (1 3) trial 3???? test of (1 3) trial 3?????????????????? ?
in1 = /1/???????????????? in1 = /1/?????????????????????????????? ?
in2 = /3/???????????????? in2 = /3/?????????????????????????????? ?
outer=/ trial3/?????????? outer=/ trial3/???????????????????????? ?
????????????????????????????????????????????????????????????????? ?
?DAVEMTST EXEC???? A1? F 80? Trunc=80 Size=22 Line=11 Col=1 Alt=0 ?
====>???????????????????????????????????????????????????????????? ?
????0 * * * Top of File * * *???????????????????????????????????? ?
????1 /* test parse */??????????????????????????????????????????? ?
????2 "q cplevel"???????????????????????????????????????????????? ?
????3 "q cmslevel"??????????????????????????????????????????????? ?
????4 parse version v???????????????????????????????????????????? ?
????5 say v?????????????????????????????????????????????????????? ?
????6?? trest = '() trial 1'????????????????????????????????????? ?
????7?? say 'test of () trial 1'????????????????????????????????? ?
????8?? s = dotell(trest)???????????????????????????????????????? ?
????9?? trest = '(1) trial 2'???????????????????????????????????? ?
???10?? say 'test of (1) trial 2'???????????????????????????????? ?
???11?? s = dotell(trest)???????????????????????????????????????? ?
???12?? trest = '(1 3) trial3'??????????????????????????????????? ?
???13?? say 'test of (1 3) trial 3'?????????????????????????????? ?
???14?? s = dotell(trest)???????????????????????????????????????? ?
???15?? exit????????????????????????????????????????????????????? ?
???16???????????????????????????????????????????????????????????? ?
???17 dotell:???????????????????????????????????????????????????? ?
???18?? parse arg with '(' in1 in2 ')' outer????????????????????? ?
???19?? say 'in1 = /'in1'/'?????????????????????????????????????? ?
???20?? say 'in2 = /'in2'/'?????????????????????????????????????? ?
???21?? say 'outer=/'outer'/'???????????????????????????????????? ?
???22?? return 0????????????????????????????????????????????????? ?
???23 * * * End of File * * *???????????????????????????????????? ?






Join [email protected] to automatically receive all group messages.