{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Leftmost m the rule to be followed is

Info icon This 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: <M> can be <P>*<P>. So we go left and check the first <P>, <P> can an Integer and finally a 5. Now, we have to go back to the first level we left incomplete, which is the <P>*<P>, because we need to complete the second <P>, so that <P> is an Integer and finally a 2. Now we need to go back until an incomplete level, that would be <E> to the top, and we can say now that <E> can be <M> + <M> One more example, consider the following expression: 5 * (2 + 10) Homework. Do the derivation trees for the following two expressions. • (5 * 2) + 10 • 5 * 2 * 10 2. Syntax Diagrams As for lexical analysis there is a way to express rules using text (Regular expressions) or using a visual diagram (DFA); for syntax we also have these two options. We can use the BNF or EBNF (text- based) or we can use syntax diagrams (visual- based). The previous grammar can be expressed with the followings diagrams: 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 Notice that terminal elements are symbolized with circles, when non- terminals are represented with rectangles. Notice that the arrowheads represent the flow on the diagram, “or” expressions are represented with diverse paths coming out from the root of each diagram. Now, what if we want to define a new grammar that is able to recognize logical, relational, and arithmetical operations? And use it to evaluate the following expression: 10 + 20 > 15 & - 10 != 1 | 20 / 10 + 1 > 5 The first step is to define the precedence of all this operations. So logical operations are the ones with higher precedence, then comes the relational, and then arithmetical. Notice that this precedence is defined by how one rule calls (uses) a subsequent rule. The diagrams below represent the grammar, where <E> is the starting symbol. Notice that according with the diagram, <E> is expressed in terms of <A>. Notice that the precedence of the operations is defined by how one rule calls (uses) a subsequent rule. Homework. Generate the BNF or EBNF for these diagrams....
View Full Document

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern