For Stud
For Stud
INDEX
Marks
Sr. Date of Date of Signature
Title of Experiment Obtained
No performance Submission of Faculty
(10)
Write a program to implement Pass-I of
Two-pass assembler for Symbols and
Literal processing (For hypothetical
instruction set from Dhamdhere)
considering following cases
1
i. Forward references
i. DS and DC statement
iii. START, EQU, LTORG, END.
iv. Error handling: symbol used but not
defined, invalid instruction/register etc.
Write a program to implement Pass-II of
Two-pass assembler for output of
2
Assignment 1 (The subject teacher should
provide input file for this assignment )
Study Assignment for Macro Processor.
3
(Consider all aspects of Macro Processor )
Write a program to implement Lexical
4
Analyzer for subset of C.
Write a program to implement a Recursive
5 Descent Parser .
Write a program to implement calculator
6 using LEX and YACC.
Write a program for Intermediate code
generation using LEX &YACC for Control
7
Flow statement ( Either While loop or
Switch case)
LAB INNOVATION
We will be using the Linux command line tool, the Terminal, in order to compile a simple C
program. To open the Terminal, you can use the Ubuntu Dash or the Ctrl+Alt+T shortcut.
In order to compile and execute a C program, you need to have the essential packages installed on
your system. Enter the following command as root in your Linux Terminal:
You will be asked to enter the password for root; the installation process will begin after that.
Please make sure that you are connected to the internet.
#include<stdio.h>
int main()
{
printf("\nA sample C program\n\n");
return 0;
}
Then save the file with .c extension. In this example, I am naming my C program as
sampleProgram.c
Alternatively, you can write the C program through the Terminal in gedit as follows:
$ gedit sampleProgram.c
This will create a .c file where you can write and save a program.
In your Terminal, enter the following command in order to make an executable version of the
program you have written:
Syntax:
$ gcc [programName].c -o programName
Example:
$ gcc sampleProgram.c -o sampleProgram
Make sure your program is located in your Home folder. Otherwise, you will need to specify
appropriate paths in this command.
The final step is to run the compiled C program. Use the following syntax to do so:
$ ./programName
Example:
$ ./sampleProgram
You can see how the program is executed in the above example, displaying the text we wrote to
print through it.
Experiment No. 1
**Write a program to implement Pass-I of Two-pass assembler for Symbols and literal processing**
Marks: / 10
Date of Performance: Sign with Date
/ /20
Aim: Write a program to implement Pass-I of Two-pass assembler for Symbols and Literal
processing (For hypothetical instruction set from Dhamdhere) considering following cases
i. Forward references
ii. DS and DC statement
iii. START, EQU, LTORG, END.
iv. Error handling: symbol used but not defined, invalid instruction/register etc.
Objectives:
1. To study basic translation process of assembly language to machine language.
2. To study two pass assembly process
Outcomes:
Theory:
A language translator bridges an execution gap to machine language of computer system.
An assembler is a language translator whose source language is assembly language.
Language processing activity consists of two phases, Analysis phase and synthesis phase.
Analysis of source program consists of three components, Lexical rules, syntax rules and semantic
rules. Lexical rules govern the formation of valid statements in source language. Semantic rules
associate the formation meaning with valid statements of language. Synthesis phase is concerned
with construction of target language statements, which have the same meaning as source language
statements. This consists of memory allocation and code generation.
Data structures
Pass I Pass II
Intermediate code
Data access
Control transfer
Synthesis Phase:
1. Obtain the machine operation code corresponding to the mnemonic operation code by
searching the mnemonic table.
2. Obtain the address of the operand from the symbol table.
3. Synthesize the machine instruction or the machine form of the constant as the case may
be.
Determine the storage-required for every assembly language statement and update the
location counter.
Pass II: -
Synthesize the target code by processing the intermediate code generated during
2. MOT: A table of mnemonic op-codes and related information. It has the following
fields
0 ADD IS 01 01
1 BC IS 07 01
2 COMP IS 06 01
3 DIV IS 08 01
4 EQU AD 03 -
5 DC DL 01 -
6 DS DL 02 -
7 END AD 05 -
Fields are Symbol name, Address (LC Value). Initialize all values in the address fields to -1
and when symbol gets added when it appears in label field replace address value with
current LC. The symbol if it used but not defined will have address value -1 which will be
used for error detection.
Symbol Address
Loop 204
Next 214
4. LITTAB and POOLTAB: Literal table stores the literals used in the program and
POOLTAB stores the pointers to the literals in the current literal pool.
set
04 MOVER Memory to register
05 MOVEM Register to memory
06 COMP sets condition code
07 BC branch on condition code
08 DIV analogous to SUB
09 READ First operand is not used.
10 PRINT First operand is not used.
SYMBOL TABLE
1 N 113
2 ONE 115
3 TERM 116
4 AGAIN 104
5 RESULT 114
SAMPLE CODE IC
MOVER AREG, = “5” 200) (IS,04) (1)( L,1)
MOVER BREG, = “1” 201) (IS,04)(2)(L,2)
ADD CREG, = “1” 202) (IS,01)(3)(L,2)
LTORG
203) (DL,01)__(C,005)
204) (DL,01)__(C,001)
SUB AREG, = “1” 205) (IS,02)(1)(L,03)
ORIGIN 400
MULT AREG, = “1” 400) (IS,04)(1)(L,02)
END 401)(DL,01)__(C,001)
Errors: -
2. Duplication of Symbol: -
This error occurs when some symbol is declared more than once in the program.
3. Mnemonic error:
If there is invalid instruction then this error will occur.
4. Register error: -
If there is invalid register then this error will occur.
5. Operand error: -
This error will occur when there is an error in the operand field
Conclusion: Thus we have designed and implemented pass 1of a 2 pass assembler in C.
Write short answer of following questions : (4-5 Max)
S Name of PO PO PO PO PO PO PO PO PO P P P
N Experiment 1 2 3 4 5 6 7 8 9 O O O
o 10 11 12
01
Implementatio
n of Pass I
Assembler
CO and PO Mapping:
COs PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12
/POs
CO1
CO2
CO3
Experiment No. 2
** Write a program to implement Pass-II of Two-pass assembler for output of Assignment 1**
Marks: / 10
Date of Performance: Sign with Date
/ /20
Aim:- Write a program to implement Pass-II of Two-pass assembler for output of Assignment 1
(The subject teacher should provide input file for this assignment)
Objectives:
Outcomes:
At the end of the assignment the students should have
1. Understood the design and implementation of pass II of assembler
Theory: -
POOLTAB stores the pointers to the literals in the current literal pool.
Data Structure used by Pass II:
1. OPTAB: A table of mnemonic opcodes and related information.
2. SYMTAB: The symbol table
3. LITTAB: A table of literals used in the program
4. Intermediate code generated by Pass I
5. Output files containing Target code / error listing.
START
101
READ N 101) (IS,09) (0) (S,1) 101) + 09 0 113
MOVER BREG ONE 102) (IS, 04)( 2) S,2) 102) + 04 2 115
MOVEM BREG TERM 103) (IS, 05)( 2)(S,4) 103) + 05 2 116
AGAIN MULT BREG TERM 104) + 03 2 (S,4) 104) + 03 2 116
MOVER CREG TERM 105) + 04 3 (S,4) 105) + 04 3 116
ADD CREG ONE 106) + 01 3 (S,2) 106) + 01 3 115
MOVEM CREG TERM 107) + 05 3 (S.4) 107) + 05 3 116
COMP CREG N 108) + 06 3 (S,1) 108) + 06 3 113
BC LE AGAIN 109) + 07 2(S,3) 109) + 07 2 104
RESUL
MOVEM BREG T 110) + 05 2 (S,5) 110) + 05 2 114
PRINT RESULT 111) + 10 0 (S,5) 111) + 10 0 114
STOP 112) (IS,0)-- --- 112) + 00 0 000
N DS 1 113)(DL,02)_(C,001) 113)
RESULT DS 1 114) (DL,02)_(C,001) 114)
ONE DC „1‟ 115) (DL,01)_(C,001) 115) +01 0 001
TERM DS 1 116) (DL,02)_(C,001) 116)
END
01 Implementation of PASS II
assembler
CO and PO Mapping:
COs PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12
/POs
CO1
CO2
CO3
Experiment No. 3
Marks: / 10
Date of Performance: Sign with Date
/ /20
Objective: -
1. To understand macro facility, features and its use in assembly language programming.
2. To study how the macro definition is processed and how macro call results in the expansion
of code.
Outcomes:
At the end of the assignment the students should have
1. Understood macro facility, features and its use in assembly language
programming
2. Understood macro definition processing and macro call results in the expansion
of code
Theory:
An assembly language macro facility is to extend the set of operations provided in an
assembly language.
In order that programmers can repeat identical parts of their program macro facility can be
used. This permits the programmer to define an abbreviation for a part of program & use
this abbreviation in the program. This abbreviation is treated as macro definition & saved by
the macro processor. For all occurrences the abbreviation i.e. macro call, macro processor
substitutes the definition.
Macro Facilities:
1. Use of AIF & AGO allows us alter the flow of control during expansion.
2. Loops can be implemented using expansion time variables.
Design Procedure:
1. Step 1 is definition processing - Scan all macro definitions and for each macro definition
enter the macro name in macro name table (MNT). Store entire macro definition in macro
definition table (MDT) and add auxiliary information in MNT such as no of positional
parameters (#PP) no of key word parameters (#KP), macro definition table position
(MDTP) etc.
2. Step 2 is macro expansion - Examine all statement in assembly source program to detect the
macro calls. For each macro call locate the macro in MNT, retrieve MDTP, establish the
correspondence between formal & actual parameters and expand the macro.
3. Do Begin
Read next statement
a. If label field has sequencing symbol (SS) then,
If SS is already present in SSNTAB, retrieve its index in q.
Else
Begin
Enter SS in SSNTAB q
SSNTAB – ptr
Increment SSNTAB – ptr by one.
End
Store MDT – ptr in SSTAB as STAB [SSTP + q] MDT – ptr. b. Check type of the
statement
c. If Preprocessor Statement –
Begin
i. If SET statement then search each expansion time variable in EVNTAB & generate
(E, # m).
ii. If AIF or AGO then if SS is already present in SSNTAB, retrieve its index in q
Else
Begin
Enter SS in SSNTAB q
SSNTAB – ptr
Increment SSNTAB – ptr by 1
End
Replace symbol by (SS, SSTP+q)
iii) Enter intermediate code in MDT & increment MDT – ptr by one.
End
d. If MEND
Begin
Enter MEND in MDT, increment MDT_ptr by 1.
If SSNTAB is empty i.e.
SSNTAB – ptr = = 0 then SSTP = SSTAB_ptr
Else
SSTAB – ptr = SSTAB – ptr + SSNTAB – ptr.
If #kp == 0 then KPDTP = 0
Return to main logic ie step 6 of main logic.
End.
ii. If model statement then replace operands of the form (p, #n) & (E, #m) by values in
APTAB & EVTAB respectively.
iii. If set statement with specification (E, #m) in label field then set appropriate value in
EVTAB [m] & increment MEC by one.
iv. If AGO statement with (s, #s) specification in operand field then set new value of MEC
SSTAB[SSTP + s]
v. If AIF statement with (s, #s) specification in operand field & if condition in A/F is true
then
MEC SSTAB [SSTP +s]
Else
0
System Programming TE-IT
COs /POs PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12
CO1
CO2
CO3
1
System Programming TE-IT
Experiment No. 4
** Write a program to implement Lexical Analyzer for subset of C**
Marks: / 10
Date of Performance: Sign with Date
/ /20
Objective:
To understand the role of Lexical analyzer
Outcomes:
At the end of the assignment the students should have
1. Understood the design and implementation of lexical analyzer
Input:
1) Source File
2) Terminal Symbol Table
Output:
1) Symbol Table
2) Literal Table
3) Universal Table
Theory:
2
System Programming TE-IT
Lexical analysis is the process of converting a sequence of characters into a sequence of tokens. A
program or function which performs lexical analysis is called a lexical analyzer, lexer or scanner.The
specification of a programming language will often include a set of rules which defines the lexer. These
rules usually consist of regular expressions and they define the set of possible character sequences that
are used to form individual tokens or lexemes whitespace is also defined by a regular expression and
influences the recognition of other tokens, but does not itself contribute any tokens.
A token is a string of characters, categorized according to the rules as a symbol (e.g. IDENTIFIER,
NUMBER, COMMA, etc.). The process of forming tokens from an input stream of characters is called
tokenization and the lexer categorizes them according to a symbol type. A token can look like anything
that is useful for processing an input text stream or text file.
A lexical analyzer generally does nothing with combinations of tokens, a task left for a parser. For
example, a typical lexical analyzer recognizes parenthesis as tokens, but does nothing to ensure that each
'(' is matched with a ')'.
Consider this expression in the C programming language:
sum=3+2;
Tokenized in the following table:
lexeme token type
sum Identifier
= Assignment operator
3 Number
+ Addition operator
2 Number
; End of statement
Tokens are frequently defined by regular expressions, which are understood by a lexical analyzer
generator such as lex. The lexical analyzer (either generated automatically by a tool like lex, or hand-
crafted) reads in a stream of characters, identifies the lexemes in the stream, and categorizes them into
tokens. This is called "tokenizing." If the lexer finds an invalid token, it will report an error.
ALGORITHM:
1) Start the program.
2) Declare all the variables and file pointers.
3) Display the input program.
4) Separate the keyword in the program and display it.
5) Display the header files of the input program.
6) Separate the operators of the input program and display it.
7) Print the punctuation marks.
8) Print the constant that are present in input program.
9) Print the identifiers of the input program.
10) Stop the program.
Conclusion: Thus we have implemented Lexical Analyzer for subset of C
3
System Programming TE-IT
4
System Programming TE-IT
No
01 Implementation of lexical
analyzer
CO and PO Mapping:
COs /POs PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12
CO1
CO2
CO3
5
System Programming TE-IT
Experiment No. 5
** Recursive Descent parser for assignment statement **
/ /20
Objective: -
To understand the process of parsing & to study bottom-up & top down parsing.
Outcomes:
At the end of the assignment the students should have
1. Understood the design and implementation of parser
Theory:
One of the most straightforward forms of parsing is recursive descent parsing. This is a top-down
process in which the parser attempts to verify that the syntax of the input stream is correct as it is read
from left to right. A basic operation necessary for this involves reading characters from the input stream
and matching then with terminals from the grammar that describes the syntax of the input. Our recursive
descent parsers will look ahead one character and advance the input stream reading pointer when proper
matches occur.
What a recursive descent parser actually does is to perform a depth-first search of the derivation tree for
the string being parsed. This provides the 'descent' portion of the name. The 'recursive' portion comes
from the parser's form, a collection of recursive procedures.
6
System Programming TE-IT
E x+T
T (E)
Tx
A recursive descent parser traverses the tree by first calling a procedure to recognize an E. This
procedure reads an 'x' and a '+' and then calls a procedure to recognize a T.
Input:
1. Grammar Rules
2. String
Output:
Evaluation of String
Algorithm:
1. Give input string.
2. Mention Grammar.
3. Compare each toke of string with grammar.
4. If token satisfies the grammar rule then return the evaluation of string else evaluation not
possible.
7
System Programming TE-IT
8
System Programming TE-IT
CO and PO Mapping:
COs /POs PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12
CO1
CO2
CO3
9
System Programming TE-IT
Experiment No. 6
** Implementation of Calculator using LEX and YACC **
/ /20
Objective: -
1. To understand the role of LEX and YACC.
Outcomes:
At the end of the assignment the students should have
1. Understood implementation of LEX and YACC
Theory:
Lex several tools have been built for constructing lexical analyzers from special purpose
notations based on regular expressions several algorithms exist for compiling regular expressions into
pattern matching algorithms Lex is a tool which uses such algorithm
Lex is a tool widely used to specify lexical analyzers for variety of languages. The tool shows
how the speciation of patterns using regular expression can be combined with actions that LA may be
required to perform.
10
System Programming TE-IT
Specification of Lexical Analyzer is prepared by creating a program lex.1 in Lex language. Lex.1 is run
through Lex compilers to produce yy.c which consist of a tabular representation of transition diagram
constructed from regular expression of Lex.1, together with a standard routine that uses the table to
recognize lexemes actions associated with regular expressions in Lex.l R pieces of C code and are
carried over directly to Lex.yy.c finally lex.yy.c is run through C compiler to produce a.out which is the
lexical analyzer that transforms an input stream into a sequence of tokens
Lex Specifications:
Declarations
%%
Transition Rules
%%
Auxiliary Procedures
/* Example of Declaration */
%{
#include “yy.tab.h”
extern int yylval;
%}
11
System Programming TE-IT
install_id ()
{
/*
*/
}
install_num ()
{
/*
*/
Explanation
12
System Programming TE-IT
Translation Rules Structure of LA is such that it keeps trying to recognize tokens, until action
associated with one found causes a return.
Yylval is a variable whose definition appears in Lex output lex.yy.c and which is also available
to parser. Purpose of yylval is to hold the lexical value returned. „return‟ statement can only return a
code for token class.
Variable yytext corresponds to the pointer to the first character of lexeme & yyleng is integer telling
how long the lexeme is.
Parser Generators
YACC – yet another compiler – compiler facilitates the construction of front end of the Yacc
specification
Declarations
%%
Transition rules
%%
supporting C routines
Declaration Part
Translation rules part % % & then rules each translation rule consist of a grammar production &
associated semantic action.
13
System Programming TE-IT
1) „+‟,‟-„ are quoted single characters of type „c‟ and are treated as terminal symbols
2) Unquoted strings of letters and digits not declared to be tokens are taken as non-terminals –expr.
3) Alternative right sides can be separated by a vertical bar and a semicolon follows each left side
with its alternatives & their semantic actions first left side is taken as start symbol.
YACC semantic action is a sequence of „C‟ statements. In semantic action $$ refers to the value
associated with non terminal on left and while $i refers to the value associated with ith grammar symbol
[T \ NT] on right.
Supporting C – routines - other procedures such as error recovery routines may be provided.
14
System Programming TE-IT
1. What is yylex()?
2. What does the ‘Definition section’ contain?
3. What does the ‘Rule section’ contain?
4. What does the last section contain?
5. What is the difference between yylex() and scanf()?
6. How is the instruction in the first section used?
7. Explain longest match.
8. What is the rule of lex to specify file
9. Explain more applicable rule
10. Is Yacc a compiler?
15
System Programming TE-IT
COs /POs PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12
CO1
CO2
CO3
16
System Programming TE-IT
Experiment No. 7
** Intermediate code generation using LEX &YACC for Control Flow and Switch Case statements.**
Marks: / 10
Date of Performance: Sign with Date
/ /20
Aim : Intermediate code generation using LEX &YACC for Control Flow and Switch Case
statements.
Objective: -
1. To understand intermediate code generation using LEX and YACC
Outcomes:
At the end of the assignment the students should have
1. Understood intermediate code generation using LEX And YACC
Theory:
LEX
The unix utility lex parses a file of characters. It uses regular expression matching; typically it is used to
„tokenize‟ the contents of the file. In that context, it is often used together with the yacc utility.
However, there are many other applications possible.
17
System Programming TE-IT
...definitions...
%%
...rules...
%%
...code...
Definition Section:
C code Any indented code between %{ and %} is copied to the C file. This is typically used for defining
file variables, and for prototypes of routines that are defined in the code segment.
definitions A definition is very much like a #define cpp directive. For example
letter [a-zA-Z]
These definitions can be used in the rules section: one could start a rule
{letter}+ {...
state definitions If a rule depends on context, it‟s possible to introduce states and incorporate those in
the rules. A state definition looks like %s STATE, and by default a state INITIAL is already given.
Rules section
The rules section has a number of pattern-action pairs. The patterns are regular expressions, and
the actions are either a single C command, or a sequence enclosed in braces.
If the lex program is to be used on its own, this section will contain a main program. If you leave
this section empty you will get the default main:
int main()
{
yylex(); return
0;
}
18
System Programming TE-IT
YACC
The unix utility yacc (Yet Another Compiler Compiler) parses a stream of token, typically generated by
lex, according to a user-specified grammar.
...definitions...
%%
...rules...
%%
...code...
Definitions :
All code between %{ and %} is copied to the beginning of the resulting C file.
Rules:
A number of combinations of pattern and action: if the action is more than a single command it needs to
be in braces.
Code:
This can be very elaborate, but the main ingredient is the call to yylex, the lexical analyser. If the code
segment is left out, a default main is used which only calls yylex.
We could translate the source program directly into the target language. However, there are benefits to
having an intermediate, machine-independent representation.
1. A clear distinction between the machine-independent and machine-dependent parts of the
compiler
2. Retargeting is facilitated the implementation of language processors for new machines will
require replacing only the back-end.
3. We could apply machine independent code optimization techniques
Intermediate representations span the gap between the source and target languages.
3-ADDRESS CODE
The general form is x := y op z, where “op” is an operator, x is the result, and y and z are operands. x, y,
z are variables, constants, or “temporaries”. A three-address instruction consists of at most 3 addresses
19
System Programming TE-IT
A TAC instruction has at most one operator on the RHS of an instruction; no built-up arithmetic
expressions are permitted.
e.g. x + y * z can be translated as t1 =
y*z
t2 = x + t1
Where t1 & t2 are compiler–generated temporary names.
There are different types of statements in source program to which three address code has to be
generated. Along with operands and operators, three address code also use labels to provide flow of
control for statements like if-then-else, for and while. The different types of three address code
statements are:
Assignment statement a = b
op c
In the above case b and c are operands, while op is binary or logical operator. The result of applying op
on b and c is stored in a.
Unary operation
t2 = t1 * b
t3 = t2 + d a = t3
Copy Statement a = b
v. Creates label L, generate code for expression exp, If the exp returns value true then go to the
statement labelled L. exp returns a value false go to the statement immediately following the if
20
System Programming TE-IT
statement.
Function call
Param a2
…
Param an Call
fun, n
Where param defines the arguments to function.
Array indexing
In order to access the elements of array either single dimension or
multidimension, three address code requires base address and offset value. Base address consists of the
address of first element in an array. Other elements of the array can be accessed using the base address
and offset value.
Example: x = y[i]
similarly x[i] = y
Pointer assignment
Intermediate representation should have an operator set which is rich to implement most of the
operations of source language. It should also help in mapping to restricted instruction set of target
machine.
21
System Programming TE-IT
Three address code is represented as record structure with fields for operator and operands. These
records can be stored as array or linked list. Most common implementations of three address code are-
Quadruples, Triples and Indirect triples.
Quadruples-
Quadruples consists of four fields in the record structure. One field to store operator op, two fields to
store operands or arguments arg1and arg2 and one field to store result res. res = arg1 op arg2 Example: a
=b+c
Unary operators like „-„do not use agr2. Operators like param do not use agr2 nor result. For conditional
and unconditional statements res is label. Arg1, arg2 and res are pointers to symbol table or literal table
for the names.
Example: a = -b * d + c + (-b) * d
t2 = t1 * d
t3 = t2 + c
t4 = - b
t5 = t4 * d
t6 = t3 + t5 a = t6
Triples
22
System Programming TE-IT
Triples uses only three fields in the record structure. One field for operator, two fields for operands
named as arg1 and arg2. Value of temporary variable can be accessed by the position of the statement
the computes it and not by location as in quadruples.
Example: a = -b * d + c + (-b) * d
Arg1 and arg2 may be pointers to symbol table for program variables or literal table for constant or
pointers into triple structure for intermediate results.
Example: Triples for statement x[i] = y which generates two records is as follows
Triples are alternative ways for representing syntax tree or Directed acyclic graph for program defined
23
System Programming TE-IT
names.
Indirect Triples
Indirect triples are used to achieve indirection in listing of pointers. That is, it uses pointers to triples
than listing of triples themselves.
Example: a = -b * d + c + (-b) * d
Syntax Trees
Syntax trees are high level IR. They depict the natural hierarchical structure of the source program.
Nodes represent constructs in source program and the children of a node represent meaningful
components of the construct. Syntax trees are suited for static type checking.
if(a<b) then
x=y+z
else p=q+r
3 address code:
1. if(a<b) goto 3
2. goto 6
3. t1=y+z
4. x=t1
5. goto 8
24
System Programming TE-IT
6. t2=q+r
7. p=t2
8.
While statement
while(a<b)
do x=y+z
3 address code
1. if(a<b) goto 3
2. goto 6
3. t1=y+z
4. x=t1
5. goto 1
do while statement do
x=y+z while
a<b
3 address code
1. t1=y+z
2. .x=t1
3. if a<b goto 1
4. goto....
For statement
for(i=1;i<=20;i++)
x=y+z
3 address code
1. i=1
2. if i<=20 goto 7
3. goto 10
4. t1=i+1
5. i=t1
6. goto 2
25
System Programming TE-IT
7. t2=y+z
8. x=t2
9. goto 4
10.
Conclusion: Thus we have implemented Intermediate code generation using LEX &YACC for Control
Flow and Switch Case statements.
26
System Programming TE-IT
27
System Programming TE-IT
CO and PO Mapping:
COs /POs PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12
CO1
CO2
CO3
28