Answered! You are to write a lexical scanner for the language SIMPL. The scanner will be written as a class with a function that…

Project: Phase I Undergraduate Requirements: You are to write a lexical scanner for the language SIMPL The scanner will be written as a class with a function that returns a token structure containing an identification number, and the string value of the token. Also write a driver program, which continually calls the scanner, until the end of file is reached. For each token it gets, the driver should print the token identification number, and the token string. You will also document your scanner with some supplemental material. You should turn in a of all of your token types, and their identification numbers and a list DFA for your scanner. Your lexical scanner should read its input from standard input, and output to standard error messages should be output to standard error. If the scanner encounters an unexpected character, no error message should be printed by the scanner, but the current incomplete token, together with the unexpected character, should be returned as an error token. There is no the length of an identifier, or number. Your scanner should limit on take this into account. You will turn in a listing of your code, and supporting materials. You will also demonstrate your program to me. The test files used in the demonstration are available for your inspection on the tests directory of your SIMPL distribution. reserved The following is a list of SIMPL token types: if while identifier number ERROR EOF

You are to write a lexical scanner for the language SIMPL. The scanner will be written as a class with a function that returns a token structure containing an identification number, and the string value of the token. Also write a driver program, which continually calls the scanner, until the end of file is reached. For each token it gets, the driver should print the token identification number, and the token string. You will also document your scanner with some supplemental material. You should turn in a list of all of your token types, and their identification numbers, and a DFA for your scanner. Your lexical scanner should read its input from standard input, and output to standard output. Any error messages should be output to standard error. If the scanner encounters an unexpected character, no error message should be printed by the scanner, but the current incomplete token, together with the unexpected character, should be returned as an error token. There is no limit on the length of an identifier, or number. Your scanner should take this into account. You will turn in a listing of your code, and supporting materials. You will also demonstrate your program to me. The test files used in the demonstration are available for your inspection on the tests directory of your SIMPL distribution. The following is a list of SIMPL token types:

Expert Answer

 #include<stdio.h>

#include<stdlib.h>
#include<string.h>
#include<ctype.h>
int isKeyword(char buffer[]){
char keywords[32][10] = {“auto”,”break”,”case”,”char”,”const”,”continue”,”default”
“do”,”double”,”else”,”enum”,”extern”,”float”,”for”,”goto”
“if”,”int”,”long”,”register”,”return”,”short”,”signed”
“sizeof”,”static”,”struct”,”switch”,”typedef”,”union”
“unsigned”,”void”,”volatile”,”while”};
int i, flag = 0;
for(i = 0; i < 32; ++i){
if(strcmp(keywords[i], buffer) == 0){
flag = 1;
break;
}
} r
eturn flag;
} i
nt main(){
char ch, buffer[15], operators[] = “+‐*/%=”;
FILE *fp;
int i,j=0;
fp = fopen(“program.txt”,”r”);
if(fp == NULL){
printf(“error while opening the filen”);
exit(0);
} while((ch = fgetc(fp)) != EOF){

for(i = 0; i < 6; ++i){
if(ch == operators[i])
printf(“%c is operatorn”, ch);
} i
f(isalnum(ch)){
buffer[j++] = ch;
}e
lse if((ch == ‘ ‘ || ch == ‘n’) && (j != 0)){
buffer[j] = ‘’;
j = 0;
if(isKeyword(buffer) == 1)
printf(“%s is keywordn”, buffer);
else
printf(“%s is indentifiern”, buffer);
}
} f
close(fp);
return 0;
}

Still stressed from student homework?
Get quality assistance from academic writers!