(define-module (modules parser parser) #:use-module (ice-9 match) #:export (p-program)) (define (die) (error "syntax error")) (define (p-program tokens) (match tokens ((func ...) `(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))) (_ (die)))) (define (p-statement tokens) (match tokens (`(return ,expr semi-colon) `(return ,(p-exp (list expr)))) (_ (die)))) (define (p-exp tokens) "Matches any list containing a single number, " (match tokens (((? number? const)) `(constant ,const)) (_ (die))))