CS453 Intro and PA1 1CS453 Lecture Ambiguous Grammars 1Plan for Today Ambiguous Grammars– Due to associativity– Due to precedence Making Grammars Non-Ambiguous– example related to PA3 What do the SableCC errors look like for ambiguous grammars?CS453 Lecture Ambiguous Grammars 2Example Ambiguous Grammars: AssociativityProductions stm = exp ; exp = {minus_rule} [left]:exp minus [right]:exp | {num_rule} num ;Productions stm = exp ; exp = {assign_rule} [left]:exp assign [right]:exp | {id_rule} id ;CS453 Lecture Ambiguous Grammars 3Example Ambiguous Grammars: PrecedenceProductions stm = exp ; exp = {or_rule} [left]:exp or [right]:exp | {and_rule} [left]:exp and [right]:exp | {true_rule} true | {false_rule} false ;CS453 Lecture Ambiguous Grammars 4Example Ambiguous Grammars: BothTokens pow = ‘^’; dot = ‘.’;Productions stm = exp ; exp = {pow_rule} [left]:exp pow [right]:exp | {field_rule} exp dot id | {paren_rule} lparen exp rparen | {plus_rule} [left]:exp plus [right]:exp | {id_rule} id ;Precedence (high to low)() id.^+CS453 Intro and PA1 2CS453 Lecture Ambiguous Grammars 5Example Ambiguous Grammars: SableCC errorsProductions stm = exp ; exp = {minus_rule} exp minus exp | {num_rule} num ;Verifying identifiers.java.lang.RuntimeException: [30,35] Redefinition of AMinusRuleExp.Exp.Productions stm = exp ; exp = {minus_rule} [left]:exp minus [right]:exp | {num_rule} num ;shift/reduce conflict in state [stack: PExp TMinus PExp *] on TMinus in { [ PExp = PExp * TMinus PExp ] (shift), [ PExp = PExp TMinus PExp * ] followed by TMinus
View Full Document