Hacker News new | past | comments | ask | show | jobs | submit login

You can do that with any language that has an eval function. Eval takes a string and feeds it into the interpreter.



For some reason I didn't see that he'd said, "during compilation". Perl is an interpreted language, so there's no compilation stage. A compiled language is modified in this way using a preprocessor. It doesn't really make sense to claim it's possible to inject code during compilation, that's the entire purpose of a compiler, to generate machine code from a syntax tree.

But code generation and execution during runtime, which is what I think you meant, is capable in any language with eval().


Perl is an interpreted language, so there's no compilation stage.

Perl claims to have a compilation stage, by which the documentation means that the lexer and parser produce an optree, which the runtime phase traverses. During that compilation stage, it's possible to run code which changes how the parser will treat subsequent syntactic elements.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: