flemme de mettre un message de commit

This commit is contained in:
Yohan Simard 2021-03-11 21:28:04 +01:00
父節點 729cbf9a50
當前提交 2ffc6c5111

21
main.py
查看文件

@ -95,12 +95,15 @@ def print_unit_rules(rules):
""") """)
for element in rule[1]: for element in rule[1]:
elem_code = get_code(element) elem_code = get_code(element)
if elem_code != "":
print(f""" nbCharParsed = parse_{elem_code}(word, pos + totalCharParsed); print(f""" nbCharParsed = parse_{elem_code}(word, pos + totalCharParsed);
if (!nbCharParsed) {{ if (nbCharParsed == -1) {{
printf("Fail {elem_code} in {code}{rules_dict[left]}\\n"); printf("Fail {elem_code} in {code}{rules_dict[left]}\\n");
return 0; return -1;
}} }}
totalCharParsed += nbCharParsed;""") totalCharParsed += nbCharParsed;""")
else:
print(f" printf(\"Epsilon! -> Success\\n\");")
print(f""" print(f"""
printf("Success {code}{rules_dict[left]}\\n"); printf("Success {code}{rules_dict[left]}\\n");
return totalCharParsed; return totalCharParsed;
@ -116,11 +119,11 @@ def print_global_rules():
for i in range(1, value + 1): for i in range(1, value + 1):
print(f""" print(f"""
nbCharParsed = parse_{code}{i}(word, pos); nbCharParsed = parse_{code}{i}(word, pos);
if (nbCharParsed) {{ if (nbCharParsed != -1) {{
return nbCharParsed; return nbCharParsed;
}}""") }}""")
print(""" print("""
return 0; return -1;
}""") }""")
@ -131,12 +134,16 @@ def get_code(s):
def print_terminal_rules(): def print_terminal_rules():
for t in terminals_set: for t in terminals_set:
code = get_code(t) code = get_code(t)
l = len(t)
print(f"""int parse_{code}(char* word, int pos) {{ print(f"""int parse_{code}(char* word, int pos) {{
if (strcomp(word[pos], "{t}") == 0) {{ char substr[{l+1}];
substr[0] = '\\0';
strncat(substr, &word[pos], {l});
if (strcmp(substr, "{t}") == 0) {{
print_with_indent(pos, "{code}\\n"); print_with_indent(pos, "{code}\\n");
return 1; return {l};
}} else {{ }} else {{
return 0; return -1;
}} }}
}}""") }}""")