[编译原理]识别浮点常量问题


识别浮点常量问题
http://acm.sdut.edu.cn/web/showproblem.php?pid=2098&cid=1088

#include 
#include 
int judge(int flag,char ch)
{
    switch(flag)
    {
        case 0:
            if(ch=='+'||ch=='-')
                return 1;
	  else if(ch>='0'&&ch<='9')
                return 2;
	  else
                return 8;
            break;
        case 1:
            if(ch>='0'&&ch<='9')
                return 2;
	  else
                return 8;
            break;
        case 2:
            if(ch>='0'&&ch<='9')
                return 2;
	  else if(ch=='.')
                return 3;
	  else if(ch=='e'||ch=='E')
                return 4;
            break;
        case 3:
            if(ch>='0'&&ch<='9')
                return 5;
	  else
                return 8;
        case 4:
            if(ch=='+'||ch=='-')
                return 6;
	  else if(ch>='0'&&ch<='9')
                return 7;
	  else
                return 8;
            break;
		case 5:
            if(ch>='0'&&ch<='9')
                return 5;
	  else if(ch=='e'||ch=='E')
                return 4;
	  else
                return 8;
            break;
        case 6:
            if(ch>='0'&&ch<='9')
                return 7;
	  else
                return 8;
            break;
        case 7:
            if(ch>='0'&&ch<='9')
                return 7;
	  else
                return 8;
            break;
        default:
            return 8;
    }
    return 0;
}
int main()
{
    int i,len,flag=0;
    char str[260];
    gets(str);
    len=strlen(str);
    for(i=0;i

发表评论