Docsity

compiler design is use for computer science students, Essays (university) of Compiler Design

Toggle sidebar
bg1
Compiler design
PROBLEM STATEMENT:lexical analysis is the process of converting a sequence of charcters from
source program into a sequence of charchters from source program into a sequence of tokens. A program
which performs lexical analysis is termed as a lexical analyzer,tokenizer or scanner
SOURCE CODE:
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.
SCANNER:
The tokens are passed on to the parser from the lexical analyser.Although scanner is the first phase of
compiler,the compilation operation is initiated onliy in the parser .hence the scanner program is not
independent routine;it acts as a subroutine for the parser.
PARSER:
The parser starts checking for the structure or the syntax of the language specified by the context free
grammer.whenever we it is need of a token from parsing , it requests the scanner program for the
token .In turn the scanner reads the source code ,separates the tokens , and passes in to the parser.the
parser then checks for the structure of the sentence specified by the grammer.
TOKENS:
pf3
pf4
pf5

Partial preview of the text

Download compiler design is use for computer science students and more Essays (university) Compiler Design in PDF only on Docsity!

Compiler design

PROBLEM STATEMENT:lexical analysis is the process of converting a sequence of charcters from source program into a sequence of charchters from source program into a sequence of tokens. A program which performs lexical analysis is termed as a lexical analyzer,tokenizer or scanner

SOURCE CODE:

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.

SCANNER: The tokens are passed on to the parser from the lexical analyser.Although scanner is the first phase of compiler,the compilation operation is initiated onliy in the parser .hence the scanner program is not independent routine;it acts as a subroutine for the parser. PARSER: The parser starts checking for the structure or the syntax of the language specified by the context free grammer.whenever we it is need of a token from parsing , it requests the scanner program for the token .In turn the scanner reads the source code ,separates the tokens , and passes in to the parser.the parser then checks for the structure of the sentence specified by the grammer. 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; contains the tokens: int (keyword), value (identifier), = (operator), 100 (constant) and ; (symbol). Specifications of Tokens

SYMBOL TABLE :Symbol table is an important data structure created and

maintained by compilers in order to store information about the occurrence of

various entities such as variable names, function names, objects, classes,

interfaces, etc. Symbol table is used by both the analysis and the synthesis parts

of a compiler.

METHODS:

IDENTIFIER:Identifiers are symbols used to uniquely identify a program

element in the code. They are also used to refer to types, constants, macros

and parameters. An identifier name should indicate the meaning and usage

of the element being referred.

  • It can start only with a letter of the alphabet or underscore(_),

but not a number

  • It can be a combination of numbers, letters, connectors, Unicode

escape sequence, etc.

  • It cannot be a keyword
  • It should not contain white space
  • It has to be declared before it is referred KEYWORDS:Keywords are reserved words which cannot ne used as identifiers. PROPERTIES:
  • (^) These cannot be used as identifiers.

for(j=startid; j<=endid; j++) printf("%c", str[j]); printf(" : Identifier");state=0;i--; } break; KEYWORD CODE: //States for 'if switch(ch) { case1:if(str[i]=='f') state=2; else { state=17; startid=i-1; i--; } case2: if(str[i]=='(' || str[i]==NULL) { printf("if : Keyword"); state=0; i—; } else { state=17; startid=i-2; i--; } break; }

OPERATORS CODE:

if(str[i]=='=') state=24; else { printf("= : Assignment operator"); i--; state=0; } break;

DELIMITERS CODE: /State for special character '(' switch(ch) { case 1: printf("(:Special character"); startid=i; state=0; i--; break; }

/State for special character ')' switch(ch) { case 1: printf(") : Special character"); state=0; i--; break; }

//state for special character ';' switch(ch)