From 8e5f643f876ffce3e563ba9b46bffc6178ca4c69 Mon Sep 17 00:00:00 2001 From: Shagun Agrawal Date: Tue, 15 Oct 2024 23:48:26 +0530 Subject: Add parser and analyzer changes for fn declarations Function declaration resolution --- src/cljcc/parser.clj | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) (limited to 'src/cljcc/parser.clj') diff --git a/src/cljcc/parser.clj b/src/cljcc/parser.clj index 065a4eb..0541406 100644 --- a/src/cljcc/parser.clj +++ b/src/cljcc/parser.clj @@ -321,15 +321,6 @@ :parameters params :body body})) -(defn declaration-node - ([dtype identifier] {:type :declaration - :declaration-type dtype - :identifier identifier}) - ([dtype identifier v] {:type :declaration - :declaration-type dtype - :identifier identifier - :initial v})) - (defn- parse-param-list [tokens] (let [void? (= :kw-void (:kind (first tokens)))] (if void? @@ -347,6 +338,7 @@ [_ tokens] (expect :right-paren tokens) map-param-f (fn [p] {:parameter-name (:literal p) + :identifier (:literal p) :parameter-type (:kind p)}) params (map map-param-f (into [ident-token] (vec rest-params)))] [params tokens])))) @@ -373,7 +365,7 @@ (= kind :assignment) (let [[_ tokens] (expect :assignment tokens) [exp-node tokens] (parse-exp tokens) [_ tokens] (expect :semicolon tokens)] - [(declaration-node (:literal ident-token) exp-node) tokens]) + [(variable-declaration-node (:literal ident-token) exp-node) tokens]) :else (throw (ex-info "Parser error. Not able to parse variable declaration." {}))))) (defn- parse-declaration [tokens] @@ -421,11 +413,7 @@ return var0; ")) (pp/pprint (parse-from-src " - -int main(void) { -return !three(); -} - +int add(int x, int y); ")) (pp/pprint -- cgit v1.2.3