summaryrefslogtreecommitdiff
path: root/src/modules/parser/parser.scm
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules/parser/parser.scm')
-rw-r--r--src/modules/parser/parser.scm18
1 files changed, 8 insertions, 10 deletions
diff --git a/src/modules/parser/parser.scm b/src/modules/parser/parser.scm
index e70a825..ceac389 100644
--- a/src/modules/parser/parser.scm
+++ b/src/modules/parser/parser.scm
@@ -1,34 +1,32 @@
(define-module (modules parser parser)
#:use-module (ice-9 match)
+ #:use-module (modules ast syntax-tree)
#:export (p-program))
(define (die)
(error "syntax error"))
-
(define (p-program tokens)
(match tokens
((func ...)
- `(program ,(p-function func)))
+ (make-program (p-function func)))
(_ (die))))
(define (p-function tokens)
(match tokens
(('int (? string? id) 'left-paren 'void 'right-paren 'open-brace stmt ... 'close-brace)
- `(function (identifier ,id) ,(p-statement stmt)))
+ (make-function (make-id id) (p-stmt stmt)))
(_ (die))))
-(define (p-statement tokens)
+(define (p-stmt tokens)
(match tokens
(`(return ,expr semi-colon)
- `(return ,(p-exp (list expr))))
+ (make-stmt (p-expr (list expr))))
(_ (die))))
-(define (p-exp tokens)
- "Matches any list containing a single number,
-"
+(define (p-expr tokens)
(match tokens
- (((? number? const))
- `(constant ,const))
+ (((? number? int))
+ (make-expr int))
(_ (die))))