| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1282 人关注过本帖
标题:小小码屋
只看楼主 加入收藏
朱大哥
Rank: 3Rank: 3
等 级:论坛游侠
威 望:2
帖 子:72
专家分:123
注 册:2015-1-16
结帖率:22.22%
收藏
已结贴  问题点数:10 回复次数:19 
小小码屋
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define KEYSIZE 17
#define SYMBILESIZE 6
#define KEYWORLD 1
#define DEFINED  2
#define SYMBOL   3
#define ISCHARACTER ((97<=*str&&*str<=122)||(65<=*str&&*str<=90))
#define ISCHAR_NUM_UNDERLINE ((97<=*(str+i)&&*(str+i)<=122)||(65<=*(str+i)&&*(str+i)<=90)||(48<=*(str+i)&&*(str+i)<=57)||(*(str+i)=='_'))
//typedef struct{
//    char definedname[10];
//    int  dataspecies;
//    int  pointspecies;
   
//}
typedef struct{
    char keyname[10];
    char keyexp[100];
}keyword;
char dealword[100];
keyword key[KEYSIZE]={
        "char","字符型",
        "int","整型",
        "short","短整型",
        "long","长整型",
          "float","浮点型",
        "double","双精度浮点型",
        "signed","有符号的",
        "unsigned","无符号的",
        "auto","自动的",
        "extern","全局的",
        "static","静态的",
        "typedef","别名",
        "union","共用体",
        "struct","结构体",
        "enum","枚举体",
        "void","无返回值或者无参或者无类型",
        "*","指针",
        };
char symbol[]={'[',']','(',')',',',' '};
int issymbol(char c)
{
    int i=0,flag=0;
    while(i<SYMBILESIZE){
        if(c==symbol[i]){
            flag=i;
            break;
        }
        i++;
    }
            return flag;
}
int isdefined(char *str)
{
    int i=1;
    if( ISCHARACTER ){
        while(*(str+i)){
            if(!ISCHAR_NUM_UNDERLINE){
                printf("%s:标识符不合法\n",str);
                return 0;
            }   
            i++;
        }
        for(i=0;i<KEYSIZE;i++)
            if(!strcmp(key[i].keyname,str)){
                printf("%s:这是个关键字:%s\n",key[i].keyname,key[i].keyexp);
                break;
            }
        if(i==KEYSIZE)           
          printf("%s:这是个标识符\n",str);   
    }
    else{
        printf("%s:标识符不合法\n",str);
        return 0;
    }   
}
int readword(char *str,int i)
{
        int n,j=0;
        if(*(str+i)=='\0')
            return 0;
   
        if((n=issymbol(*(str+i)))){
            i++;
        }
        else{
            for(;*(str+i)!='\0';i++){
                if(!issymbol(*(str+i))){
                    dealword[j]=*(str+i);
                    j++;
                }
                else{
                  
                     break;
                }
            }   
            isdefined(dealword);
            memset(dealword,0,100);
        }
      
        readword(str,i);
   
}
int main(int argc,char **argv)
{
    char *str="long fast bbc ok 999,union,oo34*@&#^!ok,bcnbads9";
    readword(str,0);        
}
 



[ 本帖最后由 朱大哥 于 2015-1-28 16:59 编辑 ]
搜索更多相关主题的帖子: include 
2015-01-27 22:09
诸葛欧阳
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:流年
等 级:贵宾
威 望:82
帖 子:2790
专家分:14619
注 册:2014-10-16
收藏
得分:10 
这是要干嘛?

一片落叶掉进了回忆的流年。
2015-01-28 02:55
朱大哥
Rank: 3Rank: 3
等 级:论坛游侠
威 望:2
帖 子:72
专家分:123
注 册:2015-1-16
收藏
得分:0 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define KEYSIZE 17
#define SYMBOLSIZE 6
#define KEYWORD  1
#define DEFINED  2
#define SYMBOL   3
#define NUM      4
#define ERROR    5
#define ISCHARACTER ((97<=*str&&*str<=122)||(65<=*str&&*str<=90))
#define ISCHAR_NUM_UNDERLINE ((97<=*(str+i)&&*(str+i)<=122)||(65<=*(str+i)&&*(str+i)<=90)||(48<=*(str+i)&&*(str+i)<=57)||(*(str+i)=='_'))
#define IS_NUM(A)    (48<=A&&A<=57)
//typedef struct{
//    char definedname[10];
//    int  dataspecies;
//    int  pointspecies;
   
//}
typedef struct{
    char keyname[10];
    char keyexp[100];
}keyword;
char dealword[100];
keyword key[KEYSIZE]={
        "char","字符型",
        "int","整型",
        "short","短整型",
        "long","长整型",
          "float","浮点型",
        "double","双精度浮点型",
        "signed","有符号的",
        "unsigned","无符号的",
        "auto","自动的",
        "extern","全局的",
        "static","静态的",
        "typedef","别名",
        "union","共用体",
        "struct","结构体",
        "enum","枚举体",
        "void","无返回值或者无参或者无类型",
        "*","指针",
        };
char symbol[]={'[',']','(',')',',',' '};
char exp_sequence[40];
char exp_symbol_sequence[20];
char exp_keyword_sequence[20];
char exp_error_sequence[20][20];
int  exp_num_sequence[20];
int  exp_sequence_flag=0;
int  exp_symbol_seq_flag=0;
int  exp_keyword_seq_flag=0;
int  exp_num_seq_flag=0;
int  exp_error_seq_flag=0;
int issymbol(char c)
{
    int i=0,flag=0;
    while(i<SYMBOLSIZE){
        if(c==symbol[i]){
            flag=i;
            break;
        }
        i++;
    }
            return flag;
}
int isdefined(char *str)
{
    int i=1,num;
    if( ISCHARACTER ){
        while(*(str+i)){
            if(!ISCHAR_NUM_UNDERLINE){
                exp_sequence[exp_sequence_flag]=ERROR;
                exp_sequence_flag++;
                return 0;
            }   
            i++;
        }
        for(i=0;i<KEYSIZE;i++)
            if(!strcmp(key[i].keyname,str)){
                exp_sequence[exp_sequence_flag]=KEYWORD;
                exp_sequence_flag++;
                exp_keyword_sequence[exp_keyword_seq_flag]=i;
                exp_keyword_seq_flag++;
                break;
            }
        if(i==KEYSIZE){           
            exp_sequence[exp_sequence_flag]=DEFINED;
            exp_sequence_flag++;
        }   
    }
    else if(IS_NUM(*str)){
        num=*str-48;
        while(*(str+i)){
            if(!IS_NUM(*(str+i))){
               
                exp_sequence[exp_sequence_flag]=ERROR;
                exp_sequence_flag++;
                return 0;
            }
            num*=10+(*(str+i)-48);   
            i++;
           
        }
        exp_sequence[exp_sequence_flag]=NUM;
        exp_sequence_flag++;
        exp_num_sequence[exp_num_seq_flag]=num;
        exp_num_seq_flag++;
      
    }
    else{
      
        exp_sequence[exp_sequence_flag]=ERROR;
        exp_sequence_flag++;
        return 0;
    }   
    return 1;
}
int readword(char *str,int i)
{
        int n,j=0;
        if(*(str+i)=='\0')
            return 0;
        if((n=issymbol(*(str+i)))){
           
            if(*(str+i)!=' '){
                exp_sequence[exp_sequence_flag]=SYMBOL;
                exp_sequence_flag++;
                exp_symbol_sequence[exp_symbol_seq_flag]=n;
                exp_symbol_seq_flag++;
            }      
            i++;
        }
        else{
            for(;*(str+i)!='\0';i++){
                if(!issymbol(*(str+i))){
                    dealword[j]=*(str+i);
                    j++;
                }
                else{
                    dealword[j]='\0';
                         break;
                }
            }   
            if(!isdefined(dealword)){
                strcpy(exp_error_sequence[exp_error_seq_flag],dealword);
                exp_error_seq_flag++;
            }
            memset(dealword,0,100);
        }
      
        readword(str,i);
   
}
int main(int argc,char **argv)
{
    int i,j=0;
    char *str="long 10a,bbc7,$adqw";
    readword(str,0);   
    for(i=0;i<exp_sequence_flag;i++)
        if(exp_sequence[i]==SYMBOL)
            printf("符号 ");
        else if(exp_sequence[i]==DEFINED)
            printf("标识符 ");
        else if(exp_sequence[i]==ERROR){
            printf("[%s]:表达式错误 ",exp_error_sequence[j]);
            j++;
        }
        else if(exp_sequence[i]==NUM)
            printf("数字 ");
        else
            printf("关键字 ");
    printf("\n");
}


[ 本帖最后由 朱大哥 于 2015-1-28 03:38 编辑 ]
2015-01-28 03:21
朱大哥
Rank: 3Rank: 3
等 级:论坛游侠
威 望:2
帖 子:72
专家分:123
注 册:2015-1-16
收藏
得分:0 
回复 2楼 诸葛欧阳
你拿过去编译一下不就晓得是干嘛了嘛 这么懒
2015-01-28 03:45
砖家的谎言
Rank: 12Rank: 12Rank: 12
等 级:禁止访问
威 望:30
帖 子:693
专家分:3898
注 册:2013-12-6
收藏
得分:0 
哈哈,你好逗啊,是来让大家帮你编译程序还是提问呢?

我不是砖家,要努力成为砖家。
2015-01-28 15:00
朱大哥
Rank: 3Rank: 3
等 级:论坛游侠
威 望:2
帖 子:72
专家分:123
注 册:2015-1-16
收藏
得分:0 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define KEYSIZE 17
#define SYMBOLSIZE 6
#define KEYWORD  1
#define DEFINED  2
#define SYMBOL   3
#define NUM      4
#define ERROR    5
#define ISCHARACTER ((97<=*str&&*str<=122)||(65<=*str&&*str<=90))
#define ISCHAR_NUM_UNDERLINE ((97<=*(str+i)&&*(str+i)<=122)||(65<=*(str+i)&&*(str+i)<=90)||(48<=*(str+i)&&*(str+i)<=57)||(*(str+i)=='_'))
#define IS_NUM(A)    (48<=A&&A<=57)
//typedef struct{
//    char definedname[10];
//    int  dataspecies;
//    int  pointspecies;
   
//}
typedef struct{
    char keyname[10];
    char keyexp[100];
}keyword;
char dealword[100];
keyword key[KEYSIZE]={
        "char","字符型",
        "int","整型",
        "short","短整型",
        "long","长整型",
          "float","浮点型",
        "double","双精度浮点型",
        "signed","有符号的",
        "unsigned","无符号的",
        "auto","自动的",
        "extern","全局的",
        "static","静态的",
        "typedef","别名",
        "union","共用体",
        "struct","结构体",
        "enum","枚举体",
        "void","无返回值或者无参或者无类型",
        "*","指针",
        };
char symbol[]={'(','[',')',']',',',' '};
char exp_sequence[40];
char exp_symbol_sequence[20];
char exp_keyword_sequence[20];
char exp_error_sequence[20][20];
int  exp_num_sequence[20];
int  exp_sequence_flag=0;
int  exp_symbol_seq_flag=0;
int  exp_keyword_seq_flag=0;
int  exp_num_seq_flag=0;
int  exp_error_seq_flag=0;
int issymbol(char c)
{
    int i=0,flag=0;
    while(i<SYMBOLSIZE){
        if(c==symbol[i]){
            flag=i+1;
            break;
        }
        i++;
    }
            return flag;
}
int isdefined(char *str)
{
    int i=1,num;
    if( ISCHARACTER ){
        while(*(str+i)){
            if(!ISCHAR_NUM_UNDERLINE){
                exp_sequence[exp_sequence_flag]=ERROR;
                exp_sequence_flag++;
                return 0;
            }   
            i++;
        }
        for(i=0;i<KEYSIZE;i++)
            if(!strcmp(key[i].keyname,str)){
                exp_sequence[exp_sequence_flag]=KEYWORD;
                exp_sequence_flag++;
                exp_keyword_sequence[exp_keyword_seq_flag]=i;
                exp_keyword_seq_flag++;
                break;
            }
        if(i==KEYSIZE){           
            exp_sequence[exp_sequence_flag]=DEFINED;
            exp_sequence_flag++;
        }   
    }
    else if(IS_NUM(*str)){
        num=*str-48;
        while(*(str+i)){
            if(!IS_NUM(*(str+i))){
               
                exp_sequence[exp_sequence_flag]=ERROR;
                exp_sequence_flag++;
                return 0;
            }
            num*=10+(*(str+i)-48);   
            i++;
           
        }
        exp_sequence[exp_sequence_flag]=NUM;
        exp_sequence_flag++;
        exp_num_sequence[exp_num_seq_flag]=num;
        exp_num_seq_flag++;
      
    }
    else{
      
        exp_sequence[exp_sequence_flag]=ERROR;
        exp_sequence_flag++;
        return 0;
    }   
    return 1;
}
int readword(char *str,int i)
{
        int n,j=0;
        if(*(str+i)=='\0')
            return 0;
        if((n=issymbol(*(str+i)))){
           
            if(*(str+i)!=' '){
                exp_sequence[exp_sequence_flag]=SYMBOL;
                exp_sequence_flag++;
                exp_symbol_sequence[exp_symbol_seq_flag]=n;
                exp_symbol_seq_flag++;
               
            }      
            i++;
        }
        else{
            for(;*(str+i)!='\0';i++){
                if(!issymbol(*(str+i))){
                    dealword[j]=*(str+i);
                    j++;
                }
                else{
                    dealword[j]='\0';
                         break;
                }
            }   
            if(!isdefined(dealword)){
                strcpy(exp_error_sequence[exp_error_seq_flag],dealword);
                exp_error_seq_flag++;
            }
            memset(dealword,0,100);
        }
      
        readword(str,i);
   
}
int symbolmatching()
{
    int flag1=0,flag2=0,i=0,error_flag=0;
    for(;i<exp_symbol_seq_flag;i++){
        if(exp_symbol_sequence[i]==1)
            flag1++;
        else if(exp_symbol_sequence[i]==3)
            flag1--;
        else if(exp_symbol_sequence[i]==2)
            flag2++;
        else    if(exp_symbol_sequence[i]==4)
            flag2--;
        else
            ;
        if(flag1<0||flag2<0 \
           ||(exp_symbol_sequence[i]==1&&exp_symbol_sequence[i+1]==4) \
           ||(exp_symbol_sequence[i]==2&&exp_symbol_sequence[i+1]==3)){
            //printf("符号不匹配");
            return 0;
        }
    }
    if(flag1>0||flag2>0){
            //printf("符号号不匹配");
            return 0;
        }
   
   
    return 1;
   
}
int main(int argc,char **argv)
{
    int i,j=0;
    char *str="[(])";
    readword(str,0);   
    for(i=0;i<exp_sequence_flag;i++)
        if(exp_sequence[i]==SYMBOL)
            printf("符号 ");
        else if(exp_sequence[i]==DEFINED)
            printf("标识符 ");
        else if(exp_sequence[i]==ERROR){
            printf("[%s]:表达式错误 ",exp_error_sequence[j]);
            j++;
        }
        else if(exp_sequence[i]==NUM)
            printf("数字 ");
        else
            printf("关键字 ");
    if(!symbolmatching())
        printf("括号不匹配");
      
    printf("\n");
   
}


[ 本帖最后由 朱大哥 于 2015-1-28 16:29 编辑 ]
2015-01-28 16:11
朱大哥
Rank: 3Rank: 3
等 级:论坛游侠
威 望:2
帖 子:72
专家分:123
注 册:2015-1-16
收藏
得分:0 
回复 5楼 砖家的谎言
因为我的操作系统是双系统 linux+win7
不知道为什么 我打代码喜欢在linux下面  打游戏看黄片又喜欢在win7里面
所以问题就来了 :在linux下我可以看代码 写代码
               但是在win7里面就不行了,因为vs6.0装不上,VS太大 其他的又用不来
               咋办呢 ,我想在win7下看到代码,并且思索代码,打草稿
               我的办法是:坛子里放个帖子,存起来。
               这样的好处有如下:
               操作系统重新装了,东西不怕掉
               翻阅查找方便
               
               至于访客 看与不看 其实没多大关系
               
            
2015-01-28 16:39
zklhp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:china
等 级:贵宾
威 望:254
帖 子:11485
专家分:33241
注 册:2007-7-10
收藏
得分:0 
以下是引用朱大哥在2015-1-28 16:39:21的发言:

因为我的操作系统是双系统 linux+win7
不知道为什么 我打代码喜欢在linux下面  打游戏看黄片又喜欢在win7里面
所以问题就来了 :在linux下我可以看代码 写代码
               但是在win7里面就不行了,因为vs6.0装不上,VS太大 其他的又用不来
               咋办呢 ,我想在win7下看到代码,并且思索代码,打草稿
               我的办法是:坛子里放个帖子,存起来。
               这样的好处有如下:
               操作系统重新装了,东西不怕掉
               翻阅查找方便
               
               至于访客 看与不看 其实没多大关系
               
            

我好奇 你在Linux下面用什么写代码呢?
2015-01-28 16:42
zklhp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:china
等 级:贵宾
威 望:254
帖 子:11485
专家分:33241
注 册:2007-7-10
收藏
得分:0 
我们网站其实有关专门贴代码的地方

https://www.bccn.net/paste/

但站长从来没有宣传过这东西 我也不大用
2015-01-28 16:44
朱大哥
Rank: 3Rank: 3
等 级:论坛游侠
威 望:2
帖 子:72
专家分:123
注 册:2015-1-16
收藏
得分:0 
回复 9楼 zklhp
我用vim啊,写点编译相关的
帖子可以回帖
我一点一点的堆代码
堆点存点
真的堆榻了,这不原始资料都在
2015-01-28 16:55
快速回复:小小码屋
数据加载中...
 
   



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

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