0603 notes

# In order to add these new patterns

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

This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: n integer or a float (if it has the decimal point). CSE 340 Principles of Programming Languages Summer 2013 Lecture 3 – Date: June 3rd, 2013 Warning! These notes are not meant to replace your notes from class. They are not meant to be exhaustive. If you see a topic that is mentioned here and not elaborated upon, you should go back to your class notes for details. SYNTAX ANALYZER Once the lexical analysis is done, what we have is bunch of tokens. We know for sure that all those tokens are valid. The next step is to review the syntax, i.e., that the words follow the rules to be combined. This rules form the grammar of the language. 1. BNF Grammars can be expressed using the BNF that is the text- based form to express a grammar. BNF uses two elements, terminal and non- terminal elements. When an expression is evaluated to verify if it follows or not a grammar expressed in a BNF, we create a derivation tree. This three shows the followed path to cover the expression using the rules in the grammar. One goal is to have non- ambiguous grammars. A grammar is ambiguous when there is possible to create more than one derivation tree to represent an expression. So, how to avoid ambiguity? Here are some rules: 1. It is needed to define a symbol that would be used as the starting symbol. 2. It is needed to define which is the first rule of the grammar. For default, the first rule in the grammar would be the first rule in the list and we should use the leftmost derivation principle. Given the following grammar <E> à༎ <E> + <E> <E> à༎ <E> * <E> <E> à༎ (<E>) <E> à༎ Integer According with previous rules the first rule in the grammar is the first in the list; thus, <E> is the starting symbol. Beside that we need to follow the leftmost derivation. Given that, to evaluate the previous expression we will do the following: And if we have the following expression: 10 + 20 * 30. So we took the first rule <E> à༎ <E> + <E>, and start from the left side, that is how we identify that we need an Integer and that the 10 fits that rule. Then we know that we need a plus symbol, and an...
View Full Document

## This note was uploaded on 09/29/2013 for the course CSE 340 taught by Professor Richa during the Spring '13 term at Arizona State University.

Ask a homework question - tutors are online