Professional Documents
Culture Documents
CSF-401 LabRecord AnkushNegi 1000015073
CSF-401 LabRecord AnkushNegi 1000015073
of
Compiler Design
(CSF401)
Session 2023-24
Code:
Code:
Code:
Outputs:
#include <stdio.h>
#include <string.h>
{ int i = 0;
{ i++;
{ int i = 0;
{ i++;
{ i++;
if (matchAStar(input)) {
} else {
printf("The string does not match any of the specified
patterns.\n"); }
return 0;
}
Outputs:
#include <stdbool.h>
#include <string.h>
#include <ctype.h>
{ return false;
}
for (int i = 0; str[i] != '\0'; i++)
{ if (!isValidIdentifierChar(str[i]))
{ return false;
if (strcmp(str, keywords[i]) == 0)
{ return false;
return true;
int main() {
char identifier[100];
printf("Enter an identifier:
if (isValidIdentifier(identifier)) {
} else {
return 0;
Outputs:
#include <stdbool.h>
char validOperators[] = {'+', '-', '*', '/', '%', '=', '<', '>', '!', '&', '|', '^', '~', '?'};
{ if (op == validOperators[i]) {
return true;
return false;
int main() {
char operator;
printf("Enter an operator:
if (isValidOperator(operator)) {
} else {
return 0;
Output:
#include <stdio.h>
%}
DIGIT [0-9]
WS [ \t\n]
OPERATOR
[+-/*]
%%
%%
int main()
{ yylex();
return 0;
Output:
Code:
%{
#include <stdio.h>
%}
%%
%%
int main()
{ yylex();
return 0;
Output:
#include <stdio.h>
%}
%%
%%
int main()
{ yylex();
return 0;
Output:
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
float num;
int op;
%}
%%
digit [0-9]
%%
{digit} {
num = atof(yytext);
if (op == 0) {
} else {
switch (op)
{ case '+':
num += atof(yytext);
break;
case '-':
num -=
atof(yytext); break;
case '*':
num *= atof(yytext);
break;
case '/':
n"); exit(1);
} else {
num /= atof(yytext);
break;
default:
exit(1);
{op} {
op = yytext[0];
.{
printf("\n");
Output: