What on Earth? LEXEMETOKENPATTERN print p,r,i,n,t (leftpar( 4number4 *arith* 5number5 )rightpar) userAnswerID Letter followed by letters and digits “Game.

Slides:



Advertisements
Similar presentations
CS 31003: Compilers Introduction to Phases of Compiler.
Advertisements

The Functions and Purposes of Translators Code Generation (Intermediate Code, Optimisation, Final Code), Linkers & Loaders.
 Lex helps to specify lexical analyzers by specifying regular expression  i/p notation for lex tool is lex language and the tool itself is refered to.
1 Pass Compiler 1. 1.Introduction 1.1 Types of compilers 2.Stages of 1 Pass Compiler 2.1 Lexical analysis 2.2. syntactical analyzer 2.3. Code generation.
CPSC Compiler Tutorial 9 Review of Compiler.
Yu-Chen Kuo1 Chapter 1 Introduction to Compiling.
Chapter3: Language Translation issues
Chapter 3 Program translation1 Chapt. 3 Language Translation Syntax and Semantics Translation phases Formal translation models.
Compiler Construction
Compiled by Benjamin Muganzi 3.2 Functions and Purposes of Translators Computing 9691 Paper 3 1.
2.2 A Simple Syntax-Directed Translator Syntax-Directed Translation 2.4 Parsing 2.5 A Translator for Simple Expressions 2.6 Lexical Analysis.
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.
CSC 338: Compiler design and implementation
Compiler Phases: Source program Lexical analyzer Syntax analyzer Semantic analyzer Machine-independent code improvement Target code generation Machine-specific.
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.
Lexical Analysis - An Introduction Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at.
Lexical Analysis - An Introduction Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at.
Lexical Analysis Hira Waseem Lecture
Lexical Analysis I Specifying Tokens Lecture 2 CS 4318/5531 Spring 2010 Apan Qasem Texas State University *some slides adopted from Cooper and Torczon.
CMSC 104, Version 9/011 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program 104 C Programming Standards and Indentation.
COP 4620 / 5625 Programming Language Translation / Compiler Writing Fall 2003 Lecture 3, 09/11/2003 Prof. Roy Levow.
Unit-1 Introduction Prepared by: Prof. Harish I Rathod
CS30003: Compilers Lexical Analysis Lecture Date: 05/08/13 Submission By: DHANJIT DAS, 11CS10012.
Recognizing PL/SQL Lexical Units. 2 home back first prev next last What Will I Learn? List and define the different types of lexical units available in.
Review: Compiler Phases: Source program Lexical analyzer Syntax analyzer Semantic analyzer Intermediate code generator Code optimizer Code generator Symbol.
What am I?. Translators Translators – Module Knowledge Areas Types of translators and their use Lexical analysis Syntax analysis Code generation and.
CPS 506 Comparative Programming Languages Syntax Specification.
Introduction to Compilers. Related Area Programming languages Machine architecture Language theory Algorithms Data structures Operating systems Software.
What Do I Represent?. Translators – Module Knowledge Areas Revisiting object code When we disassemble code we can view the opcodes used This is just a.
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.
D Goforth COSC Translating High Level Languages Note error in assignment 1: #4 - refer to Example grammar 3.4, p. 126.
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.
. n COMPILERS n n AND n n INTERPRETERS. -Compilers nA compiler is a program thatt reads a program written in one language - the source language- and translates.
Compiler Design Introduction 1. 2 Course Outline Introduction to Compiling Lexical Analysis Syntax Analysis –Context Free Grammars –Top-Down Parsing –Bottom-Up.
Compiler Construction By: Muhammad Nadeem Edited By: M. Bilal Qureshi.
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
2/1/20161 Programming Languages and Compilers (CS 421) Grigore Rosu 2110 SC, UIUC Slides by Elsa Gunter, based in.
What is a compiler? –A program that reads a program written in one language (source language) and translates it into an equivalent program in another language.
1 Lexical Elements, Operators, and the C System. 2 Outline Characters and Lexical Elements Syntax Rules Comments Keywords Identifiers Constants String.
Compilers Computer Symbol Table Output Scanner (lexical analysis)
ICS312 Introduction to Compilers Set 23. What is a Compiler? A compiler is software (a program) that translates a high-level programming language to machine.
Overview of Compilation Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Principles Lecture 2.
Introduction to C Programming
CS 404Ahmed Ezzat 1 CS 404 Introduction to Compiler Design Lecture 1 Ahmed Ezzat.
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
1 Compiler Construction Vana Doufexi office CS dept.
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 2 Compiler Design Lexical Analysis By lecturer Noor Dhia
System Software Theory (5KS03).
Component 1.6.
Introduction to Compiler Construction
Component 1.6.
Chapter 6 Compiler.
Lexical and Syntax Analysis
A Simple Syntax-Directed Translator
Lexical Analysis.
Compiler Construction (CS-636)
-by Nisarg Vasavada (Compiled*)
Introduction to C Topics Compilation Using the gcc Compiler
Review: Compiler Phases:
Compilers B V Sai Aravind (11CS10008).
Compiler design.
Software Development Environment, File Storage & Compiling
Compiler Construction
Lexical Elements & Operators
WJEC GCSE Computer Science
Python fundamental.
Presentation transcript:

What on Earth? LEXEMETOKENPATTERN print p,r,i,n,t (leftpar( 4number4 *arith* 5number5 )rightpar) userAnswerID Letter followed by letters and digits “Game of Jones”literalAny string between “ and “

Translators

Translators – Module Knowledge Areas Types of translators and their use Lexical analysis Syntax analysis Code generation and optimisation Library routines

Translators – Module Knowledge Areas Lexical analysis Describe what happens during lexical analysis So, we need to know: What is meant by Lexical Analysis What the key language is What part lexical analysis plays in the translation process How lexical analysis works How to identify the key aspects of lexical analysis

Translators – Lexical Analysis So far we have investigated the link between source code, assembly code and machine code In reality there are many more steps involved in getting code to run There are a number of compilation phases: Parsing the source code (Lexical analysis) Syntax analysis Type checking Machine code generation Code block sequencing Register allocation Optimization Linking of libraries

Translators - Parsing Consider this flow diagram of the translation process: The source code is parsed …… Parsing is analysis of the source code Each line eg print(4*5) is read The compiler allocates a type (tokenizes) to each element eg keyword/reserved word, variable, constant …..

Translators - Parsing In the example print(4*5) print and * are recognised (in its simplest form, print is known as a reserved word for print and * is known as the multiplier or an arithmetic token) If the example were written Print 4*5 the parser would not recognise mistakes in syntax – that is not the job of lexical analysis Because Print does not match a pattern for a keyword the compiler will assume it is a variable (often give the token ID) and will have the token for that assigned to it. 4 and 5 will have tokens for number (specifically integer) applied and the * has an arithmetic token applied In effect, what happens is that a pair is created comprised of the token and the lexeme White space, eg extra lines in source code, spaces between characters and comments are stripped out as these are unnecessary for code to be translated into machine code

Translators - Parsing Look again at the parsing table: Each lexeme is a component of the source code Each token specifies the type of data the lexeme is The lexeme and token make a pair When parsing the source code, each lexeme follows a pattern EG print has the pattern p,r,i,n,t whilst the left parentheses has only one component in the pattern LEXEMETOKENPATTERN print p,r,i,n,t (leftpar( 4number4 *arith* 5number5 )rightpar)

Translators - Parsing Where key/reserved words are concerned, the pattern for the lexeme-token pair must match exactly If we add the line print(“The answer to 4 * 5 is”) the lexeme- token, pattern for the content in the quotes would be: The translator knows that text surrounded by quotations has the token literal and that the quotations should be ignored Once the source code has been analysed by the lexer it is ready for the next stage – syntax analysis LEXEMETOKENPATTERN “The answer to 4 * 5” literalSequence of characters inside the quotes but not including the quotes