LLVM编译错误“;错误:‘;向量&x2019;在命名空间中‘;标准&x2019;不为类型命名";

LLVM编译错误“;错误:‘;向量&x2019;在命名空间中‘;标准&x2019;不为类型命名";,llvm,Llvm,在这篇文章的最后,我试图编译llvm代码。然而,我得到下面的错误。怎么了?我忘了带图书馆了吗 它适用于使用工具Bison的解析器 谢谢 文件parser.y如下所示: %{ #include < iostream> #include < cstdio> #include < cstdlib> #include < vector> #include < cstring> #inc

在这篇文章的最后,我试图编译llvm代码。然而,我得到下面的错误。怎么了?我忘了带图书馆了吗

它适用于使用工具Bison的解析器

谢谢



文件parser.y如下所示:

    %{
    #include < iostream>
    #include < cstdio>
    #include < cstdlib>
    #include < vector>
    #include < cstring>
    #include < llvm/IR/IRBuilder.h>
    #include < llvm/IR/Module.h>
    #include <llvm/IR/Function.h>
    #include "parser.h"

    extern "C" int yylex();
    //extern "C" int yyparse();
    extern "C" FILE *yyin;
    void yyerror(const char *s);


    llvm::Function *function;
    llvm::IRBuilder<> *builder;
    llvm::LLVMContext &context = llvm::getGlobalContext();
    llvm::Module module("TestModule", context);


    %}
    %token TokenId
    %token TokenNumber
    %token TokenPlus
    %token TokenMult
    %token TokenParOpen
    %token TokenParClose
    %token ty
    %token TokenComma
    %token TokenSemicolon

    //std::vector<Type *> ParamTys;
    std::vector<Type *> types;

    %union
    {
    // For 'A' and 'B'
    std::vector<llvm::Type *> *types;
    // For 'Type'
    llvm::Type *type;
    // For 'id'
    char *name;
    }
    %%**
    Function: ty TokenId TokenParOpen First_param TokenParClose                 TokenSemicolon
    {
    llvm::Constant *constant =         module.getOrInsertFunction(TokenId,llvm::ArrayType::get(types,0));
    }
    |
    First_param: ty TokenId Following_param
    {
    types.push_back(First_param);
    }
    | 
    Following_param: TokenComma ty TokenId Following_param
    {
    types.push_back(Following_param);
    }

    %%

    int main(int argc, char **argv)
    {



    // Syntax
    if (argc != 2)
    {
    std::cerr << "Syntax: ./main <file>\n";
    exit(1);
    }
    // Open file in 'yyin'
    yyin = fopen(argv[1], "r");
    if (!yyin)
    {
    std::cerr << "Cannot open file\n";
    exit(1);
    }
    // Parse input until there is no more
    do
    {
    yyparse();
    } while (!feof(yyin));
    // Accept
    std::cout << "Program accepted\n";
    }
    void yyerror(const char *s)
    {
    std::cerr << s << std::endl;
    exit(1);
    }
%{
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括“parser.h”
外部“C”int yylex();
//外部“C”int yyparse();
外部“C”文件*yyin;
无效错误(常量字符*s);
llvm::函数*函数;
llvm::IRBuilder*builder;
llvm::LLVMContext&context=llvm::getGlobalContext();
llvm::模块模块(“TestModule”,上下文);
%}
%令牌ID
%令牌号码
%代币+代币
%代币
%记号笔
%代币
%象征性的
%标记逗号
%标记分号
//std::向量参数;
std::载体类型;
%联合
{
//对于“A”和“B”
std::vector*类型;
//对于“类型”
llvm::Type*Type;
//“身份证”
字符*名称;
}
%%**
函数:ty TokenId TokenParOpen First_param TokenParClose token分号
{
llvm::Constant*Constant=module.getOrInsertFunction(TokenId,llvm::ArrayType::get(types,0));
}
|
第一个参数:参数后的ty TokenId
{
类型。推回(第一个参数);
}
| 
Following_param:tokeny逗号TokenId Following_param
{
类型。推回(遵循参数);
}
%%
int main(int argc,字符**argv)
{
//语法
如果(argc!=2)
{

您能提供更多关于如何编译该文件的信息吗?这看起来像是
YACC
Bison
的文件,您是否尝试过使用这两种工具将其转换为C/C++文件?
    %{
    #include < iostream>
    #include < cstdio>
    #include < cstdlib>
    #include < vector>
    #include < cstring>
    #include < llvm/IR/IRBuilder.h>
    #include < llvm/IR/Module.h>
    #include <llvm/IR/Function.h>
    #include "parser.h"

    extern "C" int yylex();
    //extern "C" int yyparse();
    extern "C" FILE *yyin;
    void yyerror(const char *s);


    llvm::Function *function;
    llvm::IRBuilder<> *builder;
    llvm::LLVMContext &context = llvm::getGlobalContext();
    llvm::Module module("TestModule", context);


    %}
    %token TokenId
    %token TokenNumber
    %token TokenPlus
    %token TokenMult
    %token TokenParOpen
    %token TokenParClose
    %token ty
    %token TokenComma
    %token TokenSemicolon

    //std::vector<Type *> ParamTys;
    std::vector<Type *> types;

    %union
    {
    // For 'A' and 'B'
    std::vector<llvm::Type *> *types;
    // For 'Type'
    llvm::Type *type;
    // For 'id'
    char *name;
    }
    %%**
    Function: ty TokenId TokenParOpen First_param TokenParClose                 TokenSemicolon
    {
    llvm::Constant *constant =         module.getOrInsertFunction(TokenId,llvm::ArrayType::get(types,0));
    }
    |
    First_param: ty TokenId Following_param
    {
    types.push_back(First_param);
    }
    | 
    Following_param: TokenComma ty TokenId Following_param
    {
    types.push_back(Following_param);
    }

    %%

    int main(int argc, char **argv)
    {



    // Syntax
    if (argc != 2)
    {
    std::cerr << "Syntax: ./main <file>\n";
    exit(1);
    }
    // Open file in 'yyin'
    yyin = fopen(argv[1], "r");
    if (!yyin)
    {
    std::cerr << "Cannot open file\n";
    exit(1);
    }
    // Parse input until there is no more
    do
    {
    yyparse();
    } while (!feof(yyin));
    // Accept
    std::cout << "Program accepted\n";
    }
    void yyerror(const char *s)
    {
    std::cerr << s << std::endl;
    exit(1);
    }