Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

solve part 1 and 2 please code provided: Scanner scan = new Scanner(System.in); String s = scan.next(); int q = 0 ; for (char c

solve part 1 and 2 please

code provided:

Scanner scan = new Scanner(System.in); String s = scan.next();

int q = 0;

for (char c : s.toCharArray()) {

switch (q) {

case 0: q = (c=='i')? 1 : 0; break;

case 1: q = (c=='n')? 2 : ((c=='i')? 1 : 0); break; case 2: q = (c=='g')? 3 : ((c=='i')? 1 : 0); break; case 3: q = (c=='i')? 1 : 0;

}

}

if (q==3) System.out.println("accept."); else System.out.println("reject.");

image text in transcribed
A lexical analyzer reads the characters from a file or standard input and produces a set of TOKENS such as: IDENTIFIERS, CONSTANT, KEYWORD IF, KEYWORD_EISE, KEYWORD_THEN ... 1. Draw a DFA that recognizes the words \{do, while, for\}. 2. Modify the code in the slides (that recognizes words ending with ing) to a code that recognizes the keywords do, while and for. In case it recognizes if it should output KEYWORD_DO, KEYWORD_WHILE, and KEYWORD_FOR. If the word is not recognized, it should retum ERROR message. Code in the slides Scanner scan = new Scanner(System.in); String s = scan.next(); int q=0; for (char c : s.toCharArray()) \{ switch (q) I case 0:q=(c==ii) ? 1:0; break; case 1: q=(c=en) 2 2: ((c=)?1 : 0); break; case 2: q=(c=ng) ? 3: ((c==7) ? 1:0); break; case 3: q= (c=e) ? 1:0; 1 if (q=3) System.out.printin ("accept."); else System.out.printin ("reject.")

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

Databases In Networked Information Systems 6th International Workshop Dnis 2010 Aizu Wakamatsu Japan March 2010 Proceedings Lncs 5999

Authors: Shinji Kikuchi ,Shelly Sachdeva ,Subhash Bhalla

2010th Edition

3642120377, 978-3642120374

More Books

Students also viewed these Databases questions

Question

Discuss the techniques of sales forecasting.

Answered: 1 week ago

Question

Write short notes on Marketing mix.

Answered: 1 week ago

Question

Analyse the process of new product of development.

Answered: 1 week ago