Tries and Lexers
blog.ircmaxell.com
Tries and Lexers
1–10 of 29 posts
Re: Tries and Lexers
#2Re: Tries and Lexers
#3Is this correct to say?
Re: Tries and Lexers
#4"Parsers work at the grammatical level, lexers work at the word level." Is this correct to say?
A stricter definition would be "lexers work at the lexical level" for NLP (in which case it's nearly tautologically obvious), or "lexers work at the token level" for programming languages.
(Creds: lexing / wordbreaking is the topic of my masters research in linguistics. Tries are a good starting point for that, but it turns out that they are a special case of simple morphological analyzer, and you need more complicated ones to do a good job on natural languages.)
Re: Tries and Lexers
#5"Parsers work at the grammatical level, lexers work at the word level." Is this correct to say?
Re: Tries and Lexers
#6"Parsers work at the grammatical level, lexers work at the word level." Is this correct to say?
Re: Tries and Lexers
#7"Parsers work at the grammatical level, lexers work at the word level." Is this correct to say?
Lexers work at the lexeme level, which are generally understood to be words, assuming that a word is a non-decomposable unit of language.
Re: Tries and Lexers
#8Want to build an ultra-fast lexer? Ragel is the way. http://en.wikipedia.org/wiki/Ragel http://www.colm.net/open-source/ragel/
The Wikipedia page links two publications by (I suppose) the creator of Ragel, and two publications that do not seem to be specifically about Ragel; and the product page mentions nothing in the way of publications or references to uses in industry. Is Ragel actually widely used?
Re: Tries and Lexers
#9Here are some things a lexer for a programming language might have to deal with:
1. Comments (some even do nested - which means regular expressions are out for that).
2. Continuation lines.
3. Includes (if done at the lexical level).
4. Filename/line/column number for nice error messages (can really hurt with branch mispredictions).
5. Evaluation of literals: decimal/hex/octal/binary integers, floats, strings (with escapes), etc.
6. Identifiers.
So matching keywords is mostly the straightforward part. However I have found that matching many keywords is the perfect (and in my experience so far, the only) use case for a perfect hashing tool like gperf - it would normally be much faster than any pointer-chasing trie. gperf mostly elminated keyword matching from the profile of any lexer I've done.
Re: Tries and Lexers
#10Edit: fixed the regexp to allow for single-char identifiers.