From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.107.34.1 with SMTP id i1mr17175204ioi.117.1514219559529; Mon, 25 Dec 2017 08:32:39 -0800 (PST) X-Received: by 10.157.90.22 with SMTP id v22mr845362oth.12.1514219559260; Mon, 25 Dec 2017 08:32:39 -0800 (PST) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!border1.nntp.ams1.giganews.com!border2.nntp.ams1.giganews.com!nntp.giganews.com!peer02.ams1!peer.ams1.xlned.com!news.xlned.com!peer03.am4!peer.am4.highwinds-media.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!g80no2451948itg.0!news-out.google.com!s63ni4311itb.0!nntp.google.com!g80no2451947itg.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Mon, 25 Dec 2017 08:32:38 -0800 (PST) In-Reply-To: <3eb3c336-fcb5-432d-a79d-cd52021301de@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=174.114.57.218; posting-account=yfhumQoAAACUMOSAPBmheMxZJWoNg1wi NNTP-Posting-Host: 174.114.57.218 References: <2d87298a-4d1f-446a-9d46-d4f03879246b@googlegroups.com> <3eb3c336-fcb5-432d-a79d-cd52021301de@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Writing a scanner and parser in Ada From: Yves Cloutier Injection-Date: Mon, 25 Dec 2017 16:32:39 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Received-Bytes: 4366 X-Received-Body-CRC: 3191168308 Xref: reader02.eternal-september.org comp.lang.ada:49633 Date: 2017-12-25T08:32:38-08:00 List-Id: 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,=20 > >=20 > > I'm new to Ada, but not to programming. > >=20 > > I'd like to know if there are any examples of how to write a scanner an= d parser in Ada. >=20 > Welcome! >=20 > 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 new= sgroup or the equivalent. What has been going on is providing support for = specialized areas of programming. (Some of the extensions like the contain= er 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 bou= nds for trig functions they are there as well.) >=20 > There are plenty of books out there on software engineering, or on variou= s subfields like proofs of correctness. If you want to do that in Ada, you= probably want to download some SPARK documentation. But SPARK is essentia= lly an Ada subset plus a prover, and all that is integrated into GNAT. >=20 > 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 c= alculator program I wrote mostly to check the (fixed-point) arithmetic and = numeric I/O on our compiler. Again recursive descent about two pages. >=20 > If you want to get into other types of parsing, I was one of two people w= ho 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 reti= red. Not as dumb as it seems. Writing a recursive descent (LL(1)) compile= r is fairly easy even without supporting tools. If you do have tools? Loo= k-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 b= y 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 c= ode that's already been done. Of course I don't have the disk ;( I also ordered Compiler Engineering Using PASCAL, and thought I could follo= w that but try to code in Ada instead of Pascal. Writing a full blown compiler is something I eventually want to do, but her= e is the approach I want to take: 1. use my DSL as an exercise in scanning/parsing/code generation. Target co= de being Groff. My DSL: https://www.dropbox.com/sh/d5emub0yza1r14r/AAA-f9MP= mAQRuK_pX5GirrQoa?dl=3D0 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 t= hose out too.