Professional Documents
Culture Documents
STUDENT ID - 201001102018
BATCH - BCA1
STREAM - BCA(H)
SEMESTER NO. - 2
ASSIGNMENT NO. -2
1)Explain nested macro call with short example.
ANS:
Nested Macro Call :
MACRO
CAL &P
MOVE , AREGR, &P, ADD, ‘I’ (Set of instruction of macro)
MEND
MACRO X Y Z (Argument X,Y,Z passed through &P1,&P2,&P3)
CAL 1 &P1,P2,P3
CAL &P 1 CAL X
MOVE , AREGR X, ADD X, ‘I’
CAL &P 2 CAL Y
MOVE , AREGR Y, ADD Y, ‘I’
CAL & P3 CAL Z
MOVE , AREGR Z, ADD Z, ‘I’
CAL 1 X,Y,Z
MEND
Example :
A macro may be used in the definition of another macro as illustrated below.
Program illustrates this concept. In this program, Area is a function of x, and the cost of
painting the area is defined as a function of area in the macro definition.
#include<stdio.h>
#define Area(x) x*x
#define Costpaint(x,y,z) (z*y + Area (x))
void main()
{
int A = 8, B= 6, C = 4;
clrscr();
printf("The area of square= %d\n", Area(A));
printf("Cost of paint= %d\n", Costpaint(A,B,C));
}
- It becomes increasingly difficult to handle large number of segments when the input code is
written in a variety of HLL say one routine in pascal and one in FORTRAN and so on.
- Such loaders make designing modular programs and systems near impossible.
ANS:
LEX
Lex is a computer program that generates lexical analyzers. Mike Lex and Eric Schmidt are
the original developers of Lex. It is a standard lexical analyzer generator on various UNIX
systems. Lex is specified as a part of the POSIX standard. Generally, Lex is used with the
Yacc parser generator. Furthermore, Lex reads an input stream specifying the lexical
analyzer. Then, it outputs the source code implementing the lexer in the C language.
Rules: It contains regular expression patterns with C statements. When the lexer identifies
that the text in the input matches a given pattern, it will execute the associated C code.
YACC
Yacc stands for Yet Another Compiler-Compiler. Stephan C. Johnson developed it, and it is
used in UNIX systems. It is a standard utility on BSD and AT&T UNIX. Additionally, GNU
based Linux distributions include Bison, forward-compatible Yacc replacement.
Moreover, the input to Yacc is a grammar of C code that is attached to its rules. The output is
a shift-reduce parser in C. After recognizing the rule, it executes the C code associated with
each rule. Further, the typical actions include generating the parse tree.
ANS:
Scanning: Turning source code into a token stream. This stage removes white space and
comments, and identifies what kind of token each piece of the code is.
Parsing: Turning a token stream into a parse tree. This stage checks that the sequence of
tokens is grammatically correct and can be grouped together according to the specifications
of how the language works.
ANS:
Macro Subroutine
Macro can be called only in the program it is Subroutine can be called from other
defined. programs also.
Macro can be called only after its definition. This is not true for Subroutine.
Macro is used when the same thing is to be Subroutine is used for modularization.
done in a program a number of times.