Compiler Lexical Analyser

  • Uploaded by: Ramprakash
  • 0
  • 0
  • December 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Compiler Lexical Analyser as PDF for free.

More details

  • Words: 142
  • Pages: 3
LEXICAL ANALYSER #include #include #include #include<string.h> #include class lexical { private: char st[100]; public: void token(); }; void lexical::token() { fstream fin,in; ofstream fout; char ke[25]; int f=0; fin.open("TEXT.TXT",ios::in); fin>>st; fout.open("OUT.TXT",ios::in); while(fin.get()!=EOF) { in.open("KEY.TXT",ios::in); in>>ke; while(in.get()!=EOF) { if(strcmp(st,ke)==0) { fout<<"\n"<<st<<"\tKEYWORD\t"; f=1; } in>>ke; } in.close(); in.open("SYMBOL.TXT",ios::in); in>>ke;

while(in.get()!=EOF) { if(strcmp(st,ke)==0) { fout<<"\n"<<st<<"\t"<<"OPERATOR"; f=1; } in>>ke; } in.close(); if(f==0) { if(isdigit(st[0])) { fout<<"\n"<<st<<"\t"<<"CONSTANT"; } else { fout<<"\n"<<st<<"\tIDENTIFIER\t"; } } f=0; fin>>st; } fin.close(); fout.close(); } void main() { clrscr(); lexical l; l.token(); cout<<"\nTHE OUTPUT IS STORED IN OUT.TXT"; getch(); }

INPUT: TEXT.TXT: INT A = INT B + INT C + 50 ;

KEY.TXT: INT FLOAT DOUBLE LONG STR CHAR

SYMBOL.TXT: = + * -

OUTPUT: THE OUTPUT IS STORED IN OUT.TXT OUT.TXT: INT A = INT B + INT C + 50

KEYWORD IDENTIFIER OPERATOR KEYWORD IDENTIFIER OPERATOR KEYWORD IDENTIFIER OPERATOR CONSTANT

Related Documents

Compiler Lexical Analyser
December 2019 9
Analyser
November 2019 26
Compiler
May 2020 15
Compiler
October 2019 27
Compiler
July 2020 10
Compiler
December 2019 24

More Documents from "Thaval"

Student Projects
November 2019 13
Compiler Lexical Analyser
December 2019 9