syntax -- grammar: putting together keywords etc the right way semantics -- the meaning S -> N V N . N -> cat | ufo | apple | fox | dog | hotdog | ipod | itec V -> bite | run | jump | hit | love | spin | hear cat bite ufo. S -> N V N . -> cat V N . -> cat V ufo . - > cat bite ufo . A derivation: Take a string containing a nonterminal, and replace that nonterminal with a right-hand-side from the grammar. We say a string can be "dervied" from S if there is a series of 0 or more derivations that start from "S" and reach the target string. For class, we'll use *left-most* derivations: always replace the left-most nonterminal when making one derivation. S -> N V N . -> cat V N . -> cat bite N . - > cat bite ufo . This is also equivalent to a tree: S / | \ \ N V N . | | | cat bite ufo The "parse tree", or "syntax tree": --------- new grammar -------- S -> NP CV NP . NP -> ART N ART -> a | an | the CV -> V s | V ed N -> cat | ufo | apple | fox | dog | hotdog | ipod | mongo | itec V -> bite | run | jump | hit | love | spin | hear t/f: I can derive "the cat biteed the ufo." from S ? How about "a apple spin hotdogs."? S -> NP CV NP . -> ART N CV NP . -> a N CV NP . -> a apple CV NP . -> a apple V s NP . -> a apple spin s NP. -- oops, doesn't seem possible. ---------------- E -> E + E | E * E | N N -> any number Can E derive "2+3*4" ? Yes. E -> E + E -> N + E // n.b. you can't jump to "2+E" -> 2 + E -> 2 + E * E -> 2 + N * E -> 2 + 3 * E -> 2 + 3 * N -> 2 + 3 * 4 E / | \ E + E | /|\ N E * E | | | 2 N N | | 3 4 HOWEVER, there is a second way to derive "2+3*4" from E, using a different rule on the very first derivation: E -> E * E -> ... -> 2 + 3 * 4. E / | \ E * E / | \ | E + E N | | | N N 4 | | 2 3 A grammar that has some string with two different parse trees is called _____ambiguous_____. We don't like ambiguous. (Java: 39 operators, with 13 levels of precedence...) VD -> TYPE IDENT ; | ACCMOD TYPE IDENT ; ACCMOD -> public | private | synchronized TYPE -> int | char | short | double | IDENT IDENT -> any valid identifier