Is D's grammar really context-free?

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

    The grammar cannot be context-free if I need I can't tell the type of an expression just by looking at it.

    No, that's flat out wrong. The grammar cannot be context-free if you can't tell if it is an expression just by looking at it and the parser's current state (am I in a function, in a namespace, etc).

    The type of an expression, however, is a semantic meaning, not syntactic, and the parser and the grammar do not give a penny about types or semantic validity or whether or not you can have tuples as values or keys in hashmaps, or if you defined that identifier before using it.

    The grammar doesn't care what it means, or if that makes sense. It only cares about what it is.

提交回复
热议问题