context-free grammar

Rainer Schuetze r.sagitario at gmx.de
Fri Mar 4 23:54:04 PST 2011


The ambiguities are simply resolved by this rule in the language 
specification: "Any ambiguities in the grammar between Statements and 
Declarations are resolved by the declarations taking precedence." ( 
http://www.digitalmars.com/d/2.0/statement.html ).

Simon Buerger wrote:
> It is often said that D's grammar is easier to parse than C++, i.e. it 
> should be possible to seperate syntactic and semantic analysis, which is 
> not possible in C++ with the template-"< >" and so on. But I found 
> following example:
> 
> The Line "a * b = c;" can be interpreted in two ways:
> -> Declaration of variable b of type a*
> -> (a*b) is itself a lvalue which is assigned to.
> 
> Current D (gdc 2.051) interprets it always in the first way and yields 
> an error if the second is meant. The Workaround is simply to use parens 
> like "(a*b)=c", so it's not a real issue. But at the same time, C++ (gcc 
> 4.5) has no problem to distinguish it even without parens.
> 
> So, is the advertising as "context-free grammar" wrong?
> 
> - Krox


More information about the Digitalmars-d mailing list