问题描述
我对编写汇编程序的概念很陌生,即使在阅读了大量材料后,我仍然很难将脑袋围绕着几个概念.
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.
-
实际上将源文件分解为令牌的过程是什么?我相信这个过程称为词法化,我在高低两下搜索了一个有意义的真实代码示例,但是我找不到一个非常受欢迎的简单代码示例;)
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 ;)
解析时,是否需要在树上向上或向下传递信息?我问的原因如下:
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
然后输出将是:
11 n n
这意味着它提出了一个问题,LD节点根据操作数返回的内容是否有所不同,还是操作数返回的内容?以及如何实现呢?如果时间允许,更简单的代码示例将非常有用.
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.
我最想在这里学习一些原始过程,而不是查看现有的高级工具,因此请记住这一点,然后再将我发送到 Yacc 或 Flex .
I'm most interested in learning some of the raw processes here rather than looking at advanced existing tools so please bear that in mind before sending me to Yacc or Flex.
推荐答案
好吧,您真正想要的树的结构对寄存器和存储器进行操作的指令涉及偏移位移和索引寄存器的寻址模式看起来像这样:
Well, the structure of the tree you really want foran instruction that operates on a register and an memoryaddressing mode involing an offset displacement and an index registerwould look like this:
INSTRUCTION-----+
| | |
OPCODE REG OPERAND
| |
OFFSET INDEXREG
是的,您想在树上上下传递值.正式指定这种值传递的方法称为属性语法",然后为您装饰语法带有值传递的语言(在您的情况下为汇编语法)以及这些值的计算.要了解更多背景,请参见关于属性语法的维基百科.
And yes, you want want to pass values up and down the tree.A method for formally specifying such value passing is called"attribute grammars", and you decorate the grammar for yourlangauge (in your case, your assembler syntax) with the value-passingand the computations over those values. For more background,see Wikipedia on attribute grammars.
在您问的相关问题中,我讨论了工具, DMS ,处理表达式语法和构建树.作为语言操作工具,DMS上下完全一样树信息流问题.这不应该让你感到惊讶,作为高端语言操作工具,它可以处理直接进行语法计算.
In a related question you asked, I discussed atool, DMS,which handles expression grammars and building trees. As language manipulation tool, DMS faces exactly these same up-and-downthe tree information flows issues. It shouldn't surprise you,that as a high-end language manipulation tool, it can handleattribute grammar computations directly.
这篇关于编写Z80汇编器-编写ASM词法并使用合成来构建解析树?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!