help-bison
[Top][All Lists]
Advanced

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

Re: Recognize grammar prefix.


From: lfinsto1
Subject: Re: Recognize grammar prefix.
Date: Sun, 13 Jan 2008 19:46:26 +0100 (CET)
User-agent: SquirrelMail/1.4.9a

> S1: token1 S2
> S2: token2 S3 | token3 S2
> S3: token4 ....
>
> Now, If I call bison and I try to validate "token1 token2" sequence, the
> parser fails because token2 must be followed by S3, but in my situation
> lex
> have no others tokens for bison at a certain moment...

I don't understand.  Does `yylex' return when it runs out of tokens?  What
happens when it returns?  Is it passing a token, e.g. an `END' token to
`yyparse'?

> I want to validate
> this type of sequence (a "prefix" of terminal-symbol sequence...In others
> words is a "part" of a valid sequence...). Obviously it work if I change
> my
> grammar:
>
>  S1: token1 S2
> S2: token2 | token2 S3 | token3 S2
>
> ...but the only way is rewrite the grammar or exist others solutions in
> Bison?

I don't quite understand what it is you want to do.  If an input is valid,
`yyparse' will return successfully and if a particular input, that you
define as being valid, is processed by `yyparse' correctly, then `yyparse'
_may_ implement your grammar correctly.  The correctness or otherwise of a
grammar or of the implementation of a function is a very tricky question.

If you want `yyparse' to handle a particular input, you must write your
grammar rules accordingly.  I find names of symbols like `S1', `token1',
etc., difficult to understand.  It would be easier for others to
understand what you're trying to do if you used more descriptive names.

Generally speaking, I think you will get best results from Bison if you
use it in the way it's meant to be used.  If you try to make it jump
through hoops, it's likely to not work well.

In most grammars, it's a good idea to have most inputs reduce to something
like an `expression' or a `statement'.  Then, a `program' can be a
sequence of `statements', `expressions', or whatever.  I don't know what
the advantage would be in "validating" an input as opposed to actually
processing it.

Perhaps you could explain a bit more about what you're trying to do.

Laurence









reply via email to

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