使用flex / yacc编写C ++编译器需要多少时间? [英] How much time would it take to write a C++ compiler using flex/yacc?

查看:188
本文介绍了使用flex / yacc编写C ++编译器需要多少时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用lex / yacc编写C ++编译器需要多少时间?

How much time would it take to write a C++ compiler using lex/yacc?

在哪里可以开始使用?

推荐答案

有很多解析规则不能由bison / yacc解析器解析(例如,在某些情况下区分声明和函数调用)。另外有时,令牌的解释需要来自解析器的输入,特别是在C ++ 0x中。例如,处理字符序列>> 极其依赖于解析上下文。

There are many parsing rules that cannot be parsed by a bison/yacc parser (for example, distinguishing between a declaration and a function call in some circumstances). Additionally sometimes the interpretation of tokens requires input from the parser, particularly in C++0x. The handling of the character sequence >> for example is crucially dependent on parsing context.

这两个工具是解析C ++的非常差的选择,你将不得不放入很多特殊情况下逃避这些工具依赖的基本框架,以正确解析C ++。它会花费你很长时间,即使你的解析器可能会有奇怪的错误。

Those two tools are very poor choices for parsing C++ and you would have to put in a lot of special cases that escaped the basic framework those tools rely on in order to correctly parse C++. It would take you a long time, and even then your parser would likely have weird bugs.

yacc和bison是 LALR(1)解析器生成器,它们不够复杂,不能有效地处理C ++。正如其他人已经指出的,大多数C ++编译器现在使用递归下降解析器,以及其他几个

yacc and bison are LALR(1) parser generators, which are not sophisticated enough to handle C++ effectively. As other people have pointed out, most C++ compilers now use a recursive descent parser, and several other answers have pointed at good solutions for writing your own.

C ++模板不适用于处理字符串,即使是常量(虽然这可能固定在C ++ 0x,我没有仔细研究),但如果他们是,你可以很容易地编写一个递归下降解析器在C ++模板语言。我觉得很有趣。

C++ templates are no good for handling strings, even constant ones (though this may be fixed in C++0x, I haven't researched carefully), but if they were, you could pretty easily write a recursive descent parser in the C++ template language. I find that rather amusing.

这篇关于使用flex / yacc编写C ++编译器需要多少时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆