C# 将树结构解析为If语句

C# 将树结构解析为If语句,c#,java,python,.net,c,C#,Java,Python,.net,C,所附文件表示一个树结构,我想将其转换为java源代码,将树表示为嵌套的if语句 STOP_WORDS > 0 | NEXT_TYPE > 5: X | NEXT_TYPE <= 5: Y STOP_WORDS <= 0 … If (STOP_WORDS > 0) { If (NEXT_TYPE > 5) { Return X

所附文件表示一个树结构,我想将其转换为java源代码,将树表示为嵌套的if语句

STOP_WORDS > 0
| NEXT_TYPE > 5: X
| NEXT_TYPE <= 5: Y
STOP_WORDS <= 0
…


If (STOP_WORDS > 0)
{
                If (NEXT_TYPE > 5)
                {
                                Return X
                }
                If ( NEXT_TYPE <= 5)
                {
                                Return Y
                }
}
If (STOP_WORDS <= 0)
{
….
}
STOP\u WORDS>0
|下一个类型>5:X
|下一步(第5类)
{
返回X
}
如果(下一个)类型5:5
|第五类:2
||以前的_类型5:2

|| |下一个_TYPE你的问题非常不清楚,但这是一个开始

barometer = 0
with open('path/to/input') as infile:
    for line in infile:
        barometer += delta
        line = ''.join(itertools.dropwhile(lambda c: c in ' |', line))
        if ":" in line:
            cond, act = line.split(":",1)
            print "If (%s) { Return %s }" %(cond, act)
        else:
            delta = barometer - sum(1 for i in itertools.takewhile(lambda c: c in ' |', line))
            if delta < 0:
                print " {}"[delta/abs(delta)]*abs(delta)
            print "If (%s) {" %cond
气压计=0
以open('path/to/input')作为填充:
对于填充中的线:
气压计+=增量
line=''.join(itertools.dropwhile(lambda c:c在'|',行中))
如果“:”在同一行:
cond,act=line.split(“:”,1)
打印“如果(%s){返回%s}”%(条件,动作)
其他:
delta=气压计-总和(i在itertools.takewhile中为1(λc:c在“|”行中))
如果δ<0:
打印“{}”[delta/abs(delta)]*abs(delta)
打印“如果(%s){”%cond
我现在必须睡觉了,但这至少可以让你开始了
你忘记了Haskell、C++、露比…还有很多其他的…你到底需要哪种语言?语言并不重要。你可以用任何语言来解释这不是我们的,这是关于你的。AnilChaubey@Anil谢谢!~请读这封信谢谢我会检查你的密码。谢谢。我也会检查你的密码。很棒的密码。这正是我想要的。我是真的非常感谢你…非常感谢。。。
barometer = 0
with open('path/to/input') as infile:
    for line in infile:
        barometer += delta
        line = ''.join(itertools.dropwhile(lambda c: c in ' |', line))
        if ":" in line:
            cond, act = line.split(":",1)
            print "If (%s) { Return %s }" %(cond, act)
        else:
            delta = barometer - sum(1 for i in itertools.takewhile(lambda c: c in ' |', line))
            if delta < 0:
                print " {}"[delta/abs(delta)]*abs(delta)
            print "If (%s) {" %cond
with open('input.txt') as f:
    indent = 8
    prev_depth = -1
    closes = []
    for line in f:
        line = line.strip()
        if not line: continue

        depth = line.count('|')
        while prev_depth >= depth:
            prev_depth -= 1
            print(closes.pop())
        pad = ' ' * (depth*indent)
        print(pad + 'If ({})'.format(line.lstrip('| ').split(':', 1)[0]))
        print(pad + '{')
        closes.append(pad + '}')
        if ':' in line:
            pad2 = ' ' * ((depth+1)*indent)
            print(pad2 + 'Return {}'.format(line[line.find(':')+1:].strip()))
        prev_depth = depth
    while closes:
        print(closes.pop())