添加

ID783
姓名匿名用户
内容import json
import re
class F:
def __init__(self,code):
super().__init__()
self.stack=[] #F stack

self.list = []
self.lines = filter(lambda y: y!="", map(lambda x : x.strip(),code.splitlines()) ) # 去除空白行
self.it = iter(self.lines)

self.id = 0

def parse(self):
def tree(level=0):
try:
token = next(tokens)
except StopIteration:
if level != 0:
raise Exception('missing closing paren')
else:
return []
if '}' in token:
if level == 0:
raise Exception('missing opening paren')
else:
return []
elif '{' in token:
self.id+=1
name = re.match("(\w+)\((.*)\)",token).group(1)
value = re.match("(\w+)\((.*)\)",token).group(2)

return [ { name : {"id":self.id,"value": value,"children": tree(level+1)}} ] + tree(level)
else:
self.id+=1
return [{"id":self.id,"value":token.replace("//",""),"children":[]} ] + tree(level)
tokens = self.it
return tree()


def visit(self,tree):
pass

def show(self):
#print(self.lines)
print(self.list)





code = """
main(start){

//todo1
//todo2
//todo3

if(age>18){
if(sex==0){
//todo4
}
}

while(true){
//todo5
//todo6
if(ok){
//todo7
//todo8
//todo9
}
}

}
"""

d=F(code).parse()
data_json = json.dumps(d)

#print(d)

print(data_json)
状态1
创建时间2020-09-22 06:33:48
更新时间2020-09-22 06:33:48
姓名评论创建日期操作
没有找到数据。