use c language.
below are surporting files for the assignment
this is tokens.h
this is pl-scanner-yu
this is the makefile
this is driver.cc
1. (1.5pt) Add the necessary rules to recognize the arithmetic operators: +,-, *./.+ = ++.=,==, ---, . See the file tokens.h to determine the constants to be used (they start with the prefix 'OP.'). 2. (2pt) Modify the rule returning the T.ID token to recognize all identifiers matching the following: identifiers must start with the character 'a'. the character immediately following the 'o' must be a letter. . Our language will be case insensitive, so there will be no distinction between upper and lower case strings. For example, the identifiers "SUM.42" and "sum.42" will be considered the same. characters following the initial '@' and the first letter can be any letter (upper or lower case), digit or the underscore'' symbol. Examples of valid identifiers are (commas used separate identifiers): Giter, Gii, Gali, Qa_xe, ab.p, b20, 9A.b.C.2.. Examples of invalid identifiers are commas used separate identifiers): 2, at, 2., 125_5, abC24, Q.543, delta, 0. // keywords #define K_FOREACH 200 #define K_PRINT 201 #define K_WHILE 202 #define K REPEAT 203 #define K_UNTIL 204 #define K BEGIN 205 #define K END 206 #define K_DECLARE 209 #define K IF 210 #define K_THEN 211 #define K MAIN 212 #define K INTEGER 213 #define K FLOAT 214 // operators #define OP ASSIGN 220 #define OP ADD 221 #define OP_SUB 222 #define OP_MUL 223 #define OP_DIV 224 #define OP LT 225 #define OP_GT 226 #define OP_LEQ 227 #define OPGEQ 228 #define OP_EQ 229 // OP DIFF is - #define OP_DIFF 230 // OP_PLUSPLUS is ++ #define OP_PLUSPLUS 231 // OP_ADDINC is += #define OP_ADDINC 232 #define CAR A 400 #define CAR B 401 #define CAR C 402 #define CAR AB 403 // literals #define T ID 240 #define L INTEGER 241 #define L_FLOAT 242 #define TEOF 280 E pl-scanner (1).yy 1 %{ 2 /ame, ID; 3 4 #include "tokens.h" 5 # undef yywrap 6 # define yywrap() 1 7 8 #undef YY_DECL #define YY_DECL int yylex() YY_DECL; 9 10 11 12 13 14 15 16 17 18 // Code run each time a pattern is matched. #undef YY_USER_ACTION # define YY_USER_ACTION {} 19 %} 20 21 22 23 24 %option yylineno %option noyywrap 25 26 DIGIT [0-9] ALPHA [a-zA-Z] 27 28 W.*$ { } [ \t]+ [ ]+ { return ';'; } return OP_ASSIGN; "main" |||| return K_MAIN; il return 3 } {DIGIT}+ { 9 1 2 53 54 55 III||| return L_INTEGER; } {ALPHA}+ {ALPHA}+ 55 56 57 return T_ID; 58 > { return T_EOF; } { return yytext[@]; } I 59 60 61 62 63 64 65 66 67 68 69 ze %% int dummy_function() { return 1; } Makefile 1 2 SRCS = driver.cc lex.yy.c 3 BIN = pl-scanner.exe 4 CFLAGS = -03 -I. 5 SCANNER = pl-scanner 6 #SCANNER = example-flex 7 FLEX = flex 8 CC = g++ 9 LO all: scanner bin L1 L2 bin: $(SRCS) L3 $(CC) $(CFLAGS) -0 $(BIN) $(SRCS) 14 L5 scanner: $(SCANNER).yy 16 $(FLEX) $(SCANNER).yy 17 18 clean: 19 Irm .exe lex.yy.c *. 20 driver.cc 1 #include
2 #include 3 #include "tokens.h" 4 5 extern char * yytext; 5 7 extern B int yylex (); 3 1 2 3 4 5 6 7 8 -9 int main() { int next; while ((next = yylex ()) != T_EOF) { printf ("token = %d (%) ", next, yytext); } return; } 1. (1.5pt) Add the necessary rules to recognize the arithmetic operators: +,-, *./.+ = ++.=,==, ---, . See the file tokens.h to determine the constants to be used (they start with the prefix 'OP.'). 2. (2pt) Modify the rule returning the T.ID token to recognize all identifiers matching the following: identifiers must start with the character 'a'. the character immediately following the 'o' must be a letter. . Our language will be case insensitive, so there will be no distinction between upper and lower case strings. For example, the identifiers "SUM.42" and "sum.42" will be considered the same. characters following the initial '@' and the first letter can be any letter (upper or lower case), digit or the underscore'' symbol. Examples of valid identifiers are (commas used separate identifiers): Giter, Gii, Gali, Qa_xe, ab.p, b20, 9A.b.C.2.. Examples of invalid identifiers are commas used separate identifiers): 2, at, 2., 125_5, abC24, Q.543, delta, 0. // keywords #define K_FOREACH 200 #define K_PRINT 201 #define K_WHILE 202 #define K REPEAT 203 #define K_UNTIL 204 #define K BEGIN 205 #define K END 206 #define K_DECLARE 209 #define K IF 210 #define K_THEN 211 #define K MAIN 212 #define K INTEGER 213 #define K FLOAT 214 // operators #define OP ASSIGN 220 #define OP ADD 221 #define OP_SUB 222 #define OP_MUL 223 #define OP_DIV 224 #define OP LT 225 #define OP_GT 226 #define OP_LEQ 227 #define OPGEQ 228 #define OP_EQ 229 // OP DIFF is - #define OP_DIFF 230 // OP_PLUSPLUS is ++ #define OP_PLUSPLUS 231 // OP_ADDINC is += #define OP_ADDINC 232 #define CAR A 400 #define CAR B 401 #define CAR C 402 #define CAR AB 403 // literals #define T ID 240 #define L INTEGER 241 #define L_FLOAT 242 #define TEOF 280 E pl-scanner (1).yy 1 %{ 2 /ame, ID; 3 4 #include "tokens.h" 5 # undef yywrap 6 # define yywrap() 1 7 8 #undef YY_DECL #define YY_DECL int yylex() YY_DECL; 9 10 11 12 13 14 15 16 17 18 // Code run each time a pattern is matched. #undef YY_USER_ACTION # define YY_USER_ACTION {} 19 %} 20 21 22 23 24 %option yylineno %option noyywrap 25 26 DIGIT [0-9] ALPHA [a-zA-Z] 27 28 W.*$ { } [ \t]+ [ ]+ { return ';'; } return OP_ASSIGN; "main" |||| return K_MAIN; il return 3 } {DIGIT}+ { 9 1 2 53 54 55 III||| return L_INTEGER; } {ALPHA}+ {ALPHA}+ 55 56 57 return T_ID; 58 > { return T_EOF; } { return yytext[@]; } I 59 60 61 62 63 64 65 66 67 68 69 ze %% int dummy_function() { return 1; } Makefile 1 2 SRCS = driver.cc lex.yy.c 3 BIN = pl-scanner.exe 4 CFLAGS = -03 -I. 5 SCANNER = pl-scanner 6 #SCANNER = example-flex 7 FLEX = flex 8 CC = g++ 9 LO all: scanner bin L1 L2 bin: $(SRCS) L3 $(CC) $(CFLAGS) -0 $(BIN) $(SRCS) 14 L5 scanner: $(SCANNER).yy 16 $(FLEX) $(SCANNER).yy 17 18 clean: 19 Irm .exe lex.yy.c *. 20 driver.cc 1 #include 2 #include 3 #include "tokens.h" 4 5 extern char * yytext; 5 7 extern B int yylex (); 3 1 2 3 4 5 6 7 8 -9 int main() { int next; while ((next = yylex ()) != T_EOF) { printf ("token = %d (%) ", next, yytext); } return; }