Once you understand the original program

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: 2013 Lecture 1 – Date: May 29th, 2013 FUNDAMENTALS OF LEXICAL ANALYSIS 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. 1. Compiling The following table shows examples of different errors. Text in red represents the error on the line. For the definition of lexical and syntax errors each line was considered independently while for the semantic errors all the lines were considered as a single piece of code. Notice that when we are compiling a code, once an error is detected, there is not need to keep reviewing for further errors. Expression int x = 5; float y = “hello”; String @z = “9.5”; int x= cse340; if (x>14) while (5==5) if (int a) a = 1; x = x; y = 13.45.0; int me = 9999900000111122211111122223443483045830948; while {x != 9} ( ); int {x} = 10; Four steps compose a compiler: 1. Lexical analysis 2. Syntax analysis 3. Semantical analysis 4. Code generation Lex Syn Sem x x x x x ? x x 2. Lexical Analysis It has been defined that a language is composed by words and rules. Where rules should be understood as the grammar that define the language. Alphabet – set of characters valid in a particular language String – combination of characters Patterns – are the rules to form a word Word - is a string that follows a valid pattern in a particular language. Token –Words have a type or a category (a particular pattern defines a category), these categories are named tokens, such as String (hello), an integer number (5557), a float number (5.7), and ID (x), characters (‘x’), operators (= + - * /), delimiters ([ ] ( ) { } ) Example 1. This line has 4 words, we know that there are 4 words because they follow a pattern; thus it is possible to categorize each word in type. x = 5; x - ID = - operator 5 - integer ; - delimiter So in order to be able to define the tokens in a line it is important to know the patterns and being able to identify those patterns. There are two ways to identify patterns: • (text- based) Reg...
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