lex demo
来源:互联网 发布:身份证app扫描软件 编辑:程序博客网 时间:2024/05/20 20:22
%{enum {LOOKUP =0,VERB,ADJ,CONJ};int state;int add_word(int type, char *word);int lookup_word(char *word);%}%option noyywrap%%\n{state = LOOKUP;}^VERB{state = VERB;}^ADJ{state = ADJ;}^CONJ{state = CONJ;}.;/*ignore anything else*/[a-zA-Z]+ {/*a normal word , define it or look it up */ if(state != LOOKUP){/* define the current word */add_word(state, yytext);}else{switch(lookup_word(yytext)){case VERB: printf("%s is verb\n",yytext); break;case ADJ: printf("%s is adj\n",yytext); break;case CONJ: printf("%s is conj\n",yytext); break;default: printf("oh, i can't recognize it!!\n");break; }}}%%main(){ yylex();}/*define a linked list of words and types*/struct word *word_list; /*first element in word list */extern void *malloc();struct word{char *word_name;int word_type;struct word *next;};int add_word(int type, char *word){if(lookup_word(word) != 0)return 0;/*word not there, allocate a new entry and link it on the list*/struct word *tem;tem = malloc(sizeof(struct word));tem->next = word_list;char *c = malloc(sizeof(char)*(strlen(word)+1));strcpy(c,word);tem->word_name = c;tem->word_type = type;word_list = tem;return 1;}int lookup_word(char *word){struct word *t = word_list;for(;t;t = t->next){ int r = strcmp(word, t->word_name); if(r ==0)return t->word_type;}return 0;}
0 0
- lex demo
- lex
- lex
- Lex
- lex
- Lex/Yacc 初识Lex
- Yacc Lex
- lex & yacc
- lex&yacc
- Lex Yacc
- lex bison
- lex入门
- lex &yacc
- yacc & lex
- lex&yacc
- lex 命令
- YACC & LEX
- lex yacc
- C语言未定义行为
- 延迟系统时间但系统又能同时能执行其它任务
- gpu简介
- iframe 无刷新提交表单
- HDU_1020Encoding
- lex demo
- [LeetCode]14.Longest Common Prefix
- Android下HelloWorld项目的R.java文件介绍
- MSSQL 事务级别
- Swing JComboBox的详细使用
- extjs环境搭建
- Pat(Advanced Level)Practice--1074(Reversing Linked List)
- 排序之归并排序
- extjs学习笔记