help-bison
[Top][All Lists]
Advanced

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

Re: Stopping as soon as a valid symbol is read


From: Hans Aberg
Subject: Re: Stopping as soon as a valid symbol is read
Date: Mon, 25 Jul 2011 22:57:19 +0200

On 25 Jul 2011, at 16:22, Ludovic Courtès wrote:

> However, with a pure API, I don’t see how to get yyresult back from user
> code?  The code snippet in the manual pushes tokens but never asks for
> the result.

Typically one adds the value as an extra argument, as a reference in C++ or 
pointer in C. Check out the C++ example.

My program with syntax on top of Guile uses
  %parse-param { parser& driver }
  %lex-param   { parser& driver }
which means that the function will have 'driver' as extra function name. Then, 
in a suitable action (near the sentences symbol), I use
%%
unit:
    statement { driver.result = $1; YYACCEPT; };
  | "∎"       { driver.result = eval(driver.result); YYACCEPT; };
  | error     { std::cout << "Parser error!" << std::endl;
                driver.result = unspecified; yyrestart(stdin); YYABORT; }
;

...

Hans





reply via email to

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