krizmotlhala
asked on
line by line
I am developing a CPU simulator. So have a textArea where I input a an assembly language code, should be taken as instructions and put into the memory.
So what I want to do is check whether the entered code is a valid assembly language code or what.
Example of a valid one is: LDA 5
ADD 2
SUB 3
I so I am planning to take the code line by line and check its validity. How can I take that code line after line from the textArea? I trust you guys. Help me.
So what I want to do is check whether the entered code is a valid assembly language code or what.
Example of a valid one is: LDA 5
ADD 2
SUB 3
I so I am planning to take the code line by line and check its validity. How can I take that code line after line from the textArea? I trust you guys. Help me.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Don't forget to catch exception in order to output error message.
>>String operand = instructionAtoms[1].trim() ;
Of course you shouldn't assume that the instruction *has* an operand (check array length)
Of course you shouldn't assume that the instruction *has* an operand (check array length)
StringReader in = new StringReader(ta.getText()) ;
String line = null;
while (null!=(line=in.readLine() )
{
// then parse the line
}
String line = null;
while (null!=(line=in.readLine()
{
// then parse the line
}
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
String[] instructions = ta.getText().split("\n");