-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
36 lines (28 loc) · 892 Bytes
/
Copy pathapp.py
File metadata and controls
36 lines (28 loc) · 892 Bytes
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
from flask import Flask, render_template, request
from lexer import tokenize
from parser import analyze as syntax_analyze
from semantic import analyze as semantic_analyze
app = Flask(__name__)
@app.route("/", methods=["GET", "POST"])
def home():
tokens = []
syntax_errors = []
semantic_errors = []
code = ""
if request.method == "POST":
code = request.form.get("code", "")
# 🔥 STEP 1: Tokenize
tokens = tokenize(code)
# 🔥 STEP 2: Syntax Analysis
syntax_errors = syntax_analyze(tokens)
# 🔥 STEP 3: Semantic Analysis (always run)
semantic_errors, _ = semantic_analyze(tokens)
return render_template(
"index.html",
tokens=tokens,
syntax_errors=syntax_errors,
semantic_errors=semantic_errors,
code=code
)
if __name__ == "__main__":
app.run(debug=True)