For lexer.java, please add the following state machines and produce the same output:    private Token processWord() {         StringBuilder value = new StringBuilder();         while (!stringHandler.isDone() && (Character.isLetterOrDigit(stringHandler.peek(0)) || stringHandler.peek(0) == '_' || stringHandler.peek(0) == ',')) {             value.append(stringHandler.getChar());             charPosition++;         }         return new Token(TokenType.WORD, value.toString(), lineNumber, charPosition - value.length());     }         private Token processNumber() {         StringBuilder value = new StringBuilder();         while (!stringHandler.isDone() && (Character.isDigit(stringHandler.peek(0)) || stringHandler.peek(0) == '.')) {             value.append(stringHandler.getChar());             charPosition++;         }

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter9: Advanced Array Concepts
Section: Chapter Questions
Problem 18RQ
icon
Related questions
Question

For lexer.java, please add the following state machines and produce the same output: 

 

private Token processWord() {
        StringBuilder value = new StringBuilder();
        while (!stringHandler.isDone() && (Character.isLetterOrDigit(stringHandler.peek(0)) || stringHandler.peek(0) == '_' || stringHandler.peek(0) == ',')) {
            value.append(stringHandler.getChar());
            charPosition++;
        }
        return new Token(TokenType.WORD, value.toString(), lineNumber, charPosition - value.length());
    }

   
    private Token processNumber() {
        StringBuilder value = new StringBuilder();
        while (!stringHandler.isDone() && (Character.isDigit(stringHandler.peek(0)) || stringHandler.peek(0) == '.')) {
            value.append(stringHandler.getChar());
            charPosition++;
        }
        return new Token(TokenType.NUMBER, value.toString(), lineNumber, charPosition - value.length());
    }

Expert Solution
Step 1: Define given code

This code includes the "processWord" and "processNumber" methods, which process words and numbers according to your requirements, and it also handles keywords, symbols, comments, and whitespace. You can run this code with different input strings to tokenize and output the tokens accordingly.

steps

Step by step

Solved in 4 steps

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

I ran the code and this is the error I got. Make sure to take screenshots of the output. Please add the following state machines and produce the same output: 

 

private Token processWord() {
        StringBuilder value = new StringBuilder();
        while (!stringHandler.isDone() && (Character.isLetterOrDigit(stringHandler.peek(0)) || stringHandler.peek(0) == '_' || stringHandler.peek(0) == ',')) {
            value.append(stringHandler.getChar());
            charPosition++;
        }
        return new Token(TokenType.WORD, value.toString(), lineNumber, charPosition - value.length());
    }

   
    private Token processNumber() {
        StringBuilder value = new StringBuilder();
        while (!stringHandler.isDone() && (Character.isDigit(stringHandler.peek(0)) || stringHandler.peek(0) == '.')) {
            value.append(stringHandler.getChar());
            charPosition++;
        }
        return new Token(TokenType.NUMBER, value.toString(), lineNumber, charPosition - value.length());
    }

Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Threads in linked list
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
CMPTR
CMPTR
Computer Science
ISBN:
9781337681872
Author:
PINARD
Publisher:
Cengage
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781305480537
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Np Ms Office 365/Excel 2016 I Ntermed
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:
9781337508841
Author:
Carey
Publisher:
Cengage