Hi guys, I'm very new to the concept of writing an assembler and even after reading a great deal of material, I'm still having difficulties wrapping my head around a couple of concepts.
1) What is the process to actually break up a source file into tokens? I believe this process is called lexing and I've searched high and low for a real code examples that make sense but I can't find a thing so simple code examples very welcome ;)
2) When parsing, does information ever need to be passed up or down the tree, the reason I ask is as follows, take:
LD BC, nn
It needs to be turned into the following parse tree once tokenized???
___ LD ___
| |
BC nn
Now, when this tree is traversed it needs to produce the following machine code:
01 n n
If the instruction had been:
LD DE,nn
Then the output would need to be:
11 n n
Meaning that it raises the question, does the LD node return something different based on the operand or is it the operand that returns something? and how is this achieved? More simple code examples would be excellent if time permits.
I'm most interested in learning some of the raw processes here rather than looking at advanced existing tools so please bare that in mind before sending me to Yacc or Flex.
Best regards, GP