One goal is to have non ambiguous grammars

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: other <E>. Now, we now that an <E> could be <E> * <E>, that is the rule we use, and again, for each <E> we can say that and <E> can be an Integer. Let see another example: 10 + 20 + 30. For this case, we will have problems with ambiguity due to the fact even though we start from the left side there is an option to find at least two different derivation trees. We start with the first rule: <E> à༎ <E> + <E>; however, when it comes to define the leftmost <E> there is an option to use the rule <E>à༎ integer or <E> à༎ <E> + <E>. This problem is caused because we have several expressions for the same element <E>. So, the solution is to have the start symbol, e.g., <E> and then the first rule in terms of other elements and the same for the rest of the rules. For example, the previous grammar could be expressed as follows: <E> à༎ <M> + <M> <M> à༎ <P> * <P> <P> à༎ (<N>) | <N> <N> à༎ Integer In this grammar <E> is the starting element and it is in terms of M, M is in terms of P, P is in terms of N, and N in terms of a terminal element. With this grammar there is not an option to have more that one derivation tree, i.e., it is not ambiguous. Note that by doing this, we are also solving problems with the precedence of the operations + and *. However, this grammar has a problem, all the expressions need to have an addition, due to the first rule <E> à༎ <M> + <M>. To fix this problem we need to modify the grammar to be the following: NOTE 1: The notation used here is different from the one reviewed on class to match it with the textbook. NOTE 2: 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> à༎ (<N>) | <N> <N> à༎ Integer The start symbol is still <E> and the first rule is still the first on the list. However, by adding the “{“ and “}” symbols we are...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online