help-bison
[Top][All Lists]
Advanced

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

Re: How to ignore a token if it doesn't fit in with a rule?


From: Hans Aberg
Subject: Re: How to ignore a token if it doesn't fit in with a rule?
Date: Sat, 23 Jul 2011 12:43:43 +0200

On 23 Jul 2011, at 02:40, uclacasey wrote:

> I'm writing a program that handles comments as well as a few other things. If
> a comment is in a specific place, then my program does something.
> 
> Flex passes a token upon finding a comment, and Bison then looks to see if
> that token fits into a particular rule. If it does, then it takes an action
> associated with that rule.
> 
> Here's the thing: the input I'm receiving might actually have comments in
> the wrong places. In this case, I just want to ignore the comment rather
> than flagging an error.
> 
> My question: 
> How can I use a token if it fits into a rule, but ignore it if it doesn't?
> Can I make a token "optional"?

You can turn start conditions on/off by having a global variable which is set 
in the parser actions. Then the first thing the lexer does is checking this 
variable, setting the correct start condition.

You might check the Usenet newsgroup comp.compilers for other suggestions.

Hans





reply via email to

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