06.01.2015 Views

Manual

Manual

Manual

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 10: C++ Language Interface 107<br />

Use the two following directives to enable parser tracing and verbose error messages.<br />

%debug<br />

%error-verbose<br />

Semantic values cannot use “real” objects, but only pointers to them.<br />

// Symbols.<br />

%union<br />

{<br />

int<br />

ival;<br />

std::string *sval;<br />

};<br />

The code between ‘%{’ and ‘%}’ after the introduction of the ‘%union’ is output in the ‘*.cc’<br />

file; it needs detailed knowledge about the driver.<br />

%{<br />

# include "calc++-driver.hh"<br />

%}<br />

The token numbered as 0 corresponds to end of file; the following line allows for nicer error<br />

messages referring to “end of file” instead of “$end”. Similarly user friendly named are<br />

provided for each symbol. Note that the tokens names are prefixed by TOKEN_ to avoid<br />

name clashes.<br />

%token END 0 "end of file"<br />

%token ASSIGN ":="<br />

%token IDENTIFIER "identifier"<br />

%token NUMBER "number"<br />

%type exp "expression"<br />

To enable memory deallocation during error recovery, use %destructor.<br />

%printer { debug_stream ()

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!