Lesson Objectives Aims Key Words

Slides:



Advertisements
Similar presentations
CPSC 388 – Compiler Design and Construction
Advertisements

Sub and Function Procedures
Introduction To Compilers And Phase 1 Inside a compiler. Inside a C-- compiler. The compilation process. Example C-- code. Extended Backus-Naur.
From Cooper & Torczon1 The Front End The purpose of the front end is to deal with the input language Perform a membership test: code  source language?
Semantic analysis Parsing only verifies that the program consists of tokens arranged in a syntactically-valid combination, we now move on to semantic analysis,
The Symbol Table Lecture 13 Wed, Feb 23, The Symbol Table When identifiers are found, they will be entered into a symbol table, which will hold.
CPSC Compiler Tutorial 9 Review of Compiler.
Chapter3: Language Translation issues
Environments and Evaluation
Chapter 3 Program translation1 Chapt. 3 Language Translation Syntax and Semantics Translation phases Formal translation models.
INTRODUCTION TO COMPUTING CHAPTER NO. 06. Compilers and Language Translation Introduction The Compilation Process Phase 1 – Lexical Analysis Phase 2 –
Chapter 1 Introduction Dr. Frank Lee. 1.1 Why Study Compiler? To write more efficient code in a high-level language To provide solid foundation in parsing.
Lexical Analysis - An Introduction. The Front End The purpose of the front end is to deal with the input language Perform a membership test: code  source.
Concordia University Department of Computer Science and Software Engineering Click to edit Master title style COMPILER DESIGN Review Joey Paquet,
Lexical Analysis Hira Waseem Lecture
Chapter 6 Programming Languages (2) Introduction to CS 1 st Semester, 2015 Sanghyun Park.
Joey Paquet, Lecture 12 Review. Joey Paquet, Course Review Compiler architecture –Lexical analysis, syntactic analysis, semantic.
Interpretation Environments and Evaluation. CS 354 Spring Translation Stages Lexical analysis (scanning) Parsing –Recognizing –Building parse tree.
Review 1.Lexical Analysis 2.Syntax Analysis 3.Semantic Analysis 4.Code Generation 5.Code Optimization.
Unit-1 Introduction Prepared by: Prof. Harish I Rathod
What on Earth? LEXEMETOKENPATTERN print p,r,i,n,t (leftpar( 4number4 *arith* 5number5 )rightpar) userAnswerID Letter followed by letters and digits “Game.
Overview of Previous Lesson(s) Over View  A program must be translated into a form in which it can be executed by a computer.  The software systems.
1 Compiler Design (40-414)  Main Text Book: Compilers: Principles, Techniques & Tools, 2 nd ed., Aho, Lam, Sethi, and Ullman, 2007  Evaluation:  Midterm.
IN LINE FUNCTION AND MACRO Macro is processed at precompilation time. An Inline function is processed at compilation time. Example : let us consider this.
The Functions and Purposes of Translators Syntax (& Semantic) Analysis.
1 Lex & Yacc. 2 Compilation Process Lexical Analyzer Source Code Syntax Analyzer Symbol Table Intermed. Code Gen. Code Generator Machine Code.
Introduction to Compiling
Compilers I CNS History Wires Wires Machine Language Machine Language FFBA FFBA No Translation necessary No Translation necessary Assembly Language.
Compiler Construction By: Muhammad Nadeem Edited By: M. Bilal Qureshi.
The Model of Compilation Natawut Nupairoj, Ph.D. Department of Computer Engineering Chulalongkorn University.
1 Compiler & its Phases Krishan Kumar Asstt. Prof. (CSE) BPRCE, Gohana.
What am I? while b != 0 if a > b a := a − b else b := b − a return a AST == Abstract Syntax Tree.
The Role of Lexical Analyzer
Compiler Construction CPCS302 Dr. Manal Abdulaziz.
CS412/413 Introduction to Compilers Radu Rugina Lecture 11: Symbol Tables 13 Feb 02.
CS 404Ahmed Ezzat 1 CS 404 Introduction to Compiler Design Lecture 1 Ahmed Ezzat.
OCR A Level F453: The function and purpose of translators Translators a. describe the need for, and use of, translators to convert source code.
Lecture 9 Symbol Table and Attributed Grammars
Component 1.6.
Compiler Design (40-414) Main Text Book:
Component 1.6.
CS170 – Week 1 Lecture 3: Foundation Ismail abumuhfouz.
Lexical and Syntax Analysis
Lexical Analysis.
F453 Computing Questions and Answers
Algorithms Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
Chapter 1. Introduction to Computers and Programming
-by Nisarg Vasavada (Compiled*)
Introduction to C Topics Compilation Using the gcc Compiler
Programming Problem steps must be able to be fully & unambiguously described Problem types; Can be clearly described Cannot be clearly described (e.g.
Compiler Lecture 1 CS510.
Lexical analysis Jakub Yaghob
Bison: Parser Generator
Front End vs Back End of a Compilers
Lesson Objectives Aims You should be able to:
Chapter 2: A Simple One Pass Compiler
Compilers B V Sai Aravind (11CS10008).
CMPE 152: Compiler Design August 21/23 Lab
Lesson Objectives Aims Key Words
Compiler design.
Lesson Objectives Aims Understand Syntax Analysis.
Software Development Environment, File Storage & Compiling
Chapter 10: Compilers and Language Translation
Lec00-outline May 18, 2019 Compiler Design CS416 Compiler Design.
Lecture 18 Compilers and Language Translation (S&G, ch. 9)
WJEC GCSE Computer Science
Language translation Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Sections
Compiler Design 3. Lexical Analyzer, Flex
Faculty of Computer Science and Information System
PYTHON - VARIABLES AND OPERATORS
Presentation transcript:

Lesson Objectives Aims Key Words Be able to understand Lexical Analysis Define the terms Lexical Analysis, Syntax, Symbol and Token Key Words

Stages of Compilation

Lexical Analysis Lexical analysis is the act of “parsing” source code Parsing means to read in sections and “make sense” of it The outcome is a “tokenised” version of the code and a symbol table

Parse each line (work out what is a variable, operator, function name, key word etc) Tokenise each unique element (tokens for key words etc will already be defined) Token stream

Symbol Table Token Identifier Key word/Type 001 IF 002 THEN 003 MyName VARIABLE Any time an identifier is found in the code, the token will be put in its place Tokens are unique and not duplicated The symbol table should store: an index or identifier the name of the token data type scope and restrictions.

Why Compilers/computers do not need human readable identifiers Long identifiers and key words take up more space in memory Identifying each unique token ensures efficient compilation

Lexical analysis In order to do this, code must first be stripped of unnecessary data Spaces Comments During this task, delimiters and end of line symbols etc are used to break code down in to its “atomic” elements An atomic piece of code is one single key word, operator or name

Errors generated at this stage: Things that don’t match a key word Or identifiers Or a literal value

Things it does NOT do… Lexical analysis does NOT “read” the code No syntax errors are generated at this stage It is checking for patterns: DIMMM Jiggle AS Interrrrger This would pass lexical analysis – but is clearly syntactically incorrect Why would it pass lexical analysis?

How does this work? Lexical analysis uses regular expressions (pattern matching) to try and find code that is acceptable Regular expressions can be quite complex, and make use of a set of symbols that have individual meanings…

Regular Expression Symbols Some meanings: Symbol Meaning [] A set | OR * 0 or more ? 0 or 1 $ End of line ^ NOT

Example

Tokenise this line of code: IF A>5 THEN A = A * 2 Task Tokenise this line of code: IF A>5 THEN A = A * 2 Make a symbol table Identify each unique key word Output a token stream Token Type Identifier/Value 1 IF -

1 2 3 4 5 2 6 2 7 8

Review/Success Criteria You should know: What lexical analysis is What lexical analysis does How What it cannot do!