=> <var> = <expression> <stmt_list> | <stmt> ; <stmt_list> begin ; end <stmt> <var> = <expression> => begin A = <expression> ; <stmt_list> end <var> A | B | C => begin A = <var> + <var> ; <stmt_list> end <expression> <var> + <var> => A = B + <var> <stmt_list> begin ; end | <var> - <var> | <var> => begin A = B + C ; <stmt_list> end => begin A = B + C ; <stmt> end => A = B + C <var> = <expression> begin ; end => begin A = B + C ; B = <expression> end => begin A = B + C ; B = <var> end => A = B + C B = C begin ; end Exercise #1 Given Grammar Leftmost Derivation w/ Target Syntax A DOG PETS A DOG <sentence> -> <subject> <predicate> <subject> -> <article> <noun> <predicate> -> <verb> <sentence> -> Answer: <direct-object> -> <article> <noun> => <article> -> THE | A A <noun> -> MAN | DOG A A <verb> -> BITES | PETS A DOG A DOG A DOG PETS A DOG PETS A DOG Exercise #2 Given Grammar Rightmost Derivation w/ Target Syntax THE MAN BITES A DOG <sentence> -> <subject> <predicate> <subject> -> <article> <noun> (rightmost!!) <predicate> -> <verb> Answer: => <subject> <subject> <direct-object> -> <article> <noun> <article> -> THE | A <subject> <noun> -> MAN | DOG <subject> <verb> -> BITES | PETS <subject> <verb> A <subject> BITES A <article> <noun> BITES A
| <stmt> ; <stmt_list> <stmt> <var> = <expression> <var> A | B | C <expression> <var> + <var> | <var> - <var> | <var> => begin <var> = <expression> ; <stmt_list> end => begin A = <expression> ; <stmt_list> end => begin A = <var> + <var> ; <stmt_list> end => begin A = B + <var> ; <stmt_list> end => begin A = B + C ; <stmt_list> end => begin A = B + C ; <stmt> end => begin A = B + C ; <var> = <expression> end => begin A = B + C ; B = <expression> end => begin A = B + C ; B = <var> end => begin A = B + C ; B = C end Exercise #1 Given Grammar Leftmost Derivation w/ Target Syntax <sentence> -> <subject> <predicate> <subject> -> <article> <noun> <predicate> -> <verb> <direct-object> -> <article> <noun> <article> -> THE | A <noun> -> MAN | DOG <verb> -> BITES | PETS A DOG PETS A DOG <sentence> -> Answer: => A A A A DOG A DOG A DOG PETS A DOG PETS A DOG Exercise #2 Given Grammar Rightmost Derivation w/ Target Syntax <sentence> -> <subject> <predicate> <subject> -> <article> <noun> <predicate> -> <verb> <direct-object> -> <article> <noun> <article> -> THE | A <noun> -> MAN | DOG <verb> -> BITES | PETS THE MAN BITES A DOG (rightmost!!) Answer: => <subject> <subject> <subject> <subject> <subject> <verb> A <subject> BITES A <article> <noun> BITES A
GrammarsAndParseTrees(Syntax).docx