Toy C++ program for custom string conversion

I am working on lexer part of compilers right now, the task I was doing is to putting up keyword definitions in cool.flex file. Keywords were given in another file in this format:

//for example keyword is class
#define CLASS 234

and I am supposed to be writing it in cool.flex like this:

//keywords are case-insensitive
[cC] + [lL] + [aA] + [sS] + [sS]        {return (CLASS);}

Instead of doing all this by hand I wrote this C++ program and it worked fine.

#include <iostream>
#include <fstream>

using namespace std;

int main()
 string str, str1;
 fstream myfile("test.file");
 ofstream file("temp.file");
 while(getline(myfile, str))
 for(int i=0;i<str.length();i++)
 if(isupper(str[i]) && str[i+1]!=' ')
 char ch=putchar(tolower(str[i]));
 else if(isupper(str[i]) && str[i+1]==' ')
 char ch=putchar(tolower(str[i]));
 file<<" { return("<<str1<<");} \n";
 return 0;

Help to improve or comment as you wish

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s