Re: [問題] 請問compiler的LEX如何作Debug?
※ 引述《akdsy (我很想妳)》之銘言:
: ※ 引述《halajohn (Wei Hu)》之銘言:
: : 不就是用 debug mode 然後 step by step 去看為什麼 output
: : 不是你想要的嗎?
: 我當初也是想說要這樣作,
: 但是呢我給他設完break point之後,(我給他設在lex所產生的.c檔裡)
: 他給我出現類似"中斷點出現太多的訊息"......(我只設了兩個= =")
: 可能是有用到lex的語法,(lex在win32上操作)
: 接下來按下確定之後,
: 我還是給他繼續偵錯,(不過那些break point已經消失了)
: 所以他跑進去main裡的yylex()........這算是lex的預設,一定會進去
: main 裡也只有那一行( yylex() )而已...
: 偵錯箭頭就指向yylex()....然後就不動了,
: 所以想請問沒有前輩使用過lex所產生的.c的compiler完之後,
: 再去對他偵錯的?
之前那個錯誤已經用別的寫法來去除了!
現在有另一個問題產生(有5~6 個error)
是關於檔案的的讀取(.txt)...有鑑於有版友希望我po出原始碼...大概是這樣...
以下是 ***.l檔
%{
#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include <fstream.h>
void read_file(char*name);
%}
%%
這裡的lex應該是正確的,因為之前我已經測過了
%%
main(int argc, char *argv[])
{
read_file(argv[1]); //這是打算傳入檔案名稱
yylex();
}
void read_file(char*word)
{
printf("file name is %s\n",word);
FILE *fp = fopen(word,"r"); //若從這裡以下全部註解起來,結果將會是正確的
char ch ;
if(fp==NULL){
printf("無法開啟檔案\n");
return 0;
}
else {
printf("檔案開啟成功\n");
while((ch=fgetc(fp)) !=EOF ){
putchar(ch);
}
}
yywrap() {}
以下是錯誤訊息:
Compiling...
lex.yy.c
lex.yy.c(1603) : warning C4013: 'exit' undefined; assuming extern returning
int
test5.l(176) : error C2275: 'FILE' : illegal use of this type as an expression
這裡我不知道為什麼會錯 不是已經有include<stdio.h>嗎?
我還多用了一個<fstream.h>
以下幾乎都是因為讀檔產生錯誤.....
c:\program files\microsoft visual studio\vc98\include\stdio.h(156) :
see declaration of 'FILE'
test5.l(176) : error C2065: 'fp' : undeclared identifier
test5.l(178) : error C2143: syntax error : missing ';' before 'type'
test5.l(180) : warning C4047: '==' : 'int ' differs in levels of indirection
from 'void *'
test5.l(183) : warning C4098: 'read_file' : 'void' function returning a value
test5.l(189) : error C2065: 'ch' : undeclared identifier
test5.l(189) : warning C4047: 'function' : 'struct _iobuf *' differs in
levels of indirection from 'int '
test5.l(189) : warning C4024: 'fgetc' : different types for formal and actual
parameter 1
test5.l(196) : error C2143: syntax error : missing ';' before '{'
test5.l(197) : fatal error C1004: unexpected end of file found
Error executing cl.exe.
lex.yy.obj - 6 error(s), 5 warning(s)
感謝大家幫忙!!
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.116.117.151
推
04/17 16:32, , 1F
04/17 16:32, 1F
→
04/17 16:32, , 2F
04/17 16:32, 2F
→
04/17 16:34, , 3F
04/17 16:34, 3F
推
04/17 16:42, , 4F
04/17 16:42, 4F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 4 之 4 篇):
Programming 近期熱門文章
PTT數位生活區 即時熱門文章
14
24