Link to home
Start Free TrialLog in
Avatar of krizmotlhala
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.
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

The easiest way is to take the whole text and parse it:

String[] instructions = ta.getText().split("\n");
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Webstorm
Webstorm

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)
StringReader in = new StringReader(ta.getText());
String line = null;
while (null!=(line=in.readLine())
{
   // then parse the line
}
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial