[Subject Prev][Subject Next][Thread Prev][Thread Next][Subject Index][Thread Index]

Re: About Bison



On Wed, Jan 03, 2001 at 06:39:42PM +0530, Shridhar Daithankar wrote:
> Hi all
> 
> I am calling a bison parser on a string that is collecting key strokes in a char
> array, in Qt event loop...
> 
> Say A/B/C/D are my terminal/non-terminals.
> 
> then the rule
> 
> E        :    A B C D
> 
> fails if(well always) bison can not look ahead as array is over. 

[ Trying to refresh all the compiler stuff I learnt in school ]

This is incomplete information. Much depends on the non-terminals. If bison
can't figure out whether to shift or reduce (I think bison uses shift/reduce
parsing) on seeing a non-terminal, then your grammer requires look ahead.
(Research on LL(1), LALR(1) etc on the net). 

Now, there are two possibilities:

1. Your language requires look ahead, in which case there is not much you
   can do.

2. (1) is not true, in which case, you can rewrite the grammar in such a
   way that look ahead is not necessary. Read Aho/Sethi/Ulman for more.


> What I am doing
> is hardcoding all possible terminal/non terminals in front of D like
> 
> E        :    A B C D F
> 
> This works but it does not generate any out put tlll next character(in F) is
> typed, which is but obvious.
> 

This method is guaranteed NOT to achieve your objective ( to see output as
soon as all terminals for A B C D are seen).

> Is there any way I can instruct bison not to look ahead in a particular
> situation?

See above.

In many cases, bison may be an overkill. A simple tokenizer, along with a
recursive descent parser is faster and easier to write, but may be more
error prone.

	-Arun