Package edu.iu.jrsalata
Class MacroProcessor
java.lang.Object
edu.iu.jrsalata.MacroProcessor
- All Implemented Interfaces:
MacroProcessorInterface
The MacroProcessor class is responsible for processing macros in assembly language.
It implements the MacroProcessorInterface and provides methods to add lines to a macro,
set a label for a macro, and retrieve the processed lines with arguments.
-
Constructor Summary
ConstructorDescriptionConstructs a new MacroProcessor with default values.MacroProcessor
(String[] parameters) Constructs a new MacroProcessor with the specified parameters. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a line to the macro's definition after preprocessing it.Processes the macro definition by replacing placeholders with the provided arguments.void
Sets the label for the macro processor.
-
Constructor Details
-
MacroProcessor
public MacroProcessor()Constructs a new MacroProcessor with default values. Initializes the label to an empty string, parameters to an empty array, and definition to an empty ArrayList. -
MacroProcessor
Constructs a new MacroProcessor with the specified parameters.- Parameters:
parameters
- an array of strings representing the parameters for the macro processor
-
-
Method Details
-
addLine
Adds a line to the macro's definition after preprocessing it. The preprocessing involves: 1. Replacing each parameter in the line with its respective position placeholder. The placeholders are in the format of {i}, where i is the index of the parameter. 2. If a label is available, it is prepended to the line followed by three spaces. The label is then reset to an empty string to ensure it is only used once.- Specified by:
addLine
in interfaceMacroProcessorInterface
- Parameters:
line
- The line to be added to the macro's definition.
-
setLabel
Sets the label for the macro processor. Note: This method must be called before adding any lines using addLine(String line).- Specified by:
setLabel
in interfaceMacroProcessorInterface
- Parameters:
label
- the label to set
-
getLines
Processes the macro definition by replacing placeholders with the provided arguments.- Specified by:
getLines
in interfaceMacroProcessorInterface
- Parameters:
args
- An array of strings representing the arguments to replace the placeholders in the macro definition.- Returns:
- A Queue of strings where each string is a line from the macro definition with placeholders replaced by the corresponding arguments.
- Throws:
InvalidAssemblyFileException
- If the number of provided arguments does not match the number of parameters in the macro definition.
-