aboutsummaryrefslogtreecommitdiff
path: root/src/cljcc/parser.clj
diff options
context:
space:
mode:
authorShagun Agrawal <agrawalshagun07@gmail.com>2024-08-03 02:45:43 +0530
committerShagun Agrawal <agrawalshagun07@gmail.com>2024-08-03 02:45:43 +0530
commite0de6ddf16a37435966e31a73b4425a0300dc1e6 (patch)
treee99d8a9eeec4ae923e3c86e0ec436a542fcabe82 /src/cljcc/parser.clj
parentec2e54a2977ff30e51eee15f464e52dc1e8390ab (diff)
Add tacky IR stage
Add Tacky IR stage General formatting etc
Diffstat (limited to 'src/cljcc/parser.clj')
-rw-r--r--src/cljcc/parser.clj19
1 files changed, 8 insertions, 11 deletions
diff --git a/src/cljcc/parser.clj b/src/cljcc/parser.clj
index d19ddd1..8852d91 100644
--- a/src/cljcc/parser.clj
+++ b/src/cljcc/parser.clj
@@ -11,10 +11,11 @@
(def c-parser
(insta/parser
"<program> = function+
- function = #'int\\b' identifier <'('> #'void\\b' <')'> <'{'> statement+ <'}'>
+ function = #'int\\b' identifier <'('> #'void\\b' <')'> <'{'> statement <'}'>
statement = #'return\\b' exp <';'>
exp = exp-prime
- <exp-prime> = constant | unop exp-prime | <'('> exp-prime <')'>
+ <exp-prime> = constant | unop-exp | <'('> exp-prime <')'>
+ unop-exp = unop exp
unop = #'-' | #'~'
identifier = #'[a-zA-Z_]\\w*\\b'
constant = #'[0-9]+\\b'
@@ -29,21 +30,17 @@
(comment
- (parse "int main(void) {return 2;}")
+ (parse "int main(void) {return 2;}")
- (parse "
+ (parse "
int main(void) {
return 2;
- return 2;
}")
- (parse "int main(void) {
+ (parse "int main(void) {
return -(((((10)))));
}")
- (parse "int main(void) {
- return --2;
+ (parse "int main(void) {
return -(((((10)))));
- }")
-
- ,)
+ }"))