Professional Documents
Culture Documents
Assginment 01 - Complier Construction
Assginment 01 - Complier Construction
Qno: 01
List of Portable Compilers and differentiate any five
of them?
BDS Unix
GCC
GNU
Interactive C
Visual Express
Clang
GNU:
The GNU Compiler Collection (GCC) is an optimizing compiler produced by
the GNU Project supporting various programming languages, hardware
architectures and operating systems.
BDX:
The Berkeley Software Distribution or Berkeley Standard Distribution. BSD
was initially called Berkeley Unix because it was based on the source code of
the original Unix developed at Bell Labs. In the 1980s, although these
proprietary BSD derivatives were largely superseded in the 1990s by
UNIX SVR4 and OSF/1, later releases provided the basis for several open-
source operating systems
GCC:
GNU Compiler Collection is the compiler produced by the GNU Project. This
supports many programming languages and it is a free software foundation
under the General Public License. This compiler was first released in 1987 and
it supported only C- Programming language during the start. Slowly it
expanded to C++, Java, Android, and IOS. Here, each of the different language
compilers has its own program that reads the code written and sends the
machine code as the output. All of these have a common internal structure.
Clang:
Clang; including C, is also a compiler for C++, Objective-C, and objective C++
programming languages. This compiler uses LLVM for the back end code
related compilations. Clang has many contributors including Apple, Microsoft,
Google, Sony, and Intel. It is open-source software. LLVM was first used by
GCC for the front end compilation, but GCC had caused some problems for
developers at Apple, as the source code is large and difficult to use. So, they
had come up with Clang.
Qno: 02
What is Hash Table? Explain the working of Hash
Table?
Hash Table:
Hash Table is a data structure which stores data in an associative manner. In a
hash table, data is stored in an array format, where each data value has its own
unique index value. Access of data becomes very fast if we know the index of the
desired data. it becomes a data structure in which insertion and search operations
are very fast irrespective of the size of the data. Hash Table uses an array as a
storage medium and uses hash technique to generate an index where an element is
to be inserted or is to be located from.
(1,20)
(2,70)
(42,80)
(4,25)
(12,44)
(14,32)
(17,11)
(13,78)
(37,98)
1 1 1 % 20 = 1 1
2 2 2 % 20 = 2 2
3 42 42 % 20 = 2 2
4 4 4 % 20 = 4 4
5 12 12 % 20 = 12 12
6 14 14 % 20 = 14 14
7 17 17 % 20 = 17 17
8 13 13 % 20 = 13 13
9 37 37 % 20 = 17 17
Qno: 03
What's the meaning of GNU, GCC, POSIX in
compiler? Explanation required with example?
GNU:
GNU stands for GNU's Not UNIX. It is a UNIX like computer operating system,
but unlike UNIX, it is free software and contains no UNIX code. It is pronounced
as guh-noo. Sometimes, it is also written as GNU General Public License. It is
based on the GNU Hurd kernel and It is intended to develop and share software for
free, for all its users. The main objective of GNU was to provide free software.
Due to its similar design to UNIX, it is named as UNIX like computer system but it
contains no UNIX code. It is available in multiple language
This compiler comes by default with most *nix based operating systems, so if you
have installed and/or using Unix or Linux based operating system, in your system,
then you can find and use it easily.
For compiling your source code using GNU C compiler, you need to write like
this:
gcc program_name
GCC:
GCC stands for GNU Compiler Collections which is used to compile mainly C and
C++ language. It can also be used to compile Objective C and Objective C++. The
most important option required while compiling a source code file is the name of
the source program, rest every argument is optional like a warning, debugging,
linking libraries, object file etc. The different options of gcc command allow the
user to stop the compilation process at different stages.
gcc [-c|-S|-E] [-std=standard]
Example:
This will compile the source. c file and give the output file as a.out file which is
default name of output file given by gcc compiler, which can be executed
using ./a.out
gcc source.c
POSIX:
The POSIX thread libraries are a standards based thread API for C/C++. It allows
one to spawn a new concurrent process flow. It is most effective on multi-
processor or multi-core systems where the process flow can be scheduled to run on
another processor thus gaining speed through parallel or distributed processing.
Threads require less overhead than "forking" or spawning a new process because
the system does not initialize a new system virtual memory space and environment
for the process. While most effective on a multiprocessor system, gains are also
found on uniprocessor systems which exploit latency in I/O and other system
functions which may halt process execution. (One thread may execute while
another is waiting for I/O or some other system latency.) Parallel programming
technologies such as MPI and PVM are used in a distributed computing
environment while threads are limited to a single computer system. All threads
within a process share the same address space. A thread is spawned by defining a
function and it's arguments which will be processed in the thread. The purpose of
using the POSIX thread library in your software is to execute software faster.
Example:
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
main()
{
pthread_t thread1, thread2;
char *message1 = "Thread 1";
char *message2 = "Thread 2";
int iret1, iret2;
Compile:
C compiler: cc -lpthread pthread1.c
or
C++ compiler: g++ -lpthread pthread1.c
Run: ./a.out
Results:
Thread 1
Thread 2
Thread 1 returns: 0
Thread 2 returns: 0
The End