写一个Z80汇编 - 乐星ASM,建设使用成分解析树? [英] Writing an z80 assembler - Lexing ASM and building a parse tree using composition?

查看:337
本文介绍了写一个Z80汇编 - 乐星ASM,建设使用成分解析树?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很新编写汇编的理念和阅读材料大量甚至后,我仍然有困难的包装我的头周围的几个概念。

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)什么是真正打破了一个源文件转换为标记的过程?我相信,这个过程被称为词法,我已经搜查高和低一个真正的code例子有意义,但我不能找到一个东西那么简单code的例子非常欢迎;)

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)在解析时,就不断需要传递向上或向下的树,我想问的原因是信息如下,以:

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

现在,当这棵树进行遍历它需要产生以下机code:

Now, when this tree is traversed it needs to produce the following machine code:

01 n n

如果指令已经:

LD DE,nn

然后,输出将需要:

Then the output would need to be:

11 n n

含义,它提出了一个问题,是否根据操作数的LD节点返回不同的东西或者是它返回的东西操作数?而这是怎么实现的?更简单code例子是优秀的如果时间允许。

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 bare that in mind before sending me to Yacc or Flex.

最好的问候,GP

推荐答案

好了,你真的想为树的结构
上寄存器和存储器进行操作的指令
寻址模式involing偏移位移和索引寄存器
应该是这样的:

Well, the structure of the tree you really want for an instruction that operates on a register and an memory addressing mode involing an offset displacement and an index register would look like this:

    INSTRUCTION-----+
    |      |        |
  OPCODE  REG     OPERAND
                  |     |
                OFFSET  INDEXREG

是的,你要想要传递值向上和向下的树。
一种正式指定这样的价值传递方法被调用
属性语法,而你装饰了你的语法
的langauge(在你的情况,你的汇编语法)与传值
和的计算过这些值。欲了解更多的背景下,
看到维基百科上的属性文法

在一<一href=\"http://stackoverflow.com/questions/1317256/z80-asm-bnf-structure-im-am-on-the-right-track\">related问题你问,我讨论了
工具, DMS
其中前处理pression语法和建筑树。如
语言处理工具,DMS面临确切这些相同的向上和向下
树信息流的问题。它不应该让你吃惊,
作为一个高端语言操纵的工具,它可以处理
直接属性文法计算。

In a related question you asked, I discussed a tool, DMS, which handles expression grammars and building trees. As language manipulation tool, DMS faces exactly these same up-and-down the tree information flows issues. It shouldn't surprise you, that as a high-end language manipulation tool, it can handle attribute grammar computations directly.

这篇关于写一个Z80汇编 - 乐星ASM,建设使用成分解析树?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆