Presentation is loading. Please wait.

Presentation is loading. Please wait.

ISBN 0-321-19362-8 Chapter 3 More Syntax –BNF –Derivations –Practice.

Similar presentations


Presentation on theme: "ISBN 0-321-19362-8 Chapter 3 More Syntax –BNF –Derivations –Practice."— Presentation transcript:

1 ISBN 0-321-19362-8 Chapter 3 More Syntax –BNF –Derivations –Practice

2 Copyright © 2004 Pearson Addison-Wesley. All rights reserved.3-2 BNF: Grammar Rules A rule has a left-hand side (LHS) and a right-hand side (RHS), and consists of terminal and nonterminal symbols A grammar is a finite nonempty set of rules An abstraction (or nonterminal symbol) can have more than one RHS  | begin end

3 Copyright © 2004 Pearson Addison-Wesley. All rights reserved.3-3 BNF vs. EBNF BNF:  + | - |  * | / | EBNF:  {(+ | -) }  {(* | /) }

4 Copyright © 2004 Pearson Addison-Wesley. All rights reserved.3-4 Examples EBNF for a switch statement BNF for Boolean expressions (&& || !)

5 Copyright © 2004 Pearson Addison-Wesley. All rights reserved.3-5 Derivations A derivation is a repeated application of rules, starting with the start symbol and ending with a sentence (all terminal symbols) Derivations can be used to generate all the possible sentences in a grammar

6 Copyright © 2004 Pearson Addison-Wesley. All rights reserved.3-6 An example grammar  | ;  =  a | b | c | d  + | -  | const => => = => a = => a = + => a = b + => a = b + const

7 Copyright © 2004 Pearson Addison-Wesley. All rights reserved.3-7 Parse Tree A hierarchical representation of a derivation const a = b +

8 Copyright © 2004 Pearson Addison-Wesley. All rights reserved.3-8 Assignment grammar  =  A | B | C  + | * | ( ) | Derivation for: A = A * (B + ( C * A))

9 Copyright © 2004 Pearson Addison-Wesley. All rights reserved.3-9 Assignment grammar  =  A | B | C  + |  * |  ( ) | Derivation for: A = (A + B) * C


Download ppt "ISBN 0-321-19362-8 Chapter 3 More Syntax –BNF –Derivations –Practice."

Similar presentations


Ads by Google