csci 2325 clite syntax
play

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


  1. 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 ¡produc+on ¡ § ¡Parse ¡tree/deriva+on ¡ § ¡Le:-­‑most ¡vs. ¡right-­‑most ¡deriva+on ¡ § ¡Ambiguous ¡grammar ¡ § ¡Language ¡ 1 ¡

  2. 9/15/14 ¡ 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 � � 2 ¡

  3. 9/15/14 ¡ Concrete ¡Syntax ¡(cont…) Expression → Conjunction { || Conjunction } Conjunction → Equality { && Equality } � Equality → Relation [ EquOp Relation ] EquOp → == | != � Relation → Addition [ RelOp Addition ] Note: ¡Operators ¡and ¡ punctua+on ¡symbols ¡are ¡ RelOp → < | <= | > | >= part ¡of ¡lexical ¡syntax ¡ Addition → Term { AddOp Term } AddOp → + | - Term → Factor { MulOp Factor } � MulOp → * | / | % Factor → [ UnaryOp ] Primary UnaryOp → - | ! Primary → Identifier [ [ Expression ] ] | Literal | ( Expression ) | Type ( Expression ) � Lexical ¡Syntax: ¡ ¡ Lexemes ¡ à ¡Tokens 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 ‘ 3 ¡

  4. 9/15/14 ¡ Abstract ¡Syntax ¡Tree Parse ¡Tree ¡for ¡ ¡ z ¡= ¡x ¡+ ¡2*y; ¡ Fig. ¡2.9 4 ¡

  5. 9/15/14 ¡ Abstract ¡Syntax ¡Tree ¡for ¡ ¡ z ¡= ¡x ¡+ ¡2*y; ¡ Fig. ¡2.10 OpBonal ¡Reading ¡ Pages ¡49 ¡-­‑-­‑ ¡54 ¡ 5 ¡

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend