问题描述
通过概念/函数/实现,编译器和解析器之间有什么区别?
By concept/function/implementation, what are the differences between compilers and parsers?
推荐答案
的几个组件,其中之一是解析器。
编译器中常见的一组组件是:
A compiler is often made up of several components, one of which is a parser.A common set of components in a compiler is:
- Lexer - 将程序分解成单词。
- 解析器 - 检查句子的语法是否正确。
- 语义分析 - 检查句子是否有意义。
- 代码生成器 - 使用另一个词汇表输出具有等效语义的东西。
添加一点:
- Lexer - break the program up into words.
- Parser - check that the syntax of the sentences are correct.
- Semantic Analysis - check that the sentences make sense.
- Optimizer - edit the sentences for brevity.
- Code generator - output something with equivalent semantic meaning using another vocabulary.
To add a little bit:
如前所述,小C是一个递归体面的编译器生成代码,因为它解析。基本上一次语法分析,语义分析和代码生成。
As mentioned elsewhere, small C is a recursive decent compiler that generated code as it parsed. Basically syntactical analysis, semantic analysis, and code generation in one pass. As I recall, it also lexed in the parser.
很久以前,我写了一个C编译器(实际上是几个:Introl-C系列的微控制器),它使用递归的,在解析期间进行语法和语义检查,并产生了生成代码的程序的树表示。
A long time ago, I wrote a C compiler (actually several: the Introl-C family for microcontrollers) that used recursive decent and did syntax and semantic checking during the parse and produced a tree representation of the program from which code was generated.
今天,我正在开发一个来源 - > tokens - > AST - > IR - >代码,大致如上所述。
Today, I'm working on a compiler that does source -> tokens -> AST -> IR -> code, pretty much as I described above.
这篇关于编译器和解析器之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!