《领域特定语言》章节试读

出版社:机械工业出版社华章公司
出版日期:2013-3
ISBN:9787111413059
作者:Martin Fowler
页数:488页

《领域特定语言》的笔记-第447页

误译一处,影响理解。

《领域特定语言》的笔记-第99页

误译一处,影响理解。
原文“动态”,译为“静态”。参见英文原文:
I find that Templated Generation works best when there's a lot of static code in the output and only a few dynamic bits—particularly since I can look at the template file and get a good sense of what gets generated.

《领域特定语言》的笔记-第399页

误译一处,影响理解。

《领域特定语言》的笔记-第237页 - 树的创建

《领域特定语言》的笔记-第313页 - 对象范围

书中代码给了一个区域安全检查的例子,C#,下面是我画的类图。

《领域特定语言》的笔记-第120页 - Semantic Model

语义模型与领域模型的不同:
A Semantic Model is a notion very similar to that of a Domain Model [poeaa]. I use a separate term because although Semantic Models are often subsets of Domain Models, they don't have to be. I use Domain Model to refer to a behaviorally rich object model, while a Semantic Model may be data alone. A Domain Model captures the core behavior of an application, while a Semantic Model may play a supporting role. A good example of this is an object-relational mapper that coordinates data between an object model and a relational database. You could use a DSL to describe object-relational mappings, and the resulting Semantic Model would consist of the Data Mappers [poeaa], not the Domain Model that is the subject of the mapping.
语言模型与抽象语法树的不同:
A Semantic Model is usually different from a syntax tree because they serve separate purposes. A syntax tree corresponds to the structure of the DSL scripts. Although an abstract syntax tree may simplify and somewhat reorganize the input data, it still takes fundamentally the same form. The Semantic Model, however, is based on what will be done with the information from a DSL script. It often will be a substantially different structure, and usually not a tree structure. There are occasions when an AST is an effective Semantic Model for a DSL, but these are the exception rather than the rule.
语言模型使得DSL不同于通用语言:
Traditional discussions of languages and parsing don't use a Semantic Model. This is part of the difference between working with DSLs and with general-purpose languages. A syntax tree usually makes a suitable structure to base code generation for a general-purpose language, so there's less desire to have a different Semantic Model. From time to time, a Semantic Model is used; for instance, a call graph representation is very useful for optimization. Such models are referred to as intermediate representations—they are usually intermediate steps before code generation.

《领域特定语言》的笔记-第252页 - foreign code

foreign code
predicate
排除某些字符

《领域特定语言》的笔记-第208页

《领域特定语言》的笔记-第387页

C#语言实现类似这样的效果: 3.grams.flour
参考 Martin Fowler的代码,我做如下实现。
3.chi(),三尺 转换为国际标准单位制米。
namespace int_ext
{
class Program
{
static void Main(string[] args)
{
System.Console.WriteLine( 3.chi() ); // output 0.999
}
}
public static class int_e
{
public static double chi(this int arg)
{
return arg * 0.333;
}
}
}

《领域特定语言》的笔记-第448页

#define的高级用法,两处

《领域特定语言》的笔记-第259页 - 可变分词方式

原文 Alternative Tokenization
意为 词法分析的变形,非常规的词法分析
嵌套引号的解析方法
转义
不常用的字符组合
多种分隔符供选择
成对花括号,利用 下推自动机的能力

《领域特定语言》的笔记-第188页

BNF中的递归。译文含义不清,不过正确的译法我也没想出来。

《领域特定语言》的笔记-第377页 - Class Symbol Table

益处
identifier
实现手段: 反射
以command为例

《领域特定语言》的笔记-第284页

如何使“无状态”的函数序列具有状态,使用语境变量。

《领域特定语言》的笔记-第225页 - 使用代沟

《领域特定语言》的笔记-第296页

Specification Pattern

《领域特定语言》的笔记-第290页

嵌套函数中,有多个同类型的参数,希望次序无关,如何区分这些参数。
问题
解决方案public enum Types { TopBorder, BottomBorder, LeftMargin, RightMargin, Transparent }

《领域特定语言》的笔记-第218页 - 解析器生成器 嵌入动作

参考ANTLR手册更好。

《领域特定语言》的笔记-第401页

lambda operator in C#.

《领域特定语言》的笔记-第106页

附图中的阴影被删除了,影响理解。

《领域特定语言》的笔记-第366页

子树与代码转换的能力
作者有趣的担心
递归遍历树
构建过程与讲解过程 的差异

《领域特定语言》的笔记-第243页 - 嵌入式语法翻译

helper的位置
Semantic Model的容器
两个问题的解决方案:
分层语境,前向引用
hierarchic context and forward references.

《领域特定语言》的笔记-第211页 - 解析器组合子

类图,继承和聚合关系,详图和简图;composite模式。
grammar用 parser comibinator in java描述
composite pattern
composite pattern应用于 parser comibinator,简图
继承和聚合关系,展开的详图

《领域特定语言》的笔记-第118页

误译一处,影响阅读。

《领域特定语言》的笔记-第279页

Expression Builder
单一Builder
多Builder

《领域特定语言》的笔记-第206页

Combinators are designed to be composed to create more complex operations of the same type as their input.

《领域特定语言》的笔记-第220页 - 编写基本文法

红笔括起那段提到的不加EOF可能导致停止解析这个问题我从未遇到。哪位大侠了解 ,请指点我。先行感谢。
我又查了一下,Martin Fowler 在别的场合又提到一次这个问题,如下。
catalog : item* EOF;
...
Inevitably I did have problems even with this simple example. My biggest blocker was that I originally defined the catalog term as catalog : item*;, that is without the EOF. I then got confused because the parser didn't indicate an error when it got spurious input (like xitem foo). This wasn't helped by inconsistencies between Antlr and AntlrWorks (the latter did show an error and older versions of AntlrWorks would handle whitespace differently too.)
[http://martinfowler.com/bliki/HelloAntlr.html]

《领域特定语言》的笔记-第445页

这一处,老马与我们的工作不同。
他使用更薄的DSL。

《领域特定语言》的笔记-第319页 - 闭包

各种语言称谓不同。
C语言可以用带有 void* 参数存储变量引用的 函数指针实现闭包。
问题的提出:用对象作为谓词,语法麻烦。
实例:C#2.0 & C#3.0
总结闭包:
1. 变量引用,而非复制,lexical scope;
2. lazy eval;
3. 闭包的创建、保存、执行。


 领域特定语言下载 更多精彩书评


 

农业基础科学,时尚,美术/书法,绘画,软件工程/开发项目管理,研究生/本专科,爱情/情感,动漫学堂PDF下载,。 PDF下载网 

PDF下载网 @ 2024