| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2442 人关注过本帖
标题:[求助]如何修改语法错误error C2059: syntax error : '['
只看楼主 加入收藏
Zorro1996
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2017-5-31
结帖率:0
收藏
已结贴  问题点数:20 回复次数:1 
[求助]如何修改语法错误error C2059: syntax error : '['
源代码如下,这是对编译原理的词法分析的c语言源代码。73到81行全提示错误error C2059: syntax error : '[',但是到底该怎么改呢?

#include"stdio.h"
#include"string.h"
#include"conio.h"
#include"ctype.h"
char prog[80]={'\0'},
    token[8];         /*存放构成单词符号的字符串*/
char ch;
int syn,                  /*存放单词字符的种别码*/
      n,
    sum,                  /*存放整数型单词*/
    m,p;                  /*p是缓冲区prog的指针,m是token的指针*/
char *rwtab[6]={"begin","if","then","while","do","end"};
void scaner(){
    m=0;
    sum=0;
    for(n=0;n<8;n++)
        token[n]='\0';
    ch=prog[p++];
    while(ch==' ')
        ch=prog[p++];
    if(isalpha(ch))    /*ch为字母字符*/
    {
        while(isalpha(ch)||isdigit(ch))    /*ch为字母字符或数字字符*/
        {
            token[m++]=ch;
            ch=prog[p++];}
        token[m++]='\0';
        ch=prog[p--];
        syn=10;
        for(n=0;n<6;n++)
            if(strcmp(token,rwtab[n])==0)   /*字符串的比较*/
                {
                syn=n+1;
                break;}}
    else
        if(isdigit(ch))     /*ch是数字字符*/
    {
        while(isdigit(ch))    /*ch是数字字符*/
        {
            sum=sum*10+ch-'0';
            ch=prog[p++];}
        ch=prog[p--];
        syn=11;}
    else
        switch(ch){
            case'<':m=0;token[m++]=ch;ch=prog[p++];
                if(ch=='>'){
                    syn=21;
                    token[m++]=ch;}
                else if(ch=='='){
                    syn=22;
                    token[m++]=ch;}
                else{
                    syn=20;
                    ch=prog[p--];}
                break;
            case'>':m=0;token[m++]=ch;ch=prog[p++];
                if(ch=='='){
                    syn=24;
                    token[m++]=ch;}
                else{
                    syn=23;
                    ch=prog[p--];}
                break;
            case':':m=0;token[m++]=ch;ch=prog[p++];
                if(ch=='='){
                    syn=18;
                    token[m++]=ch;}
                else{
                    syn=17;
                    ch=prog[p--];}
                break;
            case'+':syn=13;token=[0]=ch;break;
            case'-':syn=14;token=[0]=ch;break;
            case'*':syn=15;token=[0]=ch;break;
            case'/':syn=16;token=[0]=ch;break;
            case'=':syn=25;token=[0]=ch;break;
            case';':syn=26;token=[0]=ch;break;
            case'(':syn=27;token=[0]=ch;break;
            case')':syn=28;token=[0]=ch;break;
            case'#':syn=0;token=[0]=ch;break;
            default:syn=-1;}}
void main()
{
    printf("\n\nThe significance of the figures:\n"
    "1.figures 1 to 6 said Keyword\n"
    "2.figures 10 and 11 said Other indicators\n"
    "3.figures 13 to 28 said Operators\n");
p=0;
    printf("\nplease input string:\n");
    do{
        ch=getchar();
        prog[p++]=ch;
       }while(ch!='#');
p=0;
    do{
        scaner();
        switch(syn){
            case 11:printf("(%d,%d)\n",syn,sum);break;
            case -1:printf("\n ERROR;\n");break;
            default:printf("(%d,%s)\n",syn,token);
}
    }while(syn!=0);
    getch();
}
        
        
搜索更多相关主题的帖子: include 源代码 缓冲区 字符串 
2017-05-31 17:03
grmmylbs
Rank: 14Rank: 14Rank: 14Rank: 14
等 级:贵宾
威 望:54
帖 子:1409
专家分:5845
注 册:2016-2-14
收藏
得分:20 
token=[0]=ch
中间多了个=?
2017-05-31 17:20
快速回复:[求助]如何修改语法错误error C2059: syntax error : '['
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.041276 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved