2012-01-06 128 views
0

Parser.h奇怪的編譯器錯誤的解析器代碼

enum { PLUS, MINUS, DIVIDE, MULTIPLY, NUMBER, END } type; 

int token; 

/* parsing functions */ 
void parse_token (void); 

Parser.c

的錯誤

parser.c:14:6: warning: conflicting types for ‘parse_token’ [enabled by default] 
parser.c:11:2: note: previous implicit declaration of ‘parse_token’ was here 
parser.c: In function ‘parse_token’: 
parser.c:16:2: warning: passing argument 2 of ‘strchr’ makes integer from pointer without a cast [enabled by default] 
/usr/include/string.h:235:14: note: expected ‘int’ but argument is of type ‘char *’ 
parser.c:17:3: error: ‘type’ undeclared (first use in this function) 
parser.c:17:3: note: each undeclared identifier is reported only once for each function it appears in 
parser.c:17:10: error: ‘NUMBER’ undeclared (first use in this function) 
parser.c:19:2: warning: passing argument 2 of ‘strchr’ makes integer from pointer without a cast [enabled by default] 
/usr/include/string.h:235:14: note: expected ‘int’ but argument is of type ‘char *’ 
parser.c:20:10: error: ‘PLUS’ undeclared (first use in this function) 
parser.c:22:2: warning: passing argument 2 of ‘strchr’ makes integer from pointer without a cast [enabled by default] 
/usr/include/string.h:235:14: note: expected ‘int’ but argument is of type ‘char *’ 
parser.c:23:10: error: ‘MINUS’ undeclared (first use in this function) 
parser.c:25:2: warning: passing argument 2 of ‘strchr’ makes integer from pointer without a cast [enabled by default] 
/usr/include/string.h:235:14: note: expected ‘int’ but argument is of type ‘char *’ 
parser.c:26:10: error: ‘DIVIDE’ undeclared (first use in this function) 
parser.c:28:2: warning: passing argument 2 of ‘strchr’ makes integer from pointer without a cast [enabled by default] 
/usr/include/string.h:235:14: note: expected ‘int’ but argument is of type ‘char *’ 
parser.c:29:10: error: ‘MULTIPLY’ undeclared (first use in this function) 
parser.c:32:10: error: ‘END’ undeclared (first use in this function) 
parser.c: In function ‘show_error’: 
parser.c:40:2: warning: incompatible implicit declaration of built-in function ‘exit’ [enabled by default] 

我徹底班博ozled。 。?:(

任何幫助

+0

哪些是parser.c的第14行和第11行? – 2012-01-06 10:24:34

+0

你有沒有包含parser.h? parser.c:17:10:error:'NUMBER'未申報(首次在此函數中使用) – 2012-01-06 10:25:20

+0

只是爲了記錄,它不是解析,它是[詞法分析](http://en.wikipedia.org/wiki/ Lexical_analysis)。而且該工具不是解析器,而是詞法分析器。 – Jan 2012-01-06 10:31:53

回答

5

一個你得到它編譯(通過包括頭,作爲L uchian Grigore說),你會發現你不能在常量字符串上做strcat()

常量字符串被分配在只讀存儲器中,無法修改。即使你可以修改它,你也會覆蓋其他內存。

+0

+1我錯過了'strcat()' – 2012-01-06 10:38:40

3

你不包括你的頭,所以沒有辦法對翻譯單元瞭解的typetoken聲明

您需要:

#include "Parser.h" 

在執行文件的開頭