comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Ada to Ada Translator ?
Date: Mon, 20 May 2019 18:19:54 -0500
Date: 2019-05-20T18:19:54-05:00	[thread overview]
Message-ID: <qbvcmq$98f$1@franka.jacob-sparre.dk> (raw)
In-Reply-To: 64883feb-3e49-4c6a-855c-6673068e970c@googlegroups.com

"Optikos" <optikos@verizon.net> wrote in message 
news:64883feb-3e49-4c6a-855c-6673068e970c@googlegroups.com...
...
>Conversely, if you utilize Yacc & Flex, it would be LR(k) bottom-up parser,
>which would be an admirable accomplishment in its own right.

Why? There are a number of such grammars out there, and Janus/Ada was 
designed from the beginning (in 1980!) using an LALR parser. (That was a 
requirement of the class project at the University of Wisconsin that formed 
the basis of Janus/Ada, and we discovered that switching was impractical as 
an LL parser was going to be several times larger than the 48K RAM available 
on CP/M-80. With some clever storage, we got the LR tables to fit with space 
to spare.)

>It is purported to be more difficult to craft meaningful error messages in 
>LR
>parsers, because LL parsers can explain in detail what was expected but,
>without care in crafting the grammar, LR parsers can lack the context to 
>make
>"hmmm, it looks like you were trying to do /this/, but I found troublesome
>/that/ instead" type of error messages.

This is definitely not true and irrelevant at the same time. :-) An LR 
parser has plenty of context (there is always a state that contains a vast 
amount of information). The problem (to the extent that there is one) is 
situations where you have already gone a long ways down an incorrect path 
before finding out a problem -- Ada luckily does not have many of these. 
(The worst one in Janus/Ada is an "is" following a subprogram in a package 
specification; you've gone too far for an correction to fix the situation.)

>Writing an LR-based (i.e., yacc-based) parser can create an awesome fast
>parser, but to do so requires a generous amount of expanding the base
>language's grammar to consider all the commonplace mistakes to build up
>enough context to emit that aforementioned type of useful error message.

Maybe for some languages, but there isn't much of that in Janus/Ada's 
grammar. Instead, error correction is based on the grammar tables 
themselves, and costs for insertion and deletions of tokens. That turns out 
to be cheap, fast, and reliable -- the only issue is getting the costs right 
(and they aren't that critical, they're mainly used to break ties).

But I think that error messages for *syntax* in a compiler are pretty much 
irrelevant these days; it's the IDE's job to check the syntax before calling 
the compiler, and in the IDE you only care about the first error anyway. 
Presuming the check is fast enough (and it is on all but the largest files), 
you check, then fix, then check again until it is correct.

                                         Randy.



  parent reply	other threads:[~2019-05-20 23:19 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-17 14:21 Ada to Ada Translator ? foo wong
2019-05-17 21:00 ` Simon Wright
2019-05-18 12:05   ` foo wong
2019-05-18 12:11     ` foo wong
2019-05-18 14:47     ` Simon Wright
2019-05-18 15:26       ` foo wong
2019-05-18 16:48         ` Simon Wright
2019-05-19 16:04         ` G.B.
2019-05-19 17:08           ` Simon Wright
2019-05-19 18:27             ` Optikos
2019-05-19 21:27               ` Simon Wright
2019-05-19 21:42               ` Simon Wright
2019-05-21 20:54                 ` Optikos
2019-05-22  6:59                   ` Simon Wright
2019-05-22 12:06                     ` Optikos
2019-05-22 12:33                       ` Simon Wright
2019-05-22 12:57                         ` foo wong
2019-05-22 15:24                           ` Shark8
2019-05-22 16:34                             ` Optikos
2019-05-22 20:07                               ` Randy Brukardt
2019-05-23  7:21                           ` G. B.
2019-05-22 13:33                         ` Optikos
2019-05-20 14:11         ` Optikos
2019-05-20 16:37           ` foo wong
2019-05-18 15:44       ` foo wong
2019-05-18 16:49         ` Simon Wright
2019-05-19 15:04         ` G.B.
2019-05-19 12:41 ` Optikos
2019-05-19 17:38   ` foo wong
2019-05-19 22:52   ` foo wong
2019-05-20 23:19   ` Randy Brukardt [this message]
2019-05-21  0:13     ` Optikos
2019-05-21 22:15       ` Randy Brukardt
2019-05-22  0:16         ` Optikos
2019-05-22 20:16           ` Randy Brukardt
2019-05-22 23:27             ` foo wong
2019-05-23  7:56               ` Simon Wright
2019-05-23 12:29                 ` foo wong
2019-05-21 22:20       ` Randy Brukardt
2019-05-21  0:17     ` Optikos
2019-05-22 18:49 ` Optikos
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox