-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
67 lines (55 loc) · 1.7 KB
/
Copy pathmain.py
File metadata and controls
67 lines (55 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from parser import parser, had_error as parser_had_error
import parser
def verify(code):
print("\n--- Verifying Syntax ---")
parser.had_error = False
parser.parser.parse(code)
if parser.had_error:
print("Syntax errors found.")
else:
print("Syntax is valid! No errors detected.")
def code_input():
print("\nEnter your JavaScript code below.")
print("Type 'exit' on a new line to verify.\n")
code = ""
while True:
line = input("js> ")
if line.strip().lower() == "exit":
break
code += line + "\n"
return code
def main():
while True:
print("JavaScript Syntax Verifier (PLY)")
print("1. Variable declaration/instantiation")
print("2. Iterative constructs (for/while)")
print("3. Selective constructs (if/else)")
print("4. Function declaration")
print("5. Array declaration")
print("6. Combination of all the above constructs")
print("7. Exit")
choice = input("\nEnter your choice: ")
if choice == "1":
code = code_input()
verify(code)
elif choice == "2":
code = code_input()
verify(code)
elif choice == "3":
code = code_input()
verify(code)
elif choice == "4":
code = code_input()
verify(code)
elif choice == "5":
code = code_input()
verify(code)
elif choice == "6":
code = code_input()
verify(code)
elif choice == "7":
break
else:
print("Invalid choice. Please enter a number between 1 and 7.\n")
if __name__ == "__main__":
main()