RegEx for a simple Lexer

Tim Holzschuh via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue May 13 12:53:03 PDT 2014


Hi there,
I read a book about an introduction to creating programming languages 
(really basic).

The sample code is written in Ruby, but I want to rewrite the examples in D.

However, the Lexer uses Ruby's regex features to scan the code.

I'm not very familiar with D's RegEx system (nor with another..), so it 
would be very helpful to receive some tips on how to "translate" the 
ruby RegEx's to D's implementation.

If in Ruby I have a string called src, I just can use this: 
src[/\A([A-Z]\w*)/, 1].

Would match( src, r"([A-Z]\w*)" ); essentially do the same?
(I know I have to use .captures to receive the found expression)

If I also want to create a RegEx to filter string-expressions a la " xyz 
", how would I do this?

At least match( src, r"^\" (.*) $\" " ); doesn't seem to work and I 
couldn't find in the Library Reference how to change it..

Sorry if these questions seem dumb to you..

Ahh, I forgot one:
In the book a parser generator like Yacc is used to create a suitable 
parser.
Is there an equivalent for D?
Or if not: is it really that hard to create a parser that is able to 
parse sth. like this:

// Example
class Foo:
     def name:
         "name"

     def asdf:
         100

foo = Foo.new

print( foo.nam )
print( foo.asdf )


Thank you for helping,
     Tim


More information about the Digitalmars-d-learn mailing list