{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Eg e and then the first rule in

Info iconThis preview shows page 1. Sign up to view the full content.

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

Unformatted text preview: saying that <E> could be <M> added with 0 or more <M>’s terms. Something similar happens with the rule <M>. This new notation is named Extended BNF or EBNF. Where the symbols “{“ and “}” are used to represent a repetition of elements (0 or more) and symbols “[“ and “]” are used to represent an optional element (0 or 1). Now if we have the expression 10 + 20 + 30. In the graph above, the first rule to be followed is <E>à༎<M> + <M>, then for the leftmost <M> the rule to be followed is that <M> à༎ <P>, then <P> à༎ <N>, and <N>à༎ Integer. Then, we go back to the first rule that is incomplete, in this case, the rightmost <M>. Then, we go down to complete it. We go back again, to find out that there is another “+” symbol, so we need an extra <M>, and again we complete it. Now, if we have the following expression: 5 * (1+7) + 6 * 5 E M P * P N ( N ) Integer 5 Notice that when we get to the point where we use the rule <P>à༎ (<N>) we got stick, due to the fact <N> can only be an Integer, and we have a whole expression there “1 + 7”. So, we need to modify the grammar again, to be the following. NOTE: The grammar here was updated (and it is different from the one reviewed in class) to make it simpler. It is the same that appears in the slides. <E> à༎ <M> {+ <M>} <M> à༎ <P> {* <P>} <P> à༎ (<E>) | Integer So going back to the expression: 5 * (1+7) + 6 * 5. We can say that <P>à༎(<E>) and that <E>à༎<M>+<M>. When we finish with that expression we go back, we finish the (E) expression, so we go back, the P*P is complete, so we go back all the way to <E> and notice that we have another “+” symbol so we use the {+ <M>} section of the rule and complete it. One more example, consider the following expression: 5 * 2 + 10 The first rule is <E>, the next rule will be <M> (alone) because the next character is a ´*´, so we cannot apply the <M> + <M>. Now...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online