无籽石榴真的没有子吗:我看BNF,请问parser是什么意思?

来源:百度文库 编辑:高校问答 时间:2024/04/29 05:47:25
BNF is so unambiguous that there is a lot of mathematical theory around these kinds of grammars, and one can actually mechanically construct a parser for a language given a BNF grammar for it.
(There are some kinds of grammars for which this isn't possible, but they can usually be transformed manually into ones that can be used.)
Programs that do this are commonly called "compiler compilers". The most famous of these is YACC, but there are many more.

parser 就是语言或语句的分析器,它是一段程序和一组子程序,执行:
"循环: 读一字符,判断:如果,则,否则;读一字符,如果,则,否则...".
它把读入的一个一个字符,分解成一个一个的词,分析出词意,句意.

例如读入: y = (2.0 * cos(0.1) - x * sin(0.1));
分解成x,y,2.0,0.1,cos,sin 等词
分析出: 数 2.0,0.1;变量x,y;函数名cos,sin
运算符-,*,(,)
行结束符分号
然后分析句意,先算函数,再做乘法,再减法,再赋值.

parser 类似编译器.