From: "Yannick Duchêne (Hibou57)" <yannick_duchene@yahoo.fr>
Subject: Re: LALR parser question
Date: Tue, 30 Apr 2013 06:11:06 +0200
Date: 2013-04-30T06:11:06+02:00 [thread overview]
Message-ID: <op.wwb5wszeule2fv@cardamome> (raw)
In-Reply-To: nospam-AAB08E.22031329042013@news.aioe.org
Le Tue, 30 Apr 2013 04:03:13 +0200, John B. Matthews
<nospam@nospam.invalid> a écrit:
> In article <op.wwbxyoz9ule2fv@cardamome>,
> Yannick Duchêne (Hibou57) <yannick_duchene@yahoo.fr> wrote:
>
>> Note: GNAT uses a hand-written parser (I'm pretty sure to remember
>> I've seen it somewhere).
>
> See also GNAT: The GNU Ada Compiler, §2.2 The Parser, cited here:
>
> <http://stackoverflow.com/a/15544761/230513>
>
While hand‑written parser is not the only worth choice, a good reason for
this choice is as they say:
“GNU Ada Compiler, §2.2 The Parser”:
> At the architectural level the main subprogram of the
> GNAT parser is an Ada function (Par) that is called to
> analyze each compilation unit. The parser code is organized
> as a set of packages (subunits of the top-level function)
> each of which contains the parsing routines associated with
> one chapter of the Ada Reference Manual [AAR95].
You can't do this with a parser generated automatically from a grammar,
you can't split the generated parser as it's an automata generated as a
indivisible whole.
There are still some points I don't agree with…
> Better error messages. GNAT generates clear andprecise error messages
There is a common idiom with automatically generated parsers, to complete
the grammar so that it include wrong production, which normally does not
introduce ambiguities, as these are wrong and normally not recognized by
the grammar. But I agree this is easier with a hand‑written parser.
> Clarity. The GNAT parser follows faithfully the
> grammar given in the Ada Reference Manual [AAR95]
You get the same from an AST produced by an automatically generated
parser; clarity just happens to be visible more later.
> Performance. The GNAT parser is as fast as any Ada
> table driven parser, and arguably faster than a
> LALR parser.
The main issue with this argument, is that performance isn't a big issue
at this stage. What comes next — analyses, transformations, code
generation — is more important for the overall performance of a compiler.
Then anyway, being exact is far more important than being fast, for a
compiler, and in that matter, the two previous points values a lot more
(the points about clarity and precision).
--
“Syntactic sugar causes cancer of the semi-colons.” [1]
“Structured Programming supports the law of the excluded muddle.” [1]
[1]: Epigrams on Programming — Alan J. — P. Yale University
next prev parent reply other threads:[~2013-04-30 4:11 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-04-28 13:37 LALR parser question Stephen Leake
2013-04-28 14:43 ` Dmitry A. Kazakov
2013-04-30 1:19 ` Yannick Duchêne (Hibou57)
2013-04-30 2:03 ` John B. Matthews
2013-04-30 4:11 ` Yannick Duchêne (Hibou57) [this message]
2013-04-30 11:55 ` Peter C. Chapin
2013-04-30 13:14 ` john
2013-04-30 14:14 ` Dmitry A. Kazakov
2013-05-01 11:33 ` Peter C. Chapin
2013-04-30 16:06 ` Shark8
2013-04-30 17:15 ` Yannick Duchêne (Hibou57)
2013-04-30 17:51 ` Shark8
2013-04-30 18:52 ` Yannick Duchêne (Hibou57)
2013-05-01 12:31 ` Stephen Leake
2013-05-01 13:57 ` Shark8
2013-04-30 21:18 ` Dmitry A. Kazakov
2013-04-30 22:09 ` Shark8
2013-05-02 1:49 ` Randy Brukardt
2013-05-02 2:39 ` Yannick Duchêne (Hibou57)
2013-05-02 21:57 ` Randy Brukardt
2013-05-06 18:25 ` Oliver Kellogg
2013-05-03 9:45 ` Stephen Leake
2013-05-03 22:57 ` Randy Brukardt
2013-05-06 9:45 ` Stephen Leake
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox