Once you understand the original program

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: 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

{[ 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