ANTLR grammar for D?

Wesley Hamilton via Digitalmars-d digitalmars-d at puremagic.com
Fri Jun 20 11:53:46 PDT 2014


On Friday, 20 June 2014 at 18:45:15 UTC, Wesley Hamilton wrote:
> On Friday, 20 June 2014 at 18:20:36 UTC, Brian Schott wrote:
>> On Friday, 20 June 2014 at 09:22:07 UTC, Wesley Hamilton wrote:
>>> Thanks. Just realized that the "add grammar" button for ANTLR 
>>> grammar list is broken... so that could be why it's not 
>>> there. I'll probably still finish the grammar I'm making 
>>> since I'm 75% done. That's a great reference, though. I think 
>>> it's missing a few minor details like delimited strings, 
>>> token strings, and assembly keywords.
>>
>> Keep in mind that assembly keywords aren't keywords outside of 
>> ASM blocks. You need your lexer to identify them as 
>> identifiers.
>>
>>> It should help where the Language Reference pages aren't 
>>> accurate. For example, I think HexLetter is incorrectly 
>>> defined.
>>
>> If you find problems in the grammar please file an issue on 
>> Github or create a pull request.
>>
>> If you need the AST of some D code, you'll save a lot of time 
>> by downloading D-Scanner and running "dscanner --ast 
>> sourcecode.d > sourcecode_ast.xml"
>
> My intent is to develop a language based on D and a compiler to 
> go with it. I've done something similar using ANTLR once 
> before. I might turn it into a BS project.

I realize assembly instruction keywords aren't actually tokens 
for the lexer. Having a clean ANTLR file that doesn't include 
predicates and language dependent code is nice as a starting 
point, but the parser eventually needs to check validity of the 
asm statements. Identifier DelimitedStrings need predicates too. 
Also, TokenStrings can't be a simple parse rule since the dot 
operator only applies to characters and not tokens.


More information about the Digitalmars-d mailing list