flemme de mettre un message de commit
This commit is contained in:
parent
729cbf9a50
commit
2ffc6c5111
1 changed files with 15 additions and 8 deletions
21
main.py
21
main.py
|
@ -95,12 +95,15 @@ def print_unit_rules(rules):
|
|||
""")
|
||||
for element in rule[1]:
|
||||
elem_code = get_code(element)
|
||||
if elem_code != "":
|
||||
print(f""" nbCharParsed = parse_{elem_code}(word, pos + totalCharParsed);
|
||||
if (!nbCharParsed) {{
|
||||
if (nbCharParsed == -1) {{
|
||||
printf("Fail {elem_code} in {code}{rules_dict[left]}\\n");
|
||||
return 0;
|
||||
return -1;
|
||||
}}
|
||||
totalCharParsed += nbCharParsed;""")
|
||||
else:
|
||||
print(f" printf(\"Epsilon! -> Success\\n\");")
|
||||
print(f"""
|
||||
printf("Success {code}{rules_dict[left]}\\n");
|
||||
return totalCharParsed;
|
||||
|
@ -116,11 +119,11 @@ def print_global_rules():
|
|||
for i in range(1, value + 1):
|
||||
print(f"""
|
||||
nbCharParsed = parse_{code}{i}(word, pos);
|
||||
if (nbCharParsed) {{
|
||||
if (nbCharParsed != -1) {{
|
||||
return nbCharParsed;
|
||||
}}""")
|
||||
print("""
|
||||
return 0;
|
||||
return -1;
|
||||
}""")
|
||||
|
||||
|
||||
|
@ -131,12 +134,16 @@ def get_code(s):
|
|||
def print_terminal_rules():
|
||||
for t in terminals_set:
|
||||
code = get_code(t)
|
||||
l = len(t)
|
||||
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");
|
||||
return 1;
|
||||
return {l};
|
||||
}} else {{
|
||||
return 0;
|
||||
return -1;
|
||||
}}
|
||||
}}""")
|
||||
|
||||
|
|
Loading…
Reference in a new issue