On Sun, 5 Aug 2007, Hans Aberg wrote:

> When I tried it, it worked:
> $ bison parser.y++
> parser.y++: conflicts: 455 shift/reduce, 1 reduce/reduce

I never upload non-working versions.  If I have a similar question
again, I'll upload examples to an ftp server.  Sorry for the
inconvenience this time.

> So then it hard for anyone but yourself to fix the problem. If you are sure it
> is a bug, report it to Bison Bugs <[EMAIL PROTECTED]>. Be sure to include
> relevant data.

No, I'm sure it's not a bug in Bison, just something Bison's not meant
or equipped to handle, or me trying to use Bison in a way it's not
meant to be used.

> It is your grammar, but I think it will be unmanageable. 

Well, it's not completely mine.  It's based on the grammar of
Metafont, written by Donald Knuth.  However, he implemented his parser
from scratch in Pascal. I used his description of the grammar in
Backus-Naur as the basis of the rules I've written in Bison.  

However, Metafont doesn't define that many types or operations, so my 
grammar has become much larger than the grammar of Metafont.  I've also 
made some changes because of the way Bison works.

While it is somewhat large and complex, many of the rules fall
into patterns that are repeated over and over for the various types.
I have a pretty good overview of it, having written every line of it.
I'm sure it would be difficult for someone else to understand, coming
to it now, without having read it when it was smaller and simpler.  I
think a knowledge of the rules of the Metafont grammar would be nearly
indispensable.  It's a moot point, however, since no one has ever
expressed an interest in understanding it.  

The problem (if it is a problem) with the shift/reduce conflicts appeared 
very early on.  The correct resolution is always to shift, so I didn't 
worry about it, unless a rule caused a large increase in the number of
s/r conflicts.  I didn't think that it caused extra work for Bison or
that they needed to be kept track of.  If they do, I may have problems
that will probably not be so easy to solve.

> The Bison has a
> suggestion for fixing reduce/reduce conflicts. In, some cases, when it can't
> be resolve compile time, one may have to use GLR (%glr). 

I'll have to look this up, but I think there may have been some issue
with using GLR.  If the `yyparse' generated when using this option
isn't thread-safe, I won't be able to use it.

There is only one reduce/reduce conflict.  I don't remember the
details, since I wrote those rules so long ago, but it has to with the
syntax for defining a `path' using `points' and "connectors", i.e.,
something very basic to a Metafont-like language.  I determined at the
time after a lot of fiddling that I couldn't do anything about it, but
that the parser behaved the way I wanted it to.

> I think there is an
> example of how to do that with C++. But one has been able to make a LALR(1)
> for C++, too. 

I'm not sure whether this is relevant, but I only use C++ in the
actions;  Bison generates the regular C version of `yyparse'.

> So it is a question of style. Even if a language has given
> grammar, it may not be adapted for a parser general. So rewriting it
> is normal implementing.

I'm sure you're right, and it's always been a matter of compromise.
I've been getting very good results with Bison for the 6 years I've
been working on this project.  I simply don't have the knowledge to
write a parser from scratch, and I doubt that I would want to
implement one the way Knuth did in the 1980's using Pascal, even if I
had the leisure to read through his code.  I'm sure he did it very
well, but that's not the point.

If I had invented the grammar from scratch, I surely would have tried
to avoid all shift/reduce conflicts.  However, they seem to be
inherent in Knuth's rules, when one tries to implement them using
Bison.  

I just tried getting rid of all the `any_variable: <type>_variable'
rules, but it didn't work:  I got five fewer s/r conflicts but four
additional r/r conflicts, and input that previously worked caused an
error at run-time.  That is, it caused an error in one of my
functions, not an error affecting the run environment.  Obviously,
this will require some thorough investigation. 

I don't really think that my grammar needs a major rewrite, even if I
had the time for something like that.  I will try to get rid of any
unnecessary rules and simplify the grammar wherever I can.  I had
already determined that it works better to have more rules that are
simpler instead of fewer rules that are more complicated.

In case anyone wants to try running the program, there's an option for
outputting the debugging output produced by Bison, namely
`--bison-trace' (can be abbreviated to `-bi').

I've put an example in the attached file `ttemp.txt'.

Thanks again,

Laurence
(Enter:) 3dldf --bison-trace --silent 

(Output:)

3dldf -bi -si
Starting parse
Entering state 0
Reducing stack by rule 2 (line 5394), -> statement_list
Stack now 0
Entering state 2
Reading a token: * 

(Enter:) point p; p := (1, 2, 3); end;

(Output:)

3dldf --bison-trace --silent 
Starting parse
Entering state 0
Reducing stack by rule 2 (line 5394), -> statement_list
Stack now 0
Entering state 2
Reading a token: *  point p; p := (1, 2, 3); end;
Next token is token POINT_DECLARATOR ()
Shifting token POINT_DECLARATOR, Entering state 23
Reading a token: Next token is token SYMBOL_0 ()
Shifting token SYMBOL_0, Entering state 5
Reducing stack by rule 2016 (line 91024), SYMBOL_0 -> tag
Stack now 0 2 23
Entering state 453
Reducing stack by rule 1998 (line 89385), tag -> symbolic_token
Stack now 0 2 23
Entering state 451
Reducing stack by rule 2024 (line 91730), -> declared_suffix
Stack now 0 2 23 451
Entering state 1515
Reading a token: Next token is token SEMI_COLON ()
Reducing stack by rule 1918 (line 83313), symbolic_token declared_suffix -> 
declared_variable
Stack now 0 2 23
Entering state 450
Reducing stack by rule 1916 (line 83120), declared_variable -> declaration_list
Stack now 0 2 23
Entering state 463
Next token is token SEMI_COLON ()
Reducing stack by rule 1850 (line 77380), POINT_DECLARATOR declaration_list -> 
point_declaration
Stack now 0 2
Entering state 363
Reducing stack by rule 1773 (line 75230), point_declaration -> declaration
Stack now 0 2
Entering state 351
Next token is token SEMI_COLON ()
Shifting token SEMI_COLON, Entering state 1512
Reducing stack by rule 6 (line 5903), declaration SEMI_COLON -> statement
Stack now 0 2
Entering state 166
Reducing stack by rule 3 (line 5401), statement_list statement -> statement_list
Stack now 0
Entering state 2
Reading a token: Next token is token SYMBOL_0 ()
Shifting token SYMBOL_0, Entering state 5
Reducing stack by rule 2016 (line 91024), SYMBOL_0 -> tag
Stack now 0 2
Entering state 429
Reducing stack by rule 235 (line 20534), -> suffix
Stack now 0 2 429
Entering state 1513
Reading a token: Next token is token ASSIGN ()
Reducing stack by rule 234 (line 20513), tag suffix -> variable
Stack now 0 2
Entering state 227
Reading a token: Next token is token POINT ()
Shifting token POINT, Entering state 1276
Reducing stack by rule 328 (line 22070), variable POINT -> point_variable
Stack now 0 2
Entering state 276
Reading a token: Next token is token ASSIGN ()
Shifting token ASSIGN, Entering state 1419
Reading a token: Next token is token LEFT_PARENTHESIS ()
Shifting token LEFT_PARENTHESIS, Entering state 1490
Reading a token: Next token is token INTEGER ()
Shifting token INTEGER, Entering state 591
Reducing stack by rule 1108 (line 43300), INTEGER -> numeric_token
Stack now 0 2 276 1419 1490
Entering state 668
Reading a token: Next token is token COMMA ()
Reducing stack by rule 990 (line 40528), numeric_token -> numeric_token_atom
Stack now 0 2 276 1419 1490
Entering state 661
Reducing stack by rule 987 (line 40361), numeric_token_atom -> numeric_atom
Stack now 0 2 276 1419 1490
Entering state 660
Next token is token COMMA ()
Reducing stack by rule 991 (line 40539), numeric_atom -> numeric_primary
Stack now 0 2 276 1419 1490
Entering state 662
Reducing stack by rule 1081 (line 42246), numeric_primary -> numeric_secondary
Stack now 0 2 276 1419 1490
Entering state 1234
Next token is token COMMA ()
Reducing stack by rule 1101 (line 42981), numeric_secondary -> numeric_tertiary
Stack now 0 2 276 1419 1490
Entering state 975
Next token is token COMMA ()
Reducing stack by rule 1107 (line 43275), numeric_tertiary -> numeric_expression
Stack now 0 2 276 1419 1490
Entering state 1813
Next token is token COMMA ()
Shifting token COMMA, Entering state 2482
Reading a token: Next token is token INTEGER ()
Shifting token INTEGER, Entering state 591
Reducing stack by rule 1108 (line 43300), INTEGER -> numeric_token
Stack now 0 2 276 1419 1490 1813 2482
Entering state 668
Reading a token: Next token is token COMMA ()
Reducing stack by rule 990 (line 40528), numeric_token -> numeric_token_atom
Stack now 0 2 276 1419 1490 1813 2482
Entering state 661
Reducing stack by rule 987 (line 40361), numeric_token_atom -> numeric_atom
Stack now 0 2 276 1419 1490 1813 2482
Entering state 660
Next token is token COMMA ()
Reducing stack by rule 991 (line 40539), numeric_atom -> numeric_primary
Stack now 0 2 276 1419 1490 1813 2482
Entering state 662
Reducing stack by rule 1081 (line 42246), numeric_primary -> numeric_secondary
Stack now 0 2 276 1419 1490 1813 2482
Entering state 1234
Next token is token COMMA ()
Reducing stack by rule 1101 (line 42981), numeric_secondary -> numeric_tertiary
Stack now 0 2 276 1419 1490 1813 2482
Entering state 975
Next token is token COMMA ()
Reducing stack by rule 1107 (line 43275), numeric_tertiary -> numeric_expression
Stack now 0 2 276 1419 1490 1813 2482
Entering state 3028
Reducing stack by rule 1112 (line 43398), numeric_expression COMMA 
numeric_expression -> numeric_sublist
Stack now 0 2 276 1419 1490
Entering state 1523
Next token is token COMMA ()
Shifting token COMMA, Entering state 2484
Reading a token: Next token is token INTEGER ()
Shifting token INTEGER, Entering state 591
Reducing stack by rule 1108 (line 43300), INTEGER -> numeric_token
Stack now 0 2 276 1419 1490 1523 2484
Entering state 668
Reading a token: Next token is token RIGHT_PARENTHESIS ()
Reducing stack by rule 990 (line 40528), numeric_token -> numeric_token_atom
Stack now 0 2 276 1419 1490 1523 2484
Entering state 661
Reducing stack by rule 987 (line 40361), numeric_token_atom -> numeric_atom
Stack now 0 2 276 1419 1490 1523 2484
Entering state 660
Next token is token RIGHT_PARENTHESIS ()
Reducing stack by rule 991 (line 40539), numeric_atom -> numeric_primary
Stack now 0 2 276 1419 1490 1523 2484
Entering state 662
Reducing stack by rule 1081 (line 42246), numeric_primary -> numeric_secondary
Stack now 0 2 276 1419 1490 1523 2484
Entering state 1234
Next token is token RIGHT_PARENTHESIS ()
Reducing stack by rule 1101 (line 42981), numeric_secondary -> numeric_tertiary
Stack now 0 2 276 1419 1490 1523 2484
Entering state 975
Next token is token RIGHT_PARENTHESIS ()
Reducing stack by rule 1107 (line 43275), numeric_tertiary -> numeric_expression
Stack now 0 2 276 1419 1490 1523 2484
Entering state 3029
Reducing stack by rule 1113 (line 43414), numeric_sublist COMMA 
numeric_expression -> numeric_sublist
Stack now 0 2 276 1419 1490
Entering state 1523
Next token is token RIGHT_PARENTHESIS ()
Shifting token RIGHT_PARENTHESIS, Entering state 2485
Reducing stack by rule 1111 (line 43369), LEFT_PARENTHESIS numeric_sublist 
RIGHT_PARENTHESIS -> numeric_list
Stack now 0 2 276 1419
Entering state 670
Reducing stack by rule 1197 (line 47368), numeric_list -> point_primary
Stack now 0 2 276 1419
Entering state 671
Reading a token: Next token is token SEMI_COLON ()
Reducing stack by rule 1265 (line 49180), point_primary -> point_secondary
Stack now 0 2 276 1419
Entering state 672
Next token is token SEMI_COLON ()
Reducing stack by rule 1275 (line 50175), point_secondary -> point_tertiary
Stack now 0 2 276 1419
Entering state 673
Next token is token SEMI_COLON ()
Reducing stack by rule 1278 (line 50614), point_tertiary -> point_expression
Stack now 0 2 276 1419
Entering state 2356
Reducing stack by rule 108 (line 8582), point_variable ASSIGN point_expression 
-> point_assignment
Stack now 0 2
Entering state 182
Reducing stack by rule 39 (line 7397), point_assignment -> assignment
Stack now 0 2
Entering state 168
Next token is token SEMI_COLON ()
Shifting token SEMI_COLON, Entering state 1263
Reducing stack by rule 7 (line 6004), assignment SEMI_COLON -> statement
Stack now 0 2
Entering state 166
Reducing stack by rule 3 (line 5401), statement_list statement -> statement_list
Stack now 0
Entering state 2
Reading a token: Next token is token END ()
Shifting token END, Entering state 118
Reducing stack by rule 1 (line 5210), statement_list END -> program




_______________________________________________
help-bison@gnu.org http://lists.gnu.org/mailman/listinfo/help-bison

Reply via email to