Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. Assume the following text is presented to a C scanner: main(){ const float payment = 384.00; float bal; int month = 0; bal=15000; while

1. Assume the following text is presented to a C scanner:

main(){

const float payment = 384.00;

float bal;

int month = 0;

bal=15000;

while (bal>0){

printf("Month: %2d Balance: %10.2f ", month, bal);

bal=bal-payment+0.015*bal;

month=month+1;

}

}

image text in transcribed

Programming: Use Lex to produce a lexical analyzer. You can use the regular definitions and actions in the page 143 of our text book. You have to include all tests, make files, etc.

What token sequence is produced? For which tokens must extra information be returned in addition to the token code?

3.5. THE LEXICAL-ANALYZER GENERATOR LEX 143 %{ /* definitions of manifest constants LT, LE, EQ, NE, GT, GE, IF, THEN, ELSE, ID, NUMBER, RELOP */ %} /* regular definitions */ delim [ \t ] WS {delim)+ letter [A-Za-z] digit [0-9] id {letter} ({letter}|{digit})* number {digit}+(\.{digit}+)?(E[+-]?{digit }+)? %% {ws) {/* no action and no return */} if {return(IF);} then {return(THEN);} else {return(ELSE);} {id} {yylval = (int) installID(); return(ID);} {number} {yylval = (int) installNum(); return (NUMBER); } {yylval = LT; return(RELOP); } {yylval = LE; return(RELOP); } " {yylval = EQ; return(RELOP); } {yylval = NE; return(RELOP); } > {yylval = GT; return(RELOP); } {yylval = GE; return(RELOP); } %% int installID () {/* function to install the lexeme, whose first character is pointed to by yytext, and whose length is yyleng, into the symbol table and return a pointer thereto */ } int installNum) {/* similar to installID, but puts numer- ical constants into a separate table */ } Figure 3.23: Lex program for the tokens of Fig. 3.12

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_2

Step: 3

blur-text-image_3

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

Time Series Databases New Ways To Store And Access Data

Authors: Ted Dunning, Ellen Friedman

1st Edition

1491914726, 978-1491914724

More Books

Students also viewed these Databases questions

Question

Have issues been prioritized?

Answered: 1 week ago

Question

d. How will lack of trust be handled?

Answered: 1 week ago

Question

Are the rules readily available?

Answered: 1 week ago