logo

Compiler Design: Phases and Grammar for Domain Specific Language

   

Added on  2023-06-10

13 Pages1794 Words407 Views
COMPUTER SCIENCE
By Name
Course
Instructor
Institution
Location
Date

[Q3]
(a)
Block diagram

The diagram above shows the block diagram showing the scope of the compiler design and the
various phases stepwise the design shall use to fully develop the compiler for the domain specific
language. The scope of this task is to come up with the compiler that shall convert the pure high-
level language from the pre-processor into the assembly language. The interest is to look deep in the
compiler phase of the program execution and come up with the necessary phases that shall be useful
in coming up with the compiler (Fischer, Cytron and LeBlanc, 2009). The individual scope as per
the diagram is explained below,
Lexical Analysis
The scope of this phase is to take the program and read it and then convert it into tokens that are
also called streams of tokens. All the white spaces shall be removed at this stage and any comments.
This shall be made possible using the pattern set up for the compiler to identify tokens, operators,
and identifiers. Once the streams of tokens are output, this shall act as the input for the next scope
(Mogensen, 2017).
Syntax analysis
This stage also called the parse. The syntax analyser shall take the tokens given by the lexical
analysis phase and convert it into a parse tree The syntax analyse shall take all the tokens, one by
one ad it is also going to take a grammar generally called context-free grammar with the help of the
production rules, the input is going to be checked whether it is given according to the production
rules defined in the grammar. Thd scope of this stage is to enable debugging of syntax errors parse
tree formed shall be given as the input for the next phase (Grune et al., 2012).
Semantic analysis
The semantic analysis phase is going to verify whether the parse tree it has received has some
logical meaning or not which is called a parse tree which can be verified semantically. Once the
parse tree is verified semantically. All the type checking shall be done at this stage it will be input to
an intermediate code generator phase as input.
Intermediate code generator
The scope here is to generate the three address code. There is various three address code which shall
be used in the design, The output of the three address code shall input to the code optimizer.
Code optimizer

The scope of the code optimizer is to minimize the size of the program or to minimize the number
of lines. The output shall be given to the target code generator.
Target code generator
The scope of this phase is to actually generate the assembly code for the domain specific language.
This phase scope is to write the code that the assembler can understand
During all the phases are going to take support from a module known as the symbol table manager.
Moreover, all the phases shall talk with the module called the error handler
(b)
This sections describes the grammer for the domain specific language. The grammer shown in this
sections shall be during implementation as it will act as reference. Context-free grammar has
application in programming languages and compiler design. Informally the grammar used for the
compiler shall contain four components namely;
1) Terminal Symbols
This is similar to the alphabetical symbols we consider when we talk about the finite
automata. The set of the terminal symbols shall be the alphabet of the grammar.
2) Variables
This represents a finite set of symbols with each representing a specific language
3) Start symbol
This represents the language we first start with
4) production
These are rules that we would use to describe the language
To better define the grammar, the following was defined systematically; Expression, Operators,
Statements, Functions, Classes and the various punctuation to be used
a) Expression
The following defines the expression part of the grammer for the domain specific language.
Expression:
Exp1 [AssignOperator Exp1]
AssignOperator
=
+=
-=

End of preview

Want to access all the pages? Upload your documents or become a member.

Related Documents
MiniJava-Compiler =================.
|4
|450
|88

Octal Integer literal (OIL)
|9
|1927
|21