aboutsummaryrefslogtreecommitdiff
path: root/src/cljcc/analyzer.clj
diff options
context:
space:
mode:
authorShagun Agrawal <agrawalshagun07@gmail.com>2024-08-30 20:01:01 +0530
committerShagun Agrawal <agrawalshagun07@gmail.com>2024-08-30 20:01:01 +0530
commit552c41552c71c7bb3c0497d8b92c52688a14d22b (patch)
tree2838eea40aacc7831cf188303eca70dc3d742b7a /src/cljcc/analyzer.clj
parent276b0c200e5159b1d099ff85aab544480c2ac757 (diff)
Add parsing for conditional and if statements
Diffstat (limited to 'src/cljcc/analyzer.clj')
-rw-r--r--src/cljcc/analyzer.clj9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/cljcc/analyzer.clj b/src/cljcc/analyzer.clj
index 7d82f53..5970be4 100644
--- a/src/cljcc/analyzer.clj
+++ b/src/cljcc/analyzer.clj
@@ -27,6 +27,9 @@
(resolve-exp (:right e) mp)
(:binary-operator e))
:unary-exp (p/unary-exp-node (:unary-operator e) (resolve-exp (:value e) mp))
+ :conditional-exp (p/conditional-exp-node (resolve-exp (:left e) mp)
+ (resolve-exp (:middle e) mp)
+ (resolve-exp (:right e) mp))
(throw (ex-info "Analyzer error. Invalid expression type" {:exp e}))))
(defn- resolve-declaration [d mp]
@@ -46,6 +49,12 @@
(condp = (:statement-type s)
:return (p/return-statement-node (resolve-exp (:value s) mp))
:expression (p/expression-statement-node (resolve-exp (:value s) mp))
+ :if (if (:else-statement s)
+ (p/if-statement-node (resolve-exp (:condition s) mp)
+ (resolve-statement (:then-statement s) mp)
+ (resolve-statement (:else-statement s) mp))
+ (p/if-statement-node (resolve-exp (:condition s) mp)
+ (resolve-statement (:then-statement s) mp)))
:empty (p/empty-statement-node)
(throw (ex-info "Analyzer error. Invalid statement." {:statement s}))))