324-lecture15 - Principles Principles of Programming...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
Principles of Programming Languages Lecture 15 University of Toronto Wael Aboulsaadat [email protected] http://portal.utoronto.ca/ 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Grammar: introduction Grammar: – A Grammar is a formalism that describes which sequence of terminals are meaningful in a PL. Formally, it is defined as a quadruple ( N , T , P , S ) where: N is the set of symbols called Nonterminals T is the set of symbols called Terminals P is the set of productions S subsetof N is the nonterminal called the starting symbol University of Toronto – Example: G = (N,T,P,S) where N = {S} , T = {a,b}, P={S b a S, S b b S, S b } Production: A production is a rule of the form X b Y where X is a string of symbols ( terminals or nonterminals ) containing at least one nonterminal , and Y is a string of symbols ( terminals or nonterminals ) 2
Background image of page 2
Grammar: Grammar: example example Naive Grammar for noun phrases! noun-phrase adjective-list noun adjective-list adjective adjective* noun day | park adjective lovely | secluded | sunny Nonterminals rminals S production University of Toronto 3 terminals
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Language – The collection of all valid strings e.g. the language of noun phrases = { lovely park , sunny lovely park , lovely day , …. .} Grammar: definitions noun-phrase adjective-list noun adjective-list adjective adjective* noun day | park adjective lovely | secluded | sunny University of Toronto Sentence – A finite sequence of terminals , constructed according to the rules of the grammar for that PL e.g. lovely park 4
Background image of page 4
A derivation is a sequence of productions that begin with the start symbol (noun-phrase in this case) and derives a valid string in the language called the yield E.g. Is sunny day a valid sentence in the language of noun phrases? oun hrase djective st ay Grammar: definitions University of Toronto noun-phrase adjective-list day adjective-list sunny Two productions were used to generate the yield sunny day Sentential form – A finite sequence of terminals and non-terminals constructed according to the rules of the grammar for that PL 5
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Grammar: derivation Grammar: derivation types types Leftmost Derivation – In a leftmost derivation , the replaced nonterminal is always the leftmost nonterminal. noun-phrase adjective-list noun adjective-list adjective adjective* noun day | park adjective lovely | secluded | sunny University of Toronto Rightmost Derivation – In a rightmost derivation , the replaced nonterminal is always the rightmost nonterminal. 6 noun-phrase adjective-list noun adjective-list adjective adjective* noun day | park adjective lovely | secluded | sunny
Background image of page 6
Grammar: Grammar: parsers parsers Top-down Parsers 1. Start from the grammar 2. Expand the top most rule 3. Keep expanding till you get a yield similar to input or error – E.g. LL parsers ( L eft-to-right scan, Left most derivation) University of Toronto Bottom-up Parsers 1. Start from the input code, read a token 2. Find the most basic rule that matches that token,
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 45

324-lecture15 - Principles Principles of Programming...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online