What programming languages are context-free?

前端 未结 9 987
萌比男神i
萌比男神i 2020-12-07 13:17

Or, to be a little more precise: which programming languages are defined by a context-free grammar?

From what I gather C++ is not context-free due to things like mac

9条回答
  •  孤城傲影
    2020-12-07 13:50

    VHDL is somewhat context sensitive:

    VHDL is context-sensitive in a mean way. Consider this statement inside a process:

    jinx := foo(1);
    

    Well, depending on the objects defined in the scope of the process (and its enclosing scopes), this can be either:

    • A function call
    • Indexing an array
    • Indexing an array returned by a parameter-less function call

    To parse this correctly, a parser has to carry a hierarchical symbol table (with enclosing scopes), and the current file isn't even enough. foo can be a function defined in a package. So the parser should first analyze the packages imported by the file it's parsing, and figure out the symbols defined in them.

    This is just an example. The VHDL type/subtype system is a similarly context-sensitive mess that's very difficult to parse.

    (Eli Bendersky, “Parsing VHDL is [very] hard”, 2009)

提交回复
热议问题