Example Chomsky normal form
abstract syntax tree of arithmetic expression a^2+4*b wrt. example grammar (top) , chomsky normal form (bottom)
the following grammar, start symbol expr, describes simplified version of set of syntactical valid arithmetic expressions in programming languages c or algol60. both number , variable considered terminal symbols here simplicity, since in compiler front-end internal structure not considered parser. terminal symbol ^ denoted exponentiation in algol60.
in step start of above conversion algorithm, rule s0→expr added grammar. after step term , grammar looks this:
after step bin , following grammar obtained:
since there no ε-rules, step del doesn t change grammar. after step unit , following grammar obtained, in chomsky normal form:
the na introduced in step term powop, open, , close. ai introduced in step bin addop_term, mulop_factor, powop_primary, , expr_close.
Comments
Post a Comment