Is D's grammar really context-free?

后端 未结 7 1136
萌比男神i
萌比男神i 2021-01-30 03:18

I\'ve posted this on the D newsgroup some months ago, but for some reason, the answer never really convinced me, so I thought I\'d ask it here.


The grammar of D is

7条回答
  •  南方客
    南方客 (楼主)
    2021-01-30 03:47

    There is a construct in D's lexer:

    string ::= q" Delim1 Chars newline Delim2 "
    

    where Delim1 and Delim2 are matching identifiers, and Chars does not contain newline Delim2.

    This construct is context sensitive, therefore D's lexer grammar is context sensitive.

    It's been a few years since I've worked with D's grammar much, so I can't remember all the trouble spots off the top of my head, or even if any of them make D's parser grammar context sensitive, but I believe they do not. From recall, I would say D's grammar is context free, not LL(k) for any k, and it has an obnoxious amount of ambiguity.

提交回复
热议问题