comp.lang.ada
 help / color / mirror / Atom feed
From: Yves Cloutier <yves.cloutier@gmail.com>
Subject: Re: Writing a scanner and parser in Ada
Date: Mon, 25 Dec 2017 08:32:38 -0800 (PST)
Date: 2017-12-25T08:32:38-08:00	[thread overview]
Message-ID: <acde3cea-b00f-4305-8914-d802ed09038e@googlegroups.com> (raw)
In-Reply-To: <3eb3c336-fcb5-432d-a79d-cd52021301de@googlegroups.com>

On Saturday, December 23, 2017 at 11:07:37 PM UTC-5, Robert Eachus wrote:
> On Saturday, December 23, 2017 at 8:15:05 PM UTC-5, Yves Cloutier wrote:
> > Hi there, 
> > 
> > I'm new to Ada, but not to programming.
> > 
> > I'd like to know if there are any examples of how to write a scanner and parser in Ada.
> 
> Welcome!
> 
> You don't really need to worry about learning Ada, and even Ada 83 texts will get you started.  Going beyond Ada 95 really requires reading this newsgroup or the equivalent.  What has been going on is providing support for specialized areas of programming.  (Some of the extensions like the container library are more general.)  For example, if you don't deal with complex numbers, you can pretty much skip Annex G.  (Well, if you need accuracy bounds for trig functions they are there as well.)
> 
> There are plenty of books out there on software engineering, or on various subfields like proofs of correctness.  If you want to do that in Ada, you probably want to download some SPARK documentation.  But SPARK is essentially an Ada subset plus a prover, and all that is integrated into GNAT.
> 
> As for parsing examples, you can get the GNAT source code, and I think it still uses a recursive descent parser.  I may be able to dig up a simple calculator program I wrote mostly to check the (fixed-point) arithmetic and numeric I/O on our compiler.  Again recursive descent about two pages.
> 
> If you want to get into other types of parsing, I was one of two people who supported and extended the LALR(k) tool on Multics.  Parsing seems to be one of those areas which was solved once, and all the experts are now retired.  Not as dumb as it seems.  Writing a recursive descent (LL(1)) compiler is fairly easy even without supporting tools.  If you do have tools?  Look-ahead LR (LALR) allows for better recovery from syntax errors, but there is no particular reason today to design a language which cannot be parsed by an LL(1) parser.

Hi Robert, thanks for the warm welcome.

I've actually ordered Ada As a Second Language (15$ from abebooks.com) and Programming in Ada: A First Course.

I have Ada 95: Problem Solving and Program Design but right from the first chapter it makes reference to compiling code that's on the disk for using code that's already been done. Of course I don't have the disk ;(

I also ordered Compiler Engineering Using PASCAL, and thought I could follow that but try to code in Ada instead of Pascal.

Writing a full blown compiler is something I eventually want to do, but here is the approach I want to take:

1. use my DSL as an exercise in scanning/parsing/code generation. Target code being Groff. My DSL: https://www.dropbox.com/sh/d5emub0yza1r14r/AAA-f9MPmAQRuK_pX5GirrQoa?dl=0
2. Use this experience to implement a transpiler. Maybe parsing Oberon and generating code in another language.
3. Then finally extending this to generate native code.

A few other folks have provided some useful guidance below and I'll check those out too.

  reply	other threads:[~2017-12-25 16:32 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-24  1:15 Writing a scanner and parser in Ada Yves Cloutier
2017-12-24  4:07 ` Robert Eachus
2017-12-25 16:32   ` Yves Cloutier [this message]
2017-12-24  9:08 ` Dmitry A. Kazakov
2017-12-24 15:09   ` Niklas Holsti
2017-12-25 16:37     ` Yves Cloutier
2017-12-25 16:35   ` Yves Cloutier
2017-12-25 17:08     ` Dmitry A. Kazakov
2017-12-25 18:57       ` Yves Cloutier
2017-12-25 19:19         ` Dmitry A. Kazakov
2017-12-26 18:06           ` Shark8
2017-12-26 21:45             ` Dmitry A. Kazakov
2017-12-26 22:20             ` Dmitry A. Kazakov
2017-12-24 14:40 ` Tero Koskinen
2017-12-25 16:36   ` Yves Cloutier
2017-12-24 15:33 ` Lucretia
replies disabled

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