首页 > 解决方案 > 野牛:警告:3 班次/减少冲突 [-Wconflicts-sr]

问题描述

我是野牛的新手,但我能够编写以下代码 - 它工作得很好,但我有 3 个关于移位/减少冲突的警告。任何人都可以帮我处理这段代码吗?我已经打开了 bison 的冗长,但我没有足够的经验来发现冲突......我试图移动一些代码部分,但它没有帮助

%skeleton "lalr1.cc"
%require  "3.0"
%debug 
%defines 
%define api.namespace {myns::id_file}
%define api.parser.class {id_file_parser}

%code requires
{
   namespace myns 
   {
        namespace id_file 
        {
            struct id_file_driver;
            struct id_file_scanner;
        }
   }
}
%parse-param { id_file_scanner & scanner  }
%parse-param { id_file_driver & driver  }

%code{

#include <string>
#include <iostream>

#include "id_file_driver.hpp"


#undef yylex
#define yylex scanner.yylex

}

%define api.value.type variant


%token END    0     "end of file"
%token MODULE HASH INTERFACE COLLECTION NAMESPACE CONST COLON COMMA LBRACE RBRACE LPARENTHESIS RPARENTHESIS SEMICOLON OTHER PRAGMA_TYPE PRAGMA_INCLUDE PRAGMA_ERROR_TYPE
%token <std::string> TYPE
%token <std::string> ID
%token <std::string> TYPE_ID

%locations

%type<std::string> interface_name
%type<std::string> method_type
%type<std::string> method_name
%type<std::string> argument_type
%type<std::string> argument_name

%%

file: END | modules END;

modules: module_def | modules module_def;

module_def: MODULE module_name LBRACE module_content RBRACE { driver.pop_module(); };

module_name: ID { driver.push_module( $1 ); };

module_content: module_namespaces | pragmas module_namespaces;

pragmas: pragma_def | pragmas pragma_def;

pragma_type_def: HASH PRAGMA_TYPE ID SEMICOLON { driver.push_pragma( $3, pragmas_t::type ); };

pragma_include_def: HASH PRAGMA_INCLUDE ID SEMICOLON { driver.push_pragma( $3, pragmas_t::include ); };

pragma_error_type_def: HASH PRAGMA_ERROR_TYPE ID SEMICOLON { driver.push_pragma( $3, pragmas_t::error_type ); };

pragma_def: pragma_type_def | pragma_include_def | pragma_error_type_def;

namespace_def: NAMESPACE namespace_name LBRACE namespace RBRACE { driver.pop_namespace(); };

namespace_name: ID { driver.push_namespace( $1 ); };

module_namespaces: namespace_def | module_namespaces namespace_def;

namespace: interfaces | namespace_def | namespace namespace_def;

interfaces: interface_def | interfaces interface_def;

interface_def: interface_sig LBRACE methods RBRACE { driver.pop_interface(); };

interface_sig: interface_sig_interface |  interface_sig_collection;

interface_sig_interface: INTERFACE interface_name { driver.push_interface( $2, interface_t::iface, "" ); };

interface_sig_collection: COLLECTION method_type interface_name { driver.push_interface( $3, interface_t::collection, $2 ); };

interface_name: ID; 

methods: method_def | methods method_def |;

method_def: method_sig LPARENTHESIS arguments RPARENTHESIS method_is_const SEMICOLON

method_is_const: | method_const;

method_const: CONST { driver.set_const_method(); };

method_sig: method_type method_name { driver.push_method($1, $2); };

method_type: TYPE | TYPE_ID | ID; 

method_name: ID;

arguments: argument_def | arguments COMMA argument_def |;

argument_def: argument_type argument_name { driver.add_argument($1, $2); };

argument_type: TYPE | TYPE_ID | ID;

argument_name: ID;

%%

void myns::id_file::id_file_parser::error(location_type const & l, std::string const & err_message)
{
   std::cerr << "error: " << err_message << " at " << l << std::endl;
}

标签: grammarbison

解决方案


推荐阅读