Is D's grammar really context-free?

后端 未结 7 1134
萌比男神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:31

    These answers are making my head hurt.

    First of all, the complications with low level languages and figuring out whether they are context-free or not, is that the language you write in is often processed in many steps.

    In C++ (order may be off, but that shouldn't invalidate my point):

    1. it has to process macros and other preprocessor stuffs
    2. it has to interpret templates
    3. it finally interprets your code.

    Because the first step can change the context of the second step and the second step can change the context of the third step, the language YOU write in (including all of these steps) is context sensitive.

    The reason people will try and defend a language (stating it is context-free) is, because the only exceptions that adds context are the traceable preprocessor statements and template calls. You only have to follow two restricted exceptions to the rules to pretend the language is context-free.

    Most languages are context-sensitive overall, but most languages only have these minor exceptions to being context-free.

提交回复
热议问题