在Perl中编写部分编译器(用c ++编写) [英] Writing part of a compiler (written in c++) in Perl

查看:281
本文介绍了在Perl中编写部分编译器(用c ++编写)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想了解更多关于编译器和编程语言的信息,不幸的是我的大学没有提供编译器的课程,所以我必须自己做(感谢互联网)。

i am trying to learn more about compilers and programming languages, unfortunately my university doesnt offer a course about compilers and so i have to do myself (thank you internet).

此时im tryin 可以理解并为我的语言实现一个词法分析器,我需要正则表达式。

At the moment im tryin to understand and to implement a lexer for my language and i need regular expressions.

我用来脚本perl regex很快,我认为,我可以嵌入Perl在我的C + +语言。现在的问题是:

I am used to script perl regex pretty quickly and i thought that i could embed Perl in my C++ lexer. Now the questions are:


  • 这会造成沉重的开销吗?

  • 与BOOST(或任何其他c ++库好gor regex)?

感谢您阅读:)

推荐答案

没有理由你不能,一个好的程序员的一部分是使用正确的工具,perl是非常好的文本处理。

No reason you can't, part of being a good programmer is using the right tool for the job, and perl is VERY good at text processing.

但是,不要考虑在C ++编译器(用C ++编写,而不是编译C ++)中填充一个基于perl的词法分析器,我们应该考虑在C ++中编写一个perl模块,并让编译器驱动程序在perl ,执行lexing,填充数据结构,然后调用C ++模块的函数来完成编译。

However, instead of thinking about stuffing a perl-based lexer into your C++ compiler (written in C++, not compiling C++, I hope), you should think about writing a perl module in C++, and letting the compiler driver be written in perl, do the lexing, fill in data structures, and then call the C++ module's functions to finish the compile.

这篇关于在Perl中编写部分编译器(用c ++编写)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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