Experiment No 1
Experiment No 1
AIM: Design a lexical analyzer for given language and the lexical analyzer should ignore redundant
spaces, tabs and new lines. It should also ignore comments.
Although the syntax specification states that identifiers can be arbitrarily long, you may restrict the
length to some reasonable value. Simulate the same in C language.
CODE:-
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <stdlib.h>
if (ch == ' ' || ch == '+' || ch == '-' || ch == '*' || ch == '/' || ch == ',' || ch == ';' || ch == '>' ||
return (false);
ch == '=')
str[0] == '6' || str[0] == '7' || str[0] == '8' || str[0] == '9' || isDelimiter(str[0]) == true)
return (false);
return (true);
}
!strcmp(str, "break") ||
return (false);
return (false);
'4'&& str[i] != '5'&& str[i] != '6'&& str[i] != '7'&& str[i] != '8'&& str[i] != '9' || (str[i] == '-'&& i > 0))
return (false);
}return (true);
hasDecimal = true;
return (hasDecimal);
int i;
char* subStr = (char*)malloc( sizeof(char) * (right - left + 2)); for (i = left; i <= right; i++)
while (right <= len && left <= right) { if (isDelimiter(str[right]) == false) right++;
left = right;
else if (isDelimiter(str[right]) == true && left != right || (right == len && left != right))
if (isKeyword(subStr) == true)
left = right;
}}
return;
int main()
return (0);