Search code examples
c++perlcompiler-constructionprogramming-languageslexer

Writing part of a compiler (written in c++) in Perl


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).

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

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:

  • Will it cause Heavy overhead?
  • Should i try to make peace with BOOST (or any other c++ library good gor regex) ?

Thank you for reading this :)


Solution

  • 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.

    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.