Add basic parser
这个提交包含在:
父节点
35418a690e
当前提交
62894d15db
共有 2 个文件被更改,包括 17 次插入 和 11 次删除
24
main.py
24
main.py
|
@ -1,16 +1,18 @@
|
|||
# This is a sample Python script.
|
||||
|
||||
# Press Shift+F10 to execute it or replace it with your code.
|
||||
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
|
||||
def parse(lines):
|
||||
lines = [line.strip() for line in lines]
|
||||
lines = [line.split("->") for line in lines]
|
||||
rules = [(line[0], line[1].strip().split(" ")) for line in lines]
|
||||
print_rules(rules)
|
||||
|
||||
|
||||
def print_hi(name):
|
||||
# Use a breakpoint in the code line below to debug your script.
|
||||
print(f'Hi, {name}') # Press Ctrl+8 to toggle the breakpoint.
|
||||
def print_rules(rules):
|
||||
for rule in rules:
|
||||
print("void parse_%s(...) {" % rule[0])
|
||||
for element in rule[1]:
|
||||
print(" parse_%s(...);" % element)
|
||||
print("}")
|
||||
|
||||
|
||||
# Press the green button in the gutter to run the script.
|
||||
if __name__ == '__main__':
|
||||
print_hi('PyCharm')
|
||||
|
||||
# See PyCharm help at https://www.jetbrains.com/help/pycharm/
|
||||
with open("sample.txt", "r") as f:
|
||||
parse(f.readlines())
|
||||
|
|
4
sample.txt
普通文件
4
sample.txt
普通文件
|
@ -0,0 +1,4 @@
|
|||
T -> S u S
|
||||
T -> x S y
|
||||
S -> a S b
|
||||
S ->
|
正在加载…
在新工单中引用