[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: gnubol: Re: Magic tokens





RKRayhawk@aol.com wrote:

> (no need for a special hack for GIVING in add).

True. Someone else pointed this out too and I have fixed it.

> (bison 101 - if and other conditional verbs)
> Anyway, just intended as tips, hope it's useful..
> Bob Rayhawk

I reread the bison manual on precedence and I have gotten it going beyond
expressions (which I was already using it for) - after a lloonngg time. You have
to define the token as %left %right or %nonassoc or else it ignores any precedence
on that token - so I can leave most of my tokens in alphabetical order. All the
tk_VERB_HAS_END magic tokens are gone except for two.

The two remaining ones are for the evaluate and search verbs. Both of these can
include nested when phrases but they are
different 'when' phrases, which makes it hard to parse them when nested.

Why nest them when you are not allowed to nest conditionals except at the end of
if-bits and maybe one other case)? Here is why:

The correct parsing for the following statement is IMO as follows:

add a to b
     size error
           add c to d << ERROR illega; nested conditional statement
                not size error
                      display "assert(0)"
.

Now if I just define add something like this:

add:
stuff a_size_error
;

a_size_error:
size error imperatives
|not size error imperatives
| size error imperatives not size error imperatives
| not size error imperatives size error imperatives
;

It will happily parse the test case above as:
add a to b
     size error
           add c to d
     not size error
           display "assert(0)"
.
Which is wrong IMO and difficult to fix.

So I am parsing the nested conditionals and then flagging them YYERRORs. OK so on
this train of logic, I need to parse nested conditionals.

This is why the problem with search and evaluate comes up.

search a
      when x=a(i)
           evaluate b
                 when

                  when <<< who owns this 'when'
etc
.

Now I know I am going to flag it anyway so but bison doesn't know and complains.
So I need to disallow nested conditional search and replace most of the time. This
is easy to do via magic has-end tokens.

The section name magic token is also gone.

I want to add function calls which will require an extra symbol table lookup to
disambiguate function max (a (b)). Once I have that and the hacks written I will
repost the grammar, and start testing.

Tim Josling





--
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.