Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Chomsky normal form
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
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''.
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
Chomsky normal form
(section)
Add topic