An Overview of a Compiler

Powerful Essays
An Overview of a Compiler - Part 1
Y.N. Srikant
Department of Computer Science Indian Institute of Science Bangalore 560 012

NPTEL Course on Compiler Design

Y.N. Srikant

Compiler Overview

Outline of the Lecture

1 2 3 4 5

Compiler overview with block diagram Lexical analysis with LEX Parsing with YACC Semantic analysis with attribute grammars Intermediate code generation with syntax-directed translation Code optimization examples

6

Topics 5 and 6 will be covered in Part II of the lecture

Y.N. Srikant

Compiler Overview

Language Processing System

Y.N. Srikant

Compiler Overview

Compiler Overview

Y.N. Srikant

Compiler Overview

Translation Overview - Lexical Analysis

Y.N. Srikant

Compiler Overview

Lexical Analysis

LA can be generated automatically from regular expression specifications
LEX and Flex are two such tools

Tokens of the LA are the terminal symbols of the parser LA is usually called to deliver a token when the parser needs it Why is LA separate from parsing?
Simplification of design - software engineering reason I/O issues are limited LA alone LA based on finite automata are more efficient to implement than pushdown automata used for parsing (due to stack)

Y.N. Srikant

Compiler Overview

LEX Example

%% [A-Z]+ %% yywrap(){} main(){yylex();}

Y.N. Srikant

Compiler Overview

Form of a LEX File

LEX has a language for describing regular expressions It generates a pattern matcher for the REs described General structure of a LEX program {definitions} %% {rules} %% {user subroutines} A LEX compiler generates a C-program lex.yy.c as output

Y.N. Srikant

Compiler Overview

Definitions Section

Definitions Section contains definitions and included code
Definitions are like macros and have the following form: name translation digit [0-9] number {digit} {digit}* Included code is all code included between %{ and %} %{ float number; int count=0; %}

Y.N. Srikant

Compiler

You May Also Find These Documents Helpful

  • Powerful Essays

    Compiler

    • 32912 Words
    • 132 Pages

    CS 375, Compilers: Class Notes Gordon S. Novak Jr. Department of Computer Sciences University of Texas at Austin novak@cs.utexas.edu http://www.cs.utexas.edu/users/novak Copyright c Gordon S. Novak Jr.1 A few slides reproduce figures from Aho, Lam, Sethi, and Ullman, Compilers: Principles, Techniques, and Tools, Addison-Wesley; these have footnote credits. 1 1 I wish to preach not the doctrine of ignoble ease, but the doctrine of the strenuous life. – Theodore Roosevelt Innovation requires…

    • 32912 Words
    • 132 Pages
    Powerful Essays
  • Good Essays

    Compiler Construction

    • 376 Words
    • 3 Pages

    Compiler-a program that translates an executable program in one language into an executable program in another language Interpreter-a program that reads an executable program and produces the results of running that program Why do we care to study compiler construction Compiler construction is a microcosm of computer science artificial intelligence greedy algorithms learning algorithms Algorithms graph algorithms union-find dynamic programming Theory DFAs for scanning parser generators lattice…

    • 376 Words
    • 3 Pages
    Good Essays
  • Powerful Essays

    Compiler Construction

    • 2658 Words
    • 11 Pages

    How to Create a Decision Tree Edited by Madhva_madhu, Leona 0 Article EditDiscuss A decision tree is a kind of flowchart -- a graphical representation of the process for making a decision or a series of decisions. Businesses use them to determine company policy, sometimes simply for choosing what policy is, other times as a published tool for their employees. Individuals can use decision trees to help them make difficult decisions by reducing them to a series of simpler, or less emotionally…

    • 2658 Words
    • 11 Pages
    Powerful Essays
  • Good Essays

    Compiler Phases

    • 306 Words
    • 2 Pages

    The compiler has a number of phases plus symbol table manager and an error handler. Input Source Program ↓ Lexical Analyzer ↓ Syntax Analyzer ↓ Symbol Table Manager Semantic Analyzer Error Handler ↓ Intermediate Code Generator ↓ Code Optimizer ↓ Code Generator ↓ Out Target Program The cousins of the compiler are Preprocessor. Assembler. Loader and Link-editor…

    • 306 Words
    • 2 Pages
    Good Essays
  • Good Essays

    Compiler Design

    • 7419 Words
    • 30 Pages

    DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 2007-2008, EVEN SEMESTER PRINCIPLES OF COMPILER DESIGN-CS1352 TWO-MARK QUESTIONS 1. What does translator mean? A translator is a program that takes a input program on one programming language (source language) and produces output in another language (object language or target language). 2. What are the phases of a compiler? • Lexical analysis phase or scanning phase • Syntax analysis phase • Intermediate code generation • Code optimization • Code generation…

    • 7419 Words
    • 30 Pages
    Good Essays
  • Satisfactory Essays

    Compiler Construction Quiz

    • 1134 Words
    • 5 Pages

    FROM OTHER(S) AS ONE’S OWN WILL BE PENALIZED AS DEFINED IN “AIOU PLAGIARISM POLICY”. Course: Compiler Construction (3468) Semester: Autumn, 2012 Level: BS (CS) Total Marks: 100 ASSIGNMENT No. 1 Note: All questions carry equal marks. Q. 1 (a) Define Compiler, using a diagram describes the three phases of analysis of source program. (b) Explain all the phases of Compiler. (c) Consider the following grammar. S ―> XaYb X ―> bXc | b Y…

    • 1134 Words
    • 5 Pages
    Satisfactory Essays
  • Powerful Essays

    Cloud Compiler

    • 6075 Words
    • 25 Pages

    improper handling of application the source file may get damaged or lost by system crash. To solve all these problems we are designing a Cloud Based Multi-Language Programming Compiler to executing different types of source code on one editor providing all type of security. Cloud Based Multi-Language Programming Compiler is an application which greatly lightens the student’s workload at the initial stage of programming. At this stage, they neither have to deal with the complexities of the installation…

    • 6075 Words
    • 25 Pages
    Powerful Essays
  • Satisfactory Essays

    building a compiler

    • 2613 Words
    • 11 Pages

    Universität Dortmund Building a compiler (considering characteristics of embedded processors) Peter Marwedel University of Dortmund, Germany  P. Marwedel, Univ. Dortmund/Informatik 12 + ICD/ES, 2006 Fri2 - 1 - Universität Dortmund Effort for building a compiler  So far we assumed that all the optimizations can be added to some existing tool chain.  Sometimes, a custom compiler is required, but: the effort for building a custom compiler is underestimated.  It is not sufficient…

    • 2613 Words
    • 11 Pages
    Satisfactory Essays
  • Powerful Essays

    Structure of Compiler

    • 1758 Words
    • 8 Pages

    The Structure of a Compiler A compiler performs two major tasks: • • Analysis of the source program being compiled Synthesis of a target program Almost all modern compilers are syntax-directed: The compilation process is driven by the syntactic structure of the source program. A parser builds semantic structure out of tokens, the elementary symbols of programming language syntax. Recognition of syntactic structure is a major part of the analysis task. Semantic analysis examines the…

    • 1758 Words
    • 8 Pages
    Powerful Essays
  • Good Essays

    Thesis of Compiler

    • 913 Words
    • 4 Pages

    Chapter I THE PROBLEM AND ITS BACKGROUND Introduction Have we ever noticed some individuals nowadays, how they construct their sentence in a grammar context? Or how they speak? In particularly, students in our present time have difficulties making a simple sentence. It causes low comprehension and lack of vocabulary words. Students nowadays encountered a big problem in terms of translating our very own language to universal language or Filipino to English.…

    • 913 Words
    • 4 Pages
    Good Essays