lex yacc简单实例
来源:互联网 发布:数据库实施工程师 编辑:程序博客网 时间:2024/06/18 10:24
//文件Name.y
%{
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef char* string;
#define YYSTYPE string
%}
%token NAME EQ AGE
%%
file : record file
| record
;
record : NAME EQ AGE {
printf("%s is %s years old!!!\n",$1,$3);}
;
%%
int main()
{
yyparse();
return 0;
}
int yyerror(char *msg)
{
printf("Error encountered:%s \n",msg);
}
//Name.l文件
%{
#include "y.tab.h"
#include <stdio.h>
#include <string.h>
extern char* yylval;
%}
char [A-Za-z]
num [0-9]
eq [=]
name {char}+
age {num}+
%%
{name} {yylval=strdup(yytext);
return NAME;}
{eq} {return EQ;}
{age} {yylval=strdup(yytext);
return AGE;}
%%
int yywrap()
{
return 1;
}
//text.txt
test = 123
编译链接:
$yacc -d Name.y
$lex Name.l
$gcc y.tab.c lex.yy.c
$./a.out < text.txt
输出:test is 123 years old!!!
- lex yacc简单实例
- yacc lex使用实例
- Lex&yacc简单计算器
- 正则语言引擎:一个简单LEX和YACC结合运用的实例
- 使用lex与yacc构建简单计算器
- Yacc Lex
- lex & yacc
- lex&yacc
- Lex Yacc
- lex &yacc
- yacc & lex
- lex&yacc
- YACC & LEX
- lex yacc
- yacc&lex
- lex && yacc
- Lex & Yacc
- LEX, YACC
- Hive文件格式(RCFILE)
- solr 排序限制
- Android 4.4 Kitkat Phone工作流程浅析(七)__来电(MT)响铃流程
- HDU 1421 DP
- 1>/dev/null 2>&1的含义
- lex yacc简单实例
- 关于多线程的问题
- 获取JAVA文件路径
- solr 查询参数说明
- Java OCR 图像智能字符识别技术,可识别中文
- #ifndef#define#endif防止头文件重复包含, 你不是真的懂
- OpenCV中Mat操作clone() 与copyto()的区别
- 【翻译】企业级SOA之路——在Web Service中使用HTTP和JMS
- CCSprite利用Bezier(贝塞尔)做抛物线动作