Preview

Structure of Compiler

Powerful Essays
Open Document
Open Document
1758 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
Structure of Compiler
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 meaning (semantics) of the program. Semantic analysis plays a dual role. It finishes the analysis task by performing a variety of correctness checks (for example, enforcing type and scope rules). Semantic analysis also begins the synthesis phase. The synthesis phase may translate source programs into some intermediate representation (IR) or it may directly generate target code.

CS 536 Spring 2008

©

29

CS 536 Spring 2008

©

30

If an IR is generated, it then serves as input to a code generator component that produces the desired machinelanguage program. The IR may optionally be transformed by an optimizer so that a more efficient program may be generated.

Source Program

Tokens

Scanner
(Character Stream)

Parser

Abstract Syntax Tree (AST)

Type Checker

Decorated AST

Translator
Intermediate Representation Symbol Tables (IR)

Optimizer
IR Code Generator

Target Machine Code

The Structure of a Syntax-Directed Compiler

CS 536 Spring 2008

©

31

CS 536 Spring 2008

©

32

Scanner
The scanner reads the source program, character by character. It groups individual characters into tokens (identifiers, integers, reserved words, delimiters, and so on). When necessary, the actual character string comprising the token is also passed along for use by the semantic phases. The scanner:
• •

example, to register the presence of a particular label or identifier). Optionally formats and lists the source program




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
  • Satisfactory Essays

    Homework Week 2

    • 743 Words
    • 3 Pages

    A compiler translates one computer language into another. It also pics up errors in the program being put together.…

    • 743 Words
    • 3 Pages
    Satisfactory Essays
  • Powerful Essays

    Nt1310 Unit 1

    • 4209 Words
    • 17 Pages

    It parses and also executes the statement Displays the execution plan for the select statement automatically…

    • 4209 Words
    • 17 Pages
    Powerful Essays
  • Satisfactory Essays

    1. It keeps a count of the number of times you want to use the program to input data…

    • 351 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    pt1420 exam review

    • 738 Words
    • 3 Pages

    What both translates and executes the instructions in a high level language program? What was the first programming language designed to perform complex math functions? Interpreter.Fortran…

    • 738 Words
    • 3 Pages
    Good Essays
  • Good Essays

    Physics Midterm Exam

    • 958 Words
    • 4 Pages

    Correct answer: (d). The date of birth is not entered nor used in the program. It is irrelevant information.…

    • 958 Words
    • 4 Pages
    Good Essays
  • Satisfactory Essays

    Lab 7 Student

    • 1242 Words
    • 7 Pages

    This lab accompanies Chapter 5 (pp. 163-183 and pp. 196-201) of Starting Out with Programming Logic & Design.…

    • 1242 Words
    • 7 Pages
    Satisfactory Essays
  • Good Essays

    Week 1 Homework

    • 843 Words
    • 5 Pages

    2. What does a compiler do? What kinds of errors are reported by a compiler?…

    • 843 Words
    • 5 Pages
    Good Essays
  • Satisfactory Essays

    cis121 chapter 2 and 3

    • 993 Words
    • 6 Pages

    ____ is where a variable's data type or other information is stored as part of the name.…

    • 993 Words
    • 6 Pages
    Satisfactory Essays
  • Good Essays

    Concept Programing

    • 443 Words
    • 3 Pages

    3. (15%) Design a state diagram to recognize one form of the comments of the C-based programming languages,…

    • 443 Words
    • 3 Pages
    Good Essays
  • Satisfactory Essays

    5) When an input file is opened, its read position is initially set to the first item in the file.…

    • 544 Words
    • 4 Pages
    Satisfactory Essays
  • Powerful Essays

    Proc Report Secreates

    • 7894 Words
    • 32 Pages

    DEFINE statements. We will also dig deep into example code and explore the new ability to use multilabel formatting…

    • 7894 Words
    • 32 Pages
    Powerful Essays
  • Better Essays

    Compilation: programs are translated into machine code which can directly execute on the computer. Compiler analyzes the whole code and generates the machine code which makes it very fast process. And due to this, compiled programs don’t require any second application or package to run it. The time takes to create a program from compilation is relatively faster than interpretation. As a disadvantage, compilation process is hardware specific into which machine it get compiled. Architecture of the computer affects…

    • 1672 Words
    • 7 Pages
    Better 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
  • Better Essays

    Symbol Table

    • 1792 Words
    • 8 Pages

    A compiler uses a symbol table to keep track of scope and binding information about names.…

    • 1792 Words
    • 8 Pages
    Better Essays

Related Topics