#include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct node{ char words[255]; struct node *next; }NODE; char word[255]; //判断默认字符 int acceptation_logic_key(char *ch); int acceptation_logic(char *ch); //判断数字 int acceptation_number(char *str); int acceptation_number_key(char ch); //判断字符 int acceptation_string(char *str); int acceptation_string_key(char ch); //截取 int acceptation_str(char ch,char *str,int i,char *sch,NODE *tnode); void splitter_node_add(char *str,NODE *node); int splitter_start(char *str); void splitter_node_add(char *str,NODE *node); void word_acceptation(char *ch,NODE *tnode); void word_node(char *ch,NODE *node); void word_splitter(char* str,NODE *node); //逻辑判断 int acceptation_logic(char *ch){ int key=0; if(strcmp(ch,"begin")==0){ printf("<%s 1 > ",ch); } else if(strcmp(ch,"if")==0){ printf("<%s 2 > ",ch); } else if(strcmp(ch,"then")==0){ printf("<%s 3 > ",ch); } else if(strcmp(ch,"while")==0){ printf("<%s 4 > ",ch); } else if(strcmp(ch,"do")==0){ printf("<%s 5 > ",ch); } else if(strcmp(ch,"end")==0){ printf("<%s 6 > ",ch); } else if(strcmp(ch,"+")==0){ printf("<%s 13> ",ch); } else if(strcmp(ch,"-")==0){ printf("<%s 14> ",ch); } else if(strcmp(ch,"*")==0){ printf("<%s 15> ",ch); } else if(strcmp(ch,"/")==0){ printf("<%s 16> ",ch); } else if(strcmp(ch,":")==0){ printf("<%s 17> ",ch); } else if(strcmp(ch,":=")==0){ printf("<%s 18> ",ch); } else if(strcmp(ch,"<")==0){ printf("<%s 20> ",ch); } else if(strcmp(ch,"<=")==0){ printf("<%s 21> ",ch); } else if(strcmp(ch,"<>")==0){ printf("<%s 22> ",ch); } else if(strcmp(ch,">")==0){ printf("<%s 23> ",ch); } else if(strcmp(ch,">=")==0){ printf("<%s 24> ",ch); } else if(strcmp(ch,"=")==0){ printf("<%s 25> ",ch); } else if(strcmp(ch,";")==0){ printf("<%s 26> ",ch); } else if(strcmp(ch,"(")==0){ printf("<%s 27> ",ch); } else if(strcmp(ch,")")==0){ printf("<%s 28> ",ch); } else if(strcmp(ch,"#")==0){ printf("<%s 0> ",ch); } else{ key=1; } return key; } int acceptation_logic_key(char *ch){ int key=0; if(strcmp(ch,"begin")==0); else if(strcmp(ch,"if")==0); else if(strcmp(ch,"then")==0); else if(strcmp(ch,"while")==0); else if(strcmp(ch,"do")==0); else if(strcmp(ch,"end")==0); else if(strcmp(ch,"+")==0); else if(strcmp(ch,"-")==0); else if(strcmp(ch,"*")==0); else if(strcmp(ch,"/")==0); else if(strcmp(ch,":")==0); else if(strcmp(ch,":=")==0); else if(strcmp(ch,"<")==0); else if(strcmp(ch,"<=")==0); else if(strcmp(ch,"<>")==0); else if(strcmp(ch,">")==0); else if(strcmp(ch,">=")==0); else if(strcmp(ch,"=")==0); else if(strcmp(ch,";")==0); else if(strcmp(ch,"(")==0); else if(strcmp(ch,")")==0); else if(strcmp(ch,"#")==0); else{ key=1; } return key; } int acceptation_string_key(char ch); int acceptation_string(char *str){ int key=1; char *ch= NULL; ch=str; if(acceptation_string_key(str[0])==0){ printf("<%s 11> ",str); key=0; } return key; } int acceptation_number_key(char ch){ int key=0; if(ch<='9'&&ch>='0'){ key=0; } else key=1; return key; } int acceptation_number(char *str){ int key=0; char *ch=NULL; ch=str; while(*ch!='