Package edu.iu.jrsalata
Class AbstractStatementBuilderBuilder
java.lang.Object
edu.iu.jrsalata.AbstractStatementBuilderBuilder
- All Implemented Interfaces:
AbstractStatementBuilderBuilderInterface
public class AbstractStatementBuilderBuilder
extends Object
implements AbstractStatementBuilderBuilderInterface
The AbstractStatementBuilderBuilder class is responsible for creating and managing
a queue of AbstractStatementBuilder instances. It reads an input file or stream,
determines the appropriate builder to use, and processes the file to populate the
builder queue.
This class implements the AbstractStatementBuilderBuilderInterface and provides methods to set the input file, retrieve the builder queue, and execute the file processing.
It supports both SIC and non-SIC builders, handles macro definitions, and manages control sections within the input file.
-
Field Summary
Modifier and TypeFieldDescriptionprotected Queue<AbstractStatementBuilder>
stores each of the created buildersprotected String
stores the name of the input filestatic final Logger
Standard logger for this classstatic final String
In order to differentiate between SIC and SIC/XE, all SIC files must start with this flag -
Constructor Summary
ConstructorDescriptionConstructs a new AbstractStatementBuilderBuilder with default values. -
Method Summary
Modifier and TypeMethodDescriptionprotected AbstractStatementBuilder
choseBuilder
(Scanner sc) Chooses the appropriate statement builder based on the input from the scanner.void
execute()
Executes the process of reading an input file, selecting the appropriate builder, and processing the file to populate the builder queue.void
execute
(InputStream file) Executes the process of reading and parsing an assembly file.protected Queue<AbstractStatementBuilder>
fileInput
(Scanner sc, AbstractStatementBuilder builder) Processes the input from a Scanner and builds a queue of AbstractStatementBuilder objects.Retrieves the queue of AbstractStatementBuilder instances.protected MacroProcessorInterface
handleMacroCreation
(String line) Handles the creation of a macro processor from a given line of macro definition.void
setInputFile
(String fileName) Sets the input file name.
-
Field Details
-
SIC_FLAG
In order to differentiate between SIC and SIC/XE, all SIC files must start with this flag- See Also:
-
LOGGER
Standard logger for this class -
builderQueue
stores each of the created builders -
inputFile
stores the name of the input file
-
-
Constructor Details
-
AbstractStatementBuilderBuilder
public AbstractStatementBuilderBuilder()Constructs a new AbstractStatementBuilderBuilder with default values.This constructor initializes the input file name to "input.asm" and initializes the builder queue as an empty LinkedList.
-
-
Method Details
-
setInputFile
Sets the input file name.- Specified by:
setInputFile
in interfaceAbstractStatementBuilderBuilderInterface
- Parameters:
fileName
- the name of the input file to be set
-
getBuilders
Retrieves the queue of AbstractStatementBuilder instances.- Specified by:
getBuilders
in interfaceAbstractStatementBuilderBuilderInterface
- Returns:
- a Queue containing AbstractStatementBuilder objects.
-
execute
Executes the process of reading an input file, selecting the appropriate builder, and processing the file to populate the builder queue.- Specified by:
execute
in interfaceAbstractStatementBuilderBuilderInterface
- Throws:
InvalidAssemblyFileException
- if the assembly file is invalid.FileNotFoundException
- if the input file is not found.ScriptException
- if there is an error in the script execution.
-
execute
public void execute(InputStream file) throws InvalidAssemblyFileException, ScriptException, IOException Executes the process of reading and parsing an assembly file.- Specified by:
execute
in interfaceAbstractStatementBuilderBuilderInterface
- Parameters:
file
- the InputStream of the assembly file to be processed- Throws:
InvalidAssemblyFileException
- if the assembly file is invalidScriptException
- if there is an error in the script executionIOException
- if an I/O error occurs
-
fileInput
protected Queue<AbstractStatementBuilder> fileInput(Scanner sc, AbstractStatementBuilder builder) throws InvalidAssemblyFileException, ScriptException Processes the input from a Scanner and builds a queue of AbstractStatementBuilder objects. This method reads lines from the provided Scanner, processes them, and constructs AbstractStatementBuilder objects based on the input. It handles control sections (CSECT) and macro definitions (MACRO, MEND) within the input.- Parameters:
sc
- the Scanner to read input frombuilder
- the initial AbstractStatementBuilder to use for processing- Returns:
- a Queue of AbstractStatementBuilder objects representing the processed input
- Throws:
InvalidAssemblyFileException
- if the input file contains invalid assembly codeScriptException
- if there is an error in processing a script
-
handleMacroCreation
protected MacroProcessorInterface handleMacroCreation(String line) throws InvalidAssemblyFileException Handles the creation of a macro processor from a given line of macro definition.- Parameters:
line
- The line containing the macro definition.- Returns:
- A MacroProcessorInterface instance created from the macro definition.
- Throws:
InvalidAssemblyFileException
- If the macro definition is invalid.
-
choseBuilder
Chooses the appropriate statement builder based on the input from the scanner. If the first line of the input matches the SIC_FLAG, a SicStatementBuilder is chosen. Otherwise, a default StatementBuilder is used.- Parameters:
sc
- the Scanner object used to read the input- Returns:
- an instance of AbstractStatementBuilder, either a StatementBuilder or SicStatementBuilder
-