boost.spirit用户手册翻译(5):组织结构

22 篇文章 0 订阅
 Organization

组织结构

 

The framework is highly modular and is organized in layers:

Spirit框架是高度模块化的,且以层次结构来组织:

iterator
actor

debug

attribute
dynamic
error_handling
symbols
tree
utility

meta

core
scanner
primitives
composite
non_terminal

Spirit has four layers, plus an independent top layer. The independent layer, comprising of actor and iterator, does not rely on the other layers. The framework's architecture is completely orthogonal. The relationship among the layers is acyclic. Lower layers do not depend nor know the existence of upper layers. Modules in a layer do not depend on other modules in the same layer.

它分为四层,外加一个独立的顶层——包含动作器和迭代器,不依赖于其他层次。框架的架构是完全正交的。层次之间的关系是无回路的。低层并不依赖,也不知道上层存在与否。一层内的模块并不依赖于同层次内其他模块。

The client may use only the modules that she wants without incurring any compile time nor run time penalty. A minimalistic approach is to use only the core as is. The highly streamlined core is usable by itself. The core is sufficiently suitable for tasks such as micro parsing.

如果库的使用者只想使用那些不会导致编译时间延长或者运行时负担增加的模块,可以用极简主义风格的方法,只使用核心(core)。这个高度流水线化的核心是自给自足的。核心已足以胜任诸如轻微分析这样的任务。

The iterator module is independent of Spirit and may be used in other non-Spirit applications. This module is a compilation of stand-alone iterators and iterator wrappers compatible with Spirit. Over time, these iterators have been found to be most useful for parsing with Spirit.

迭代器模块独立于Spirit,并可以用于其他非Spirit的应用中。这个模块是兼容与Spirit的独立的迭代器及迭代器封装的汇集。时间已经证明了,这些迭代器对于用Spirit分析来说,是最有用的。

The actor module, also independent of Spirit, is a compilation of predefined semantic actions that covers the most common semantics processing tasks.

动作器模块,同样独立于Spirit,是预定义的语义动作的汇集,这些语义动作包括了最常见的语义分析目标。

The debug module provides library wide parser debugging. This module hooks itself up transparently into the core non-intrusively and only when necessary.

debug模块提供了库范围内的分析器调试工具。这个模块可以只在必要时才透明地与核心用无侵犯性的方式挂钩。

The attribute module introduces advanced semantic action machinery with emphasis on extraction and passing of data up and down the parser hierarchy through inherited and synthesized attributes. Attributes may also be used to actually control the parsing. Parametric parsers are a form of dynamic parsers that changes their behavior at run time based on some attribute or data.

属性模块带来的是一种高级的语义动作机制,这种机制强调的是通过属性的继承和合成,在分析的层次中获取和传递数据。属性也可用于实际控制分析过程。参数化分析器就是那些在运行时依照某些属性或者数据,改变其行为的动态分析器的一种形式。

The dynamic module focuses on parsers with behavior that can be modified at run-time.

动态模块聚焦于可以在运行时更改其行为的分析器。

error_handling. The framework would not be complete without Error Handling. C++'s exception handling mechanism is a perfect match for Spirit due to its highly recursive functional nature. C++ Exceptions are used extensively by this module for handling errors.

错误处理。没有错误处理,这个框架就是不完整的。由于C++异常机制的高度递归的功能特性(functional nature?拿不准),它与Spirit完美匹配。C++异常被这个模块大量使用,借以处理错误。

The symbols module focuses on symbol table management. This module is rather basic now. The goal is to build a sub-framework that will be able to accommodate C++ style multiple scope mechanisms. C++ is a great model for the complexity of scoping that perhaps has no parallel in any other language. There are classes and inheritance, private, protected and public access restrictions, friends, namespaces, using declarations, using directives, Koenig lookup (Argument Dependent Lookup) and more. The symbol table functionality we have now will be the basis of a complete facility that will attempt to model this.

符号模块专注于符号表的管理。这个模块现在还是很简陋的,它的目标是建立一个子框架以适应C++风格的多重范围控制机制。对于范围控制的复杂度来说,C++是一个很典型的例子,也许在其他任何语言中,都没有类似的。它有class和继承、私有、保护和公共等访问控制,有友元、名字空间、using声明,using定向、koenig查找(参数依赖查找)甚至更多。现有的符号表的功能将是构造适应前面这些的功能的基础。

I wish that I could ever see, a structure as lovely as a tree...

Parse Tree and Abstract Syntax Tree (AST) generation are handled by the Tree module. There are advantages with Parse Trees and Abstract Syntax Trees over semantic actions. You can make multiple passes over the data without having to re-parse the input. You can perform transformations on the tree. You can evaluate things in any order you want, whereas with attribute schemes you have to process in a begin to end fashion. You do not have to worry about backtracking and action side effects that may occur with an ambiguous grammar.

分析树和抽象语法树(AST)的创建由模块处理。使用分析树和抽象语法树比语义动作好的地方是:可以不用重新分析输入而进行多遍分析;可以对树进行转换;可以以你想要的任意顺序来进行处理,不过需要依照一份顺序处理的属性表。不需要担心二义性语法可能产生的回溯和语义动作的副作用。

The utility module is a set of commonly useful parsers and support classes that were found to be useful in handling common tasks such as list processing, comments, confix expressions, etc.

工具模块是一组通常使用的分析器和 支持类的集合,在处理常见的分析任务,比如列表处理、注释、连接声明等时,他们很有用。

meta, provides metaprogramming facilities for advanced Spirit developers. This module facilitates compile-time and run-time introspection of Spirit parsers.

,为高阶Spirit开发者提供了元编程功能。这个模块用于提高Spirit分析器编译期和运行时的性能。

 


 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值