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: Jean-Louis Grau
Subject: RE: Need help on simple lex and yacc programs
Date: Fri, 7 May 2004 10:10:51 +0200

Hello Hans,

Thank you for your help. My parser is working know. I am so impressed to see
how lex and yacc are efficient!

Regards,

Jean-Louis


-----Message d'origine-----
De : address@hidden
[mailto:address@hidden la part de Hans
Aberg
Envoye : mercredi 5 mai 2004 18:44
A : Jean-Louis Grau
Cc : address@hidden
Objet : Re: Need help on simple lex and yacc programs


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




_______________________________________________
address@hidden http://mail.gnu.org/mailman/listinfo/help-bison





reply via email to

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