help-bison
[Top][All Lists]
Advanced

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

Re: sticking custom meta informations to grammar rules


From: Hans Aberg
Subject: Re: sticking custom meta informations to grammar rules
Date: Wed, 29 Jan 2014 23:11:28 +0100

On 29 Jan 2014, at 18:48, Christian Schoenebeck <address@hidden> wrote:

> Hi everybody!

Hi!

> I am currently working on a shell and wrote custom C++ code that takes 
> Bison's 
> symbol stack at a certain point (i.e. when an error occured) and walks ahead 
> the Bison generated yyfoo tables / tree of the shell's grammar. I added that 
> custom code for two purposes: 1) providing very user friendly error messages 
> on syntax errors and 2) providing the user visual auto completion & auto 
> correction while typing in the shell.
> 
> It is already working, however to make those syntax error messages and auto 
> completion suggestions even more appropriate & human friendly, I would need 
> to 
> stick some additional custom meta informations to the individual grammar 
> rules. 

It seems that your should use LR(1); see the Bison manual, sec. 5.8.1, "LR 
Table Construction". Bison by default uses LALR(1), which merges the states in 
such a way that when an error occurs, though no further tokens will be read, 
some additional reductions may be applied before an error is issued. Using 
LR(1) guarantees that that will not happen; so you can check the lookahead 
tokens in the state, and that is also the set of valid completions. I do not 
know if LR(1) works with C++, though. And you may need to write some code in 
order to find the lookahead tokens; you might want having this code integrated 
into the Bison distribution, so that the feature does not break with updates.

Hans





reply via email to

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