Interpreting the D grammar

Jacob Carlborg via Digitalmars-d digitalmars-d at puremagic.com
Sun Aug 2 07:50:34 PDT 2015


I'm trying to read the D grammar [1] to enhance the D TextMate bundle. 
If we take the add expression as an example. It's defined like this in 
the grammar:

AddExpression:
     MulExpression
     AddExpression + MulExpression
     AddExpression - MulExpression
     CatExpression

And like this in the grammar made by Brian [2]:

addExpression:
       mulExpression
     | addExpression ('+' | '-' | '~') mulExpression
     ;

I'm not so familiar with grammars but this looks like it's recursive. Is 
it possible to translate this piece of grammar to a regular expression? 
TextMate uses regular expressions and a couple of 
enhancements/extensions to define a grammar for a language.

[1] http://dlang.org/grammar.html
[2] https://rawgit.com/Hackerpilot/DGrammar/master/grammar.html

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list