[erlang-questions] Parsing C with leex and yecc

Mikael Pettersson <>
Tue Jul 20 12:13:23 CEST 2010


Joe Armstrong writes:
 > I'm trying to parser ANSI C with leex and yecc and have run into
 > two problems.
...
 > 2) The typedef problem.
 > 
 >    How can I parse typedefs using leex and yecc?
 > 
 >    The traditional yacc/lex approach solves this with a context
 >    sensitive lex and feedback between yacc and lex. But the Erlang
 >    leex and yacc seem to be written as separated passes, are there some
 >    internal functions that allow feedback between leex and yacc?

The simplest solution in my experience is to make the scanner
proper ignore the typedef problem and just return identifier
for any identifier-like token that isn't a reserved word.  Then
you place a context-sensitive shim between then parser and the
scanner proper, where you maintain needed state to resolve
identifier-vs-typename.  Depending on implementation language
and parser technology, this may require tweaking the interface
between then parser and the shim (e.g. for state) or even embedding
the shim in the parser, but at least the scanner proper can remain clean.


More information about the erlang-questions mailing list