cd lab mannual (2)
cd lab mannual (2)
cd lab mannual (2)
LAB MANUAL
INDEX
LAB ETHICS
Do's
1. Shut down the computers before leaving the lab.
2. Keep the bags outside in the racks.
3. Enter the lab on time and leave at proper time.
4. Maintain the decorum of the lab.
5. Utilize lab hours in the corresponding experiment.
6. Get your floppies checked by lab incharge before using it in the lab.
Don’ts
1. Don't bring any external material in the lab.
2. Don't make noise in the lab
3. Don't bring the mobile in the lab.
4. If extremely necessary then keep ringers off.
5. Don't enter in server room without permission of lab in charge.
6. Don't litter in the lab.
7. Don't delete or make any modification in system files.
8. Don't carry any lab equipment’s outside the lab.
INSTRUCTIONS
Before Entering in the Lab
1. All the students are supposed to prepare the theory regarding the next program.
2. Students are supposed to bring the practical file and the lab copy.
3. Previous program should be written in the practical file.
4. Algorithm of the current program should be written in the lab copy.
5. Any student not following these instructions will be denied entry in the lab.
Like any other High level language, C provides a collection of basic building blocks, symbolic words
called lexical elements of the language. Each lexical element may be a symbol, operator, symbolic
name or word, a special character, a label, expression, reserve word, etc. All these lexical elements
are arranged to form the statements using the syntax rules of the C language. Following are the
lexical elements of the C language.
C Character Set
Every language has its own character set. The character set of the C language consists of basic
symbols of the language. A character indicates any English alphabet, digit or special symbol
including arithmetic operators. The C language character set includes:
Letter, Uppercase A ….. Z, Lower case a….z
Digits, Decimal digits 0….9.
Special Characters, such as comma, period. semicolon; colon: question mark?, apostrophe‘
quotation mark “ Exclamation mark ! vertical bar | slash / backslash \ tilde ~ underscore _
dollar $ percent % hash # ampersand & caret ^ asterisk * minus – plus + <, >, (, ), [,], {, }
White spaces such as blank space, horizontal tab, carriage return, new line and form feed.
C Tokens
In a passage of text, individual words and punctuation marks are called tokens. Similarly, in C
program, the smallest individual units are known as C tokens. C has following tokens
Keywords
Key words or Reserve words of the C language are the words whose meaning is already defined and
explained to the C language compiler. Therefore Reserve words can not be used as identifiers or
variable names. They should only be used to carry the pre-defined meaning. For example int is a
reserve word. It indicates the data type of the variable as integer. Therefore it is reserved to carry the
specific meaning. Any attempt to use it other than the intended purpose will generate a compile time
error. C language has 32 keywords. Following are some of them
auto break case char const continue
default
6
Constants
A constant can be defined as a value or a quantity which does not change during the execution of a
program. Meaning and value of the constant remains unchanged throughout the execution of the
program. These are also called as literals. C supports following types of constant.
1. Integer Constants
An integer constant refers to a sequence of digits. There three types of integer constants, namely
decimal, octal and hexadecimal. Decimal integer constant consists of set of digits from 0 to 9
preceded by an optional + or – sign.
Ex: 123, -321, 0, 4567, + 78
Embedded spaces, commas and non-digit characters are not permitted between digits. An octal
integer constant consists of any combination of digits from 0 to 7 with a leading 0(zero). Ex : 037,
0435, 0567. A sequence of digits preceded by 0x or 0X is considered as hexadecimal digit. They may
also include alphabets A to F or a to f representing numbers from 10 to 15. The largest integer value
that can be stored is machine dependant; It is 32767 for 16 bit computers. It is also possible to store
larger integer constants by appending qualifiers such U, L and UL to the constants.
4. String constants
A string constant is a sequence of characters enclosed in double quotes. The characters may be
alphabets, numbers special characters and blank space. Ex: “Hello”, “2002”, “Wel Come”, “5+3”
7
Identifiers
An identifier is a sequence of letters, digits and an underscore. Identifiers are used to identify or name
program elements such as variables, function names, etc. Identifiers give unique names to various
elements of the program. Some identifiers are reserved as special to the C language. They are called
keywords.
Variables
A variable is a data name that may be used to store data value. A value or a quantity which may vary
during the program execution can be called as a variable. Each variable has a specific memory
location in memory unit, where numerical values or characters can be stored. A variable is
represented by a symbolic name. Thus variable name refers to the location of the memory in which a
particular data can be stored. Variables names are also called as identifiers since they identify the
varying quantities. For Ex : sum = a+b. In this equation sum, a and b are the identifiers or variable
names representing the numbers stored in the memory locations.
Rules to be followed for constructing the Variable names(identifiers)
Data Types
Data refers to any information which is to be stored in a computer. For example, marks of a student,
salary of a person, name of a person etc. These data may be of different types. Computer allocates
memory to a variable depending on the data that is to be stored in the variable. So it becomes
necessary to define the type of the data which is to be stored in a variable while declaring a variable.
The different data types supported by C are as follows:
String refers to a series of characters. Strings are declared as array of char types. Ex: char name[20];
will reserve a memory location to store upto 20 characters.
Further, applying qualifiers to the above primary data types yield additional data types. A qualifier
alters the characteristics of the data type, such as its sign or size. There are two types of qualifiers
namely, sign qualifiers and size qualifiers. signed and unsigned are the sign qualifiers short and long
are the size qualifiers.
10
The above statement tells the compiler that value of variable must not be modified during the
execution of the program. Any attempt change the value will generate a compile time error.
Declaring a variable as volatile
Declaring the variable volatile qualifier tells the compiler explicitly that the variable’s value may be
changed at any time by some external source and the compiler has to check the value of the variable
each time it is encountered.
11
Parenthesis
()
Array index 1 L–R
[]
+ Unary plus
- Unary minus
++ Increment
-- Decrement
2 R–L
! Logical negation
~ One’s Complement
& Address of
sizeof(type) type cast conversion
* Multiplication
/ Division 3 L- R
% Modulus
+ Addition
4 L–R
- Subtraction
<< Left Shift
5 L–R
>> Right Shift
< Less than
<= Less than or equal to
6 L–R
> Greater than
>= Greater than or equal to
== is equal to
7 L–R
!= Not equal to
& Bitwise AND 8 L–R
12
Preprocessor directives:
There are different preprocessor directives. The table below shows the preprocessor directives.
Directive Function
#define defines a macro substitution
#undef Undefines a macro
#include Specifies the files to be included.
#ifdef Tests for a macro definition
#endif Specifies the end of #if
#ifndef Tests whether a macro is not defined
#if Tests a compile-time condition
#else Specifies alternatives when #if tests fails
Header files:
C language offers simpler way to simplify the use of library functions to the greatest extent possible.
This is done by placing the required library function declarations in special source files, called header
files. Most C compilers include several header files, each of which contains declarations that are
functionally related. stdio.h is a header file containing declarations for input/ouput routines; math.h
contains declarations for certain mathematical functions and so on. The header files also contain other
information related to the use of the library functions, such as symbolic constant definitions.
13
The required header files must be merged with the source program during the compilation process.
This is accomplished by placing one or more #include statements at the beginning of the source
program. The other header files are:
<ctype.h> character testing and conversion functions
<stdlib.h> utility functions such as string conversion routines , memory allocation routines, random
number generator etc
<string.h> String manipulations functions
<time.h> Time manipulation functions
14
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.
...definitions...
%%
...rules...
%%
...code...
%%
. charcount++;
\n {linecount++; charcount++;}
%%
int main() {
yylex();
printf("There were %d characters in %d lines\n", charcount,linecount);
return 0; }
In the example you just saw, all three sections are present:
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.
15
The heart of the input specification is a collection of grammar rules. Each rule describes an allowable
structure and gives it a name. For example, one grammar rule might be
Here, date, month_name, day, and year represent structures of interest in the input process;
presumably, month_name, day, and year are defined elsewhere. The comma ``,'' is enclosed in single
quotes; this implies that the comma is to appear literally in the input. The colon and semicolon merely
serve as punctuation in the rule, and have no significance in controlling the input. Thus, with proper
definitions, the input
July 4, 1776
16
EXPERIMENT-1
AIM:
Introduction: Objective, scope and outcome of the course.
OBJECTIVE:
The laboratory course is intended to make experiments on the basic techniques of compiler construction and
tools that can be used to perform syntax-directed translation of a high-level programming language into an
executable code. Students will design and implement language processors in C by using tools to automate parts
of the implementation process. This will provide deeper insights into the more advanced semantics aspects of
programming languages, code generation, machine independent optimizations, dynamic memory allocation,
and object orientation.
SCOPE:
The scope of this course is to explore the principle, algorithm and data structure involved in the design and
construction of compiler.
OUTCOMES:
Upon the completion of Compiler Design practical course, the student will be able to:
1. Understand the working of lex and yacc compiler for debugging of programs.
2. Understand and define the role of lexical analyzer, use of regular expression and transition diagrams.
3. Understand and use Context free grammar, and parse tree construction.
4. Learn & use the new tools and technologies used for designing a compiler.
5. Develop program for solving parser problems.
6. Learn how to write programs that execute faster.
17
Compiler is a software which converts a program written in high level language (Source Language)
to low level language (Object/Target/Machine Language).
Cross Compiler that runs on a machine ‘A’ and produces a code for another machine ‘B’. It
is capable of creating code for a platform other than the one on which the compiler is running.
Phases of a Compiler –
There are two major phases of compilation, which in turn have many parts. Each of them take input
from the output of the previous level and work in a coordinated way.
18
Analysis Phase – An semantic tree representation is created from the give source code:
1. Lexical Analyzer
2. Syntax Analyzer
3. Semantic Analyzer
Lexical analyzer divides the program into “tokens”, Syntax analyzer recognizes “sentences” in the
program using syntax of language and Semantic analyzer checks static semantics of each
construct.
EXPERIMENT-2
AIM:
PROGRAM:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char a[5][10]={"printf","scanf","if","else","break"}; char
str[10];
int i,flag;
clrscr();
for(i=0;i<strlen(str);i++)
{
if(strcmp(str,a[i])==0)
{
flag=1;
break;
}
else
flag=0;
}
20
if(flag==1)
puts("Keyword");
else
puts("String");
getch();
}
21
EXPERIMENT-3
AIM:
PROGRAM:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
static int count=0;
int isKeyword(char buffer[]){
char keywords[32][10] =
{"auto","break","case","char","const","continue","default","do","double","else","enum","extern","fl
oat","for","goto","if","int","long","register","return","short","signed","sizeof","static","struct","switc
h","typedef","union","unsigned","void","volatile","while"};
int i, flag = 0;
return flag;
}
int main(){
char ch, buffer[15] ;
FILE *fp;
int i,j=0;
fp = fopen("KESHAV3.C","r");
if(fp == NULL){
printf("error while opening the file\n");
exit(0);
22
if(isKeyword(buffer) == 1)
printf("%s is keyword\n", buffer);
}
printf("no of keywords= %d", count);
fclose(fp);
return 0;
}
23
EXPERIMENT-4
AIM:
PROGRAM:
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
static int count=0;
int main(){
char ch, buffer[15], operators[] = "+-*/%=";
FILE *fp;
int i;
clrscr();
fp = fopen("KESHAV3.C","r");
if(fp == NULL){
printf("error while opening the file\n");
exit(0);
}
}
printf("no of operators= %d", count);
fclose(fp);
return 0;
}
24
EXPERIMENT-5
AIM:
Count total occurrence of each character in a given file. [Taking file from user]
PROGRAM:
#include <stdio.h>
#include <string.h>
#include<conio.h>
int main ()
{
FILE * fp;
char string[100];
int c = 0, count[26] = { 0 }, x;
{ c=0;
while (string[c] != '\0')
{
/** Considering characters from 'a' to 'z' only and ignoring others. */
x = string[c] - 'a';
count[x]++;
25
c++;
}
}
26
EXPERIMENT-6
AIM:
Write a C program to insert, delete and display the entries in Symbol Table.
PROGRAM:
//Implementation of symbol table
#include<stdio.h>
#include<ctype.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
void main()
{
int i=0,j=0,x=0,n;
void *p,*add[5];
char ch,srch,b[15],d[15],c;
printf("Expression terminated by $:");
while((c=getchar())!='$')
{
b[i]=c;
i++;
}
n=i-1;
printf("Given Expression:");
i=0;
while(i<=n)
{
printf("%c",b[i]);
i++;
}
printf("\n Symbol Table\n");
printf("Symbol \t addr \t type");
while(j<=n)
{
c=b[j];
if(isalpha(toascii(c)))
{
p=malloc(c);
add[x]=p;
d[x]=c;
printf("\n%c \t %d \t identifier\n",c,p);
x++;
j++;
27
}
else
{
ch=c;
if(ch=='+'||ch=='-'||ch=='*'||ch=='=')
{
p=malloc(ch);
add[x]=p;
d[x]=ch;
printf("\n %c \t %d \t operator\n",ch,p);
x++;
j++;
}}}}
28
EXPERIMENT-7
AIM:
PROGRAM:
/* Rule Section */
%%
%%
// driver code
int main()
{
printf("\nEnter Mobile Number : ");
yylex();
printf("\n");
return 0;
}
int yywrap()
{
}
29
2. Valid url
%%
.+ {printf("\nURL Invalid\n");}
%%
void main() {
yylex();
printf("\n");
}
int yywrap()
{
}
30
3. Valid identifier
%%
void main() {
yylex();
printf("\n");
}
int yywrap()
{
}
31
%{
#include<stdio.h>
int i=0,yr=0,valid=0;
%}
%%
([0-2][0-9]|[3][0-1])\/((0(1|3|5|7|8))|(10|12))\/([1-2][0-9][0-9][-0-9]) {valid=1;}
([0-2][0-9]|30)\/((0(4|6|9))|11)\/([1-2][0-9][0-9][0-9]) {valid=1;}
([0-1][0-9]|2[0-8])\/02\/([1-2][0-9][0-9][0-9]) {valid=1;}
%%
void main()
{
yyin=fopen("new","r");
yylex();
if(valid==1) printf("It is a valid date\n");
else printf("It is not a valid date\n");
}
int yywrap()
{
return 1;
}
32
5. Valid time(hh:mm:ss)
%{
#include<stdio.h>
int i=0,yr=0,valid=0;
%}
%%
([0-2][0-9]:[0-6][0-9]\:[0-6][0-9]) {printf("%s It is a valid time\n",yytext);}
%%
void main()
{
yyin=fopen("new","r");
yylex();
}
int yywrap()
{
return 1;
}
33
EXPERIMENT-8
AIM:
PROGRAM:
%{
#include<stdio.h>
int lines=0, words=0,s_letters=0,c_letters=0, num=0, spl_char=0,total=0;
%}
%%
\n { lines++; words++;}
[\t ' '] words++;
[A-Z] c_letters++;
[a-z] s_letters++;
[0-9] num++;
. spl_char++;
%%
void main(void)
{
FILE *fp;
char f[50];
printf("enterfile name \n");
scanf("%s",f);
yyin= fopen(f,"r");
yylex();
total=s_letters+c_letters+num+spl_char;
printf(" This File contains ..."); printf("\
n\t%d lines", lines); printf("\n\t%d
words",words); printf("\n\t%d small
letters", s_letters); printf("\n\t%d capital
letters",c_letters); printf("\n\t%d digits",
num);
printf("\n\t%d special characters",spl_char);
printf("\n\tIn total %d characters.\n",total);
}
int yywrap()
{
return(1);
}
34
EXPERIMENT-9
AIM:
Write a lex program to count the no. of vowels and consonants in a C file.
PROGRAM:
%{
#include<stdio.h>
int vcount=0,ccount=0;
%}
%%
[a|i|e|o|u|E|A|I|O|U] {vcount++;}
[a-z A-Z (^a|i|e|o|u|E|A|I|O|U) ] {ccount++;}
%%
int main()
{
FILE *fp;
char f[50];
printf("enterfile name \n");
scanf("%s",f);
yyin= fopen(f,"r");
yylex();
printf("No. of Vowels :%d\n",vcount);
printf("No. of Consonants :%d\n",ccount);
return 0;
}
int yywrap()
{
}
35
EXPERIMENT-10
AIM:
Write a YACC program to recognize strings aaab,abbb using a^nb^n, where b>=0.
PROGRAM:
Gm.l
%{
#include "y.tab.h"
%}
%%
"a"|"A" {return A;}
"b"|"B" {return B;}
[ \t] {;}
\n {return 0;}
. {return yytext[0];}
%%
int yywrap()
{
return 1;
}
Gm.y
%{
#include<stdio.h>
%}
%token A B
%%
stmt: S
;
S: A S B
|
;
%%
void main()
{
printf("enter \n");
yyparse();
printf("valid");
exit(0);
36
}
void yyerror()
{
printf("invalid ");
exit(0);
}
37
EXPERIMENT-11
AIM:
Write a YACC program to evaluate an arithmetic expression involving operators +,-,* and /.
PROGRAM:
Expr.l
%{
#include "y.tab.h"
extern int yylval;
%}
%%
[0-9]+ {yylval=atoi(yytext);
return number;}
[\t] {;}
[\n] {return 0;}
. {return yytext[0];}
%%
int yywrap()
{
return 1;
}
Expr.y
%{
#include<stdio.h>
int res=0;
%}
%token number
%left '+' '-'
%left '*' '/'
%%
stmt:expr {res=$$;}
;
expr:expr '+' expr {$$=$1+$3;}
|expr '-' expr {$$=$1-$3;}
|expr '*' expr {$$=$1*$3;}
|expr '/' expr
{if($3==0)
exit(0);
else $$=$1/$3;}
38
|number
;
%%
void main()
{
printf(" enter expr\n");
yyparse(); printf("valid=
%d",res); exit(0);
}
void yyerror()
{
printf("invalid\n");
exit(0);
}
39
EXPERIMENT-12
AIM:
Write a YACC program to check validity of a strings abcd,aabbcd using grammar a^nb^nc^md^m,
where n , m>0
PROGRAM:
Grammer.y
%{
#include<stdio.h>
#include<stdlib.h>
int yyerror(char*);
int yylex();
%}
%token A B C D NEWLINE
%%
stmt: S NEWLINE { printf("valid\n");
return 1;
}
;
S: X Y
;
X: A X B
|
;
Y: C Y D
|
;
%%
extern FILE *yyin;
void main()
{
printf("enter \n");
do
{
yyparse();
}
while(!feof(yyin));
}
int yyerror(char* str)
{
40
printf("invalid ");
return 1;
}
Grammer.l
%{
#include"y.tab.h"
%}
%%
a|
A {return A;}
c|
C {return C;}
b|
B {return B;}
d|
D {return D;}
[ \t] {;}
"\n" {return NEWLINE;}
. {return yytext[0];}
%%
int yywrap()
{
return 1;
}
41
EXPERIMENT-13
AIM:
PROGRAM:
#include<stdio.h>
#include<ctype.h>
void FIRST(char
); int count,n=0;
char prodn[10][10], first[10];
void main()
{
int i,choice;
char c,ch;
printf("How many productions ? :");
scanf("%d",&count);
printf("Enter %d productions epsilon= $ :\n\n",count);
for(i=0;i<count;i++)
scanf("%s%c",prodn[i],&ch);
do
{ n=
0;
printf("Element :");
scanf("%c",&c);
FIRST(c);
printf("\n FIRST(%c)= { ",c);
for(i=0;i<n;i++)
printf("%c ",first[i]);
printf("}\n");
void FIRST(char c)
{
int j;
42
if(!(isupper(c)))first[n++]=c;
for(j=0;j<count;j++)
{
if(prodn[j][0]==c)
{
if(prodn[j][2]=='$') first[n++]='$';
else if(islower(prodn[j][2]))first[n++]=prodn[j][2];
else FIRST(prodn[j][2]);
}
}
}
43
Q4. Symbol table can be used for Q10. A compiler for a high level language that
A. Checking type compatibility runs on one machine and produces code for
B. Storage allocation a different machine is called
C. Suppressing duplication of error massages A. Optimizing compiler
D. All of the Above B. One pass compiler
Ans.: D C. Cross compiler
D. Multipass Compiler
Q5. A basic block can be analyzed by Ans.: C
A. A DAG
B. A graph which may involve the cycles Q11. An intermediate code form is
C. Flow Graph A. Postfix notation
D. None of These B. Syntax trees
Ans.: A C. Three address code
D. All of these
Q6. Assembly language Ans.: D
A. is usually the primary user interface
44
Q12. Which one of the following is not a syntax B. context free grammar
error C. context sensitive grammar
A. Semantic D. none of the above
B. Lexical Ans.: A
C. Arithmetic
D. Logical Q19. ‘Divide by 0’ is a
Ans.: A A. lexical error
B. syntactic error
Q13. Semantic errors can be detected C. semantic error
A. at compile time only D. internal error
B. at run time only Ans. C
C. both at compile and run time
D. none of these Q20. In which of the following has attribute
Ans.: C values at each node
A. Associated parse trees
Q14. The action of passing the source program B. Postfix parse tree
into the proper syntactic classes is known as C. Annotated parse tree
A. syntax analysis D. Prefix parse tree
B. lexical analysis Ans.: C
C. interpretation analysis
D. general syntax analysis Q21. CFG can be recognized by a
Ans.: B A. Push-down automata
B. 2-way linear bounded automata
Q15. Undeclared name is.....................error C. Both (a) and (b)
A. syntax D. None of these
B. lexical Ans. c
C. semantic
D. not an error Q22. The ambiguous grammar can have
Ans. C a. Only one parse tree
b. More than one parse tree
Q16. Intermediate code generator is used c. Parse trees with l-values
between d. None of the above
A. symbol table and code generator Ans. B
B. symbol table and code optimizer
C. code optimizer and code generator Q23. Which of the following suffices to convert
D. semantic analyzer and code optimizer an arbitrary CFG to an LL(1) grammar
Ans.: D a. Removing left recursion alone
b. Factoring the grammar alone
Q17. Grouping of characters into tokens is done c. Removing left recursion and factoring
by the the grammar
A. scanner d. None of the above
B. parser Ans. C
C. code generator
D. code optimizer Q24. The ‘k’ in LR(k) cannot be
Ans.: A a. 0
b. 1
Q18. Lexical analysis phase uses c. 2
A. regular grammar d. None of these
45
Ans. d a. (LUD)+
Q25. Non backtracking form of the top-down b. L(LUD)*
parser are called c. (LD)*
d. L(LD)*
a. Recursive-descent parsers Note: Here U stands for Union
b. Predictive parsers
c. Shift reduce parsers Ans. b
d. None of these Q31. Backtracking is possible in
Ans. b
a. LR parsing
Q26. Parsing table in the LR parsing contains b. Predictive parsing
a. action, goto c. Recursive descent parsing
b. state, action d. None of the above
c. input, action Ans. c
d. state, goto Q32. Consider the following grammar
Ans. a
a. expr op expr
Q27. The condensed form of the parse tree is b. expr->id
called c. op-> + | *
a. L-attributed Which of the following is true?
b. Inherited attributed a. op and expr are start symbols
c. DAG b. op and id are terminals
d. Syntax tree c. expr is start symbol and op is terminal
Ans. d d. none of these
Q28. The post fix form of A-B/(C*D$E) is Ans. c
46
a. LALR a. +-AB*C-D
b. SLR b. *+-ABCD
c. LR c. *+AB-CD
d. Predictive parser d. *AB+CD
Ans. a Ans. c
Q36. A top down parser generates Q42. Which of the following is true for the flow
of control among procedures during
a. left-most derivation
execution of program?
b. right-most derivation
c. right-most derivation in reverse a. Control flows randomly
d. left-most derivation in reverse b. Control flows line by line without
Ans. a jumping
c. Control flows sequentially
Q37. Synthesized attribute can easily be
d. None of these
simulated by an
Ans. c
a. LL grammar
Q43. In a syntax directed translation scheme, if
b. Ambiguous grammar
the value of an attribute of a node is a
c. LR grammar
function of the values of the attributes of its
d. None of the above
children, then it is called a
Ans. c
a. Synthesized attribute
Q38. Choose the false statement
b. Inherited attribute
a. LL(k) grammar has to be a CFG c. Canonical attribute
b. LL(k) grammar has to be unambiguous d. None of the above
c. There are LL(k) grammars that are Ans. a
not Context Free
Q44. Which of the following is not an
d. LL(k) grammars cannot have
intermediate code form?
left recursive non-terminals
Ans. c a. Postfix notation
b. Syntax trees
Q39. If a grammar is unambiguous then it is c. Three address code
surely be d. Quadruples
a. regular Ans. d
b. LL(1) Q45. Three address codes can be implemented
c. Both (a) and (b) by
d. Cannot say
Ans. d a. indirect triples
b. direct triples
Q40. Predictive parsing is a special case of c. both (a) and (b)
a. top down parsing d. none of the above
b. bottom up parsing Ans. a
c. recursive descent parsing Q46. In a bottom up evaluation of a syntax
d. none of the above directed definition, inherited attributes can
Ans. c be
Q41. The prefix form of (A+B)*(C-D) is
47
48
10. Write a program to perform following operations on a link list: Creation, Insertion and Display
11. Write a program to perform following operations on a link list: Creation, Insertion and Deletion
13. Write a program to recognize a valid arithmetic expression that uses operators +,-,*,/ using
YACC
14. Write a program to recognize a valid variable which starts with a letter followed by any number
of letters or digits using YACC
17. Write a program to find the Macro Statements in a given C file (Use C file as input file)
19. Write a program which will take two input strings. Find all the possible sub common strings
from the small String.
49
50