Question: 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.");

 solve part 1 and 2 please code provided: Scanner scan =

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!