Created
August 10, 2016 13:25
-
-
Save JeOam/2204c320051103cf82c4397169f73969 to your computer and use it in GitHub Desktop.
自制编程语言
Instal flex and yacc on OS X:
brew install flex
brew install bison
编译 mycalc 项目:
$ bison --yacc -dv mycalc.y # 生成 y.output y.tab.c y.tab.h 文件
$ flex mycalc.l # 生成 lex.yy.c 文件
$ cc -o mycalc y.tab.c lex.yy.c
$ ./mycalc
... 1+1
>>2.000000
Valgrind is an instrumentation framework for building dynamic analysis tools. There are Valgrind tools that can automatically detect many memory management and threading bugs, and profile your programs in detail. You can also use Valgrind to build new tools.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
一般编程语言的语法处理,都会有以下的过程:
执行词法分析的程序称为词法分析器(lexical analyzer)。lex 的工作就是根据词法规则自动生成词法分析器。
执行语法分析的程序则称为解析器(parser)。yacc 就是能根据语法规则自动生成解析器的程序。