Preview

An Overview of a Compiler

Powerful Essays
Open Document
Open Document
1494 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
An Overview of a Compiler
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

  • Good Essays

    In this phase a token is generated against all the lexemes in the source code. These lexemes and tokens are stored in the Symbol Table. Tokens against the lexemes are generated based on some patterns or rules.…

    • 703 Words
    • 3 Pages
    Good Essays
  • Good Essays

    pt1420 exam review

    • 738 Words
    • 3 Pages

    What is used to translate high level language programs to machine language (or machine code)? Compiler…

    • 738 Words
    • 3 Pages
    Good Essays
  • Good Essays

    The compiler adds a symbol table to the executable so that variable names from the source code can be understood. The compiler avoids optimizing operations so that lines of code in the executable can be related to the original lines of source code.…

    • 567 Words
    • 3 Pages
    Good Essays
  • Powerful Essays

    Task 1

    • 2644 Words
    • 8 Pages

    Also it is difficult to create new data types so this in turn reduces extensibility.…

    • 2644 Words
    • 8 Pages
    Powerful Essays
  • Powerful Essays

    Dynamic Code Analysis

    • 1554 Words
    • 7 Pages

    The objectives of the dynamic code analysis are to minimize the debugging time and to automatically pinpoint to the potential errors and explain them as they…

    • 1554 Words
    • 7 Pages
    Powerful Essays
  • Good Essays

    Part of Speech Recognizer

    • 3200 Words
    • 13 Pages

    References: [1] S. L. Abebe and P. Tonella. Natural language parsing of program element names for concept extraction. In 18th IEEE International Conference on Program Comprehension. IEEE, 2010. [2] K. Atkinson. Spell checking oriented word lists (scowl). [3] E. Boschee, R. Weischedel, and A. Zamanian. Automatic information extraction. In Proceedings of the International Conference on Intelligence Analysis, 2005. [4] B. Caprile and P. Tonella. Restructuring program identifier names. In ICSM, 2000. [5] ML Collard, HH Kagdi, and JI Maletic. An XML-based lightweight C++ fact extractor. Program Comprehension, 2003. 11th IEEE International Workshop on, pages 134–143, 2003. [6] E. Høst and B. Østvold. The programmer’s lexicon, volume i: The verbs. In International Working Conference on Source Code Analysis and Manipulation, Beijing, China, September 2008. [7] E. W. Høst and B. M. Østvold. Debugging method names. In ECOOP 09. Springer Berlin / Heidelberg, 2009. [8] J. Jiang and C. Zhai. Instance weighting for domain adaptation in nlp. In ACL 2007, 2007. [9] D. Lawrie, D. Binkley, and C. Morrell. Normalizing source code vocabulary. In Proceedings of the 17th Working Conference on Reverse Engineering, 2010. [10] L. Shen, G. Satta, and A. K. Joshi. Guided learning for bidirectional sequence classification. In ACL 07. ACL, June 2007. [11] D. Shepherd, Z. P. Fry, E. Hill, L. Pollock, and K. Vijay-Shanker. Using natural language program analysis to locate and understand action-oriented conerns. In AOSD 07. ACM, March 2007. [12] K. Toutanova, D. Klein, C. Manning, and Y. Singer. Feature-rich part-of-speech tagging with a cyclic dependency network. In HLTNAACL 2003, 2003.…

    • 3200 Words
    • 13 Pages
    Good Essays
  • Satisfactory Essays

    Regular Expression

    • 322 Words
    • 2 Pages

    Identify the lexeme that makes up the tokens in the following programs. Give reasonable attribute vcalues for the tokens.…

    • 322 Words
    • 2 Pages
    Satisfactory Essays
  • Better Essays

    Source Code with it 's unique twist on the classic time-loop scenario, brings mystery, action and a refreshing sci-fi structure for the audiences amazement. This film, like many sci-fi thrillers of the past, plays on societal issues with technology and it 's potentially dangerous implications to the world. The plot, although minimalistic at a glance, unfolds with twists and turns that carry this sci-fi thriller to places never before seen by the sci-fi genre. As film reviewer, Peter Bradshaw, put it, “with twists and turns, and at breathtaking speed, this film runs on rails.”[1]…

    • 1099 Words
    • 5 Pages
    Better Essays
  • Satisfactory Essays

    9. Name two types of applications that would be better suited to assembly language than a high-level language.…

    • 406 Words
    • 2 Pages
    Satisfactory Essays
  • Better Essays

    Games Localization Handbook

    • 2485 Words
    • 10 Pages

    Poor planning is the number-one cause of difficulties during localizations. As discussed throughout this book, a number of items must be planned for and considered when developing localized versions. For example, localization-friendly code is not something that happens late in the project, it must be planned for in advance.…

    • 2485 Words
    • 10 Pages
    Better Essays
  • Good Essays

    Engineering involves numerous paradigms and concepts that need to be used and applied at required places for making complete use of technology. One field of engineering that has gained significant importance in the last few years is software engineering. Due to the development and adaptation of different technologies in different areas and fields, different software is used for different purposes. And thus, different programming methodologies and concepts become an important part of software engineering. One important aspect of software engineering is declarative programming, which helps in describing the logic behind computation without even explaining the flow of the controls used in programming. The main phenomenon that drives such programming is logic and thus helps in the simplification of other programs for better computer programming and better output. We would thus discuss the major paradigms of declarative programming.…

    • 471 Words
    • 2 Pages
    Good Essays
  • Good Essays

    Cobol

    • 43832 Words
    • 176 Pages

    CONTENTS 1.0 Aims and Objectives 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 1.10 1.11 1.12 History of COBOL FORMAT FOR COBOL PROGRAMS STRUCTURE OF A COBOL PROGRAM CHARACTER SET COBOL WORDS DATA NAMES AND IDENTIFIERS LITERALS Language Description Notation Let us Sum up Lesson-end Activities Points for Discussion References…

    • 43832 Words
    • 176 Pages
    Good Essays
  • Satisfactory Essays

    Compiler Construction Quiz

    • 1134 Words
    • 5 Pages

    Write the intermediate representation code of the following position: = initial + rate * 60…

    • 1134 Words
    • 5 Pages
    Satisfactory Essays
  • Better Essays

    A finite automaton was the first abstract model as well as the mathematical model of digital computers. It is very powerful model of computation. It can recognize and accept regular languages. But finite automata have limited memory(states) which prevents them accepting Context free languages .Since memory is a limitation of finite automata ,a memory element is added as a stack, in order to made finite automata a powerful machine and to accept Context free languages. That new type of computational model is known as a Push down automata.PDA is similar to finite automata except that it has an extra memory unit stack. Stack is defined as a data structure where insertion and deletion of any element is possible only at one end called top of the stack.[1].…

    • 1939 Words
    • 8 Pages
    Better Essays
  • Powerful Essays

    Finite Automata

    • 26011 Words
    • 105 Pages

    The finite-state machine (FSM) and the pushdown automaton (PDA) enjoy a special place in computer science. The FSM has proven to be a very useful model for many practical tasks and deserves to be among the tools of every practicing computer scientist. Many simple tasks, such as interpreting the commands typed into a keyboard or running a calculator, can be modeled by finite-state machines. The PDA is a model to which one appeals when writing compilers because it captures the essential architectural features needed to parse context-free languages, languages whose structure most closely resembles that of many programming languages. In this chapter we examine the language recognition capability of FSMs and PDAs. We show that FSMs recognize exactly the regular languages, languages defined by regular expressions and generated by regular grammars. We also provide an algorithm to find a FSM that is equivalent to a given FSM but has the fewest states. We examine language recognition by PDAs and show that PDAs recognize exactly the context-free languages, languages whose grammars satisfy less stringent requirements than regular grammars. Both regular and context-free grammar types are special cases of the phrasestructure grammars that are shown in Chapter 5 to be the languages accepted by Turing machines. It is desirable not only to classify languages by the architecture of machines that recognize them but also to have tests to show that a language is not of a particular type. For this reason we establish so-called pumping lemmas whose purpose is to show how strings in one language can be elongated or “pumped up.” Pumping up may reveal that a language does not fall into a presumed language category. We also develop other properties of languages that provide mechanisms for distinguishing among language types. Because of the importance of context-free languages, we examine how they are parsed, a key step in…

    • 26011 Words
    • 105 Pages
    Powerful Essays

Related Topics