3 ms·
Ambiguity of a grammar is rather unrelated to how surprising it can be to a human. Something like TypeScript: var a = { label: f() }; () => { label : f
by victorNicollet 9y ago
Ambiguity of a grammar is rather unrelated to how surprising it can be to a human. Something like TypeScript:
var a = { label: f() };
() => { label : f() };
These constructs look similar, but one is an object literal and the other is a block with a useless label. All of this can be implemented as an unambiguous context-free grammar.
Relying on grammar ambiguity detection to find constructs surprising to humans is not very effective, if only because of the difference between how a human understands the grammar (pattern-based) and how EBNF expresses it (prefix-based).
- haberman 9y agoThis is a red herring. Context-free grammar tools don't solve the problem of keeping a language from ever being confusing. However they do solve the problem of allowing literal ambiguity into your language. Ambiguity is strictly worse than confusion. Ambiguity means you have to communicate more information to your users: when two parses are both syntactically valid, which one does the language actually choose?
- tomp 9y ago> Relying on grammar ambiguity detection to find constructs surprising to humans is not very effective Well yeah, obviously, that's like relying on unittests and type system to keep your program bug free... I mean, neither can guarantee your program is going to work, but either failing means that it almost certainly won't work (well).