作者akdsy (我很想你)
站内Programming
标题Re: [问题] 请问compiler的LEX如何作Debug?
时间Tue Apr 17 15:59:17 2007
※ 引述《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
1F:推 abcdefghi:vc96支援c99了吗 ? 没有的话,把FILE *fp 140.113.23.107 04/17 16:32
2F:→ abcdefghi:这一行宣告要拿到 printf() 的前面. 140.113.23.107 04/17 16:32
3F:→ abcdefghi:char ch; 这一行也要拿到前面. 140.113.23.107 04/17 16:34
4F:推 akdsy:喔喔!过了耶!!!!!感谢140.116.117.151 04/17 16:42