diff options
| author | Shagun Agrawal <agrawalshagun07@gmail.com> | 2024-07-31 23:48:08 +0530 |
|---|---|---|
| committer | Shagun Agrawal <agrawalshagun07@gmail.com> | 2024-07-31 23:48:08 +0530 |
| commit | ec2e54a2977ff30e51eee15f464e52dc1e8390ab (patch) | |
| tree | 0900ae9186e73c175a25c845a729aedeb3434ad7 /src | |
| parent | 35eae1f6626f6a18ae352a8a6adb9da747969c57 (diff) | |
Add multiple statements to function
Diffstat (limited to 'src')
| -rw-r--r-- | src/cljcc/parser.clj | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/src/cljcc/parser.clj b/src/cljcc/parser.clj index 77482f1..d19ddd1 100644 --- a/src/cljcc/parser.clj +++ b/src/cljcc/parser.clj @@ -6,12 +6,15 @@ (insta/parser "whitespace = #'\\s+'")) +(declare parse) + (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 = constant | unop exp | <'('> exp <')'> + exp = exp-prime + <exp-prime> = constant | unop exp-prime | <'('> exp-prime <')'> unop = #'-' | #'~' identifier = #'[a-zA-Z_]\\w*\\b' constant = #'[0-9]+\\b' @@ -25,10 +28,22 @@ (c-parser source)) (comment + (parse "int main(void) {return 2;}") + (parse " + int main(void) { + return 2; + return 2; + }") + + (parse "int main(void) { + return -(((((10))))); + }") + (parse "int main(void) { -return -(((((10))))); -}") + return --2; + return -(((((10))))); + }") ,) |
