Note. These notes are based on the Sebesta text. The tree diagrams in these slides are from the lecture slides provided in the instructor resources for the text, and were made by David Garrett. Introduction: syntax and semantics.
Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.
L1 = { 0, 00, 1, 11 }
G1 = ( {0,1}, {S}, { S0, S00, S1, S11 }, S )
L2 = { the dog chased the dog, the dog chased a dog, a dog chased the dog, a dog chased a dog, the dog chased the cat, … }
G2 = ({a, the, dog, cat, chased},
{S, NP, VP, Det, N, V},
{S NP VP, NP Det N, Det a  the,
N dog  cat, VP V  VP NP, V chased},
S )
Notes: S = Sentence, NP = Noun Phrase , N = Noun
VP = Verb Phrase, V = Verb, Det = Determiner
<assign> → <var> = <expression>
<if_stmt> → if <logic_expr> then <stmt>
<if_stmt> → if <logic_expr> then <stmt> else <stmt>
<if_stmt> → if <logic_expr> then <stmt>
 if <logic_expr> then <stmt> else <stmt>
<ident_list> > ident
 ident , <ident_list>
S NP VP
Det N VP
the N VP
the dog VP
the dog V NP
the dog chased NP
the dog chased Det N
the dog chased a N
the dog chased a cat
G2 = ({a, the, dog, cat, chased},
{S, NP, VP, Det, N, V},
{S NP VP, NP Det N, Det a  the,
N dog  cat, VP V  VP NP, V chased},
S)
S NP VP
Det N VP
the N VP
the dog VP
the dog V NP
the dog chased NP
the dog chased Det N
the dog chased a N
the dog chased a cat
L3 = { 0, 1, 00, 11, 000, 111, 0000, 1111, … }
G3 = ( {0, 1},
{S, ZeroList, OneList},
{S ZeroList  OneList,
ZeroList 0  0 ZeroList,
OneList 1  1 OneList },
S )
S ZeroList
0 ZeroList
0 0 ZeroList
0 0 0 ZeroList
0 0 0 0
S OneList
1 OneList
1 1 OneList
1 1 1
<program> > <stmtlist>
<stmtlist> > <stmt>
 <stmt> ; <stmtlist>
<stmt> > <var> = <expr>
<var> > a
 b
 c
 d
<expr> > <term> + <term>
 <term>  <term>
<term> > <var>
 const
<program> => <stmts>
=> <stmt>
=> <var> = <expr>
=> a = <expr>
=> a = <term> + <term>
=> a = <var> + <term>
=> a = b + <term>
=> a = b + const
<program>
<stmts>
<stmt>
<var>
=
<expr>
a
<term>
+
<term>
<var>
const
b
<proc_call> > ident [(<expr_list>)]
<term> > <term>(+) const
<ident> > letter {letterdigit}
<expr> > <expr> + <term>
 <expr>  <term>
 <term>
<term> > <term> * <factor>
 <term> / <factor>
 <factor>
<expr> > <term> {(+  ) <term>}
<term> > <factor> {(*  /) <factor>}
The following grammar is ambiguous:
<expr> > <expr> <op> <expr>  const
<op> > /  
The grammar treats the '/' and '' operators equivalently.
<expr> > <expr> <op> <expr>  const
<op> > /  
<expr>
<expr>
<expr>
<op>
<expr>
<expr>
<op>
<op>
<expr>
<expr>
<op>
<expr>
<expr>
<op>
<expr>
const

const
/
const
const

const
/
const
<expr> > <expr>  <term>  <term>
<term> > <term> / const  const
<expr>
<expr>

<term>
<term>
<term>
/
const
const
const
Below are some links to grammars for real programming languages. Look at how the grammars are expressed.
In the ones listed below, find the parts of the grammar that deal with operator precedence.
<assignmentexpression>
<conditionalexpression>
<logicalORexpression>
<logicalANDexpression>
<inclusiveORexpression>
<exclusiveORexpression>
<ANDexpression>
<equalityexpression>
<relationalexpression>
<shiftexpression>
<additiveexpression>
+
<additiveexpression>
<multiplicativeexpression>
<multiplicativeexpression>
<multiplicativeexpression>
<castexpression>
*
<castexpression>
<unaryexpression>
<castexpression>
<unaryexpression>
<postfixexpression>
<unaryexpression>
<postfixexpression>
<primaryexpression>
<postfixexpression>
<primaryexpression>
<constant>
<primaryexpression>
<constant>
3
<constant>
2
5
<expr> <expr> + <term>
<term> <term> * <factor>
<factor> <variable>  <constant>  “(” <expr> “)”
<expr> > <expr>  <expr>  <term>
<term> > <var>  <const>  “(” <expr> “)”
<expr>
<expr>
<expr>
<expr>
<expr>

<expr>
<expr>

<expr>
<expr>
<expr>
<expr>
<expr>


<term>
<term>
<term>
<term>
<term>
<term>
<expr> > <expr>  <term>  <term>
<term> > <var>  <const>  “(” <expr> “)”
<expr>
<expr>
<expr>

<term>
<expr>
<term>

<term>
Dealing with fixedsize numeric representations
Theoryvs.Reality