[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
gnubol: X-WHEN stack
Tim, you had asked for further comment about the X-WHEN stack idea. Hope this
helps.
X-WHEN stack concept
When a rule recognizes the begining of a paragraph it allocates a
paragraph control structure. One member of the structure is capable
of pointing to a linked list of X-WHEN stack plates.
each x_when stack element has an
int x_when_mode /* 0=none, 1=S_WHEN, 2=E_WHEN */ /* enum if you like */
So, ...
struct para_cntl {
... various ...
int tos_x_when_mode;
struct x_when *x_when_stack;
... various ...
}
struct x_when {
int x_when_mode;
struct *x_when;
}
First thing to know is that the paragraph 'owns' the para_cntl
data structure in
the sense that paragraph recognition leads to allocating it, and recognition
of the end of a paragraph leads to freeing the data structure. Other rules
that may operate during the life of the data structure can access, extend or
shorten the x_when linked list, but those other rules cannot delete the
para_cntl data structure.
For the various actions in a bison grammar to reach the data structure it
will have to be in global space (or else wrapped with functions C++ style).
During the reduction of a rule that recognizes the leading portion of a
SEARCH statement an S-WHEN is pushed onto the stack. The lexer interrogates
this stack. So it must be an extern. The push of S-WHEN basically happens
once, but the lexer may interrogate it repeatedly, again and again changing
WHEN to an S-WHEN token before each return to the parser. During the
reduction of the rules that recognizes the trailing portion of a SEARCH,
as in the END-SEARCH (or more obtusely an implicit scope termination), the
S-WHEN is popped from the stack.
The same kind of thing applies to the EVALUATE and the pushing once of an
E-WHEN stack item, and potentially multiple interrogations of the stack
top by the lexer before a scope termination.
The stack can push to any depth, and when it pops it reverts to the
previous status, one at a time. Thus supporting nesting. This structure and
the handling suggested so far is completely indifferent to what is being
stacked inside of what. Permission about that will be governed in the rules.
A supper implicit scope terminator must also reduce the stack to zero, forth
with. Like a period. We may need certain general high level rules that have
the
'error' special token to also reduce the stack to zero.
It may be redundant if our nesting is correct, but it might also be
advisable for any code in open paragraph context to note when it enters
upon its logic with the X-STACK at zero. So that when its scope ends we
might force the stack to zero, no matter what has happened. (I have not
sketch the data structure for that here).This would be
mostly to reinforce the code at statement boundaries in open paragraphs
that have no end of sentence markers. This actually would be vouch-safing
any rules that trapped errors for us involving damaged E/S scope
delimitation.
Anyway, we can allocate the para_cntl structure at the commencement
of the procedure
division and also at the begining of sections to allow for code that
does not appear under paragraph labels. We can use an alloc/free strategy,
or probably just keep re-using the same data structure, as long as at
boundaries it reduces the stack to zero.
This differs from any hand coded lookahead, because the lexer state changes
early enough that we do not need to look ahead. This strategy is focused on
changing the subsequent tokens, the WHENs, not the leading verb tokens.
There is no pushback in this strategy. I will need to see your next
grammar to see how if at all this is distinct in kind from your current
approach. You seem to have had pushbacks at one point. And I thought you had
posted that you got rid of many but thought you needed hand coded lookahead
and pushbacks for EVALUATE and SEARCH still.
I have sketched
int tos_x_when_mode;
within the basic data structure to save a dereference to the linked list.
Lexer's need to figure out each WHEN is the most frequent function. So it can
just look at top of stack (tos_x_when_mode;),
This suggested coding technique (the X-WHEN stack) is based upon the
assumption that WHENs keep gluing to an inner undelimited verb. I assume we
will have no way to interpret a WHEN by the topology of its condition
expression. I see no way to get a WHEN to do anything but reduce a prior WHEN
in a nested situation. Although I have hopes that WHEN OTHER actually is the
moral equivalent (or immoral equivalent) of an alternate conditional which
terminates an EVALUATES WHEN recurse (so that any WHEN after that is nolonger
that EVALUATES WHEN clause).
So I am actually saying we will need an embellishment here to pop E-WHEN from
the stack upon recognition of WHEN OTHER! That is not so hard, but we must
have a means to discipline END-EVALUATE to pop E-WHEN only if it has not
been preceded by WHEN OTHER. I think that can be done by simply having
distinct rules for
EVALUATE ....... WHEN OTHER {pop;} .... END-EVALUATE
and
EVALUATE ....... END-EVALUATE {pop;}
Bob Rayhawk
--
This message was sent through the gnu-cobol mailing list. To remove yourself
from this mailing list, send a message to majordomo@lusars.net with the
words "unsubscribe gnu-cobol" in the message body. For more information on
the GNU COBOL project, send mail to gnu-cobol-owner@lusars.net.