Compiler Lab Report
Compiler Lab Report
Student ID :182015030
1
Index Page
2
Experiment No - 01
Title
Generally, there are two type of comment in editor which we use. Those
are-
i. Single line comment.
ii. Multi line comment.
Removing the comment is happened in lexical analyzer.
Lexical analysis is the first phase of a compiler. It takes the modified
source code from language preprocessors that are written in the form of
sentences. The lexical analyzer breaks these syntaxes into a series of
tokens, by removing any whitespace or comments in the source code.
3
If the lexical analyzer finds a token invalid, it generates an error. The
lexical analyzer works closely with the syntax analyzer. It reads character
streams from the source code, checks for legal tokens, and passes the data
to the syntax analyzer when it demands.
4
Procedure:
5
Output
Limitation:
From this experiment we can understand how to remove single and multi-
line comment from a program.
6
Experiment No - 02
Title:
Learning Outcome:
After complete this experiment I will know how to separate token using
lexical analyzer in compiler.
Theory
Lexical analysis is the first phase of a compiler. It takes the modified
source code from language preprocessors that are written in the form of
sentences. The lexical analyzer breaks these syntaxes into a series of
tokens, by removing any whitespace or comments in the source code.
If the lexical analyzer finds a token invalid, it generates an error. The
lexical analyzer works closely with the syntax analyzer. It reads character
streams from the source code, checks for legal tokens, and passes the data
to the syntax analyzer when it demands.
Tokens
Lexemes are said to be a sequence of characters (alphanumeric) in a
token. There are some predefined rules for every lexeme to be identified
as a valid token. These rules are defined by grammar rules, by means of
a pattern. A pattern explains what can be a token, and these patterns are
defined by means of regular expressions.
In programming language, keywords, constants, identifiers, strings,
numbers, operators and punctuations symbols can be considered as
tokens.
For example, in C language, the variable declaration line
Int value = 100;
7
contains the tokens:
int (keyword), value (identifier), = (operator), 100 (constant) and ;
(symbol).
Special Symbols
Assignment =
Preprocessor #
8
Shift Operator >>, >>>, <<, <<<
9
Procedure
Output:
10
Discussion:
Experiment No: 03
Title:
Theory:
11
Procedure:
12
Result:
Discussion:
13
Experiment No: 04
Title:
14
Concatenation of two
languages L and M is
written as LM = {st | s is
in L and t is in M}
The Kleene Closure
of a language L is
written as L* = Zero
or more occurrence
of language L.
15
Procedure:
16
Output
17