Compiler Design Programs All
Compiler Design Programs All
#include <stdio.h>
#include <ctype.h>
#include <string.h>
int i = 0;
printf("Tokens:\n");
if (isalpha(str[i])) {
printf("Identifier: ");
while (isalnum(str[i])) {
printf("%c", str[i++]);
printf("\n");
} else if (isdigit(str[i])) {
printf("Constant: ");
while (isdigit(str[i])) {
printf("%c", str[i++]);
printf("\n");
} else {
}
}
int main() {
lexicalAnalyzer(input);
return 0;
#include <stdio.h>
#include <string.h>
typedef struct {
char name[50];
int value;
} Symbol;
Symbol table[MAX];
int count = 0;
strcpy(table[count].name, name);
table[count].value = value;
count++;
if (strcmp(table[i].name, name) == 0) {
count--;
return;
if (strcmp(table[i].name, name) == 0) {
return;
}
void modify(char name[], int value) {
if (strcmp(table[i].name, name) == 0) {
table[i].value = value;
return;
int main() {
insert("x", 10);
search("x");
modify("x", 20);
delete("x");
search("x");
return 0;
%{
#include <stdio.h>
%}
%%
. ;
%%
int main() {
yylex();
return 0;
%{
#include <stdio.h>
%}
%token NUMBER
%%
int main() {
yyparse();
return 0;
%{
#include <stdio.h>
%}
%token VARIABLE
%%
%%
int main() {
yyparse();
return 0;
return 0;
%{
#include "y.tab.h"
%}
%%
\n { return 0; }
. ;
%%
%{
#include <stdio.h>
#include <stdlib.h>
%}
%token NUMBER
%%
| NUMBER { $$ = $1; }
%%
int main() {
yyparse();
return 0;
return 0;
#include <stdio.h>
#include <string.h>
char op;
int i = 0, k = 1;
while (expr[i]) {
op = expr[i];
printf("%s\n", temp);
expr[i - 1] = t[0];
memmove(expr + i, expr + i + 2, strlen(expr) - i - 1);
i -= 2;
i++;
int main() {
printf("Three-Address Code:\n");
generateTAC(expr);
return 0;
#include <stdio.h>
#include <string.h>
} else {
int main() {
checkTypes("int x = 42;");
checkTypes("float y = 3.14;");
checkTypes("int z = 'a';");
return 0;
#include <stdio.h>
#include <string.h>
return;
}
int main() {
optimizeCode("x = x + 0;");
return 0;
#include <stdio.h>
printf("Machine Code:\n");
int main() {
generateMachineCode("a+b=c");
return 0;
#include <stdio.h>
%}
%token PATTERN
%%
%%
int main() {
yyparse();
return 0;
%{
#include "y.tab.h"
%}
%%
. { return yytext[0]; }
%%