EXPLAIN TOY COMPILER
START 100 M/C code System Software Application Software
System software is mainly An application program is
A toy compiler consist of front end and back end:
focused on the efficient mainly focused on solving the
(1) Front end MARKS DS I
management of the computer specific problems using
The front end performs the lexical, syntax and semantic analysis of system. computer as a tool.
source program. It performs following functions: TOTAL DS1 System programs support the The main focus is on the
(a) Validating the source statement operation rather than any application not on the
(b) Determining the meaning of source program P DS 1 particular application. computing system.
(c) Constructing suitable representation that can be used by System software is machine Application software is machine
synthesis phase dependent. independent.
H DC '100' System programmer requires Application programmer
Lexical analysis
Lexical analysis determines the lexical units. It organizes the lexical knowledge about the internal requires detailed knowledge
units into different lexical classes i.e. constant, id, number, etc. and READ MARKS 268 104 09 100 computer architecture. about high level language which
is used to develop an
stores it into equivalent table. application.
. Lexical analysis constructs a descriptor called token for every READ TOTAL 300 105 09 101
System program becomes Application program becomes
lexical unit. This phase is also called as scanning phase. Memory portable using concept of portable using concept of cross
Token consist of two fields allocation for the statement X:=Y+Zis MOVER AREG MARKS 106 04 01 100 bootstrapping. compiler.
(a) Class code Examples are OS, compiler, Examples are Microsoft Access,
(b) Number in class MUL AREG H ← 107 03 01 103 interpreter, assembler etc. Notepad, Photoshop etc.
Where class code represents the class of lexical unit and number in
class represents entry number of lexical unit in the corresponding Code generation DIV AREG TOTAL ← 108 08 01 101
table.
Example: X := Y + Z;
Id#1 MOVEM AREG P 109 05 01 102
Op#12 Code generation uses knowledge of target architect that means
Id#2 knowledge about instructions addressing mode of target computer. PRINT P 110 10 00 102
Op#2
Id#3 STOP
Op#10
Here Id#1 stands for identifier having entry number 1, similarly Op#1 Some of the issues in code generation are:
represents operator with entry number 1.
Syntax analysis Compiler:- Compiler is a system program that translate high level
Syntax Analysis is also called as Parsing phase. It ensure the (1) Find out the location for the intermediate result it whether in language into low lavel language.
syntactical structure of the given source program, i.e. whether the memory location or machine register
given input is syntactically correct or not. It does so by building a Assembler :- Assembler is system software which converts
data structure, called a Parse tree or Syntax tree. programs written in assembly language into machine language
The given input string is correct if it can be formed using the syntax
tree. (2) Determine the instruction to be used for the operation of type Linker :- linker merges separate files into a single program resolving
Semantic analyale conversion. the notational references .
Semantic analysis is also called as type checking phase. Semantic
analysis ensures that the source program does not violate Loader :- loader performs the function of placing object code into
consistency requirement. main memory for execution purpose .
Semantic analysis for statement X:=Y+Z can be proceed as follow: (3) Determines addressing mode for accessing variable.
(a) Information regarding the type of operands is added to IC tree. Interpreter :- interpreter is also a translator like compiler but
(b) Rules regarding assignment operator is checked and the interpreter takes one line at a time and translates it into object code
expression at right hand side is evaluated. .
Example: For staternent X:=Y+Z code generation will be, MOVER
(c) Rules for addition are checked and also the type compatibility of
OVER AREG, Y; MOVEM AREG, X;
operands is checked and then processed. Device driver :- device driver is to translate the instruction given by
Output of front end operating system into a form that will be understandable to the
Fig. 1.4.5: Parse Tree particular devices.
The output of front end intermediate representation (IR) contains
two components: A device driver tells operating system that how the devices will work
(i) Table of information (ii) Intermediate code (IC) on certain commands which are generated by user.
(2) Back end
The back end performs memory allocation and code generation.
Memory allocation
Memory allocation is simple task in which the memory required for
symbols is calculated and stored into the symbol table.