aboutsummaryrefslogtreecommitdiff
path: root/src/cljcc/cljcc.clj
diff options
context:
space:
mode:
authorShagun Agrawal <agrawalshagun07@gmail.com>2024-07-21 00:11:14 +0530
committerShagun Agrawal <agrawalshagun07@gmail.com>2024-07-21 00:11:14 +0530
commit76041390b66ae1a7e903bfd40b3b176dc895b385 (patch)
treeb93755e0bb4890f71bc2ec9d85cbb8524015879d /src/cljcc/cljcc.clj
parente2cbed9a07bcee7ef4f5444a40fc49329323e24d (diff)
add parser for ch1
Diffstat (limited to 'src/cljcc/cljcc.clj')
-rw-r--r--src/cljcc/cljcc.clj23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/cljcc/cljcc.clj b/src/cljcc/cljcc.clj
index 6493b08..1e102af 100644
--- a/src/cljcc/cljcc.clj
+++ b/src/cljcc/cljcc.clj
@@ -1,6 +1,28 @@
(ns cljcc.cljcc
+ (:require
+ [instaparse.core :as insta]
+ [clojure.java.io :as io])
(:gen-class))
+(def ex-prg "int main(void) {return 2;}")
+
+(def whitespace
+ (insta/parser
+ "whitespace = #'\\s+'"))
+
+(def c-parser
+ (insta/parser
+ "<program> = function+
+ function = #'int\\b' identifier <'('> #'void\\b' <')'> <'{'> statement <'}'>
+ statement = #'return\\b' exp <';'>
+ exp = constant
+ identifier = #'[a-zA-Z_]\\w*\\b'
+ constant = #'[0-9]+\\b'
+ keyword = #'int\\b' | #'return\\b' | #'void\\b'"
+ :auto-whitespace whitespace))
+
+(println (c-parser ex-prg))
+
(defn greet
"Callable entry point to the application."
[data]
@@ -9,4 +31,5 @@
(defn -main
"I don't do a whole lot ... yet."
[& args]
+ (let [input-file-path (first args)])
(greet {:name (first args)}))