/******** Name :- Md Firoz Islam ***********
University :- Northern University Bangladesh
********** Dhaka,Bangladesh ***************/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define yes cout<<"YES"<<endl;
#define no cout<<"NO"<<endl;
#define faster ios::sync_with_stdio(false),cin.tie(NULL);
const char* keywords[32] = {
"auto","break","case","char","const","continue","default",
"do","double","else","enum","extern","float","for","goto",
"if","int","long","register","return","short","signed",
"sizeof","static","struct","switch","typedef","union",
"unsigned","void","volatile","while"
};
const char *operators[] = {"+", "-", "*", "/", "%", "=", "==", "!=", ">", "<", ">=", "<=", "&&", "||", "++", "--"};
const char *separators[] = {",", ";", "(", ")", "{", "}", "[", "]"};
int isKeyword(const char buffer[]) {
for(int i = 0; i < 32; ++i) {
if(strcmp(keywords
[i
], buffer
) == 0) { return 1;
}
}
return 0;
}
int isOperator(char ch) {
for(int i
= 0; i
< sizeof(operators
) / sizeof(operators
[0]); ++i
) { if(ch == operators[i][0]) {
if(strlen(operators
[i
]) > 1) { return 2;
}
return 1;
}
}
return 0;
}
int isSeparator(char ch) {
for(int i
= 0; i
< sizeof(separators
) / sizeof(separators
[0]); ++i
) { if(ch == separators[i][0]) {
return 1;
}
}
return 0;
}
int main() {
char ch, buffer[15];
ifstream fp("Firoz.txt");
int j = 0;
if(!fp.is_open()) {
cout << "Error opening the file" << endl;
return 1;
}
while(fp.get(ch)) {
if(isalnum(ch)) {
buffer[j++] = ch;
}
else {
if(j != 0) {
buffer[j] = '\0';
j = 0;
if(isKeyword(buffer)) {
cout << buffer << " is a keyword" << endl;
} else {
cout << buffer << " is an identifier" <<endl;
}
}
if(isOperator(ch) == 1) {
cout << ch << " is an operator" << endl;
if(isOperator(ch) == 2) {
cout << "Multi-character operator detected" << endl;
}
}
if(isSeparator(ch)) {
cout << ch << " is a separator" << endl;
}
}
}
fp.close();
return 0;
}
LyoqKioqKioqIE5hbWUgOi0gTWQgRmlyb3ogSXNsYW0gKioqKioqKioqKioKVW5pdmVyc2l0eSA6LSBOb3J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HsKICAgICAgICBpZihzdHJjbXAoa2V5d29yZHNbaV0sIGJ1ZmZlcikgPT0gMCkgewogICAgICAgICAgICByZXR1cm4gMTsKICAgICAgICB9CiAgICB9CiAgICByZXR1cm4gMDsKfQoKaW50IGlzT3BlcmF0b3IoY2hhciBjaCkgewogICAgZm9yKGludCBpID0gMDsgaSA8IHNpemVvZihvcGVyYXRvcnMpIC8gc2l6ZW9mKG9wZXJhdG9yc1swXSk7ICsraSkgewogICAgICAgIGlmKGNoID09IG9wZXJhdG9yc1tpXVswXSkgewogICAgICAgICAgICBpZihzdHJsZW4ob3BlcmF0b3JzW2ldKSA+IDEpIHsKICAgICAgICAgICAgICAgIHJldHVybiAyOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHJldHVybiAxOwogICAgICAgIH0KICAgIH0KICAgIHJldHVybiAwOwp9CgppbnQgaXNTZXBhcmF0b3IoY2hhciBjaCkgewogICAgZm9yKGludCBpID0gMDsgaSA8IHNpemVvZihzZXBhcmF0b3JzKSAvIHNpemVvZihzZXBhcmF0b3JzWzBdKTsgKytpKSB7CiAgICAgICAgaWYoY2ggPT0gc2VwYXJhdG9yc1tpXVswXSkgewogICAgICAgICAgICByZXR1cm4gMTsKICAgICAgICB9CiAgICB9CiAgICByZXR1cm4gMDsKfQoKaW50IG1haW4oKSB7CiAgICBjaGFyIGNoLCBidWZmZXJbMTVdOwogICAgaWZzdHJlYW0gZnAoIkZpcm96LnR4dCIpOwogICAgaW50IGogPSAwOwoKICAgIGlmKCFmcC5pc19vcGVuKCkpIHsKICAgICAgICBjb3V0IDw8ICJFcnJvciBvcGVuaW5nIHRoZSBmaWxlIiA8PCBlbmRsOwogICAgICAgIHJldHVybiAxOwogICAgfQoKICAgIHdoaWxlKGZwLmdldChjaCkpIHsKICAgICAgICBpZihpc2FsbnVtKGNoKSkgewogICAgICAgICAgICBidWZmZXJbaisrXSA9IGNoOwogICAgICAgIH0KICAgICAgICBlbHNlIHsKICAgICAgICAgICAgaWYoaiAhPSAwKSB7CiAgICAgICAgICAgICAgICBidWZmZXJbal0gPSAnXDAnOwogICAgICAgICAgICAgICAgaiA9IDA7CgogICAgICAgICAgICAgICAgaWYoaXNLZXl3b3JkKGJ1ZmZlcikpIHsKICAgICAgICAgICAgICAgICAgICBjb3V0IDw8IGJ1ZmZlciA8PCAiIGlzIGEga2V5d29yZCIgPDwgZW5kbDsKICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgY291dCA8PCBidWZmZXIgPDwgIiBpcyBhbiBpZGVudGlmaWVyIiA8PGVuZGw7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KCiAgICAgICAgICAgIGlmKGlzT3BlcmF0b3IoY2gpID09IDEpIHsKICAgICAgICAgICAgICAgIGNvdXQgPDwgY2ggPDwgIiBpcyBhbiBvcGVyYXRvciIgPDwgZW5kbDsKICAgICAgICAgICAgICAgIGlmKGlzT3BlcmF0b3IoY2gpID09IDIpIHsKICAgICAgICAgICAgICAgICAgICBjb3V0IDw8ICJNdWx0aS1jaGFyYWN0ZXIgb3BlcmF0b3IgZGV0ZWN0ZWQiIDw8IGVuZGw7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KCiAgICAgICAgICAgIGlmKGlzU2VwYXJhdG9yKGNoKSkgewogICAgICAgICAgICAgICAgY291dCA8PCBjaCA8PCAiIGlzIGEgc2VwYXJhdG9yIiA8PCBlbmRsOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQoKICAgIGZwLmNsb3NlKCk7CiAgICByZXR1cm4gMDsKfQo=
/******** Name :- Md Firoz Islam ***********
University :- Northern University Bangladesh
********** Dhaka,Bangladesh ***************/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define yes cout<<"YES"<<endl;
#define no cout<<"NO"<<endl;
#define faster ios::sync_with_stdio(false),cin.tie(NULL);
const char* keywords[32] = {
"auto","break","case","char","const","continue","default",
"do","double","else","enum","extern","float","for","goto",
"if","int","long","register","return","short","signed",
"sizeof","static","struct","switch","typedef","union",
"unsigned","void","volatile","while"
};
const char *operators[] = {"+", "-", "*", "/", "%", "=", "==", "!=", ">", "<", ">=", "<=", "&&", "||", "++", "--"};
const char *separators[] = {",", ";", "(", ")", "{", "}", "[", "]"};
int isKeyword(const char buffer[]) {
for(int i = 0; i < 32; ++i) {
if(strcmp(keywords[i], buffer) == 0) {
return 1;
}
}
return 0;
}
int isOperator(char ch) {
for(int i = 0; i < sizeof(operators) / sizeof(operators[0]); ++i) {
if(ch == operators[i][0]) {
if(strlen(operators[i]) > 1) {
return 2;
}
return 1;
}
}
return 0;
}
int isSeparator(char ch) {
for(int i = 0; i < sizeof(separators) / sizeof(separators[0]); ++i) {
if(ch == separators[i][0]) {
return 1;
}
}
return 0;
}
int main() {
char ch, buffer[15];
ifstream fp("Firoz.txt");
int j = 0;
if(!fp.is_open()) {
cout << "Error opening the file" << endl;
return 1;
}
while(fp.get(ch)) {
if(isalnum(ch)) {
buffer[j++] = ch;
}
else {
if(j != 0) {
buffer[j] = '\0';
j = 0;
if(isKeyword(buffer)) {
cout << buffer << " is a keyword" << endl;
} else {
cout << buffer << " is an identifier" <<endl;
}
}
if(isOperator(ch) == 1) {
cout << ch << " is an operator" << endl;
if(isOperator(ch) == 2) {
cout << "Multi-character operator detected" << endl;
}
}
if(isSeparator(ch)) {
cout << ch << " is a separator" << endl;
}
}
}
fp.close();
return 0;
}