Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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.

Page 166:

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

Output on page 171:

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 /*Parse identifiers / case LETTER: addChar ); getChar) while (charClassLETTER II charClassDIGIT) addChar ); getChar ); nextTokenIDENT break; /Parse integer literals case DIGIT: addChar); getChar) while (charClassDIGIT) addChar ); getChar ); nextTokenINT_LIT; break; /Parentheses and operators */ case UNKNOWN: lookup (nextChar); getChar) break; EOF case EOF: nextToken = EOF; lexeme [0]'E lexeme 'O lexeme [2] 'E lexeme [ 3 ] -0 ; break; /End of switch / printf ("Next token is: %d, Next Iexeme is %s ", nextToken, lexeme); return nextToken; End of function lex / This code illustrates the relative simplicity of lexical analyzers. Of course, we have left out input buffering, as well as some other important details. Further- more, we have dealt with a very small and simple input language Consider the following expression (sum 47) / total Following is the output of the lexical analyzer of front.c when used on this expression: Next token is: 25 Next lexeme is( Next token is: 11 Next lexeme is sum Next token is: 21 Next lexeme is Next token is: 10 Next lexeme is 47 Next token is: 26 Next lexeme is Next token is: 24 Next lexeme is / Next token is: 11 Next lexeme is total Next token is: -1 Next lexeme is EOF

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

More Books

Students also viewed these Databases questions

Question

4. Describe the role of narratives in constructing history.

Answered: 1 week ago

Question

1. Identify six different types of history.

Answered: 1 week ago