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: uclacasey
Subject: Re: How to ignore a token if it doesn't fit in with a rule?
Date: Sat, 23 Jul 2011 11:15:11 -0700 (PDT)

So you're suggesting I use a parallel parser to determine whether it's in an
appropriate place to return a comment?  Well...this would definitely be
cumbersome, mainly because the input files we're working with can have them
anywhere.  The specific places they have to be are places like "above a
member variable within a struct", for example.  All these would be difficult
to detect with a parallel parser.  I appreciate the help: it's definitely
got me thinking about new ideas.


John P. Hartmann wrote:
> 
> Well, controlling the scanner from the parser is never going to work
> in general as the scanner can be way ahead.  I'm afraid you'll have to
> write a parallel "parser" using exclusive star conditions.  However
> this "parser" can be vastly simplified as it only has to figure out
> whether to return a comment.
> 
> If that becomes cumbersome, there is something wrong with the grammar
> (or your understanding of same).
> 
> For example, the REXX language uses blank as both an operator and a
> normal token delimiter.  So the scanner needs to keep track of
> expressions at least to know when it expects an operator.  The
> alternative would lead to an enormous number of shift/reduce conflicts
> (which all would be resolved by shifting), but you'll likely regret
> this as you are bound to miss a shift/reduce conflict that you need to
> resolve.
> 
> On 23 July 2011 12:43, Hans Aberg <address@hidden> wrote:
>> 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
>>
>>
>>
>> _______________________________________________
>> address@hidden https://lists.gnu.org/mailman/listinfo/help-bison
>>
> 
> _______________________________________________
> address@hidden https://lists.gnu.org/mailman/listinfo/help-bison
> 
> 

-- 
View this message in context: 
http://old.nabble.com/How-to-ignore-a-token-if-it-doesn%27t-fit-in-with-a-rule--tp32119417p32122682.html
Sent from the Gnu - Bison - Help mailing list archive at Nabble.com.




reply via email to

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