help-bison
[Top][All Lists]
Advanced

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

Help with Bison Parser


From: Jared Carlson
Subject: Help with Bison Parser
Date: Mon, 3 Oct 2016 17:15:11 -0400

Hello,

I’m having some trouble putting together a simple parser and with the errors 
I’m not really sure where to begin…

In file included from parser.cc:58:
parser.h:188:27: error: unknown type name 'semantic_type'
                    const semantic_type& v,
                          ^
parser.h:204:7: error: unknown type name 'semantic_type'
      semantic_type value;
      ^
In file included from parser.yy:77:
./scanner.h:34:45: error: no type named 'semantic_type' in 'Alloy::Parser'
    virtual Parser::token_type lex( Parser::semantic_type* yylval,
                                    ~~~~~~~~^
parser.cc:257:79: error: unknown type name 'semantic_type'
  Parser::basic_symbol<Base>::basic_symbol (typename Base::kind_type t, const 
semantic_type& v, const location_type& l)
                                                                              ^
parser.cc:395:5: error: use of undeclared identifier 'value'
    value = that.value;
    ^
parser.cc:395:18: error: no member named 'value' in 
'Alloy::Parser::basic_symbol<Alloy::Parser::by_type>'
    value = that.value;
            ~~~~ ^
parser.cc:404:5: error: use of undeclared identifier 'state'
    state = that.state;
    ^
parser.cc:404:18: error: no member named 'state' in 
'Alloy::Parser::stack_symbol_type'
    state = that.state;
            ~~~~ ^
parser.cc:405:5: error: use of undeclared identifier 'value'

Among many others errors, but all seemingly around types...

I started from the calculator example (so C++ parser using bison 3).  

The only place I have semantic_type defined is in my scanner.h file:

#ifndef __SCANNER_H__
#define __SCANNER_H__

#ifndef YY_DECL

#define YY_DECL \
  Alloy::Parser::token_type \
  Alloy::Parser::lex( \
                     Alloy::Parser::semantic_type* yylval, \
                     Alloy::Parser::location_type* yylloc \
                      )
#endif

#ifndef __FLEX_LEXER_H
#define yyFlexLexer ExampleFlexLexer
#include "FlexLexer.h"
#undef yyFlexLexer
#endif

#include "parser.h"

namespace Alloy {
  class Scanner : public ExampleFlexLexer {
  public:
    Scanner(std::istream* arg_yyin = 0,
            std::ostream* arg_yyout = 0);

    virtual ~Scanner();

    /**
     * main lexing function
     **/

    virtual Parser::token_type lex( Parser::semantic_type* yylval,
                                    Parser::location_type* yylloc);

    void set_debug(bool b);

  };
}

#endif



The bison grammar file I don’t want to post… I think most of it relatively 
straightforward (again borrowing a lot from the calculator but, with one 
notable change…  




/*** Grammar Definitions ***/

%token END 0 "end of file"
%token EOL   "end of line"
%token <int> INTEGER "integer"
%token <double> DOUBLE "double"
%token <std::string> STRING "string"

%type <Node*> node object expression
%type <std::vector<Node*>> object_list expression_list



/* End of the grammar
*/

%code {

#include <iostream>
#include <utility>
#include <string>

#include "driver.h"
#include "scanner.h"

using std::move;

#ifdef yylex
#undef yylex
#endif
#define yylex driver.lexer->lex
        
        template <class T, class V> T&& enlist(T& t, V& v) {
                 t.push_back( move(v) );
                 return move(t);
        }

}

%% /* Grammar Rules */


So I’m not sure if the Node and std::vector containers is causing the issues, 
the templates code perhaps? (I found an example that used that utility and so 
in a real sense I’m trying to stitch the two together but they didn’t look all 
that different).

If anyone has hints I’d greatly appreciate it.  Thanks!

Jared



reply via email to

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