[MLton-user] How ml-yacc works with the "error" token.
Matthew Fluet
fluet at tti-c.org
Mon Jan 15 00:50:52 PST 2007
> I am developing a compiler with ml-yacc and i would like to know how
> the report errors works.
The error recovery mechanism in ml-yacc is derived from:
'A Practical Method for LR and LL Syntactic Error Diagnosis and
Recovery', by M. Burke and G. Fisher, ACM Transactions on
Programming Langauges and Systems, Vol. 9, No. 2, April 1987,
pp. 164-197.
> I don't wanna permit any kind of correction (deletion, insertion, ...)
> by the compiler, the only thing i want is that every time the compiler
> detects an error, it reports the "statement" where that error occurred
> and then it continues parsing as if the discarded token was really a
> valid "statement".
A careful reading of the ml-yacc manual reveals some suggestions:
"The algorithm uses a parse check to evaluate corrections. A parse check
is a check of how far a correction allows a parser to parse without
encountering a syntax error. You pass an upper bound on how many tokens
beyond the error point a parser may read while doing a parse check as an
argument to the parser. This allows you to control the amount of
lookahead that a parser reads for different kinds of systems. For an
interactive system, you should set the lookahead to zero. Otherwise, a
parser may hang waiting for input in the case of a syntax error. If the
lookahead is zero, no syntax errors will be corrected."
> I searched over the web and i didn't find anything about the use of
> the "error" token by the ml-yacc.
I don't believe that the error token is a distinguished token; rather in
a given attempted parse, the token at which a parse error is discovered
is an "error token".
More information about the MLton-user
mailing list