- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Show that the whole compilation process for statement A = B * C + 20, where A, B, C are of real types
Solution
Symbol Table
S.NO. | Variable Name | Variable Type |
---|---|---|
200 | A | Float |
204 | B | Float |
208 | C | Float |
Now, we will see how we can perform the compiler phase at each level and how it works.
Lexical Analysis
This is the first step that works as an integration between the compiler and the source language code. It reads the source code one character at a time and designs a source code into a series of atomic units known as tokens.
In this phase, we will see how we can tokenize the expression.
A → Identifier: (id, 1)
= → Operator: Assignment
B → Identifier: (id, 2)
* → Operator: Multiplication
C → Identifier: (id, 3)
+ → Operator: Binary Addition
20 → Constant: Integer
The final expression is as follows −
id1=id2*id3+20
Syntax Analysis
It is also known as the parser. It receives tokens as its input generated from the previous phase (lexical analysis) and produces a hierarchical structure called syntax tree or parse tree.
In this phase, it can check the syntax after tokenized the expression.
Syntax Analysis for the expression is as follows −
Semantic Analysis
This phase makes the syntax tree input and determines the semantical accuracy of the program. However, the tokens are accurate and syntactically right; they may be precise, not semantically. Hence the semantic analyzer determines the semantics (meaning) of the statements construct. In this phase, it can verify the type and semantic action for the syntax tree.
Intermediate Code Generation
This phase takes the syntactically and semantically correct form as input and produces the same intermediate notation of the source code. In this phase, we will provide a changed parse tree and as output after transforming into the Intermediate program will create a three-address code.
T1=id2 * id3 T2=int to real (20) T3=T1+T2 id1=T3
Code Optimization
It is an optional phase. It converts the intermediate representation of the source program into an efficient code. In this phase, it would look as an input will provide three address code and as an output, and it will identify the optimized code.
T1=id2 * id3 id1=T1+ 20.0
Code Generation
This is the final step of the compilation process. It converts optimized intermediate code into Machine/Assembly code. It allocates memory locations for variables in the program.
In the last phase, it can see how can modify the final expression into the assembly program.
- Related Articles
- If ( A, B, C ) are the interior angles of a ( triangle A B C ), show that:( tan frac{B+C}{2}=cot frac{A}{2} )
- If ( A, B, C ) are the interior angles of a ( triangle A B C ), show that:( cos frac{B+C}{2}=sin frac{A}{2} )
- If $2^{a}=3^{b}=6^{c}$ then show that $ c=frac{a b}{a+b} $
- Prove that both the roots of the equation $(x-a)(x-b)+(x-b)(x-c)+(x-c)(x-a)=0$ are real but they are equal only when $a=b=c$.
- If $a, b, c$ are real numbers such that $ac≠0$, then show that at least one of the equations $ax^2+bx+c=0$ and $-ax^2+bx+c=0$ has real roots.
- Show that:( left(x^{a-b}right)^{a+b}left(x^{b-c}right)^{b+c}left(x^{c-a}right)^{c+a}=1 )
- Verify that $a ÷ (b+c) ≠ (a ÷ b) + (a ÷ c)$ for each of the following values of $a, b$ and $c$.(a) $a=12, b=- 4, c=2$(b) $a=(-10), b = 1, c = 1$
- Show that the following grammar is LR (1)\nS → A a |b A c |B c | b B a\nA → d\nB → d
- Prove that the points $P( a, b+c), Q( b, c+a)$ and $R( c, a+b)$ are Collinear.
- If the roots of the equation $a(b-c) x^2+b(c-a) x+c(a-b) =0$ are equal, then prove that $b(a+c) =2ac$.
- If $A, B$ and $C$ are interior angles of a triangle $ABC$, then show that: $sin (frac{B+C}{2}) = cos frac{A}{2}$
- How does the compilation/linking process work in C/C++?
- Show that $(a−b)^2, (a^2+b^2), (a+b)^2$ are in A.P.
- Let $f(x)=3ax^2−4bx+c$ $(a,b,c∈R,aneq 0)$ where $a, b, c$ are in A.P. Then how many roots the equation $f(x)=0$$ have? Are they real?
- Show that the point $A( 4, 2), B( 7, 5), C( 9, 7)$ are collinear.
