Question
Java Program: Attached is the rubric where all the functions must be involved below. There are errors in the lexer file which must be fixed.
Java Program: Attached is the rubric where all the functions must be involved below. There are errors in the lexer file which must be fixed. Show the entire code when it's completely fixed. Don't show half of the code. Make sure to run the files and show the output in the terminal. Below is the lexer file with the token and the shank files.
Lexer.java
package mypack;
import java.util.ArrayList; import java.util.HashMap; import java.util.List;
public class Lexer { private static final int INTEGER_STATE = 1; private static final int DECIMAL_STATE = 2; private static final int IDENTIFIER_STATE = 3; private static final int SYMBOL_STATE = 4; private static final int ERROR_STATE = 5; private static final int STRING_STATE = 6; private static final int CHAR_STATE = 7; private static final int COMMENT_STATE = 8;
private static final char EOF = (char) -1;
private static String input; private static int index; private static char currentChar; private static int lineNumber = 1; private static int indentLevel = 0; private static int lastIndentLevel = 0; private static HashMap
public List
private static int currentState() { if (Character.isDigit(currentChar)) { return INTEGER_STATE; } else if (Character.isLetter(currentChar)) { return IDENTIFIER_STATE; } else if (currentChar == '\"' || currentChar == '\'') { return currentChar == '\"' ? STRING_STATE : CHAR_STATE; } else if (currentChar == '{' || currentChar == '}') { return COMMENT_STATE; } else if (currentChar == ' ' || currentChar == '\t') { return indentationState(); } else if (isSymbol(currentChar)) { return SYMBOL_STATE; } else { return UNKNOWN_STATE; } } private static void integerState(List
private static void advance() { index++; if (index >= input.length()) { currentChar = EOF; } else { currentChar = input.charAt(index); } } }
Token.java
package mypack;
public class Token { public enum TokenType { WORD, NUMBER, SYMBOL }
public TokenType tokenType; private String value; public Token(TokenType type, String val) { this.tokenType = type; this.value = val; } public TokenType getTokenType() { return this.tokenType; }
public String toString() { return this.tokenType + ": " + this.value; } }
Shank.java
package mypack;
import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; import java.util.List;
public class Shank { public static void main(String[] args) { if (args.length != 1) { System.out.println("Error: Exactly one argument is required."); System.exit(0); }
String filename = args[0];
try { List
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started