Anyone interested in a working grammar for D?

Kelly Wilson Kelly_member at pathlink.com
Thu Feb 23 13:04:42 PST 2006


Hey everyone,

Great language Walter et al. I saw this language and the active group here when
I was seeking a project to work on in my spare time. I decided to see if I could
make a usable grammar for D and start building a new compiler (should only take
a few weeks for a new optimizing compiler, I figured.......just kidding ;).

Anyways, I have a mostly working GLR grammar that was originally based on Ivan
Senji's Dgrammar(I hope that using your grammar was ok Ivan...if you don't want
me to release this then let me know, as I have to release this under the license
for Elkhound...I don't know if your license is compatible?? Or should I just
include your license? ...I don't know how those things work). 

There are 4 constructs that I have found which won't parse....I'm sure there are
more. I can, however, parse Mango and phobos (minus the four cases ;) with this
grammar, so I think I have found most problems. The grammar contains a ton of
conflicts (about 800) and about 10 ambiguities but these are resolved using a
great parser generator called Elkhound. I can get rid of many of the conflicts
with ease (about 400), but then a few rarely used constructs wouldn't parse.

I have a lexer based on the one supplied with the Elkhound/Elsa (the C++ parser
and therefore not a totally correct lexer for D...I'll work on it later) and a
sort of mini project set up to build the lexer and parser. The parser takes one
file and parses it, reporting syntax errors using the automated Elkhound
reporting mechanisms. The parse tree (along with the ambiguities) can be viewed
using a commmand line switch.

The Abstract Sytax Tree is also being generated (though it is woefully lacking
information, at this point) by Elkhound. My next step will be to populate the
AST with meaningful info and start on semantic checking. Of course, since there
is no semantic checking at this point, my parser accepts too many programs. Most
of the time when I try to parse something really strange and it works, I can
just check the program using dmd and see a semantic error (ie. I rarely produce
any program which I can parse but dmd will fail with a grammatical
error....though I haven't written a ton of strange programs to check at this
point ;)

Anyways, I just thought I would let everyone know that I have this small project
underway. If anyone is interested in it please email me (you can find my address
on my University of Calgary website for now. Just search for "Kelly Wilson
computer science" on google. I am at the top of the resulting page :) I should
be able to send you a copy to twiddle around with if you want one.

Hope everyone is doing well,
K.Wilson

P.S. I think MSTA/COCOM could also use this grammar (changed syntax of course)
with success, as I had started out using MSTA.





More information about the Digitalmars-d mailing list