help-bison
[Top][All Lists]
Advanced

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

C++ parser and lexer


From: Jim Michaels
Subject: C++ parser and lexer
Date: Mon, 13 Oct 2008 15:39:25 -0700 (PDT)

am using bison 2.1, flex version 2.5.4 - I have no choice about using anything 
newer for now (using gnuwin32), but it would be nice to know if a bug is fixed 
in a newer version.

Q1. do I always need to write a driver for a C++ parser/lexer combo?

Q2. I haven't gotten a C++ version of the parser to successfully compile yet.  
am using version 2.1 bison.
in the lexer,
%option noyywrap batch yylineno c++

in the .y file,
%locations
%skeleton "lalr1.cc"

Q3. do I need to write a C++ driver in every case?
they do that in the C++ example in the bison manual, but I do not know if it is 
actually required or not.

Q4. I am a wee bit confused by the code generated way below starting at 
namespace yy.  maybe it is just old and experimental (2.1).
I am wondering how I can access what used to be yylval.  I think it is now 
semantic_type.
and what holds the integer token value itself? token_number_type?
how do I call the parser?  the parser class is named parser.  am I correct in 
assuming it's something like
    #include "parser.tab.hpp"
    int main(void) {
        yy:parser p;
        int returnValue = p.parse();
    }
?



namespace yy
{
  class parser;

  template <typename P>
  struct traits
  {
  };

  template <>
  struct traits<parser>
  {
    typedef unsigned short int token_number_type;
    typedef short int       rhs_number_type;
    typedef int state_type;
    typedef YYSTYPE semantic_type;
    typedef location location_type;
  };
}

namespace yy
{
  /// A Bison parser.
  class parser
  {
    /// Symbol semantic values.
    typedef traits<parser>::semantic_type semantic_type;
    /// Symbol locations.
    typedef traits<parser>::location_type location_type;

  public:
    /// Build a parser object.
    parser () :
      yydebug_ (false),
      yycdebug_ (&std::cerr)
    {
    }

    virtual ~parser ()
    {
    }

    /// Parse.
    /// \returns  0 iff parsing succeeded.
    virtual int parse ();

#if YYDEBUG
    /// A type to store symbol numbers and -1.
    typedef traits<parser>::rhs_number_type rhs_number_type;
...


 
Jim Michaels
address@hidden
http://JesusnJim.com


      


reply via email to

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