我在Visual Studio中编译我的bison生成文件,出现了以下错误:
...\position.hh(83): error C2589: '(' : '::' 右侧的非法标记
...\position.hh(83): error C2059: 语法错误:'::'
...\position.hh(83): error C2589: '(' : '::' 右侧的非法标记
...\position.hh(83): error C2059: 语法错误:'::'
对应的代码如下:
inline void columns (int count = 1)
{
column = std::max (1u, column + count);
}
我认为问题出在 std::max 上;如果我将 std::max 更改为等效代码,则不再有问题,但是是否有更好的解决方案可以避免更改生成的代码?
这是我编写的 bison 文件:
//
// bison.yy
//
%skeleton "lalr1.cc"
%require "2.4.2"
%defines
%define parser_class_name "cmd_parser"
%locations
%debug
%error-verbose
%code requires {
class ParserDriver;
}
%parse-param { ParserDriver& driver }
%lex-param { ParserDriver& driver }
%union {
struct ast *a;
double d;
struct symbol *s;
struct symlist *sl;
int fn;
}
%code {
#include "helper_func.h"
#include "ParserDriver.h"
std::string error_msg = "";
}
%token <d> NUMBER
%token <s> NAME
%token <fn> FUNC
%token EOL
%token IF THEN ELSE WHILE DO LET
%token SYM_TABLE_OVERFLOW
%token UNKNOWN_CHARACTER
%nonassoc <fn> CMP
%right '='
%left '+' '-'
%left '*' '/'
%nonassoc '|' UMINUS
%type <a> exp stmt list explist
%type <sl> symlist
%{
extern int yylex(yy::cmd_parser::semantic_type *yylval,
yy::cmd_parser::location_type* yylloc);
%}
%start calclist
%%
... grammar rules ...