Thant 2009-11-12 15:38:23
I’m building a language of sorts using Standard ML, and I’ve run into
an interesting little issue.
The problem is that in order to make certain optimizations possible, I
need to resolve variables in the lexer as the file is being parsed in.
That means that the productions’ associated smantic actions need to be
evaluated immediately so that the values that have already been read in
can be made available.
By default, ml-yacc delays evaluation of production actions. I’ve
managed to figure out that the %pure option in the grammar file turns
this behavior off. The problem is that ml-yacc also has this feature
where it will try to parse past syntax errors, calling the production
actions an arbitrary number of times and s******* up the data structure
of values. Now this only happens when there’s a syntax error anyway (I
hope!) so it in theory is no big deal. But in order to see the parser
print out the syntax errors, I’ve had to modify my code in a way that
ignores this behavior of the parser, and the modifications are such
that they might hide other errors in my code–which I don’t want to do.
How do people tend to deal with the situation where the lexer and the
parser have to share information with each other? Is there a way to
tell the parser not to do its error-correction dance? That is, set the
parser guesser to zero? I think the ml-yacc document mentioned there’s
a plain non-error-correcting parser available but I can’t find anything
Much obliged for any advice,