Should I use/write a template lexer?

No: the speed of regular expressions are implementation dependent of the Regular Expression engine. In general, every time you use a Regular Expression, it needs to be parsed itself, and then with the given model, it must use a general matcher that works with all Regular Expressions possible Given a lexer, you fine-tune the matcher: you get a specific matcher which only works for your predefined grammar. One gain is in the bootstrap case: no need to compile the Regular Expression.

Another gain is in it's lesser complexity, due to it's specific matcher, which tends to run faster Are there good resources on how to write your own lexer to interpret some sort of (template) language (I couldn't find anything I understand on google)? Lexers are quite complex.To write your own you will have to know stuff about state machines regular grammar context-free or non-context-free grammers, etc It requires some fundamental computer science knowledge before it's easy to grasp though Should I keep using regexes or is a lexer something worth exploring? Worth noting is the error-catching capabilities of well engineered lexers (e.g. An error message: "expected but found ) on line 64:38.").

I suggest writing Parsing expression grammars (PEGs), and see this answer for a PEG library in PHP. PEGs are very much alike Regular Expressions, they are greedy by nature, and never ambiguous: great for a Domain Specific Language (DSL). In general isn't the lexer way slower than using a few regexes to create a cached php template?

No: the speed of regular expressions are implementation dependent of the Regular Expression engine. In general, every time you use a Regular Expression, it needs to be parsed itself, and then with the given model, it must use a general matcher, that works with all Regular Expressions possible. Given a lexer, you fine-tune the matcher: you get a specific matcher, which only works for your predefined grammar.

One gain is in the bootstrap case: no need to compile the Regular Expression. Another gain is in it's lesser complexity, due to it's specific matcher, which tends to run faster. Are there good resources on how to write your own lexer to interpret some sort of (template) language (I couldn't find anything I understand on google)?

Lexers are quite complex. To write your own you will have to know stuff about state machines, regular grammar, context-free or non-context-free grammers, etc. It requires some fundamental computer science knowledge before it's easy to grasp though. Should I keep using regexes or is a lexer something worth exploring?

Worth noting is the error-catching capabilities of well engineered lexers (e.g. An error message: "expected ;, but found ), on line 64:38.").

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions