English 中文(简体)
Y树:我如何操纵树?
原标题:YACC|BISON :How do I manipulate parse tree?

The goal of my application is to validate an sql code and generate,in the mean time, from that code a formatted one with some modification.
For example this where clause :

where
e.student_name= c.contact_name and ( c.address = " nefta" or c.address=" tozeur ") and
e.age <18

我们本会把产出形式化,如:

where e.student_name= c.contact_name
and (c.address=trim("nefta")
or c.address=trim("tozeur") )
and e.age <18

我希望我能很好地解释我的目标。


The problem is grammars may contain recursive rules which make the rewrite task unreliable ; for instance in my sql grammar i have this :

search_condition         : search_condition OR search_condition{clbck_or}
                         | search_condition AND search_condition{clbck_and}
                         | NOT search_condition {clbck_not}
                         |  (  search_condition  ) {clbck__}
                         | predicate {clbck_pre}
                         ;

我知道,我指定了解决转移问题的优先工作

%left OR
%left AND
%left NOT

So back on the last example ; my clause where will be consumed this way:

c.address="nefta"or c.address="tozeur" -> search_condition
(c.address="nefta"or c.address="tozeur")->search_condition
e.student_name= c.contact_name and (c.address="nefta"or c.address="tozeur")-> search_condition
... and e.age<18-> search_condition

你们可以理解的是,在每一次削减引起的呼吁方面重建投入流的难度并不相同。

Any help for this problem ?

最佳回答

你的问题很模糊,因此我猜想你实际上在您的cl(or)或(em)中。” 野生动物所引出的“共同”方式是使用“遗传价值”,即(未测试):

search_condition         : search_condition OR search_condition{$$ = clbck_or($1, $3);}
                         | search_condition AND search_condition{$$ = clbck_and($1, $3);}
                         | NOT search_condition {$$ = clbck_not($2);}
                         |  (  search_condition  ) {$$ = clbck__($2);}
                         | predicate {$$ = clbck_pre($1);}
                         ;

如果你重新使用Bison,该手册在“固定点计算器:`标记'”一节中有一个很好的例子。 在座标和C后,你必须增加一些记忆处理。

问题回答

Bison在树冠上是好的,在人工帮助下,在 custom树上是好的。 之后,由你们来做你们想要的树。 好消息是,你可以做你想要的一切。 坏消息是,你仍然必须建立很多机制,来做你们想要的东西。 贵重源代码的基本问题称为“贴印”;见我的。 回答如何打印,以了解它需要做些什么,包括一切法性辛加的光谱(你不会在字面上失去越狱,正确吗?) 你们总是在如何找到你想要改变树种的树种,或者你如何把树 s改。

如果你不希望这样做的话,那么你真的想要的是program transformation system, 该系统在树苗上是好的,为你建造了yn树(你不需要思考,King是粗重的),那么你就会发现树中的模式,因为你使用的是先辈子树,而不用知道我最后能够描述我的树子。 (方案转变系统基本上包括一个小区。)

Our DMS Software Reengineering Toolkit is such a program transformation system. It has a set of predefined language definitions including SQL2011 and means for configuring for a particular dialect. Using DMS source-to-source syntax rules, you could carry out the change in your example with the following rule:

 domain SQL;

 rule trim_c_members(f: identifier, s: string):condition->condition
 = " c.f = s " ->  " c.f = trim(s) ";

This is DMS Rule language (meta) syntax to describe a rewrite on ("domain") SQL code. The rule has a name (because in complex application there s lot of rules) and it as syntactic place holders "f" and "s"; it rewrites only conditions in the code. The quotes are RSL meta-quotes; stuff inside is SQL with RSL metavariables "f" and "s"; stuff outside is RSL rule syntax. What the rule says is, "for any condition on a variable explicitly named c , with any field f, if that field is compared by equality to some literal string, then replace the literal string by trim applied to the literal string".

我略去了一些基本上说的法典,即“整个树木适用这一规则,而同一地方则不两次适用”。 这种“战略”是《战略》中的许多组成部分之一。

规则如何运作的问题。 该系统通过将Kallser应用到代议的座标上,生产“父子”yn子树,并配上 written的地主。 左侧型树则与目标树相配;右手树在左树配对地主树的带上;而地主子树则转移。 因此,你看到你知道和热爱的地表动物;该工具与树木合作,因此被案文混为一谈。

现在,我认为我的规则与你的意图完全相符,但部分原因是我可以猜测你的实际意图。 如果你想要的话,你可以撰写其他规则。

这一规则完全由辛迪加驱动;如果你想对规则适用更复杂的条件(例如,变数只能是你界定的某些范围),则可以增加一个调子(未显示),并且能够说出。 但是,阅读《刑法》比《刑法》更加简单、容易得多,而《刑法》超越了海岸地带(你在这里看到海岸警卫队?)并试图把所有这一切推向前进。

在适用规则之前和之后,都发生了 par和 pre;实施所有机器所需要的机制很多,但这种机制已建在数字管理系统中(例如,它拥有比在座建筑中建筑的生物量这样[但更强大的]),而且对于像Kall这样的预先界定的领域来说,所有单价印刷作品也都是预先配置的。

如果你想更好地了解一下与数字管理系统的全面周期需要什么(选择自己的语言,界定一个粗略的打印机,界定复杂的规则),那么,这里使用数字管理系统界定和象征性地简化缩略语





相关问题
Parse players currently in lobby

I m attempting to write a bash script to parse out the following log file and give me a list of CURRENT players in the room (so ignoring players that left, but including players that may have rejoined)...

How to get instance from string in C#?

Is it possible to get the property of a class from string and then set a value? Example: string s = "label1.text"; string value = "new value"; label1.text = value; <--and some code that makes ...

XML DOM parsing br tag

I need to parse a xml string to obtain the xml DOM, the problem I m facing is with the self closing html tag like <br /> giving me the error of Tag mismatch expected </br>. I m aware this ...

Ruby parser in Java

The project I m doing is written in Java and parsers source code files. (Java src up to now). Now I d like to enable parsing Ruby code as well. Therefore I am looking for a parser in Java that parses ...

Locating specific string and capturing data following it

I built a site a long time ago and now I want to place the data into a database without copying and pasting the 400+ pages that it has grown to so that I can make the site database driven. My site ...

热门标签