<?xml version="1.0" encoding="UTF-8" ?><rdf:RDF 
  xmlns="http://purl.org/rss/1.0/"
  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  xmlns:atom="http://www.w3.org/2005/Atom"
  xmlns:dc="http://purl.org/dc/elements/1.1/"
  xml:lang="ja">
  <channel rdf:about="http://w.atwiki.jp/dslbookwip/">
    <title>DSL Book(by Martin Fowler) 翻訳ページ</title>
    <link>http://w.atwiki.jp/dslbookwip/</link>
    <atom:link href="https://w.atwiki.jp/dslbookwip/rss10.xml" rel="self" type="application/rss+xml" />
    <atom:link rel="hub" href="https://pubsubhubbub.appspot.com" />
    <description>DSL Book(by Martin Fowler) 翻訳ページ</description>

    <dc:language>ja</dc:language>
    <dc:date>2012-04-05T19:39:34+09:00</dc:date>
    <utime>1333622374</utime>

    <items>
      <rdf:Seq>
                <rdf:li rdf:resource="https://w.atwiki.jp/dslbookwip/pages/15.html" />
                <rdf:li rdf:resource="https://w.atwiki.jp/dslbookwip/pages/16.html" />
                <rdf:li rdf:resource="https://w.atwiki.jp/dslbookwip/pages/17.html" />
                <rdf:li rdf:resource="https://w.atwiki.jp/dslbookwip/pages/22.html" />
                <rdf:li rdf:resource="https://w.atwiki.jp/dslbookwip/pages/21.html" />
                <rdf:li rdf:resource="https://w.atwiki.jp/dslbookwip/pages/20.html" />
                <rdf:li rdf:resource="https://w.atwiki.jp/dslbookwip/pages/3.html" />
                <rdf:li rdf:resource="https://w.atwiki.jp/dslbookwip/pages/13.html" />
                <rdf:li rdf:resource="https://w.atwiki.jp/dslbookwip/pages/19.html" />
                <rdf:li rdf:resource="https://w.atwiki.jp/dslbookwip/pages/18.html" />
              </rdf:Seq>
    </items>
	
		
    
  </channel>
    <item rdf:about="https://w.atwiki.jp/dslbookwip/pages/15.html">
    <title>目次</title>
    <link>https://w.atwiki.jp/dslbookwip/pages/15.html</link>
    <description>
      ----


http://d.hatena.ne.jp/dsltranslators/ にて正規の翻訳チームの方が活動されているようなので、そちらへどうぞ。


以下放置です。著作権の問題があるのでアクセス制限してます。
-----------------------------------------------------------

Martin Fowler氏が執筆中のDSL(Domain Specific Language)本を翻訳しています。暇を見つけて訳していきます。



#comment
----

*物語
序文
例によるイントロダクション
DSLの使用
DSLの実装
内部DSLの実装
外部DSLの実装
内部DSL/外部DSLの選択
計算モデル
コード生成
言語ワークベンチ

*外部DSL
ツリー生成(Tree Construction)
変換コードの埋込(Embedded Translation)
区切り文字指向変換(Delimiter Directed Translation)
文法指向変換(Syntax Directed Translation)
BNF
外部コード(Foreign Code)
選択的なトークン化(Alternative Tokenization)
ネストした式表現(Nested Expression)
文法としての改行(Syntactic Newlines)
外部DSLについてあれこれ

*内部DSL
[[Expression Builder]]
[[Function Sequence]]
[[Nested Function]]
Method Chaining
[[Object Scoping]]
Closure
[[Nested Closure]]
Literal List
Literal Map
Dynamic Reception
Annotation
Macro
Parse Tree Manipulation
Class Symbol Table
Textual Polishing
Literal Extention

*計算モデル
Adaptive Model
Decision Table
Dependency Network
Production Rule System
State Machine

*コード生成
Model-Aware Generation
Model Ignorant Generation
Transformer Generation
Templated Generation
Embedment Helper
Generation Gap

*一般的なパーサに関するトピック
Semantic Model
Symbol Table
[[Context Variable]]
Construction Builder

*どの章に入るか未定
The MDD view of the Language Landscape




- test test  -- test  (2009-06-06 05:46:30)
#comment
----
----    </description>
    <dc:date>2012-04-05T19:39:34+09:00</dc:date>
    <utime>1333622374</utime>
  </item>
    <item rdf:about="https://w.atwiki.jp/dslbookwip/pages/16.html">
    <title>このサイトについて</title>
    <link>https://w.atwiki.jp/dslbookwip/pages/16.html</link>
    <description>
      Martin Fowler氏が執筆中のDSL(Domain Specific Language)本を翻訳しています。暇を見つけて訳していきます。

主に内部DSL関連に興味があるので、内部DSLをメインに訳しています。ご自由に編集ください。

原文：DSL Book WIP
http://www.martinfowler.com/dslwip/


※：現在、各記事は非公開にしております。閲覧・編集したい場合、kyossi212@gmail.comまで連絡をください。

#comment    </description>
    <dc:date>2010-03-24T00:37:26+09:00</dc:date>
    <utime>1269358646</utime>
  </item>
    <item rdf:about="https://w.atwiki.jp/dslbookwip/pages/17.html">
    <title>対訳表</title>
    <link>https://w.atwiki.jp/dslbookwip/pages/17.html</link>
    <description>
      |英語|日本語|備考|
|fluent interface|流れるようなインターフェイス|&quot;流暢なインターフェイス&quot;が使われている場合あり|
|Internal DSL/External DSL|内部DSL/外部DSL|&quot;言語内DSL&quot;,&quot;言語外DSL&quot;が使われている場合あり|
|How it works|動作原理|別候補:&quot;どうなってるの&quot;,&quot;仕組み&quot;|
|expectation|エクスペクテーション or エクスペクテーション(expectation)|[[ここのRSpec解説&gt;http://jp.rubyist.net/magazine/?0021-Rspec]]に倣ってカタカナにし、初出箇所ではカッコ内で英語表記する|





#comment    </description>
    <dc:date>2009-12-26T02:49:39+09:00</dc:date>
    <utime>1261763379</utime>
  </item>
    <item rdf:about="https://w.atwiki.jp/dslbookwip/pages/22.html">
    <title>Context Variable</title>
    <link>https://w.atwiki.jp/dslbookwip/pages/22.html</link>
    <description>
      #contents()
原文はこちら： http://martinfowler.com/dslwip/ContextVariable.html
原文、翻訳共に作成中です。
----
*Context Variable(コンテキスト変数)
&amp;italic(){パース過程で必要となる変数を保持する}

複数のアイテムから構成されるリストをパースしているとします。それぞれのアイテム中から何らかのデータをキャプチャしているとしましょう。アイテム中のデータそれぞれは独立してキャプチャできるとして、今キャプチャしているデータを含むアイテム自体の情報も知っている必要があります。

Context Variable(文脈変数）は現在処理中のアイテムを変数に保持し、次のアイテムに進んだら順次再割り当てをすることで、この目的を達成します。

*動作原理
パース処理中、currentItemのような変数を用意し、次のアイテムに移るごとに定期的に更新しているとしたら、それはContext Variableと呼ぶことができます。

Context Variableは[[Semantic Model]]オブジェクトでも、何らかのビルダーでも構わないでしょう。[[Semantic Model]]はより直接的ですが、使えるのはパース処理中に[[Semantic Model]]の全プロパティが変更可能である時に限ります。そうでない場合は、[[Construction Builder]]のように、何らかのビルダーを使って情報を集め、最後に[[Semantic Model]]を作り上げるのが良いでしょう。

*いつ使うか
パース処理中に何らかのコンテキストを保持する必要性が生じることは良くあり、Context Variableはそのような場合の明確な候補です。Context Variableは簡単に導入できます。

しかし、Context Variableが問題となる場合があります。それは、多用しすぎてしまう場合です。Context Variableは元来、可変な状態なので、きっちり追跡しておかないとバグの温床になり得ます。というのも、Context Variableは然るべき時に更新するのを忘れやすいので、そデバッグがとても難しくなることがあります。通常の防衛策はContext Variableを必要とするパース処理を小さく保つようににパース処理を構成することです。私自身はContext Variable自体が邪悪なものだとは思っていませんが、それでもできるだけContext Variableが必要とならないテクニックを使うことを好みます（この本の中で、至る所で私のこの考えを目撃することになるでしょう）。

*例:Iniファイルの読み込み(C#)
ここでは、Context Variableがどういうものか示すために、至極簡単な例であるiniファイルのパース処理を取りげることにします。iniファイルフォーマットは例としては良い素材です。Windowsではより改善されたレジストリがあります。なのでiniファイルは古めかしいものですが、それでも幾つかのプロパティを含むシンプルなリストを扱うには可読性が高く、軽いフォーマットです。代替としてのXMLやYAMLはより複雑な構造を扱えます。それでも必要としているものがシンプルなiniファイルで十分であるような場合、iniファイルは今でも合理的な選択肢です。

例に使うのは、プロジェクトのコードが幾つかあり、各プロジェクトに幾つかのプロパティが含まれているiniファイルを取り上げます。

 [intro]
 name = Introduction
 lead = Martin
 
 [type-transmog]
 name = Type Transmogrification
 lead=Neal
 
 #line comment
 
 [lang]    #group comment
 name = Language Background Advice
 lead = Revecca # item comment

iniファイルのフォーマットには標準がありませんが、基本となる要素はプロパティの一群で、それぞれ各セクションに割り当てられています。このiniファイルでは各セクションはプロジェクトのコードです。

このiniファイルの[[Semantic Model]]は取るに足らないものです。

 class Project...
     class Project {
         public string Code {get; set;}
         public string Name {get; set;}
         public srting Lead {get; set;}
     
iniファイルフォーマットは[[Delimiter Directed Translation]]を使って簡単に読み込むことができます。パーサの基本的な構造はスクリプト(訳注:ここではiniファイルのことかと）を行分割し、各行をパースしていくという通常のアプローチです。

 class ProjectParser
 	 private TextReader input;
 	 private List&lt;Project&gt; result = new List&lt;Project&gt;();
 	
 	 public ProjectParser(TextReaer input) {
 	   	this.input = input;
 	 }
 	 public List&lt;Project&gt; Run(){
 		  string line;
 		  while((line = input.ReadLine()) != null){
 			    parseLine(line);
 		  }
 		  return result;
 	 }

最初の節では各行のパーサは空白とコメントを処理します。

 class ProjecrParser...
 	private void parseLine(string s) {
 		var line = removeComments(s);
 		if (isBlank(line)) return;
 		else if (isSection(line)) parseSection(line);
 		else if (isProperty(line)) parseProperty(line);
 		else throw new ArgumentException(&quot;Unable to parse: + line&quot;)
 	}
 	private strin removeComments(string s){
 		return s.Split(&#039;#&#039;)[0];
 	}
 	private bool isBlank(string line){
 		return Regex.IsMatch(line , @&quot;^\s*$&quot;);
 	}

Context VariableであるcurrentProject変数はその時点で割り当てられているセクションを保持するために使います。

 class ProjectParser...
    private bool isSection(string line){
 	    return Regex.IsMatch(line @&quot;^\s\[&quot;);
    }
    private void parseSection(sting line) {
 	    var code = new RegEx(@&quot;\[(.*)\]&quot;).Match(line).Groups[1].value;
 	    currentProject = new Project {Code = code};
 	    result.Add(currentProject);
    }
    private Project currentProject;

そして、Context Variable(currentPojectメンバ)をプロパティをパースするときに使います。
 class ProjectParser...
     private bool isProperty(string line){
         return Regex.IsMatch(line, @&quot;=&quot;)
     }
     private void parseProperty(string line) {
         var tokens = extractPropertyTokens(line);
         setProjectProperty(tokens[0], tokens[1]);
     }
     private sting[] extracePropertyTokens(string line){
         char[] sep = {&#039;=&#039;};
         var tokens = line.Split(sep,2);
         if (tokens.Lengs &lt; 2) throw new ArgumentException(&quot;unable to split&quot;);
         for (var i = 0; i &lt; tokens.Length; i++) tokens[i] = tokens[i].Trim();
         return tokens;
     }
     private void setProjectProperty(string name, string value){
         var proj = typeof(Project);
         var prop = proj.GetProperty(capitalize(name));
         if (prop == null) throw new ArgumentException(&quot;Unable to find property: &quot; + name);
         prop.SetValue(currentProject, value, null);
     }
     private string capitalize(string s) {
         return s.Substring(0,1).ToUpper() + s.SubString(1).ToLower();
     }
     
リフレクションを使えばコードはより複雑になりますが、[[Semantic Model]]にプロパティを追加した時にパーサのコードを変更しなくても良くなります。

#comment    </description>
    <dc:date>2009-12-23T01:09:03+09:00</dc:date>
    <utime>1261498143</utime>
  </item>
    <item rdf:about="https://w.atwiki.jp/dslbookwip/pages/21.html">
    <title>Nested Closure</title>
    <link>https://w.atwiki.jp/dslbookwip/pages/21.html</link>
    <description>
          </description>
    <dc:date>2009-12-23T01:04:49+09:00</dc:date>
    <utime>1261497889</utime>
  </item>
    <item rdf:about="https://w.atwiki.jp/dslbookwip/pages/20.html">
    <title>Nested Function</title>
    <link>https://w.atwiki.jp/dslbookwip/pages/20.html</link>
    <description>
          </description>
    <dc:date>2009-12-18T19:58:43+09:00</dc:date>
    <utime>1261133923</utime>
  </item>
    <item rdf:about="https://w.atwiki.jp/dslbookwip/pages/3.html">
    <title>右メニュー</title>
    <link>https://w.atwiki.jp/dslbookwip/pages/3.html</link>
    <description>
      //**メニュー

[[目次]]

[[原文サイト&gt;http://martinfowler.com/dslwip/index.html]]



[[このサイトについて]]
[[対訳表]]
kyossi212@gmail.com
//[[トップページ]]



//----

//**リンク

//**更新履歴
//#recent(20)


&amp;link_editmenu2(text=サイドバーを編集)    </description>
    <dc:date>2009-12-18T18:57:26+09:00</dc:date>
    <utime>1261130246</utime>
  </item>
    <item rdf:about="https://w.atwiki.jp/dslbookwip/pages/13.html">
    <title>Expression Builder</title>
    <link>https://w.atwiki.jp/dslbookwip/pages/13.html</link>
    <description>
          </description>
    <dc:date>2009-12-18T18:34:24+09:00</dc:date>
    <utime>1261128864</utime>
  </item>
    <item rdf:about="https://w.atwiki.jp/dslbookwip/pages/19.html">
    <title>Function Sequence</title>
    <link>https://w.atwiki.jp/dslbookwip/pages/19.html</link>
    <description>
          </description>
    <dc:date>2009-06-06T06:00:29+09:00</dc:date>
    <utime>1244235629</utime>
  </item>
    <item rdf:about="https://w.atwiki.jp/dslbookwip/pages/18.html">
    <title>Object Scoping</title>
    <link>https://w.atwiki.jp/dslbookwip/pages/18.html</link>
    <description>
          </description>
    <dc:date>2009-06-06T05:55:51+09:00</dc:date>
    <utime>1244235351</utime>
  </item>
  </rdf:RDF>
