parsing - 为什么`string``vector`等在野牛的联合中不起作用?
问题描述
我试图为 C 语言的一个子集编写一个解析器。但是当我包含string
或vector
在里面时%union
,它会抛出错误。使用char*
orarray
似乎没问题。
%union{
string s;
vector<int>v;
}
我在某些地方看到它与标题问题有关,他们建议在其中包含此
%code requires{
#include <string>
}
对于字符串大小写。但这对我也不起作用。
我得到的错误是
y.tab.c:1174:9: error: use of deleted function ‘YYSTYPE::YYSTYPE()’
YYSTYPE yylval;
^~~~~~
y.tab.c:223:7: note: ‘YYSTYPE::YYSTYPE()’ is implicitly deleted because the default definition would be ill-formed:
union YYSTYPE
^~~~~~~
demo.y:48:12: error: union member ‘YYSTYPE::s’ with non-trivial ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string() [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’
string s;
^
demo.y:49:16: error: union member ‘YYSTYPE::v’ with non-trivial ‘std::vector<_Tp, _Alloc>::vector() [with _Tp = int; _Alloc = std::allocator<int>]’
vector<int>v;
^
y.tab.c: In function ‘int yyparse()’:
y.tab.c:1203:30: error: use of deleted function ‘YYSTYPE::YYSTYPE()’
YYSTYPE yyvsa[YYINITDEPTH];
^
y.tab.c:1203:30: error: use of deleted function ‘YYSTYPE::~YYSTYPE()’
y.tab.c:223:7: note: ‘YYSTYPE::~YYSTYPE()’ is implicitly deleted because the default definition would be ill-formed:
union YYSTYPE
^~~~~~~
demo.y:48:12: error: union member ‘YYSTYPE::s’ with non-trivial ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::~basic_string() [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’
string s;
^
demo.y:49:16: error: union member ‘YYSTYPE::v’ with non-trivial ‘std::vector<_Tp, _Alloc>::~vector() [with _Tp = int; _Alloc = std::allocator<int>]’
vector<int>v;
^
y.tab.c:1203:30: error: use of deleted function ‘YYSTYPE::~YYSTYPE()’
YYSTYPE yyvsa[YYINITDEPTH];
^
y.tab.c:1215:11: error: use of deleted function ‘YYSTYPE::YYSTYPE()’
YYSTYPE yyval;
^~~~~
y.tab.c:1215:11: error: use of deleted function ‘YYSTYPE::~YYSTYPE()’
y.tab.c:1381:14: error: use of deleted function ‘YYSTYPE& YYSTYPE::operator=(const YYSTYPE&)’
*++yyvsp = yylval;
^~~~~~
y.tab.c:223:7: note: ‘YYSTYPE& YYSTYPE::operator=(const YYSTYPE&)’ is implicitly deleted because the default definition would be ill-formed:
union YYSTYPE
^~~~~~~
demo.y:48:12: error: union member ‘YYSTYPE::s’ with non-trivial ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::operator=(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’
string s;
^
demo.y:49:16: error: union member ‘YYSTYPE::v’ with non-trivial ‘std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = int; _Alloc = std::allocator<int>]’
vector<int>v;
^
y.tab.c:1412:24: error: use of deleted function ‘YYSTYPE& YYSTYPE::operator=(const YYSTYPE&)’
yyval = yyvsp[1-yylen];
^
y.tab.c:1569:14: error: use of deleted function ‘YYSTYPE& YYSTYPE::operator=(const YYSTYPE&)’
*++yyvsp = yyval;
^~~~~
y.tab.c:1713:14: error: use of deleted function ‘YYSTYPE& YYSTYPE::operator=(const YYSTYPE&)’
*++yyvsp = yylval;
^~~~~~
y.tab.c: In function ‘void __static_initialization_and_destruction_0(int, int)’:
y.tab.c:1174:9: error: use of deleted function ‘YYSTYPE::~YYSTYPE()’
YYSTYPE yylval;
^~~~~~
解决方案
推荐阅读
- performance - 我可以在循环中提高 UrlFetchApp.fetch() 的处理速度吗
- android - 问题无法解析 AutocompleteTextView 中的符号“DrawableRes”
- java - 我们如何检查 Android 手机中的多个 SIM 卡
- azure-blob-storage - Polybase 到 Azure Data Lake Gen 2 失败
- node.js - 如何将参数传递给中间件的构造函数?
- python - 如何用 Dask 写文件?
- java - 使用 FileReader 时出现奇怪的“权限被拒绝”
- angular - 离子存储不可分配数字到字符串
- python - 使用lxml在python中解析多个命名空间XML
- mysql - 数据库 ERD 设计 - 租车应用程序