Sep 03, 2003 ------------- - More on context free grammars - and ambiguity - dangling else problem - Another example of ambiguity - ()- in C - can mean two different things - typecasting - subtracting - Constructs and capabilities - regular expressions can capture - rules for a valid identifier in C - cfgs can capture - rules for a valid mathematical expression in C - neither can capture - that a variable must be declared before its usage - Solution - use more powerful grammars - alt: use attribute grammars - cfgs, decorated with "rules" - Attribute grammars - due to Knuth - example for variable declaration rule - int a; a=2; b=3; int b; - example grammar -> -> epsilon -> -> -> -> = -> .... -> .... -> .... - More examples - procedures in Ada - "end name" must match "beginning name" - how would you decorate the cfg?