Posts

Showing posts from 2017

IMPLEMENTATION OF A LEXICAL ANALYZER USING LEX (WITH OUTPUT)

Image
AIM:     To write a program for implementing a Lexical analyser using LEX tool in Linux platform. ALGORITHM:  Step1: Lex program contains three sections: definitions, rules, and user subroutines. Each section must be separated from the others by a line containing only the    delimiter, %%.  The format is as follows:   definitions %% rules %% user_subroutines   Step2: In definition section, the variables make up the left column, and their definitions make up the right column. Any C statements should be enclosed in %{..}%. Identifier is defined such that the first letter of an identifier is alphabet and remaining letters are alphanumeric.  Step3: In rules section, the left column contains the pattern to be recognized in an input file to yylex(). The right column contains the C program fragment executed when that pattern is recognized. The various patterns are keywords, operators, new line character, number, string, identifier, beginning and end of block, comment statements,

DEVELOP A LEXICAL ANALYZER TO RECOGNIZE A FEW PATTERNS IN C( WITH OUTPUT)

Image
AIM: To develop a lexical analyzer to identify identifiers, constants, comments, operators etc using C program ALGORITHM:  Step1: Start the program.  Step2: Declare all the variables and file pointers.   Step3: Display the input program.  Step4: Separate the keyword in the program and display it.  Step5: Display the header files of the input program  Step6: Separate the operators of the input program and display it.   Step7: Print the punctuation marks.  Step8: Print the constant that are present in input program.  Step9: Print the identifiers of the input program. PROGRAM CODE: //Develop a lexical analyzer to recognize a few patterns in C. #include<string.h> #include<ctype.h> #include<stdio.h> #include<stdlib.h> void keyword(char str[10]) {  if(strcmp("for",str)==0||strcmp("while",str)==0||strcmp("do",str)==0||strcmp("int",str)==0||strcmp("float",str)==0||strcmp("char",str)==0||st

IMPLEMENTATION OF SYMBOL TABLE USING C (WITH OUTPUT)

Image
AIM: To write a program for implementing Symbol Table using C. ALGORITHM: Step1: Start the program for performing insert, display, delete, search and modify option in symbol table Step2: Define the structure of the Symbol Table Step3: Enter the choice for performing the operations in the symbol Table Step4: If the entered choice is 1, search the symbol table for the symbol to be inserted. If the symbol is already present, it displays “Duplicate Symbol”. Else, insert the symbol and the corresponding address in the symbol table. Step5: If the entered choice is 2, the symbols present in the symbol table are displayed. Step6: If the entered choice is 3, the symbol to be deleted is searched in the symbol table. Step7: If it is not found in the symbol table it displays “Label Not found”. Else, the symbol is deleted. Step8: If the entered choice is 5, the symbol to be modified is searched in the symbol table.  PROGRAM CODE: //Implementation of symbol table #include<stdio.h&