help-bison
[Top][All Lists]
Advanced

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

Re: Need help on simple lex and yacc programs


From: Hans Aberg
Subject: Re: Need help on simple lex and yacc programs
Date: Wed, 5 May 2004 19:44:17 +0200

At 14:07 +0200 2004/05/05, Jean-Louis Grau wrote:

The first error you made, was to use styled text in this mailing list;
never do that. :-)

The second error that newbies on this list almost invariable do is to
forget cc'ing Help-Bison on replies, even if asked to do so. :-)

>Lex and yacc are new tools for me.

A good way to start using Bison is by experimenting with the calculator in
the Bison manual.


>%%
>
>File: integerAttr | stringAttr | floatAttr ;
...
>My problem is that the parser recognise the first line as an integer
>attribute (PARSER: Found an attribute of type INTEGER) and just stop after
>this (no crash and no stuck just stop parsing &)

As you have written the grammar, Bison will parse a file with exactly one
of the three options, and all input after that will then clearly be an
error. If you want to have several of these readble in a sequence, then
your grammar should probably look something like:

file:
    file_contents {}
  |               { /* admit empty file */ }
  | error {
      ...
      YYABORT;
    }
;
file_contents:
    file_contents command {}
  | command               {}
;
command:
    assignment
  | ...
;
assignment:
    DATANAME EQUAL attribute END_OF_LINE
;
attribute:
    INTEGER
  | STRING
  | FLOAT
;

I suspect that you have to put in an END_OF_LINE token in order to not get
parser conflicts. That's why many languages make use of sentence
terminators, such as ";" in C.

  Hans Aberg






reply via email to

[Prev in Thread] Current Thread [Next in Thread]