Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA: For this project I have a Token java file with an enum class for PLUS, MINUS, NUMBER, etc. and a Lexer class that is

JAVA: For this project I have a Token java file with an enum class for PLUS, MINUS, NUMBER, etc. and a Lexer class that is to print out the output.

Example; input in the command line would be 5+3 and the output from the lexer class(another .java file) would output as an arraylist such as NUMBER(5) PLUS NUMBER(3). I am entering a "5+3", "5 7 8", etc "9/4*2" not a file

Whenever i enter an input into the command line it catches the IOException error, how do I fix this?

import java.io.IOException; import java.util.Scanner; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.List; import java.util.ArrayList;

public class Basic { public static void main(String[] args) throws IOException { //If no file was entered at all or too many files if(args.length>1){ System.out.println("Too many arguments."); System.exit(0); } else if(args.length==0) { System.out.println("No file."); System.exit(0); } //file not found Path path = Paths.get(args[0]); try{ List list = Files.readAllLines(Paths.get(args[0])); for(String line: list) { if(line.equals(null)) { System.out.println("Empty line."); } else { //file found Lexer lexObj = new Lexer(line); for(int i=0;i { System.out.println(lexObj.lex(line).get(i).toString() + " "); } } } } catch(IOException e) { System.out.println("Error: " + e.getMessage()); } } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Secrets Of Analytical Leaders Insights From Information Insiders

Authors: Wayne Eckerson

1st Edition

1935504347, 9781935504344

More Books

Students also viewed these Databases questions