CD Labmanual
CD Labmanual
PRACTICAL:1
CODE:
#include <ctype.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_LENGTH 100
bool isDelimiter(char chr)
{
return (chr == ' ' || chr == '+' || chr == '-'
|| chr == '*' || chr == '/' || chr == ','
|| chr == ';' || chr == '%' || chr == '>'
|| chr == '<' || chr == '=' || chr == '('
|| chr == ')' || chr == '[' || chr == ']'
|| chr == '{' || chr == '}');
}
bool isOperator(char chr)
{
return (chr == '+' || chr == '-' || chr == '*'
|| chr == '/' || chr == '>' || chr == '<'
|| chr == '=');
}
bool isValidIdentifier(char* str)
{
return (str[0] != '0' && str[0] != '1' && str[0] != '2'
&& str[0] != '3' && str[0] != '4'
&& str[0] != '5' && str[0] != '6'
&& str[0] != '7' && str[0] != '8'
&& str[0] != '9' && !isDelimiter(str[0]));
}
Faculty of engineering and technology
Subject name: Compiler Designing .
Student Name: Maanas S Vihaayas .
ERP: 2203031240744 .
Subject Code : 303105350 .
right++;
left = right;
}
else if (isDelimiter(input[right]) && left != right
|| (right == len && left != right)) {
char* subStr
= getSubstring(input, left, right - 1);
if (isKeyword(subStr))
printf("Token: Keyword, Value: %s\n",
subStr);
else if (isInteger(subStr))
printf("Token: Integer, Value: %s\n",
subStr);
int main()
{
char lex_input[MAX_LENGTH] = "int a = b + c";
printf("For Expression \"%s\":\n", lex_input);
lexicalAnalyzer(lex_input);
printf(" \n");
char lex_input01[MAX_LENGTH]
= "int x=ab+bc+30+switch+ 0y ";
printf("For Expression \"%s\":\n", lex_input01);
lexicalAnalyzer(lex_input01);
return (0);
}
fi
fi
fi
fi
Faculty of engineering and technology
Subject name: Compiler Designing .
Student Name: Maanas S Vihaayas .
ERP: 2203031240744 .
Subject Code : 303105350 .
OUTPUT:
Faculty of engineering and technology
Subject name: Compiler Designing .
Student Name: Maanas S Vihaayas .
ERP: 2203031240744 .
Subject Code : 303105350 .
PRACTICAL: 02
AIM:Write a program to count Digits, Vowel, Symbols from the given sting.
#include <ctype.h>
#include <stdio.h>
int main() {
char line[150];
int vowels, consonant, digit, space;
line[i] = tolower(line[i]);
++vowels;
}
}
Faculty of engineering and technology
Subject name: Compiler Designing .
Student Name: Maanas S Vihaayas .
ERP: 2203031240744 .
Subject Code : 303105350 .
return 0;
}
OUTPUT:
Faculty of engineering and technology
Subject name: Compiler Designing .
Student Name: Maanas S Vihaayas .
ERP: 2203031240744 .
Subject Code : 303105350 .
PRACTICAL: 03
AIM: Program to check validation of User Name and Password in C.
#include <stdio.h>
#include <string.h>
int main() {
char username[20], password[20];
// Check against a prede ned user (replace with database access in real
applications)
if (strcmp(username, "admin") == 0 && strcmp(password, "password123") == 0) {
printf("Login successful!\n");
} else {
printf("Invalid username or password.\n");
}
return 0;
}`
fi
Faculty of engineering and technology
Subject name: Compiler Designing .
Student Name: Maanas S Vihaayas .
ERP: 2203031240744 .
Subject Code : 303105350 .
Output:
Faculty of engineering and technology
Subject name: Compiler Designing .
Student Name: Maanas S Vihaayas .
ERP: 2203031240744 .
Subject Code : 303105350 .
Faculty of engineering and technology
Subject name: Compiler Designing .
Student Name: Maanas S Vihaayas .
ERP: 2203031240744 .
Subject Code : 303105350 .
Faculty of engineering and technology
Subject name: Compiler Designing .
Student Name: Maanas S Vihaayas .
ERP: 2203031240744 .
Subject Code : 303105350 .
Faculty of engineering and technology
Subject name: Compiler Designing .
Student Name: Maanas S Vihaayas .
ERP: 2203031240744 .
Subject Code : 303105350 .
Faculty of engineering and technology
Subject name: Compiler Designing .
Student Name: Maanas S Vihaayas .
ERP: 2203031240744 .
Subject Code : 303105350 .