aboutsummaryrefslogtreecommitdiff
path: root/module/c/ast.scm
blob: bf5ad6302170a06027a0fab4cc8a04cc1192b839 (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
(define-module (c ast)
  :use-module ((c to-token) :select (preprocessing-token->token))
  :use-module ((c parse2)
               :select (build-lexical-analyzer
                        make-parser
                        error-procedure))
  :use-module ((hnh util) :select (->>))
  :use-module ((c flatten-begin)
               :select (flatten-begin
                        remove-invalid-struct-like-declarations))
  :export (build-ast))

(define (parse% lexical-analyzer)
  ((make-parser) lexical-analyzer error-procedure))

(define (build-ast cpp-tokens)
  (->> cpp-tokens
;;; 7. Whitespace tokens are discarded, each preprocessing token is converted into a token
       (map preprocessing-token->token)
;;; 8. All external objects and functions are resolved
       build-lexical-analyzer
       parse%
       flatten-begin
       remove-invalid-struct-like-declarations
       ))