Question: Can you please complete Parser.java You only need to write a Parser for the EBNF grammar I will give a thumbs up public class Parser{

Can you please complete Parser.java

You only need to write a Parser for the EBNF grammar

I will give a thumbs up

public class Parser{ private Token currentToken; Lexer scanner;

private void accept(byte expectedKind) { if (currentToken.kind == expectedKind) currentToken = scanner.scan(); else new Error("Syntax error: " + currentToken.spelling + " is not expected.", currentToken.line); }

private void acceptIt() { currentToken = scanner.scan(); }

public void parse() { scanner = new Lexer(); currentToken = scanner.scan(); parseProgram(); if (currentToken.kind != Token.EOF) new Error("Syntax error: Redundant characters at the end of program.", currentToken.line); }

//Program = {"(" Sequence ")"}. private void parseProgram() { } //Sequence = Definition | Expression | Function | Call private void parseSequence() { //else new Error("Syntax Error: assign, identifier, integer, if, operation, or not is expected", currentToken.line); } //SequenceTail = Identifier Expression | "(" Identifier {Parameter}")" private void parseSequenceTail() { //else new Error("Syntax Error: identifier or ( is expected", currentToken.line); }

//Definition = "assign" Identifier Expression. private void parseDefinition() { } /* Expression = Identifier | Literal | "if" Expression Expression [Expression] | Operation Expression Expression | "not" Expression. | "(" Expression ")" */

private void parseExpression() {

//else new Error("Syntax Error: if, operation, or not is expected", currentToken.line); } //Function = "define" "(" Identifier {Parameter}")" Expression. private void parseFunction() { } //Call = "call" Identifier {Expression}. private void parseCall() { }

//Instead writing all of the tests when you need, you can call test private boolean test() { return currentToken.kind == Token.PLUS || currentToken.kind == Token.MINUS || currentToken.kind == Token.TIMES || currentToken.kind == Token.DIVE || currentToken.kind == Token.LESS || currentToken.kind == Token.LEQ || currentToken.kind == Token.GREATER || currentToken.kind == Token.GEQ || currentToken.kind == Token.EQ || currentToken.kind == Token.NEQ || currentToken.kind == Token.OR || currentToken.kind == Token.AND || currentToken.kind == Token.LPAREN; } }

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!