程序有问题,大神看看
这个程序没有实际意义,目的在于删除程序中自带的一些注释和宏定义,但是编译会报错,请看看哪里不对。#include <stdio.h>#include <string.h>
#include <ctype.h>
#define debug(fmt,args,...) fprintf(stderr,fmt,##args)
int get_input_type(char * word)
{
if(strcmp(word," ") == 0)
return 0;
if(strcmp(word,"\t") == 0)
return 0;
if(strcmp(word,"#") == 0)
return 1;
if(strcmp(word,"define") == 0)
return 2;
if(strcmp(word,"\n") == 0)
return 4;
return 3;
}
char c;
char word;
char word_buf;
char buf;
struct macro
{
char name;
char value;
} macros;
int macro_counter = 0;
void act_print_word(void)
{
int i = 0;
for(i=0;i<macro_counter;i++)
{
if(strcmp(word,macros.name) == 0)
{
printf("%s",macros.value);
return;
}
break;
}
if(i == macro_counter)
printf("%s",word);
return;
}
void act_save_to_buf(void)
{
strcat(buf,word);
return;
}
void act_print_buf_and_word(void)
{
printf("%s",buf);
printf("%s",word);
return;
}
void act_save_word(void)
{
strcat(word_buf,word);
return;
}
void act_get_macro_name(void)
{
printf("name = <%s>\n",word_buf);
strcpy(macros.name,word_buf);
strcpy(word_buf,"");
return;
}
void act_get_macro_value(void)
{
printf("value = <%s>\n",word_buf);
strcpy(macros.value,word_buf);
strcpy(word_buf,"");
macro_counter++;
return;
}
void act_null(void)
{
return;
}
enum {s0 = 0,s1,s2,s3,s4,s5,s6};
int state_transition =
{
s0, s1, s0, s0, s0,
s1, s0, s2, s0, s0,
s3, s0, s0, s0, s0,
s3, s4, s4, s4, s0,
s5, s5, s4, s4, s0,
s5, s6, s6, s6, s0,
s6, s6, s6, s6, s0,
};
#define a0 act_print_word
#define a1 act_save_to_buf
#define a2 act_print_buf_and_word
#define a3 act_save_word
#define a4 act_get_macro_name
#define a5 act_get_macro_value
#define a6 act_null
#if 1
typedef void (*PF)(void);
PF act_table =
{
a0, a1, a0, a0, a0,
a1, a2, a1, a2, a2,
a1, a2, a2, a2, a2,
a1, a3, a3, a3, a2,
a4, a4, a3, a3, a5,
a6, a3, a3, a3, a5,
a3, a3, a3, a3, a5,
};
#endif
void getword(char * word)
{
char c;
c = getchar();
if(c == EOF)
{
*word = '\0';
return;
}
// if c is not a alpha
if(isalpha(c) == 0) // orif(!isalpha(c))
{
*word = c;
word ++;
*word = '\0';
return;
}
do
{
*word++ = c;
c = getchar();
}while(isalnum(c) || c == '_');
// current c is $ or anything else
ungetc(c,stdin);
*word = '\0';
return;
}
int main(void)
{
int state = 0;
while(1)
{
int input = 0;
void (*pf)(void);
//char word;
//c = getchar();
//input = get_input_type(c);
getword(word);
input = get_input_type(word);
//printf("c = %c,input = %d\n",c,input);it's debug sentence.
//if(c == EOF)
// break;
if(strcmp(word,"") == 0)
break;
pf = act_table;
pf();
state = state_transition;
debug("word = <%s>,input = %d,state = %d\n",word,input,state);
}
return 0;
}
五天了,没人懂?还是没人理。这人缘~~~~~:cry 本帖最后由 haiouda 于 2015-4-5 20:50 编辑
我是菜鸟,看着有点乱;
哥们,给你提点意见(可能是我水平实在太差):
哥们,要不你就把你这程序是怎么实现的,说一说(思路);
再不,你就多加些注释,这样一来,也好读懂; 本帖最后由 xxzj01 于 2015-4-6 11:17 编辑
haiouda 发表于 2015-4-5 20:46
我是菜鸟,看着有点乱;
哥们,给你提点意见(可能是我水平实在太差):
哥们,要不你就把你这程序是怎么 ...
这个程序没有实际意义,目的在于删除程序中自带的一些注释和宏定义.程序来自李明新概念C语言(git-hub).报错如下:pasting "," and "word" does not give a valid preprocessing token
页:
[1]