Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

1. Using C#, implement a console application of the source code of a lexical analyzer (front.c) on page 166 in the textbook. Your console application

1. Using C#, implement a console application of the source code of a lexical analyzer (front.c) on page 166 in the textbook. Your console application should receive an input (for example sum + 56/total) and give the similar output like on page 171. All the things you need to refer to are below. The code below is in C. thanks.

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

output on page 171 below:

image text in transcribed

/* front.c-a lexical analyzer system for simple arithmetic expressions #include #include /*Global declarations / /*Variables int charClass; char lexeme [100] char nextChar; int lexLen; int token; int nextToken; FILE *in_fp, *fopen ); Function declarations/ void addChar ) void getChar void getNonBlank () int lex ) /*Character classes #de fine LETTER 0 #de fine DIGIT 1 #de fine UNKNOWN 99 /*Token codes #de fine INT LIT 10 #de fine IDENT 11 #de fine ASSIGN OP 20 #de fine ADD OP 21 #de fine SUB OP 22 #de fine MULT OP 23 #define DIV OP 24 #define LEFT PAREN 25 #define RIGHT PAREN 26 /*main driver main) t / Open the input data file and process its contents if ((in fp -fopen ("front.in", "r")) NULL) printf ("ERROR - cannot open front.in "); else getChar; do lex ) while (nextToken EOF) ; /lookup a function to lookup operators and parentheses and return the token / int lookup (char ch) switch (ch) case '(': addChar ); nextTokenLEFT_PAREN; break; case')': addChar ); nextTokenRIGHT_PAREN; break; case '+' . addChar ); nextToken = ADD OP; break; case '- . addChar ); nextTokenSUB_OP break; case . addChar ); nextToken = MULT-OP; break; case '/' addChar ); nextTokenDIV_OP break; default: addChar); nextToken = EOF; break; return nextToken; /* addChar - a function to add nextChar to lexeme / void addChar ) if (lexLen /*Global declarations / /*Variables int charClass; char lexeme [100] char nextChar; int lexLen; int token; int nextToken; FILE *in_fp, *fopen ); Function declarations/ void addChar ) void getChar void getNonBlank () int lex ) /*Character classes #de fine LETTER 0 #de fine DIGIT 1 #de fine UNKNOWN 99 /*Token codes #de fine INT LIT 10 #de fine IDENT 11 #de fine ASSIGN OP 20 #de fine ADD OP 21 #de fine SUB OP 22 #de fine MULT OP 23 #define DIV OP 24 #define LEFT PAREN 25 #define RIGHT PAREN 26 /*main driver main) t / Open the input data file and process its contents if ((in fp -fopen ("front.in", "r")) NULL) printf ("ERROR - cannot open front.in "); else getChar; do lex ) while (nextToken EOF) ; /lookup a function to lookup operators and parentheses and return the token / int lookup (char ch) switch (ch) case '(': addChar ); nextTokenLEFT_PAREN; break; case')': addChar ); nextTokenRIGHT_PAREN; break; case '+' . addChar ); nextToken = ADD OP; break; case '- . addChar ); nextTokenSUB_OP break; case . addChar ); nextToken = MULT-OP; break; case '/' addChar ); nextTokenDIV_OP break; default: addChar); nextToken = EOF; break; return nextToken; /* addChar - a function to add nextChar to lexeme / void addChar ) if (lexLen

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_2

Step: 3

blur-text-image_step3

Ace Your Homework with AI

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

Get Started

Students explore these related Databases questions