Practical CD
Practical CD
Subject-Code:203105361
Practical-1
AIM: Program to implement Lexical Analyzer.
CODE:
code = input("Enter the string: ")
items = code.split()
for x in items:
if x in ["int", "float"]:
print("Keyword",x)
elif x.isdigit():
print("Constant", x)
elif x in ["+", "-", "*", "/", "%", "="]:
print("Operator", x)
elif x in [",", ";", "(", ")"]:
print("Symbol", x)
else:
print("Identifier", x)
Faculty of Engineering & Technology
Subject-Code:203105361
OUTPUT:
Faculty of Engineering & Technology
Subject-Code:203105361
Practical-2
AIM: Program to count digits, vowels and symbols in C
CODE:
#include <stdio.h>
#include <ctype.h>
#include <string.h>
if (isdigit(ch)) {
(*digits)++;
} else if (isalpha(ch)) {
Faculty of Engineering & Technology
Subject-Code:203105361
switch (tolower(ch)) {
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
(*vowels)++;
break;
default:
break;
}
} else {
(*symbols)++;
}
}
}
Faculty of Engineering & Technology
Subject-Code:203105361
int main() {
char inputString[100];
int digitCount = 0, vowelCount = 0, symbolCount = 0;
countDigitsVowelsSymbols(inputString, &digitCount,
&vowelCount, &symbolCount);
return 0;
}
Faculty of Engineering & Technology
Subject-Code:203105361
OUTPUT:
Faculty of Engineering & Technology
Subject-Code:203105361
Practical-3
AIM: Program to check validation of User Name and
Password in C.
CODE: #include <stdio.h>
#include <string.h>
#include <ctype.h>
if (strlen(username) == 0) {
return 0;
}
return 1;
Faculty of Engineering & Technology
Subject-Code:203105361
if (strlen(password) < 8) {
return 0;
}
int hasDigit = 0;
for (int i = 0; password[i] != '\0'; i++) {
if (isdigit(password[i])) {
hasDigit = 1;
break;
}
}
int hasUppercase = 0;
for (int i = 0; password[i] != '\0'; i++) {
if (isupper(password[i])) {
hasUppercase = 1;
Faculty of Engineering & Technology
Subject-Code:203105361
break;
}
}
int main() {
char username[50];
char password[50];
if (!isValidUsername(username)) {
Faculty of Engineering & Technology
Subject-Code:203105361
if (!isValidPassword(password)) {
printf("Invalid password. Password must be at least 8
characters long and contain at least one digit and one
uppercase letter.\n");
return 1;
}
return 0;
}
Faculty of Engineering & Technology
Subject-Code:203105361
OUTPUT: