Version française
Home     About     Download     Resources     Contact us    
Browse thread
yacc question
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Robert W. <slrn_robert@y...>
Subject: Re: [Caml-list] yacc question
On Mon, Dec 05, 2005 at 01:15:40AM +1100, skaller wrote:
> I have the 'usual' kind of parser for expressions, with two
> nonterminals 'expr' and 'atom', the latter including ( expr ) 
> and INTEGER of course.
> 
> When I have input like
> 
> 1;
> 1 + 2 ;
> (1 + 2) ;
> 
> none of the case parse as expressions, the first and
> last do parse as atoms (leaving the ; in the buffer).
> 
> What I want is to parse the longest possible match.
> The only way I can think of doing this is:
> 

ocamlyacc parses longest match by default.
Your rule for atoms seem to complex or you lexer isn't able to extract
the token for atoms correctly from the line.

>   | expr token_not_allowed_in_expressions
> 
> and then 'put back' the trailing token into the buffer.
> Is there another way?
> 
This shouldn't be necessary, normally you can redesign your parser
rules to avoid this.

-- 

	Robert...