|
|
|
|
|
by TheLoneWolfling
4046 days ago
|
|
I've always understood it to be this: A lexer is for a regular language (in the formal sense), whereas a parser is for a context-sensitive (or context-free) language. Or, for a less formal description. A lexer's transformation is one that can be expressed as a function of <<input symbol or end of file>, position in file, state> -> <<some finite number of output symbols (including zero)>, <state or done>>, where state is finite. A lexer can work without backtracking or arbitrary memory usage. Whereas a parser potentially requires either arbitrary (but finite) backtracking or arbitrary (but finite) memory usage. The boundary gets a little fuzzy, though. For instance, constants, at least for any language that allows arbitrary-sized integers. |
|