分层查询 [英] Hierarchical query
问题描述
重新发布更多说明(如Jan所说)。
假设我有一个BNFgrammar和一个解析到树中的源文本。我将如何查询
标识符声明?
所有XQuery教程(我去哪里收集一些想法)开始
有简单的例子,比如浏览/ b / b
书店/书的所有后代(而书店的XML设计是如此错误的想法
启动) 。
也许需要一些例子。一个简化的语法:
statement_block:
''声明''
declaration_item_list
''开始''
陈述
''结束''
;
陈述:
(statement_block |赋值)语句|
;
赋值:
identifier'':=' '(标识符|数字)'';''
;
declaration_item_list:
标识符''整数''''' ;''
;
假设我们解析以下文本
声明 - 令牌#1
i整数; - 代币2,3,4
开始
i:= 1; - 代币6,7,8,9
结束;
因此我们得到这样的派生树:
1 statement_block
1.1''declare''(匹配令牌#1)
1.2 declaration_item_list
1.2.1标识符(匹配令牌#2)
1.2.2''整数''(匹配令牌#3)
1.2.3'';''(匹配令牌#4)
1.3''开始''(匹配令牌#5)
1.4陈述
1.4.1分配
1.4。 1.1标识符
1.4.1.2'':=''
1.4.1.3数字
1.4.1.4'';''>
1.4.2语句(匹配空令牌)
1.5''结束'';
现在,给定一个派生树和叶节点标识符1.4。 1.1
对应于令牌#6,它是变量i,我们如何找到声明它的
节点1.2.1?
6月13日,18:11,Vadim Tr opashko< vadimtro_inva ... @ yahoo.comwrote:
重新发布更多说明(如Jan所说)。
假设我有一个BNFgrammar和一个解析成树的源文本。我将如何查询
标识符声明?
所有XQuery教程(我去哪里收集一些想法)开始
有简单的例子,比如浏览/ b / b
书店/书的所有后代(而书店的XML设计是如此错误的想法
启动) 。
也许需要一些例子。一个简化的语法:
statement_block:
''声明''
declaration_item_list
''开始''
陈述
''结束''
;
陈述:
(statement_block |赋值)语句|
;
赋值:
identifier'':=' '(标识符|数字)'';''
;
declaration_item_list:
标识符''整数''''' ;''
;
假设我们解析以下文本
声明 - 令牌#1
i整数; - 代币2,3,4
开始
i:= 1; - 代币6,7,8,9
结束;
因此我们得到这样的派生树:
1 statement_block
1.1''declare''(匹配令牌#1)
1.2 declaration_item_list
1.2.1标识符(匹配令牌#2)
1.2.2''整数''(匹配令牌#3)
1.2.3'';''(匹配令牌#4)
1.3''开始''(匹配令牌#5)
1.4陈述
1.4.1分配
1.4。 1.1标识符
1.4.1.2'':=''
1.4.1.3数字
1.4.1.4'';''>
1.4.2语句(匹配空令牌)
1.5''结束'';
现在,给定一个派生树和叶子节点标识符1.4.1.1
对应于令牌#6,它是变量i,我们如何找到声明它的
节点1.2.1?
好的。我将假设语法树使用以下DTD(用我自己的符号表示
使其更具可读性)。 (它使用
没有属性来保持简单):
< stat_bl - < decl_kw< decl_item_list< begin_kw< statements>
< semicol_kw< end-kw>
< decl_kw - EMPTY
< begin_kw - EMPTY
< end_kw - 空的
< semicol_kw - EMPTY
< statements - (< stat_bl |< assignment)+
< ;赋值 - < var< assign_kw(< var |< number)< semicol_kw>
< var - PCDATA
< assign_kw - EMPTY
< number - PCDATA
< decl_item_list - (< var< type< semicol_kw)+
< type-- PCDATA
对于初学者我会先做反向查询,所以我会假设
是变量
< blockquote> dvar,包含一个描述声明中
变量的< varelement。遍及
dvar范围内的赋值中的所有
< varnodes的XPath表达式为
如下:
(1)
Reposting with more clarification (as Jan asked).
Suppose I have a BNFgrammar and a source text parsed into a tree. How
would I query an
identifier declaration?
All the XQuery tutorials (where I went to gather some ideas) start
with simpleminded examples like browsing all the descendants of /
bookstore/book (and the bookstore XML design is such wrong idea to
boot).
Perhaps some example is needed. A simplified grammar:
statement_block:
''declare''
declaration_item_list
''begin''
statements
''end''
;
statements:
(statement_block | assignment) statements |
;
assignment:
identifier '':='' (identifier | number) '';''
;
declaration_item_list:
identifier ''integer'' '';''
;
Suppose we parse the following text
declare -- token #1
i integer; -- tokens 2,3,4
begin
i := 1; -- tokens 6,7,8,9
end;
So that we get the derivation tree like this:
1 statement_block
1.1 ''declare'' (matches token #1)
1.2 declaration_item_list
1.2.1 identifier (matches token #2)
1.2.2 ''integer'' (matches token #3)
1.2.3 '';'' (matches token #4)
1.3 ''begin'' (matches token #5)
1.4 statements
1.4.1 assignment
1.4.1.1 identifier
1.4.1.2 '':=''
1.4.1.3 number
1.4.1.4 '';''
1.4.2 statements (matches empty token)
1.5 ''end'';
Now, given a derivation tree and the leaf node identifier 1.4.1.1
corresponding to the token #6 which is variable i, how do we find the
node 1.2.1 that declares it?
On 13 jun, 18:11, Vadim Tropashko <vadimtro_inva...@yahoo.comwrote:Reposting with more clarification (as Jan asked).
Suppose I have a BNFgrammar and a source text parsed into a tree. How
would I query an
identifier declaration?
All the XQuery tutorials (where I went to gather some ideas) start
with simpleminded examples like browsing all the descendants of /
bookstore/book (and the bookstore XML design is such wrong idea to
boot).
Perhaps some example is needed. A simplified grammar:
statement_block:
''declare''
declaration_item_list
''begin''
statements
''end''
;
statements:
(statement_block | assignment) statements |
;
assignment:
identifier '':='' (identifier | number) '';''
;
declaration_item_list:
identifier ''integer'' '';''
;
Suppose we parse the following text
declare -- token #1
i integer; -- tokens 2,3,4
begin
i := 1; -- tokens 6,7,8,9
end;
So that we get the derivation tree like this:
1 statement_block
1.1 ''declare'' (matches token #1)
1.2 declaration_item_list
1.2.1 identifier (matches token #2)
1.2.2 ''integer'' (matches token #3)
1.2.3 '';'' (matches token #4)
1.3 ''begin'' (matches token #5)
1.4 statements
1.4.1 assignment
1.4.1.1 identifier
1.4.1.2 '':=''
1.4.1.3 number
1.4.1.4 '';''
1.4.2 statements (matches empty token)
1.5 ''end'';
Now, given a derivation tree and the leaf node identifier 1.4.1.1
corresponding to the token #6 which is variable i, how do we find the
node 1.2.1 that declares it?Ok. I''m going to assume the following DTD (in a notation of my own
making to make it a bit more readable) for the syntax tree. (It uses
no attributes to keep things simple):
<stat_bl--<decl_kw<decl_item_list<begin_kw<statements>
<semicol_kw<end-kw>
<decl_kw--EMPTY
<begin_kw--EMPTY
<end_kw--EMPTY
<semicol_kw--EMPTY
<statements--( <stat_bl| <assignment)+
<assignment--<var<assign_kw( <var| <number) <semicol_kw>
<var--PCDATA
<assign_kw--EMPTY
<number--PCDATA
<decl_item_list--( <var<type<semicol_kw)+
<type--PCDATA
For starters I''ll first do the reverse query, so I will assume there
is a variable
dvar that contains a <varelement that describes a
variable in a declaration. The XPath expression that walks to all the
<varnodes in an assignment that are in the scope of
dvar is as
follows:
(1)
这篇关于分层查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!