日本免费全黄少妇一区二区三区-高清无码一区二区三区四区-欧美中文字幕日韩在线观看-国产福利诱惑在线网站-国产中文字幕一区在线-亚洲欧美精品日韩一区-久久国产精品国产精品国产-国产精久久久久久一区二区三区-欧美亚洲国产精品久久久久

TCL腳本數(shù)據(jù)文件格式( 五 )


Sources {SYST:263 GOF:207}
Info {
Communicate with a representative rather than with the
actual object.
}
}Pattern "FaCADe" {
Categories {"Access control" "Structural decomposition::object"}
Sources {GOF:185}
Level design
Info {
Group sub-interfaces into a single interface.
}
}Pattern "Counted Pointer" {
Categories {"Resource handling"}
Level idiom
Sources {SYST:353}
Info {
Reference counting prevents memory leaks.
}
}這僅是我最初編寫的輸入文件的一部分,但它還是包含了足夠的數(shù)據(jù)來作為一個較好的例子.樣本的說明很短,還有些笨拙,但對這個例子來說已經(jīng)夠了.
正如你看到的,這個數(shù)據(jù)文件幾個新的特點:
▲數(shù)據(jù)被包含在一些結(jié)構(gòu)中,用大括號{}加以分組.每個結(jié)構(gòu)都由一個關(guān)鍵字開頭.
這些結(jié)構(gòu)可以嵌套,如:結(jié)構(gòu)"Pattern"可以包含一個"Info"結(jié)構(gòu).
▲結(jié)構(gòu)中的元素可以采用很多形式 。它們中的一些是標(biāo)志符或字符串(比如元素"Level"),其他的看上去象是特殊的代碼(如SYST:353),還有一些甚至是自由格式的文本(如在結(jié)構(gòu)Category和Info中的那樣).
▲每個結(jié)構(gòu)中的元素的排列順序是任意的.觀察一下最后兩個樣本就會發(fā)現(xiàn)Level和Sources兩個元素的順序可以互換.所有元素實際上都可以按你想要的順序排列.
▲數(shù)據(jù)文件包含有TCL注釋語句,他們不僅可以在結(jié)構(gòu)之間出現(xiàn),甚至可以出現(xiàn)在結(jié)構(gòu)內(nèi)部.注釋語句能讓你的數(shù)據(jù)更易理解.
你可能會想這種格式比前面的例子復(fù)雜太多了,用TCL語言為其寫一個分析器幾乎是不可能的.可能看上去不太明了,我們還可以用主動文件樣本來使此工作更加簡單.分析(解析)過程比前面的更細而已,但肯定不是"復(fù)雜".
下面是我的分析如上數(shù)據(jù)文件的工具:#我們把數(shù)據(jù)保存在以下三個列表內(nèi):
set l_patterns [list]
set l_sources [list]
set l_categories [list]#我們還需要一個變量跟蹤我們當(dāng)前所在的Pattern結(jié)構(gòu)
set curPattern ""# 下面是關(guān)鍵字"Source"的分析過程.
# 正如你所看到的,關(guān)鍵字后面跟有一個id號(是source的唯一標(biāo)志符),
#還有source的說明文本.
proc Source {id info} {
# Remember that we saw this source.
global l_sources
lappend l_sources $curSource# Remember the info of this source in a global array.
global a_sources
set a_sources($curSource,info) $info
}# The parsing proc for the "Category" keyword is similar.
proc Category {id info} {
global l_categories
lappend l_categories $curCategoryglobal a_categories
set a_categories($curCategory,info) $info
}# This is the parsing proc for the "Pattern" keyword.
# Since a "Pattern" structure can contain sub-structures,
# we use "uplevel" to recursively handle those.
proc Pattern {name args} {
global curPattern
set curPattern $name ; # This will be used in the sub-structures
# which are parsed next
global l_patterns
lappend l_patterns $curPattern# We treat the final argument as a piece of TCL code.
# We execute that code in the caller"s scope, to parse the elements
# of the structure.
# "uplevel" will call "Categories", "Level" and other commands that
# handle the sub-structures.
# This is similar to how we use the "source" command to parse the entire
# data file.
uplevel 1 [lindex $args end]set curPattern ""
}# The parsing proc for one of the sub-structures. It is called
# by "uplevel" when the "Pattern" keyword is handled.
proc Categories {categoryList} {
global curPattern ; # We access the global variable "curPattern"
# to find out inside which structure we are.
global a_patterns
set a_patterns($curPattern,categories) $categoryList
}# The following parsing procs are for the other sub-structures
# of the Pattern structure.proc Level {level} {
global curPattern
global a_patterns
set a_patterns($curPattern,level) $level

推薦閱讀