Chapter 3 Syntax Part 2 - PowerPoint PPT Presentation

1 / 14
About This Presentation
Title:

Chapter 3 Syntax Part 2

Description:

a - x a b - a b - a b b - y b 5. UMBC. Exercises With EBNF/BNF ... right - letter = right | (2) letter. letter - a | b | .... z. 7. UMBC ... – PowerPoint PPT presentation

Number of Views:17
Avg rating:3.0/5.0
Slides: 15
Provided by: Shmue2
Category:
Tags: chapter | letter | part | syntax

less

Transcript and Presenter's Notes

Title: Chapter 3 Syntax Part 2


1
Chapter 3Syntax Part 2
  • CMSC 331
  • Shon Vick

2
EBNF to BNF
ltgoalgt -gt ltagtxy ltbgt ltagt -gt z z ltbgt
-gt x y z
3
EBNF to BNF
ltexpgt -gt term ltexpgt lttermgt -gt ltfactorgt
lttermgt ltfactorgt -gt NUMBER ( ltexpgt )
4
BNF to EBNF
ltggt - gt ltagt ltggt -gt x ltbgt ltagt ltagt -gt y ltagt -gt x
ltagt ltbgt -gt ltagt ltbgt -gt ltagt ltbgt ltbgt -gt y ltbgt
5
Exercises With EBNF/BNF
  • Give a BNF/EBNF for an expression
  • with an odd number of as followed by
  • an even number of bs
  • Give the BNF/EBNF for an expression
  • with some number of as following by 1
  • plus that number of bs

6
Associativity
Consider the following productions list -gt
list digit
(1) list -
digit digit digit -gt
0 1 2 3 4 5 6 7 8 9
right -gt letter right
(2)
letter letter -gt a b .... z
7
Associativity
  • What productions would be generated for the
    following parse trees for the input
  • 9 - 5 2
  • a b c
  • How can we determine this from the grammar as
    given

8
Precedence
  • We've shown how to handle associativity in a
    grammar, how about precedence
  • Does 9 5 2 mean
  • ( 9 5 ) 2
  • 9 ( 5 2 )

9
Precedence
E -gt E T
E - T T T
-gt T F
T / F F F -gt
digit
( E )
What binds tighter? or
10
Left Recursion and its Removal
Suppose we have the production with the following
form A -gt A a
b We may substitute the following two
productions A -gt b A'
A' -gt a A' e
11
Generalization
  • A -gt A a1 A a2 A am b1 b2
    bn
  • ________________________________________
  • -gt b1 A b2 A bn A
  • -gt a1 A a2 A amA e

12
Semantic Specification
  • Operational semantics
  • denotational semantics
  • axiomatic semantics

13
Operational Semantics
  • Defines meaning of any statement in a language by
    providing a means of translating that statement
    into an equivalent statement in another language.

14
Axiomatic Semantics
  • Logical assertions.
  • For each syntactic definition, the axiomatic
    method specifies the assertions that are assumed
    to be true before the execution of the syntactic
    unit (precondition) and the assertions the must
    be true after the units execution
    (postcondition).
Write a Comment
User Comments (0)
About PowerShow.com