You are on page 1of 16

LANGUAGE

PROCESSORS
COMPILATION
Language Processors: Why do we need them?
Programmer Programmer
2
Compute surface area of
a triangle? Concepts and Ideas

Java Program

JVM Assembly code


How to bridge the
“semantic gap” ?
JVM Binary code

JVM Interpreter

X86 Processor
0101001001...
Hardware Hardware
Language Processors: What are they?
A programming language processor is any system (software
3

or hardware) that manipulates programs.


Examples:
 Editors
 Emacs
 Integrated Development Environments
 Borland jBuilder
 Eclipse
 NetBeans
 Visual Studio .Net
 Translators (e.g. compiler, assembler, disassembler)
 Interpreters
Interpreter
4
You use lots of interpreters every day!
5 Several languages are used to add dynamics and animation to HTML.
Many programming languages are executed (possibly simultaneously) in the
browser!

Browser

VBScript Control /
HTML Java Virtual
Interpreter Machine (JVM)
(compiler)
applet
HTML Interpreter
script (display formatting)
script

Communications JavaScript
HTML Control /
facilities HTML Interpreter
page
And also across the web
Web-Client Database
6
Web-Server Server

HTML-Form
(+JavaScript) Submit Call PHP DBMS
Data interpreter LAN

PHP SQL
Web-Browser WWW Script commands
Response Response Database
Reply Output
Compilation
7

 Compilation is at least a two-step process, in


which the original program (source program) is
input to the compiler, and a new program (target
program) is output from the compiler. The
compilation steps can be visualized as the
following.
Compiler (simple view)
8
Compiler
9
Hybrid compiler / interpreter
10
The Phases of a Compiler
11
Source Program

Syntax Analysis Error Reports

Abstract Syntax Tree

Contextual Analysis Error Reports

Decorated Abstract Syntax Tree

Code Generation

Object Code
Different Phases of a Compiler
The different phases can be seen as different
12

transformation steps to transform source code into


object code.

The different phases correspond roughly to the different


parts of the language specification:
 Syntax analysis <-> Syntax

 Contextual analysis <-> Contextual constraints

 Code generation <-> Semantics


Multi Pass Compiler
A multi pass compiler makes several passes over the program. The output of a preceding
13
phase is stored in a data structure and used by subsequent phases.

Dependency diagram of a typical Multi Pass Compiler:

Compiler Driver

calls calls
calls

Syntactic Analyzer Contextual Analyzer Code Generator


input input
input output output output

Source Text AST Decorated AST Object Code


Tools and Techniques
14

 Front-end: Syntax analysis


 How to build a Scanner and Lexer
 By hand in Java
 Using Tools
 JavaCC
 SableCC
 Lex and Yacc (JLex and JavaCUP)
 (lg and pg – compiler tools for .Net)
 Middle-part: Contextual Analysis
 Back-end: Code Generation
 Target Machines
 TAM
 JVM
 .Net CLR
Programming Language Implementation
Q: Which programming languages play a role in this picture?
15

input Translator output


source program object program

is expressed in the is expressed in the


source language target language

is expressed in the
implementation language

A: All of them!
Programming Language Life Cycle
16 Design

Specification

Prototype
Compiler
Manuals,
Textbooks

You might also like