Last update March 17, 2008

Grammar Posts

Difference (last change) (Author, normal page display)

Added: 2a3,8

=== 2008 ===

*2008-03-16, NG:digitalmars.D.bugs/13658, documentation anomalies

Changed: 7c13
*2006/07/14, NG:digitalmars.D/40350, Re: Import conflict resoultion
*2006/07/14, NG:digitalmars.D/40350, Re: Import conflict resolution

Changed: 47c53
*2004/11/12, [Dsource.orgTopic:428 DGrammar project]
*2004/11/12, DGrammar project

Changed: 51c57
*2004/09/06, [Dsource.orgForum:33 lr-lalr project]
*2004/09/06, lr-lalr project

Table of contents of this page



I've heard that someone wrote D language support for ANTLR (some times ago in d.announce).

Such grammar and number of syntax tree classes are already in eclipseD project, so you may wish to use it <g>.
(Now, it's at DsourceProject:ddt/browser/trunk/ddt.core/src/org/dsource/ddt/core/model -- JustinCalvarese)


It's not an LALR(1) grammar (one token lookahead), but doing LALR(1) would have compromised the look & feel I was trying to achieve. So arbitrary lookahead (LALR(n)) is needed. (A nit: it isn't a lexer problem, it's a parsing problem.) The lexer was designed from the start so that arbitrary lookahead is easy to do.

I've currently modified lapg (see to produce D output. lapg supports lexical scanner generation and LALR(1) grammars. I've also tried to create a D grammar for lapg but there are some D constructs which are context sensitive and needs >1 lookahead. The semantic and syntactic predicates of ANTLR would be very handy for this. I had a look at the ANTLR source and mailing list but I have not found a starting point or document how to create a custom language output generator, yet. If you have more luck, let me know



BTW creating a custom language binding for ANTLR seems to be a nontrivial task. For lapg more or less changing a text template and recompilation was needed. Langage support in ANTLR consists of two parts: a code generator and a support library (base classes and AST handling). The one(s) who create such a monster will probably be condemned to maintain it


ANTLR is ANother Tool for Language Recognition. It's the same idea as Lex and YACC, but has (I think) better syntax, and directly supports generating re-entrant parsers in C++, C# or Java. (Python support is on the way, as I understand it. Anybody want to take a crack at D support?) You can get it at

I haven't run this through the complete gauntlet just yet, but preliminary tests suggest that it handles a respectable subset of D, if not the whole thing. (new link:

There isn't much else going on in this parser just yet, it's little more than a syntax checker, but that also means that it's easier to gut it if you want to use the grammar for something else.



FrontPage | News | TestPage | MessageBoard | Search | Contributors | Folders | Index | Help | Preferences | Edit

Edit text of this page (date of last change: March 17, 2008 16:37 (diff))