![]() |
![]() |
|
Due
14:00in class, on D2L
I suggest using a text-editor like Word (or LibreOffice or DrRacket or similar): The derivations are best written in a text-editor where you can copy/paste one line and replace a single non-terminal to create the next line. But for parse-trees, I recommend drawing them freehand.
Your hardcopy should include your answers, and your (presumably-hand-drawn) trees. Including images is optional for the pdf; I will use your hardcopy to grade the trees.
If you do want to incorporate your images (in the single pdf), you can of course do so via Word/LibreOffice/etc.; you may also do so via DrRacket's Insert » Insert Image…, and then printing to pdf.
Your name and the assignment-number must be in a comment at the start of the file, along with a link to this assignment page.
I encourage you to actually put all the nonterminals in upper-case (or at least first-letter-upcased), just to make it easier to tell terminals from non-.
<JsFunc> → function <JsIdent>( <JsIdents> ) { <JsBody> } |
For the grammar rules, write them as in class: in basic BNF
using “→” (and “
(2pts)
As we consider how to define
Working towards a solution, the programmer MC Carthy comes up with the following attempt for a nonterminal that generates repetitions of the letter “x”, separated by commas and ending in a semicolon (which we won't end with in our part (c), next):
<XS> → ; | x; | x, <XS> |
Prove that this grammar is not correct, by giving a derivation2 of some string which is not a valid comma-separated list-of-“x”s (ending in a semicolon).
(6pts) Generating a grammar
Give a grammar for Java's boolean expressions.
(That is: a grammar describing exactly what you are allowed to put
inside the parentheses of a Java
TODO Ian: first ask for a parse tree from the book's Example 2.4, for something like “2 + (x * -4) ”. Students worked on linear-structures in previous examples, and continue that rather than seeing a tree-structure when asked for such a branching structure.
For this problem, assume that you already have grammar rules for
a Java numeric expression
(“
hints: Make sure you can derive expressions like “!!!!!!false ” and “((((targetFound)))) ”, in addition to the expression below. You might want to ask yourself:For comparison, see that book Example 2.4, and what is allowed on either side of binary operators like “
- What is allowed to follow a “
! ”?- What is allowed on each side of “
|| ”?+ ”, and also what it allowed to follow the unary-negation “- ”.
Using your grammar, give a parse tree (not a derivation) for:
In the tree, for children of
This page licensed CC-BY 4.0 Ian Barland Page last generated | Please mail any suggestions (incl. typos, broken links) to ibarland ![]() |