作者stevennick (空中精灵小金刚)
看板TransCSI
标题Re: [问题] 何谓BNF??
时间Sat May 26 00:02:05 2007
※ 引述《x0315b100 (飞来飞去)》之铭言:
: 在课本上看到了...
: 整傻住
: 什麽是BNF阿??
: 全名又是什麽??
: 希望大大能举个例子说明一下@@"
: 麻烦了~
Backus-Naur Form
– Invented by John Backus to describe Algol 58
– BNF is equivalent to
context-free grammars
– BNF is
a metalanguage used to describe another language
– In BNF, abstractions are used to represent classes of syntactic
structures--they act like syntactic variables
(also called nonterminal symbols )
BNF Fundamentals
‧
Non-terminals: BNF abstractions
‧
Terminals: lexemes and tokens
‧
Grammar: a collection of rules
– Examples of BNF rules:
<ident_list> → identifier | identifier, <ident_list>
<if_stmt> → if <logic_expr> then <stmt>
supplement:
The example Grammar :
<program> → <stmts>
<stmts> → <stmt> | <stmt> ; <stmts>
<stmt> → <var> = <expr>
<var> → a | b | c | d
<expr> → <term> + <term> | <term> - <term>
<term> → <var> | const
For
a = b + const
it's derivation is:
<program> => <stmts>
=> <stmt>
=> <var> = <expr>
=> a = <expr>
=> a = <term> + <term>
=> a = <var> + <term>
=> a = b + <term>
=> a = b + const
Read "Program Language" books for more detail.
--
空中精灵。SkyElf/Stevennick
要重新在空中飞翔‧遨游全世界 未来正在我的手中 一点一滴的实现
My Blog:
http://stevennick.dyndns.org/
My Podcasting:
http://podcast.blog.webs-tv.net/skyelf
____________________________________________________________________________
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 219.68.140.151
1F:推 x0315b100:谢谢大大喔~ 05/28 00:33