[erlang-questions] Parsing C with leex and yecc
Wed Jul 21 10:21:36 CEST 2010
> -----Original Message-----
> Behalf Of Joe Armstrong
> Sent: 20 July 2010 19:40
> To: Tony Arcieri
> Cc: Erlang
> Subject: Re: [erlang-questions] Parsing C with leex and yecc
> Yes - I've also been playing with my own peg combinator library :-).
> The problem is that LALR(1) parsers can give you pretty good automatic
> diagnostics on faulty input. Peg grammars just fail - period - and you
> have to write your own error recovery in the grammar ...
I think PEGs can be written to handle errors elegantly.
Each combinator applies an exploration strategy to the input top-down,
and passes the remaining input on to subsequent analysis steps.
When an error occurs, it should pass back the reason for the failure.
Each error ultimately originates from a failed character lexing rule.
Just as input is reduced by moving forwards, so errors are accumulated
flowing backwards. Each combinator is then responsible for merging the
error reports coming back into it. The error handling process is in
some sense dual to the original input processing, so in some sense,
each parser combinator must contain an error co-combinator.
Failure occurs when all available paths have been explored.
Depending how errors have been filtered and discarded,
it is possible for full tree of errors to be returned to the original rule.
In practice, the only interesting co-combinator is in the choice rule.
A simple co-combinator policy is to keep the deepest (rightmost) error,
so the final report is a stack trace of failed rules and input positions.
This may or may not correspond to the 'real' error.
Thales UK Ltd (Wells) DISCLAIMER: The information contained in this e-mail
is confidential. It may also be legally privileged. It is intended only for
the stated addressee(s) and access to it by any other person is
unauthorised. If you are not an addressee, you must not disclose, copy,
circulate or in any other way use or rely on the information contained in
this e-mail. Such unauthorised use may be unlawful. We may monitor all
e-mail communications through our networks. If you have received this e-mail
in error, please inform us immediately on sender's telephone number above
and delete it and all copies from your system. We accept no responsibility
for changes to any e-mail which occur after it has been sent. Attachments
to this e-mail may contain software viruses which could damage your system.
We therefore recommend you virus-check all attachments before opening.
Thales UK Ltd. Registered Office: 2 Dashwood Lang Road, The Bourne Business
Park, Addlestone, Weybridge, Surrey KT15 2NX Registered in England No.
More information about the erlang-questions