我正在尝试在本文末尾编译llvm代码。但是,我收到以下错误。怎么了?我忘了加入图书馆吗?
适用于使用Bison工具的解析器。
由于
parser.y:40:1: error: ‘vector’ in namespace ‘std’ does not name a type
// For 'A' and 'B'
^
parser.y:42:1: error: ‘llvm’ does not name a type
// For 'Type'
^
文件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);
}