你说的太泛泛了,词法分析不算复杂,出错可能和什么算法没关系,是代码吧,比如Debug版本编译器替你干的活现在不管了,所以出错,可能性很多,用排除法看看

解决方案 »

  1.   

    degug只是用_DEGUG宏加了很多调试信息而已,
    请你详细说明问题,我的分析如下:
    1、两者使用的dll等文件是不同的。有可能是release要的dll不存在或不能正常工作(和别人的dll有冲突等)
    2、dump,TRACE,等是debug专用的
    3、你自己的代码中用到了#ifdef _DEBUG等似定意,便得release和degug版本不同。
    这种情况我发生过多次。
    4、degug运行速度比release速度慢,如果程序中用到了和运行时间有关的多进程等相关问题会发生这种情况。
    再次请你详细说明问题
      

  2.   

    你用的是win2000
    所以dll不兼容的可能性最大
      

  3.   

    把你的程序到win98上测试一下
      

  4.   

    我的词法分析器是控制台程序,没有用到.dll,而且,如果用调试的话,看到的全是汇编代码,我一头雾水,faint!!!!!下面把程序贴出来
      

  5.   

    accidence.c#include <stdio.h>
    #include <stdlib.h>
    #include <io.h>
    #include "accidence.h"extern Token token_String[4096];
    extern pSymbol SymbolList[4096];static char *p_KeyWord[255];
    static char c_Temp[255];
    static int row=0,col=0;
    static FILE *fp_Error;main(int argc,char *argv[])
    {
    FILE *fp_Program,*fp_KeyWord,*fp_Token,*fp_SymbolList; int i=0;

    for(i=0;i<4096;i++) 
    {
    SymbolList[i]=NULL;
    }
    for(i=0;i<255;i++)
    {
    p_KeyWord[i]=NULL;
    }
    /* if (argc!=2)
    {
    printf("you forgot to type your programe name \n");
    exit(0);
    }
    if(!(fp_Program=fopen(argv[1],"r")))
    {
    printf("Can't open file %s!",argv[1]);
    exit(1);
    }*/
    if(!(fp_Program=fopen("rfile.pas","r")))
    {
    printf("Can't open file rfile.pas!");
    exit(1);
    }
    if(!(fp_KeyWord=fopen("KeyWord.dat","rb")))
    {
    printf("Can't open file KeyWord.dat!");
    exit(1);
    }
    if(!(fp_Error=fopen("error.txt","w+")))
    {
    printf("Can't open file error.txt!");
    exit(1);
    }
    for(i=0;!feof(fp_KeyWord);i++)
    {
    if(!(p_KeyWord[i]=(char*)malloc(20*sizeof(char))))
    {
    printf("Allocation momory fail!!");
    exit(1);
    }
    fscanf(fp_KeyWord,"%s",p_KeyWord[i]);
    }
    free(p_KeyWord[i-1]);
    p_KeyWord[i-1]=NULL; while(!feof(fp_Program))
    {
    for(i=0;;i++)
    {
    c_Temp[i]=fgetc(fp_Program);
    if(c_Temp[i]=='\n')
    break;
    if(c_Temp[i]==EOF)
    {
    c_Temp[i]='\n';
    break; 
    }
    }
    row++;
    scanner(c_Temp);
    }
    fp_Token=fopen("token.txt","w+");
    fp_SymbolList=fopen("symbol.txt","w+");
    i=0;
    while(token_String[i].Kin_Cod)
    {
    if(token_String[i].Kin_Cod<=37 && token_String[i].Kin_Cod>=34)
    {
    if(SymbolList[token_String[i].Index]->Type==IND||
    SymbolList[token_String[i].Index]->Type==STRING)
    fprintf(fp_Token,"(%d,'%s')",token_String[i].Kin_Cod,
    SymbolList[token_String[i].Index]->Addr);
    if(SymbolList[token_String[i].Index]->Type==INT)
    fprintf(fp_Token,"(%d,%d)",token_String[i].Kin_Cod,
    SymbolList[token_String[i].Index]->lVal);
    if(SymbolList[token_String[i].Index]->Type==FLOAT)
    fprintf(fp_Token,"(%d,%f)",token_String[i].Kin_Cod,
    SymbolList[token_String[i].Index]->dVal);
    }
    else
    fprintf(fp_Token,"(%d,_)",token_String[i].Kin_Cod);
    fprintf(fp_Token,"\n");
    i++;
    }
    i=0;
    while(SymbolList[i])
    {
    if(SymbolList[i]->Type==IND)
    fprintf(fp_SymbolList,"%s,   IND\n",SymbolList[i]->Addr);
    if(SymbolList[i]->Type==INT)
    fprintf(fp_SymbolList,"%ld,   INT\n",SymbolList[i]->lVal);
    if(SymbolList[i]->Type==FLOAT)
    fprintf(fp_SymbolList,"%f,   FLOAT\n",SymbolList[i]->dVal);
    if(SymbolList[i]->Type==STRING)
    fprintf(fp_SymbolList,"%s,   STRING\n",SymbolList[i]->Addr);
    i++;
    }
    for(i=0;SymbolList[i];i++) 
    free(SymbolList[i]);
    for(i=0;p_KeyWord[i];i++) 
    free(p_KeyWord[i]);
    fclose(fp_Token);
    fclose(fp_SymbolList);
    fclose(fp_Program);
    fclose(fp_KeyWord);
    fclose(fp_Error);
    system("edit token.txt");
    system("edit symbol.txt");
    system("edit error.txt");
    }
      

  6.   

    accidence.h
    #ifndef ACCIDENCE_H_
    #define ACCIDENCE_H_#include <stdio.h>
    #include <string.h>
    #include <ctype.h>enum TYPE
    {
    IND,
    INT,
    FLOAT,
    STRING,
    NUL
    };typedef struct{
    unsigned int Kin_Cod;
    int Index;
    } Token,*pToken;typedef struct{
    struct Name
    {
    int Head;
    int Tail;
    };
    enum TYPE Type;
    // unsigned int Kind;
    union
    {
    long lVal;
    double dVal;
    };
    char * Addr;
    } Symbol,*pSymbol;extern char *p_KeyWord[255];
    extern char c_Temp[255];
    extern int row,col;
    extern FILE *fp_Error;static Token token_String[4096];
    static pSymbol SymbolList[4096];
    static int tok_Curr=0,sym_Curr=0;
    printerr();
    int lookup(char *String,enum TYPE type);identifier(char Line[])
    {
    int i=0;
    int flag=0;
    char Temp[255];
    while(Line[col]==' ')
    {
    col++;
    }
    for(i=0;isalnum(Line[col]);i++,col++)
    Temp[i]=Line[col];
    Temp[i]='\0';

    for(i=1,flag=0;p_KeyWord[i]!=NULL;i++)
    {
    if(strncmp(Temp,p_KeyWord[i],255)==0)
    {
    token_String[tok_Curr].Kin_Cod=i+1;
    token_String[tok_Curr].Index=0;
    tok_Curr++;
    flag=1;
    break;
    }
    }
    if(flag==0)
    {
    token_String[tok_Curr].Kin_Cod=34;
    token_String[tok_Curr].Index=lookup(Temp,IND);
    tok_Curr++;
    }
    while(Line[col]==' ')
    {
    col++;
    }
    }re(char Line[])
    {
    char *Addr=NULL;
    while(Line[col]==' ')
    {
    col++;
    }
    if(Line[col+1]!='*')
    {
    token_String[tok_Curr].Kin_Cod=48;
    token_String[tok_Curr].Index=0;
    tok_Curr++;
    col++;
    }
    else
    {
    token_String[tok_Curr].Kin_Cod=-1;
    if(Addr=strstr(&Line[col+2],"*/"))
    {
    col+=(Addr-&Line[col]+2);
    token_String[tok_Curr].Kin_Cod=0;
    }
    else
    {
    printerr(2);
    fprintf(fp_Error,"The re in this line is not matching !\n");
    token_String[tok_Curr].Kin_Cod=0;
    col=strlen(Line)-1;
    }
    }
    while(Line[col]==' ')
    {
    col++;
    }
    }const_data(char Line[])
    {
    token_String[tok_Curr].Index=lookup(&Line[col],NUL);
    tok_Curr++;
    }const_string(char Line[])
    {
    char *Addr=NULL;
    char Temp[255];
    while(Line[col]==' ')
    {
    col++;
    }
    if(Addr=strstr(&Line[col+1],"'"))
    {
    strncpy(Temp,&Line[col+1],Addr-1-&Line[col]);
    Temp[Addr-1-&Line[col]]='\0';
    token_String[tok_Curr].Kin_Cod=37;
    token_String[tok_Curr].Index=lookup(Temp,STRING);
    tok_Curr++;
    col+=(Addr-&Line[col]+1);
    }
    else
    {
    printerr(3);
    fprintf(fp_Error,"The quotation  in this line is not matching !\n");
    col=strlen(Line)-1;
    }
    while(Line[col]==' ')
    {
    col++;
    }
    }del_code(char Line[])
    {
    while(Line[col]==' ')
    {
    col++;
    }
    switch (Line[col])
    {
    case '(':token_String[tok_Curr].Kin_Cod=39;
     token_String[tok_Curr].Index=0;
     tok_Curr++;
     col++;
     break;
    case ')':token_String[tok_Curr].Kin_Cod=40;
     token_String[tok_Curr].Index=0;
     tok_Curr++;
     col++;
     break;
    case '*':token_String[tok_Curr].Kin_Cod=41;
     token_String[tok_Curr].Index=0;
     tok_Curr++;
     col++;
     break;
    case '+':token_String[tok_Curr].Kin_Cod=43;
     token_String[tok_Curr].Index=0;
     tok_Curr++;
     col++;
     break;
    case ',':token_String[tok_Curr].Kin_Cod=44;
     token_String[tok_Curr].Index=0;
     tok_Curr++;
     col++;
     break;
    case '-':token_String[tok_Curr].Kin_Cod=45;
     token_String[tok_Curr].Index=0;
     tok_Curr++;
     col++;
     break;
    case 92: token_String[tok_Curr].Kin_Cod=46;
     token_String[tok_Curr].Index=0;
     tok_Curr++;
     col++;
     break;
    case '/':token_String[tok_Curr].Kin_Cod=48;
     token_String[tok_Curr].Index=0;
     tok_Curr++;
     col++;
     break;
    case ':':
     if(Line[col+1]=='=')
     {
     token_String[tok_Curr].Kin_Cod=51;
     token_String[tok_Curr].Index=0;
     col+=2;
     tok_Curr++;
     }
     else
     {
     token_String[tok_Curr].Kin_Cod=50;
     token_String[tok_Curr].Index=0;
     col++;
     tok_Curr++;
     }
     break;
    case '<':
     if(Line[col+1]=='=')
     {
     token_String[tok_Curr].Kin_Cod=54;
     token_String[tok_Curr].Index=0;
     col+=2;
     tok_Curr++;
     }
     else if(Line[col+1]=='>')
     {
     token_String[tok_Curr].Kin_Cod=55;
     token_String[tok_Curr].Index=0;
     col+=2;
     tok_Curr++;
     }
     else
     {
     token_String[tok_Curr].Kin_Cod=53;
     token_String[tok_Curr].Index=0;
     col++;
     tok_Curr++;
     }
     break;
    case '=':
     token_String[tok_Curr].Kin_Cod=56;
     token_String[tok_Curr].Index=0;
     col++;
     tok_Curr++;
     break;
    case '>':
     if(Line[col+1]=='=')
     {
     token_String[tok_Curr].Kin_Cod=58;
     token_String[tok_Curr].Index=0;
     col+=2;
     tok_Curr++;
     }
     else
     {
     token_String[tok_Curr].Kin_Cod=57;
     token_String[tok_Curr].Index=0;
     col++;
     tok_Curr++;
     }
     break;
    case '[':
     token_String[tok_Curr].Kin_Cod=59;
     token_String[tok_Curr].Index=0;
     col++;
     tok_Curr++;
     break;
     case ']':
     token_String[tok_Curr].Kin_Cod=60;
     token_String[tok_Curr].Index=0;
     col++;
     tok_Curr++;
     break;
     case ';':
     token_String[tok_Curr].Kin_Cod=61;
     token_String[tok_Curr].Index=0;
     col++;
     tok_Curr++;
     break;
     case 13:
         break;
     case 10:
     break;
     default:
         printerr(1);
     fprintf(fp_Error,"There have a illegal word '%c'.I have skip it now!\n",Line[col]);
     col++;
    }
    while(Line[col]==' ')
    {
    col++;
    }
    }printerr(int id)
    {
    fprintf(fp_Error,"Lin=%d,Col=%d  Error(%d) :",row,col,id);
    }int lookup(char *String,enum TYPE type)
    {
    int i=0;
    char *end=NULL;
    long lTemp=0;
    double dTemp=0;
    if(isalpha(String[0]))
    {
    i=0;
    while(SymbolList[i])
    {
    if(SymbolList[i]->Type==IND&&!strncmp(String,SymbolList[i]->Addr,255))
    return i;
    i++;
    }
    SymbolList[sym_Curr]=malloc(sizeof(Symbol));
    SymbolList[sym_Curr]->Type=type;
    SymbolList[sym_Curr]->Addr=malloc(sizeof(String[0])*
      strlen(String));
    strcpy(SymbolList[sym_Curr]->Addr,String);
    return sym_Curr++;
    }
    if(isdigit(String[0]))
    {
    if(!strstr(String,"."))
    {
    lTemp=strtol(String,&end,10);
    col+=(end-&String[0]);
    i=0;
    while(SymbolList[i])
    {
    if(lTemp==SymbolList[i]->lVal&& 
    SymbolList[i]->Type==INT)
    return i;
    i++;
    }
    SymbolList[sym_Curr]=malloc(sizeof(Symbol));
    SymbolList[sym_Curr]->lVal=lTemp;
    SymbolList[sym_Curr]->Type=INT;
    token_String[tok_Curr].Kin_Cod=35;
    return sym_Curr++;
    }
    else
    {
    dTemp=strtod(String,&end);
    col+=(end-&String[0]);
    i=0;
    while(SymbolList[i])
    {
    if(dTemp==SymbolList[i]->dVal&& 
    SymbolList[i]->Type==FLOAT)
    return i;
    i++;
    }
    SymbolList[sym_Curr]=malloc(sizeof(Symbol));
    SymbolList[sym_Curr]->dVal=dTemp;
    SymbolList[sym_Curr]->Type=FLOAT;
    token_String[tok_Curr].Kin_Cod=36;
    return sym_Curr++;
    }
    }
    }scanner(char Line[])
    {
    col=0;
    while(Line[col]!=13&&Line[col]!=10)
    {
    while(Line[col]==' ')
    col++;
    if(isalpha(Line[col]))
    identifier(Line);
    while(Line[col]==' ')
    col++;
    if(Line[col]=='/')
    re(Line);
    while(Line[col]==' ')
    col++;
    if(isdigit(Line[col]))
    const_data(Line);
    while(Line[col]==' ')
    col++;
    if(Line[col]==39)
    const_string(Line);
    while(Line[col]==' ')
    col++;
    if(!isalpha(Line[col])||Line[col]==' ')
    del_code(Line);
    while(Line[col]==' ')
    col++;
    }
    col=0;
    }#endif //ACCIDENCE_H_
      

  7.   

    在project设置中可以找到degug和release的设置不同的地方,你可以建一个新的选项,你慢慢的把从debug的设置一点点改到和release相同便可以了
      

  8.   

    另外,你说release错误百出,请把你所说的错误列出来
      

  9.   

    1fei(白天) 请指明该设置的菜单位置,谢谢哦
      

  10.   

    是运行的时候错误百出,我的win2000弹个对话框出来说0x004039fb指令引用0x00000004内存,该内存不能引用!!!!
      

  11.   

    多半是2000和VC不兼容(很多别的操作系统上的程序无法在2000上运行,包括NT)
    你把你的程序放到别人操作系统上进行吧
      

  12.   

    sorry,别的,不是别人,
    windows或NT
      

  13.   

    1fei(白天) 请指明该设置的菜单位置,谢谢哦 
      

  14.   

    谢谢1fei(白天)哦,我会大大的给分的
      

  15.   

    应该是你的内存操作有问题,越界或是别的什么,这在DEBUG中是不会有警告什么信息的,不过到了RELEASE就会错.这是常有的问题.2000对内存的操作好象特别的仔细,我碰的问题是一个类型不匹配的问题它都跳出对话框警告!
    仔细查看自己的内存操作部分吧.
      

  16.   

    主  题:为什么我的程序在nt下编译通过,而在2000下不行呢?望高手说个明白!!
    作  者:sdsuper
    所属论坛:Visual C++
    问题点数:10
    回复次数:3
    发表时间:2001-10-9 11:21:45
     
      
      为什么我的程序在nt下编译通过,而在2000下不行呢?望高手说个明白!!
    而且我把nt下编译好的程序在2000下执行也是会提示错误呢? 
    回复贴子: 
    回复人: nickysoft(nickysoft) (2001-10-9 11:28:33)  得0分 
    因为NT和2000的有些DLL文件不同,所以有时会有兼容问题 
      

  17.   

    capboy(帽子) release可全都是优化过的汇编代码啊,我看这就faint了,怎么找啊???
    1fei(白天) 我里面用了好多c-runtime的函数,我自己无法一个一个的测试啊
      

  18.   

    1fei(白天) C-runtime函数好像和.dll有点关系把,好像是做到.dll里面的吧
      

  19.   

    1fei(白天):
     
          我用win2k,VC6工作,没有遇到过兼容性问题,反而同样的程序在98中运行效率低下的情况倒是出现过.
     
        涉及游戏的东西撇开不谈
      

  20.   

    如果是内存越界,在你的程序中多用try catch语法,可以捕捉异常的。
    另外,debug中,内存越界,程序马上会跳到异常的地方去的。查看stack可以很快找到出事的函数。并不是象你说的不报警。
      

  21.   

    1fei(白天) 老大,C中那来的try catch 啊
      

  22.   

    1fei(白天) 我改了debug版本的设置,还是不行啊
      

  23.   

    goo:
    你可能接触的太少了,2000不兼容我见的太多了。越兼容的东东越效率低下。
    另外,他做的是控制台程序,这是ms正在放弃的程序格式。放在vc中主要是给初学者,或者测试算法用的。
    我以前接触的软件公司,通常是等新的操作系统稳定后才使用新的操作系统的。因为用户大部分用的是早期的环境。
    在早期的计算机及软件界大家都有个习惯,向下兼容,但自从dephi和c buidler不兼容(不同版本之间的程序不兼容,不同版本之间的vcl也不兼容)也成功的例子,ms现在很多产品都不兼容了。
    vb8据说和vb7不兼容,2000和NT兼容性不好,XP更是如此。 
      

  24.   

    to hawkgao:
    我的意思是把debug的优化选项打上,如果没问题,执行的效率和release是相同的。
      

  25.   

    你的程序编译有问题,是贴错了?不会是故意不写的吧?
    i:\prog\accidence\accidence.h(366) : warning C4715: 'lookup' : not all control paths return a value
      

  26.   

    fengye() 呵呵,没有问题,我只是在lookup函数中不是所有的控制路径都有返回,一个警告而已,没啥打不了的
      

  27.   

    1fei(白天) 怎么把优化选项打上啊,还有debug版本能不能在纯dos下跑
      

  28.   

    不是吧,如果String[0]又不是数字,又不是字母,不就没有返回值?如果你所有控制路径都有返回,编译器是不会有这个警告的。至少这不是个好习惯。
      

  29.   

    fengye() 有些情况下不必要返回的。
      

  30.   

    为了方便大家,我再把我的测试程序和关键字表贴出来,我写的是一个pascal语言的子集--simple语言,大连理工的编译上面的。关键字表KeyWord.datand
    array
    begin
    bool
    call
    case
    char
    constant
    do
    else
    end
    false
    for
    if 
    input
    integer
    not
    of
    or
    output
    procedure
    program
    read
    real
    repeat
    set
    then
    to
    true
    until
    var
    while
    write
      

  31.   

    测试程序rfile.pasprogram prochar (input,output);
    /*chu li zi fu */
    var
      ordch:integer;
      ch,predch,succch:char;
    begin
      /*input words
      read(ch);
      writeln('ch=',ch);
      /*count the ID*/
      ordch:=ord(ch);
      predch:=pred(ch);
      succch:=succ(ch);
      324344.656
      /*output*/
      writelin('ordch=',ordch,'predch=',predch,'succch=',succch);
    end
      

  32.   

    那你在用到lookup返回值的地方,可能就得到一个不确定的数字。这会引起不少问题,特别是release版。这样的编程习惯不好。建议你看看如The Prictice of Programming(程序设计实践), code complete, writing solid code, 等书
      

  33.   

    错误处理测试文件。efile.pas
      23434.324.434 prog@#ram p23443prochar (input,output);
    /*chu li zi fu  
    var
      ordch: integer  ;
      ch,predch,succch:  char;
    begin
      /*input words*/
      read(ch);
      writeln('ch=,ch);
      /*count the ID
      ordch:=ord(ch);
      predch:=pred(ch);
      succch:=succ(ch);
    2344234234
    dfklggfgd
      324344.656
      /*output*/
      writelin('ordch=',ordch,'predch=',predch,'succch=',succch);
    end
      

  34.   

    我找到了,是后面那几个free()造成的,我正在定位
      

  35.   

    找到了,是在___sbh_free_block里面的错误,这个是什么函数啊?????????
      

  36.   

    0x004039fb指令引用0x00000004内存,该内存不能引用!!!! 004039FB   test        bl,2
    004039FE   je          __output+642h (00403a0b)很明显,没有引用内存啊
      

  37.   

    找到了,是这条错误
    004039FB   mov         dword ptr [edx+4],ecx
    edx=0,ecx=0;这个是___sbh_free_block()函数里的,___sbh_free_block是free(),里面的,看来应该是2000的问题,谢谢各位了
      

  38.   

    如果free出错,往往是分配的内存访问越界,
     
    而访问越界在debug版和release版的表现很可能就是你所说的:
     
    debug看不出错误,而release非法访问.
     
    还是多检点一下自己的程序,不要老说win2k的不好
     
    to 1fei(白天):
     
    对于一个不使用系统调用,只是算法描述的"正确的"程序来说,在各种操作系统下的运行应该完全一样,只要编译器符合标准.
     
      2000不会弱到让一个正确的程序无法执行,如果提到兼容性,也应该体现在程序运行环境(涉及到API的)或者容错能力方面.而不是对一个没什么调用的算法程序有苛刻的兼容困难
      

  39.   

    内存越界很多时候debug版是看不出来的
      

  40.   

    控制台程序本质上也是一种win32程序,是不能在dos上运行的。
    to gop:
    VC是一个程序包,他设计时2000还没有出来。