Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Chomsky normal form
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Example== [[File:Syntax tree of arithmetic expression wrt Chomsky normal form grammar.gif|thumb|[[Abstract syntax tree]] of the [[expression (mathematics)|arithmetic expression]] "''a''^2+4*''b''" wrt. the example grammar ('''top''') and its Chomsky normal form ('''bottom''')]] The following grammar, with start symbol ''Expr'', describes a simplified version of the set of all syntactical valid arithmetic expressions in programming languages like [[C (programming language)|C]] or [[Algol60]]. Both ''number'' and ''variable'' are considered terminal symbols here for simplicity, since in a [[compiler front-end|compiler front end]] their internal structure is usually not considered by the [[parser]]. The terminal symbol "^" denoted [[exponentiation]] in Algol60. :{| |- | ''Expr'' | β ''Term'' | | | ''Expr'' ''AddOp'' ''Term'' | | | ''AddOp'' ''Term'' |- | ''Term'' | β ''Factor'' | | | ''Term'' ''MulOp'' ''Factor'' |- | ''Factor'' | β ''Primary'' | | | ''Factor'' ^ ''Primary'' |- | ''Primary'' | β ''number'' | | | ''variable'' | | | ( ''Expr'' ) |- | ''AddOp'' | β + | | | − |- | ''MulOp'' | β * | | | / |} In step "START" of the [[#Converting a grammar to Chomsky normal form|above]] conversion algorithm, just a rule ''S''<sub>0</sub>β''Expr'' is added to the grammar. After step "TERM", the grammar looks like this: :{| |- | ''S''<sub>0</sub> | β ''Expr'' |- | ''Expr'' | β ''Term'' | | | ''Expr'' ''AddOp'' ''Term'' | | | ''AddOp'' ''Term'' |- | ''Term'' | β ''Factor'' | | | ''Term'' ''MulOp'' ''Factor'' |- | ''Factor'' | β ''Primary'' | | | ''Factor'' ''PowOp'' ''Primary'' |- | ''Primary'' | β ''number'' | | | ''variable'' | | | ''Open'' ''Expr'' ''Close'' |- | ''AddOp'' | β + | | | − |- | ''MulOp'' | β * | | | / |- | ''PowOp'' | β ^ |- | ''Open'' | β ( |- | ''Close'' | β ) |} After step "BIN", the following grammar is obtained: :{| |- | ''S''<sub>0</sub> | β ''Expr'' |- | ''Expr'' | β ''Term'' | | | ''Expr'' ''AddOp_Term'' | | | ''AddOp'' ''Term'' |- | ''Term'' | β ''Factor'' | | | ''Term'' ''MulOp_Factor'' |- | ''Factor'' | β ''Primary'' | | | ''Factor'' ''PowOp_Primary'' |- | ''Primary'' | β ''number'' | | | ''variable'' | | | ''Open'' ''Expr_Close'' |- | ''AddOp'' | β + | | | − |- | ''MulOp'' | β * | | | / |- | ''PowOp'' | β ^ |- | ''Open'' | β ( |- | ''Close'' | β ) |- | ''AddOp_Term'' | colspan=3 | β ''AddOp'' ''Term'' |- | ''MulOp_Factor'' | colspan=3 | β ''MulOp'' ''Factor'' |- | ''PowOp_Primary'' | colspan=3 | β ''PowOp'' ''Primary'' |- | ''Expr_Close'' | colspan=3 | β ''Expr'' ''Close'' |} Since there are no Ξ΅-rules, step "DEL" does not change the grammar. After step "UNIT", the following grammar is obtained, which is in Chomsky normal form: :{| |- | ''S''<sub>0</sub> | β ''number'' | | | ''variable'' | | | ''Open'' ''Expr_Close'' | | | ''Factor'' ''PowOp_Primary'' | | | ''Term'' ''MulOp_Factor'' | | | ''Expr'' ''AddOp_Term'' | | | ''AddOp'' ''Term'' |- | ''Expr'' | β ''number'' | | | ''variable'' | | | ''Open'' ''Expr_Close'' | | | ''Factor'' ''PowOp_Primary'' | | | ''Term'' ''MulOp_Factor'' | | | ''Expr'' ''AddOp_Term'' | | | ''AddOp'' ''Term'' |- | ''Term'' | β ''number'' | | | ''variable'' | | | ''Open'' ''Expr_Close'' | | | ''Factor'' ''PowOp_Primary'' | | | ''Term'' ''MulOp_Factor'' |- | ''Factor'' | β ''number'' | | | ''variable'' | | | ''Open'' ''Expr_Close'' | | | ''Factor'' ''PowOp_Primary'' |- | ''Primary'' | β ''number'' | | | ''variable'' | | | ''Open'' ''Expr_Close'' |- | ''AddOp'' | β + | | | − |- | ''MulOp'' | β * | | | / |- | ''PowOp'' | β ^ |- | ''Open'' | β ( |- | ''Close'' | β ) |- | ''AddOp_Term'' | colspan=3 | β ''AddOp'' ''Term'' |- | ''MulOp_Factor'' | colspan=3 | β ''MulOp'' ''Factor'' |- | ''PowOp_Primary'' | colspan=3 | β ''PowOp'' ''Primary'' |- | ''Expr_Close'' | colspan=3 | β ''Expr'' ''Close'' |} The ''N''<sub>''a''</sub> introduced in step "TERM" are ''PowOp'', ''Open'', and ''Close''. The ''A''<sub>''i''</sub> introduced in step "BIN" are ''AddOp_Term'', ''MulOp_Factor'', ''PowOp_Primary'', and ''Expr_Close''.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)