CSCI-2325 CLite Syntax MOHAMMAD T. IRFAN Review of definiBons - - PDF document

csci 2325 clite syntax
SMART_READER_LITE
LIVE PREVIEW

CSCI-2325 CLite Syntax MOHAMMAD T. IRFAN Review of definiBons - - PDF document

9/15/14 CSCI-2325 CLite Syntax MOHAMMAD T. IRFAN Review of definiBons Senten+al form Sentence Grammar CFG/BNF Le:-recursive vs. right-recursive


slide-1
SLIDE 1

9/15/14 ¡ 1 ¡

CSCI-­‑2325 ¡ CLite ¡Syntax

MOHAMMAD ¡T. ¡IRFAN

Review ¡of ¡definiBons

§ ¡Senten+al ¡form ¡ § ¡Sentence ¡ § ¡Grammar ¡– ¡CFG/BNF ¡

§ Le:-­‑recursive ¡vs. ¡right-­‑recursive ¡produc+on ¡

§ ¡Parse ¡tree/deriva+on ¡

§ ¡Le:-­‑most ¡vs. ¡right-­‑most ¡deriva+on ¡

§ ¡Ambiguous ¡grammar ¡ § ¡Language ¡

slide-2
SLIDE 2

9/15/14 ¡ 2 ¡

The ¡dangling-­‑else ¡problem

§ ¡Q: ¡How ¡does ¡C/C++ ¡resolve ¡it? ¡ § ¡“The ¡else ¡ambiguity ¡is ¡resolved ¡by ¡connec+ng ¡an ¡else ¡with ¡ the ¡last ¡encountered ¡else-­‑less ¡if.” ¡[Stroustrup, ¡1991] ¡

¡ Concrete ¡Syntax ¡(EBNF): ¡ Hierarchy ¡of ¡categories

Program → int main ( ) { Declarations Statements } Declarations → { Declaration } Declaration → Type Identifier [ [ Integer ] ] { , Identifier [ [ Integer ] ] } Type → int | bool | float | char Statements → { Statement } Statement → ; | Block | Assignment | IfStatement | WhileStatement Block → { Statements } Assignment → Identifier [ [ Expression ] ] = Expression ; IfStatement → if ( Expression ) Statement [ else Statement ] WhileStatement → while ( Expression ) Statement

slide-3
SLIDE 3

9/15/14 ¡ 3 ¡

Expression → Conjunction { || Conjunction } Conjunction → Equality { && Equality } Equality → Relation [ EquOp Relation ] EquOp → == | != Relation → Addition [ RelOp Addition ] RelOp → < | <= | > | >= Addition → Term { AddOp Term } AddOp → + | - Term → Factor { MulOp Factor } MulOp → * | / | % Factor → [ UnaryOp ] Primary UnaryOp → - | ! Primary → Identifier [ [ Expression ] ] | Literal | ( Expression ) | Type ( Expression )

Concrete ¡Syntax ¡(cont…)

Note: ¡Operators ¡and ¡ punctua+on ¡symbols ¡are ¡ part ¡of ¡lexical ¡syntax ¡

Identifier → Letter { Letter | Digit } Letter → a | b | … | z | A | B | … | Z Digit → 0 | 1 | … | 9 Literal → Integer | Boolean | Float | Char Integer → Digit { Digit } Boolean → true | False Float → Integer . Integer Char → ‘ ASCII Char ‘

Lexical ¡Syntax: ¡ ¡ Lexemes ¡à ¡Tokens

slide-4
SLIDE 4

9/15/14 ¡ 4 ¡

Abstract ¡Syntax ¡Tree

Parse ¡Tree ¡for ¡ ¡ z ¡= ¡x ¡+ ¡2*y; ¡

  • Fig. ¡2.9
slide-5
SLIDE 5

9/15/14 ¡ 5 ¡ Abstract ¡Syntax ¡Tree ¡for ¡ ¡ z ¡= ¡x ¡+ ¡2*y; ¡

  • Fig. ¡2.10

OpBonal ¡Reading

¡ Pages ¡49 ¡-­‑-­‑ ¡54 ¡