免费词法分析器/扫描器源
我正在寻找适用于任何语言的手写免费词法分析器/扫描器,甚至是用类似于 C/C++ 的语言编写的玩具语言。我是创建语言和编译器设计的初学者,我想尝试一下源代码。
例如,在 Flex 生成的 lex 之前,该网站上有一个手写的词法分析器: http://en.wikipedia .org/wiki/Flex_lexical_analysisr
谢谢。
I'm looking for a hand-written free lexer/scanner for any language, even a toy language written in a language similiar to C/C++. I am a beginner in creating languages and compiler design, I'd like to play around with the source.
For example, theres a hand written lexer on this website before the flex generated lex: http://en.wikipedia.org/wiki/Flex_lexical_analyser
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我喜欢 LLVM 教程——它首先展示了一个手写的词法分析器对于一种称为万花筒的玩具语言,首先作为“文学编程”练习,对每一位进行良好的文本解释;它继续构建一个解析器,以相同的风格构建抽象语法树;然后整个内容(用于词法分析器、解析器和 AST 构建器的 400 行手写独立 C++)再次显示为完整的 .cpp 源文件,因此您不必自己将它们全部放在一起。接下来的章节展示了代码生成、JIT、优化……确实是一个真正有用的小教程!但是,如果您现在只想了解这些,您可以停止使用词法分析器;-)。
I like the LLVM tutorial -- it starts by presenting a hand-written lexer for a toy language called Kaleidoscope, first as a "literate programming" exercise with good textual explanations of each bit; it continues by building a parser that builds an abstract syntax tree in the same style; then the whole thing (400 lines of hand-writted standalone C++ for lexer, parser and AST builder) is shown again as a complete .cpp source file, so you don't have to put it all together by yourself. Following chapters show code generation, JIT, optimization, ... a truly useful little tutorial indeed! But, you can stop with the lexer, if that's all you want to understand for now;-).
Lex 和 Yacc 是用于构建语言和编译器的“经典”工具。
Lex and Yacc are the "classic" tools used for the purpose of building languages and compilers.
您可能需要 flex,它可能是地球上使用最广泛的词法分析器。
You probably want flex, which is probably the most widely used lexer on the planet.