Take the 2-minute tour ×

I'm playing with CodeMirror, a browser-based editor written in JavaScript. It has a pluggable syntax highlighting component. I'd like to be able to take standard lex files for an arbitrary language and generate a lexer in JavaScript that I could plug into CodeMirror. Is there such a lexer generator available?

share|improve this question
possible duplicate of Lexer written in Javascript? –  Bergi Sep 27 '12 at 22:15
@Bergi : I saw that, but I need something that would accept a lex file as input. –  Bartosz Milewski Sep 27 '12 at 23:17
So I guess the answer is no. –  Bartosz Milewski Oct 2 '12 at 17:27
add comment

1 Answer

I don't have a ready made solution to your question, but I may be able to help by recommending lexertl (http://www.benhanson.net/lexertl.html). Although you will need to write a code generator yourself as well as any semantic actions processing, lexertl offers a simple interface to produce the state machines from your regular expressions.

The existing code generator is setup to generate C++, but due to the modular nature of the library it is easy to write your own code generator, which of course could output Javascript.

The demo code generator outputs a table based solution, but I would go the other direction and output a char based scanner (lexertl will output char_state_machine instead of the usual state_machine).

share|improve this answer
add comment

Your Answer


