Tiny语法分析器(递归下降分析法实现)

递归规约规则是这样的

program→stmt-sequence

stmt-sequence→stmt-sequence;statement|statement

statement→if-stmt|repate-stmt|assign-stmt|read-stmt|write-stmt|var-stmt

var-stmt→var identifier-assign-name := type

identifier-assign-name→name

if-stmt→if exp then stmt-sequence ;

            |if exp then stmt-sequence else stmt-sequence ;

reapet-stmt→repeat stmt-sequence until exp

assign-stmt→identifier := exp

read-stmt→read indetifier

write-stmt→write exp

exp→simple-exp comparison simple-exp |simple-exp

comparison→<|=

simple-exp→simple-exp addop term | term

addop→+|-

term→term mulop factor | factor

mulop → *|/

factor→ (exp)|number | identifier

因为源码分了好几个文件,不太好贴出来了,所以决定上传到Github上,

项目地址:https://github.com/INnoVationes/TinyCompiler

文件内容:ExplLexicalAnalyzer  :词法分析器

ExplParsing :语法分析器

GLOBALS: 一些全局变量,包括语法树结构等

Util:打印语法树,处理变量等内容

posted @ 2016-11-01 19:26  INnoVation-V2  阅读(2332)  评论(0编辑  收藏  举报