help-bison
[Top][All Lists]
Advanced

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

Re: Some Help Understanding Bison Grammar


From: Hans Åberg
Subject: Re: Some Help Understanding Bison Grammar
Date: Sun, 2 Oct 2016 10:55:57 +0200

> On 2 Oct 2016, at 05:14, Juan Ceasar <address@hidden> wrote:

> I’m writing a Bison parser and, being relatively new to this, I’m confused 
> about how to tie my scanner (for flex) together with my bison (version 3.04 
> so I can use C++) parser.

There is a calculator example in the Bison distribution, and also in the 
manual, you might check out. It also shows how to use locations for error 
reporting.

> And so I’m a little confused, I could of course declare LBRACE and so forth 
> as tokens in the parser.y,

Yes, all tokens are declared in the gramma file, which is .yy for C++, which 
defines the token names that the lexer will use. These are macro names for C, 
but in a enum for C++, so if one has declared say
  %token LP "(")
the lexer rules end with
  return token::LP;

> But then, how does that tie in with the flex scanner??  

Then the lexer must read these by:
%{                                            /* -*- C++ -*- */
...
#include "parser.hh"
...
%}

The C++ calculator example also includes a file "driver.hh".





reply via email to

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