Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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)

image text in transcribed use c language.
below are surporting files for the assignment
image text in transcribed this is tokens.h
image text in transcribed
image text in transcribed
image text in transcribedthis is pl-scanner-yu
image text in transcribedthis is the makefile
image text in transcribedthis 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; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2014 Nancy France September 15 19 2014 Proceedings Part I Lnai 8724

Authors: Toon Calders ,Floriana Esposito ,Eyke Hullermeier ,Rosa Meo

2014th Edition

3662448475, 978-3662448472

More Books

Students also viewed these Databases questions

Question

Define and discuss the process of planned change.

Answered: 1 week ago

Question

What are the best practices for managing a large software project?

Answered: 1 week ago

Question

How does clustering in unsupervised learning help in data analysis?

Answered: 1 week ago