aboutsummaryrefslogtreecommitdiff
path: root/src/cljcc/cljcc.clj
blob: 1e102afd82dad16dd9f75589f88534001e546f35 (plain)
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
(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]
  (println (str "Hello, " (or (:name data) "World") "!")))

(defn -main
  "I don't do a whole lot ... yet."
  [& args]
  (let [input-file-path (first args)])
  (greet {:name (first args)}))