dmd support for IDEs and the D tool chain

Nick Sabalausky a at a.a
Fri Oct 16 23:27:15 PDT 2009


"Nick Sabalausky" <a at a.a> wrote in message 
news:hbblfe$2k4s$1 at digitalmars.com...
> "Ellery Newcomer" <ellery-newcomer at utulsa.edu> wrote in message 
> news:hbaom1$138v$1 at digitalmars.com...
>>
>> Well, let's see here...
>>
>> PrimExp -> structLiteral
>> PrimExp -> functionLiteral
>>
>> and suppose
>>
>> structLiteral => { /* really, really looooooooooong expression*/ }
>>
>> functionLiteral => { statement }
>> functionLiteral => { /* really, really looooooooooong expression*/ ; }
>>
>> In an LL(k) parser, when you get to PrimExp, you have to know which
>> choice to make based on the first k lookahead characters (probably
>> translates to '{' and one token past that). Obviously, that won't work
>> for this piece, so it isn't LL(k). You have to try parsing the one, and
>> back up and parse the other if the first one fails (dmd should do this,
>> but currently it just looks ahead for the first semicolon. come to think
>> of it, I should try patching that..)
>>
>> ANTLR has pretty good support for backtracking, so writing a D grammar
>> for it wasn't too difficult, but then the resultant performance isn't
>> anything near what I'd like.
>>
>> But what I'm wondering about LALR is will it have to back up if it
>> chooses wrong, or can it sail on through in one parse attempt. I bet it
>> can.
>
> I'll write up a test in a minute,

No sweat :)

-----------------------------------------------------------
"Start Symbol" = <Program>

! ------ Terminals

Identifier = {Letter}{AlphaNumeric}*
Statement = 'foo'

! ------ Rules

<Program> ::= <Prim Exp> | <Program> <Prim Exp>

<Prim Exp> ::= <StructLit> | <Func Lit>

<StructLit> ::= '{' <Expression> '}'

<Func Lit> ::= '{' Statement '}'
            |  '{' <Expression> ';' '}'

<Expression>  ::= <Expression> '+' <Mult Exp>
               |  <Expression> '-' <Mult Exp>
               |  <Mult Exp>

<Mult Exp>    ::= <Mult Exp> '*' <Negate Exp>
               |  <Mult Exp> '/' <Negate Exp>
               |  <Negate Exp>

<Negate Exp>  ::= '-' <Value>
               |  <Value>

<Value>       ::= Identifier
               |  '(' <Expression> ')'

----------------------------------------------------------- 





More information about the Digitalmars-d mailing list