parsing - What is the best way to read a file in Java? -


i writing java program simulate assembler (as assignment in college).

i have assembly program given input assembler.

the general format of every statement in assembly code follows:

[label] opcode operand1 [operand2] (each term separated space)

label , operand2 optional parts in statements these may unavailable.

in java code read each line , use stringtokenizer 4 parts separated spaces.

my question whenever label and/or operand2 not available how can find out first values returned stringtokenizer opcode value , second value operand1 value? best way this?

thanks lot

if

  1. a label can never opcode,
  2. and depending how many opcode values exist,

you might create method isopcode(string s) , test first part after tokenizing. if passes, label must have been missing. if fails, label must exist.

depending on results of test, can count remaining parts determine if operand2 present.


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -