我正在关注此博客,并根据给定的指导here实施。
当我尝试使用g++ -o parser parser.cpp tokens.cpp main.cpp
检查我的扫描仪和分析器组合时(我正在使用CYGWIN并且已经安装了BISON,G ++,GCC,FLEX,LLVM),我收到此错误:
In file included from /usr/include/llvm/Support/PointerLikeTypeTraits.h:18:0,
from /usr/include/llvm/ADT/PointerIntPair.h:17,
from /usr/include/llvm/Use.h:28,
from /usr/include/llvm/Value.h:17,
from node.h:3,
from parser.y:2:
/usr/include/llvm/Support/DataTypes.h:49:3: error: #error "Must #define __STDC_LIMIT_MACROS before #including Support/DataTypes.h"
# error "Must #define __STDC_LIMIT_MACROS before #including Support/DataTypes.h "
^
/usr/include/llvm/Support/DataTypes.h:53:3: error: #error "Must #define __STDC_CONSTANT_MACROS before " "#including Support/DataTypes.h"
# error "Must #define __STDC_CONSTANT_MACROS before " \
^
parser.y: In function ‘void yyerror(const char*)’:
parser.y:6:58: error: ‘printf’ was not declared in this scope
void yyerror(const char *s) { printf("ERROR: %s\n ", s); }
^
In file included from /usr/include/llvm/Support/PointerLikeTypeTraits.h:18:0,
from /usr/include/llvm/ADT/PointerIntPair.h:17,
from /usr/include/llvm/Use.h:28,
from /usr/include/llvm/Value.h:17,
from node.h:3,
from tokens.l:3:
/usr/include/llvm/Support/DataTypes.h:49:3: error: #error "Must #define __STDC_LIMIT_MACROS before #including Support/DataTypes.h"
# error "Must #define __STDC_LIMIT_MACROS before #including Support/DataTypes.h "
^
/usr/include/llvm/Support/DataTypes.h:53:3: error: #error "Must #define __STDC_CONSTANT_MACROS before " "#including Support/DataTypes.h"
# error "Must #define __STDC_CONSTANT_MACROS before " \
^
test.cpp: In function ‘int main()’:
test.cpp:7:1: error: ‘cout’ was not declared in this scope
cout<<"hello it's woring";
^
test.cpp:7:1: note: suggested alternative:
In file included from test.cpp:1:0:
/usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/iostream:61:18: note: ‘std::cout’
extern ostream cout; /// Linked to standard output
我再次尝试对其进行排序并找到a similar question on Stack Overflow,并且有人建议添加
-D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS
在我使用的命令之前。所以我这样做了,现在我收到了这个错误:
parser.y: In function ‘void yyerror(const char*)’:
parser.y:6:58: error: ‘printf’ was not declared in this scope
void yyerror(const char *s) { printf("ERROR: %s\n", s); }
^
test.cpp: In function ‘int main()’:
test.cpp:7:1: error: ‘cout’ was not declared in this scope
cout<<"hello it's woring";
^
test.cpp:7:1: note: suggested alternative:
In file included from test.cpp:1:0:
/usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/iostream:61:18: note: ‘std::cout’
extern ostream cout; /// Linked to standard output
如何在不收到这些错误的情况下成功检查我的词法分析器和解析器组合?