Question: % { #include #include #include #define INTEGER 1 #define STRING 2 #define IDENTIFIER 3 #define READ 4 #define PRINT 5 #define IF 6 #define THEN

%{
#include
#include
#include
#define INTEGER 1
#define STRING 2
#define IDENTIFIER 3
#define READ 4
#define PRINT 5
#define IF 6
#define THEN 7
#define ELSE 8
#define DO 9
#define PROGRAM 10
#define END 11
#define GT 12
#define LT 13
#define EQ 14
%}
%%
"PROGRAM" return PROGRAM;
"INTEGER" return INTEGER;
"READ" return READ;
"PRINT" return PRINT;
"IF" return IF;
"THEN" return THEN;
"ELSE" return ELSE;
"DO" return DO;
"END" return END;
".GT." return GT;
".LT." return LT;
".EQ." return EQ;
[0-9]+{ yylval = atoi(yytext); return INTEGER; }
[a-z]+{ yylval = strdup(yytext); return IDENTIFIER; }
\"[^\"]*\"{ yylval = strdup(yytext); return STRING; }
"=" return '=';
"+" return '+';
"-" return '-';
"(" return '(';
")" return ')';
"," return ',';
"*" return '*';
[
]+{/* Ignore new lines */}
[\t]+{/* Ignore whitespaces */}
"!"[^
]*{/* Ignore comments */}
.{ printf("Unrecognized token: %s
", yytext); exit(1); }
%%
int yywrap(){
return 1;
}
Write a flex specification for the language of F15 using the lexical grammar.
1. the lexer.l file is already provided
2. Write your main()(in a separate file FirstName_LastName_A2.c) to test your lexer.
3. Prepare a Makefile to compile the specifications and generate the lexer.
4. Prepare a test input file FirstName_LastName_A2.nc that will test all the lexical rules that you have
coded.
5. Prepare a FirstName_LastName_A2.pdf file explaining the working of your lexer and your design

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!