Java Code: Below is Parser.java and there are errors. getType() and getStart() is undefined for the type Optional and there is an error in addNode(). Make sure to get rid of all the errors in the code. Attached is images of the errors.    Parser.java import java.text.ParseException; import java.util.LinkedList; import java.util.List; import java.util.Optional; import javax.swing.ActionMap; public class Parser {     private TokenHandler tokenHandler;     private LinkedList tokens;     public Parser(LinkedList tokens) {         this.tokenHandler = new TokenHandler(tokens);         this.tokens = tokens;     }     public boolean AcceptSeparators() {         boolean foundSeparator = false;         while (tokenHandler.MoreTokens()) {             Optional currentToken = tokenHandler.getCurrentToken();             if (currentToken.getType() == Token.TokenType.NEWLINE || currentToken.getType() == Token.TokenType.SEMICOLON) {                 tokenHandler.consumeMatchedToken();                 foundSeparator = true;             } else {                 break;             }         }         return foundSeparator;     }     public ProgramNode Parse() throws ParseException {         ProgramNode programNode = new ProgramNode(null, 0);         while (tokenHandler.MoreTokens()) {             if (!ParseFunction(programNode) && !parseAction(programNode)) {                 throw new ParseException("Unexpected token: " + tokenHandler.getCurrentToken(), tokenHandler.getCurrentToken().getStart());             }         }         return programNode;     }     private boolean ParseFunction(ProgramNode programNode) {         Optional functionNameToken = tokenHandler.getCurrentToken();         if (tokenHandler.MatchAndRemove(Token.TokenType.IDENTIFIER) != null) {             FunctionDefinitionNode functionNode = new FunctionDefinitionNode(functionNameToken.getType());             programNode.addNode(functionNode);             if (tokenHandler.MatchAndRemove(Token.TokenType.LPAREN) != null) {                 if (tokenHandler.MatchAndRemove(Token.TokenType.RPAREN) != null) {                     AcceptSeparators();                     return true;                 }             }         }         return false;     }     private boolean parseAction(ProgramNode programNode) {         Optional functionNameToken = tokenHandler.getCurrentToken();         if (tokenHandler.MatchAndRemove(Token.TokenType.IDENTIFIER) != null) {             ActionMap actionMap = new ActionMap(tokenHandler.getLastMatchedToken().getType());             programNode.addNode(actionMap);             AcceptSeparators();             return true;         }         return false;     } }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Java Code: Below is Parser.java and there are errors. getType() and getStart() is undefined for the type Optional<Token> and there is an error in addNode(). Make sure to get rid of all the errors in the code. Attached is images of the errors. 

 

Parser.java

import java.text.ParseException;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;

import javax.swing.ActionMap;

public class Parser {

    private TokenHandler tokenHandler;
    private LinkedList<Token> tokens;

    public Parser(LinkedList<Token> tokens) {
        this.tokenHandler = new TokenHandler(tokens);
        this.tokens = tokens;
    }

    public boolean AcceptSeparators() {
        boolean foundSeparator = false;
        while (tokenHandler.MoreTokens()) {
            Optional<Token> currentToken = tokenHandler.getCurrentToken();
            if (currentToken.getType() == Token.TokenType.NEWLINE || currentToken.getType() == Token.TokenType.SEMICOLON) {
                tokenHandler.consumeMatchedToken();
                foundSeparator = true;
            } else {
                break;
            }
        }
        return foundSeparator;
    }

    public ProgramNode Parse() throws ParseException {
        ProgramNode programNode = new ProgramNode(null, 0);
        while (tokenHandler.MoreTokens()) {
            if (!ParseFunction(programNode) && !parseAction(programNode)) {
                throw new ParseException("Unexpected token: " + tokenHandler.getCurrentToken(), tokenHandler.getCurrentToken().getStart());
            }
        }
        return programNode;
    }

    private boolean ParseFunction(ProgramNode programNode) {
        Optional<Token> functionNameToken = tokenHandler.getCurrentToken();
        if (tokenHandler.MatchAndRemove(Token.TokenType.IDENTIFIER) != null) {
            FunctionDefinitionNode functionNode = new FunctionDefinitionNode(functionNameToken.getType());
            programNode.addNode(functionNode);
            if (tokenHandler.MatchAndRemove(Token.TokenType.LPAREN) != null) {
                if (tokenHandler.MatchAndRemove(Token.TokenType.RPAREN) != null) {
                    AcceptSeparators();
                    return true;
                }
            }
        }
        return false;
    }

    private boolean parseAction(ProgramNode programNode) {
        Optional<Token> functionNameToken = tokenHandler.getCurrentToken();
        if (tokenHandler.MatchAndRemove(Token.TokenType.IDENTIFIER) != null) {
            ActionMap actionMap = new ActionMap(tokenHandler.getLastMatchedToken().getType());
            programNode.addNode(actionMap);
            AcceptSeparators();
            return true;
        }
        return false;
    }
}

32
33
340
35
36
37
38
39
40
41
42
43
440
45
46
47
48
49
50
51
52
53
54
55
56
57
58
590
60
61
62
€63
64
65
66
67
68
69}
}
public ProgramNode Parse() throws ParseException {
ProgramNode programNode = new ProgramNode(null, 0);
while (tokenHandler. More Tokens()) {
if (!ParseFunction (programNode) && !parseAction(programNode)) {|
throw new ParseException ("Unexpected token: " + tokenHandler.getCurrentToken(), tokenHandler.ge
}
}
private boolean ParseFunction (ProgramNode programNode) {
Optional<Token > functionNameToken = tokenHandler.getCurrentToken();
if (tokenHandler.MatchAnd Remove(Token. TokenType.IDENTIFIER) != null) {
FunctionDefinitionNode functionNode = new FunctionDefinitionNode (functionName Token.getType());
}
}
return programNode;
}
programNode.addNode(functionNode);
if (tokenHandler.MatchAnd Remove(Token. TokenType.LPAREN) != null) {
if (tokenHandler.MatchAndRemove (Token. TokenType.RPAREN) != null) {
AcceptSeparators();
return true;
}
}
}
return false;
private boolean parseAction (ProgramNode programNode) {
Optional<Token› functionNameToken = tokenHandler.getCurrentToken();
if (tokenHandler.MatchAnd Remove (Token. Token Type. IDENTIFIER) != null) {
ActionMap actionMap = new Action Map (tokenHandler.getLast Matched Token ().getType());
programNode.addNode(actionMap);
AcceptSeparators();
return true;
}
return false;
#mypack
✓ Parser
.Parser(LinkedList<Token>)
AcceptSeparators(): boolean
Parse(): ProgramNode
parseAction(ProgramNode): boolean
ParseFunction(ProgramNode): boolean
The method getType() is undefined for the type Optional <Token>
Press 'F2' for focus
Transcribed Image Text:32 33 340 35 36 37 38 39 40 41 42 43 440 45 46 47 48 49 50 51 52 53 54 55 56 57 58 590 60 61 62 €63 64 65 66 67 68 69} } public ProgramNode Parse() throws ParseException { ProgramNode programNode = new ProgramNode(null, 0); while (tokenHandler. More Tokens()) { if (!ParseFunction (programNode) && !parseAction(programNode)) {| throw new ParseException ("Unexpected token: " + tokenHandler.getCurrentToken(), tokenHandler.ge } } private boolean ParseFunction (ProgramNode programNode) { Optional<Token > functionNameToken = tokenHandler.getCurrentToken(); if (tokenHandler.MatchAnd Remove(Token. TokenType.IDENTIFIER) != null) { FunctionDefinitionNode functionNode = new FunctionDefinitionNode (functionName Token.getType()); } } return programNode; } programNode.addNode(functionNode); if (tokenHandler.MatchAnd Remove(Token. TokenType.LPAREN) != null) { if (tokenHandler.MatchAndRemove (Token. TokenType.RPAREN) != null) { AcceptSeparators(); return true; } } } return false; private boolean parseAction (ProgramNode programNode) { Optional<Token› functionNameToken = tokenHandler.getCurrentToken(); if (tokenHandler.MatchAnd Remove (Token. Token Type. IDENTIFIER) != null) { ActionMap actionMap = new Action Map (tokenHandler.getLast Matched Token ().getType()); programNode.addNode(actionMap); AcceptSeparators(); return true; } return false; #mypack ✓ Parser .Parser(LinkedList<Token>) AcceptSeparators(): boolean Parse(): ProgramNode parseAction(ProgramNode): boolean ParseFunction(ProgramNode): boolean The method getType() is undefined for the type Optional <Token> Press 'F2' for focus
2
3
40
5
6
7
8
9
0
1
2
3
40
5
6
7
8
9
1
2
3
4
5
6
7
8
ge
0
2
4
6
8
}
public ProgramNode Parse() throws ParseException {
ProgramNode programNode = new ProgramNode (null, 0);
while (tokenHandler. More Tokens ()) {
}
}
if (!ParseFunction (programNode) && !parseAction(programNode)) {|
throw new ParseException ("Unexpected token: " + tokenHandler.getCurrentToken(), tokenHandler.ge
}
private boolean ParseFunction (ProgramNode programNode) {
Optional<Token› functionNameToken = tokenHandler.getCurrentToken();
if (tokenHandler.MatchAnd Remove (Token. TokenType.IDENTIFIER) != null) {
FunctionDefinitionNode functionNode = new FunctionDefinitionNode (functionName Token.getType());
programNode.addNode (functionNode);
}
return programNode;
}
if (tokenHandler.MatchAnd Remove (Token. TokenType.LPAREN) != null) {
if (tokenHandler.MatchAnd Remove (Token. TokenType.RPAREN) != null) {
AcceptSeparators();
return true;
}
}
return false;
private boolean parseAction (ProgramNode programNode) {
Optional<Token> functionNameToken = tokenHandler.getCurrentToken();
if (tokenHandler.MatchAndRemove (Token. TokenType.IDENTIFIER) != null) {
ActionMap actionMap = new ActionMap (tokenHandler.getLastMatchedToken().getType());
programNode.addNode (actionMap);
AcceptSepara
return true;
}
return false;
The method addNode(ActionMap) is undefined for the type ProgramNode
2 quick fixes available:
• Create method 'addNode(Action Map) in type 'ProgramNode'
Add cast to 'programNode'
Press 'F2' for focus
Transcribed Image Text:2 3 40 5 6 7 8 9 0 1 2 3 40 5 6 7 8 9 1 2 3 4 5 6 7 8 ge 0 2 4 6 8 } public ProgramNode Parse() throws ParseException { ProgramNode programNode = new ProgramNode (null, 0); while (tokenHandler. More Tokens ()) { } } if (!ParseFunction (programNode) && !parseAction(programNode)) {| throw new ParseException ("Unexpected token: " + tokenHandler.getCurrentToken(), tokenHandler.ge } private boolean ParseFunction (ProgramNode programNode) { Optional<Token› functionNameToken = tokenHandler.getCurrentToken(); if (tokenHandler.MatchAnd Remove (Token. TokenType.IDENTIFIER) != null) { FunctionDefinitionNode functionNode = new FunctionDefinitionNode (functionName Token.getType()); programNode.addNode (functionNode); } return programNode; } if (tokenHandler.MatchAnd Remove (Token. TokenType.LPAREN) != null) { if (tokenHandler.MatchAnd Remove (Token. TokenType.RPAREN) != null) { AcceptSeparators(); return true; } } return false; private boolean parseAction (ProgramNode programNode) { Optional<Token> functionNameToken = tokenHandler.getCurrentToken(); if (tokenHandler.MatchAndRemove (Token. TokenType.IDENTIFIER) != null) { ActionMap actionMap = new ActionMap (tokenHandler.getLastMatchedToken().getType()); programNode.addNode (actionMap); AcceptSepara return true; } return false; The method addNode(ActionMap) is undefined for the type ProgramNode 2 quick fixes available: • Create method 'addNode(Action Map) in type 'ProgramNode' Add cast to 'programNode' Press 'F2' for focus
Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Arrays
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.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education