compiler .cppp
compiler .cppp
h>
#include <ctype.h>
#include <string.h>
// List of keywords
const char *keywords[] = {"int", "float", "if", "else", "while", "return", "for", "char", "void"};
if (strcmp(str, keywords[i]) == 0)
return 1;
return 0;
return (ch == '+' || ch == '-' || ch == '*' || ch == '/' || ch == '=' || ch == '>' || ch == '<' || ch == '!');
int bufferIndex = 0;
int i = 0;
char ch = input[i];
i++;
continue;
if (isalpha(ch) || ch == '_') {
bufferIndex = 0;
buffer[bufferIndex++] = ch;
ch = input[++i];
buffer[bufferIndex] = '\0';
if (isKeyword(buffer))
printf("Keyword: %s\n", buffer);
else
continue;
// Detect numbers
else if (isdigit(ch)) {
bufferIndex = 0;
buffer[bufferIndex++] = ch;
ch = input[++i];
buffer[bufferIndex] = '\0';
continue;
// Detect operators
else if (isOperator(ch)) {
// Detect symbols
i++;
int main() {
char input[500];
return 0;