[問題] flex bison

看板C_and_CPP (C/C++)作者 (catching)時間13年前 (2012/08/20 18:01), 編輯推噓1(102)
留言3則, 2人參與, 最新討論串1/1
在網路上面找了幾個可能 header file互相include namespace的問題 還調過Makefile編譯順序 但是還出現這種問題............... 我猜可能是Makefile還是include的問題 但都解決不了 Orz # make bison -d CDNF.y g++ -c CDNF.tab.c -o CDNF.tab.o g++ -c lex.yy.c -o lex.yy.o In file included from CDNF.l:6: CDNF.y:18: error: ISO C++ forbids declaration of ‘deque’ with no type CDNF.y:18: error: invalid use of ‘::’ CDNF.y:18: error: expected ‘;’ before ‘<’ token CDNF.y:19: error: ISO C++ forbids declaration of ‘deque’ with no type CDNF.y:19: error: invalid use of ‘::’ CDNF.y:19: error: expected ‘;’ before ‘<’ token CDNF.y:20: error: ISO C++ forbids declaration of ‘deque’ with no type CDNF.y:20: error: invalid use of ‘::’ CDNF.y:20: error: expected ‘;’ before ‘<’ token ----------------------------------------------------------------------------- Makefile: CC = gcc CXX = g++ LEXYACC = CDNF TARGET = run LDLIBS = -lfl OBJS = parser.o lex.yy.o $(LEXYACC).tab.o all: $(TARGET) $(TARGET): $(OBJS) $(CXX) -g -o $(TARGET) $(OBJS) $(LDLIBS) $(LEXYACC).tab.o: $(LEXYACC).tab.c $(CXX) -c $(LEXYACC).tab.c -o $(LEXYACC).tab.o parser.o: parser.cpp parser.h $(CXX) -c parser.cpp -o parser.o lex.yy.o: lex.yy.c $(CXX) -c lex.yy.c -o lex.yy.o lex.yy.c: $(LEXYACC).l flex $(LEXYACC).l $(LEXYACC).tab.c: $(LEXYACC).y bison -d $(LEXYACC).y clean: rm -f $(TARGET) lex.yy.c $(LEXYACC).tab.c $(LEXYACC).tab.h *.o --------------------------------------------------------------------------- CDNF.y: %{ #include <stdio.h> #include <stdlib.h> #include <deque> #include "parser.h" #include <iostream> #include <utility> extern int yylex(); int yyerror(const char*); %} %union{ std::string *name_t; bool val_t; struct Prop *expr_t; std::deque<Prop*> *exprs_t; std::deque<VarProp*> *vars_t; std::deque<struct Node*> *stmts_t; std::pair<struct Node*, struct Node*> *stmt_t; } ......... ----------------------------------------------------------------------------- CDNF.l: %{ #include <stdio.h> #include <stdlib.h> #include <string> #include "CDNF.tab.h" #include "parser.h" %} %% [ \t\n]+ { } [0-9]+ { yylval.val_t = atoi(yytext); return CONST; } ...... ----------------------------------------------------------------------------- -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.109.23.11 ※ 編輯: ykaich 來自: 140.109.23.11 (08/20 18:01) ※ 編輯: ykaich 來自: 140.109.23.11 (08/20 18:06)

08/20 23:49, , 1F
bison 生的 .tab.h 檔裡不包括 %{ %} 之間的 include
08/20 23:49, 1F

08/20 23:49, , 2F
在 .l 的 %{ %} 裡也要自己 include 需要的 stl header
08/20 23:49, 2F

08/21 10:02, , 3F
感謝樓上 已解決
08/21 10:02, 3F
文章代碼(AID): #1GCWhhZo (C_and_CPP)
文章代碼(AID): #1GCWhhZo (C_and_CPP)