public inbox for
 help / color / mirror / Atom feed
From: Duncan Mak <>
To: kawa mailing list <>
Subject: Analyzing Scheme source code
Date: Tue, 8 Dec 2020 18:49:08 -0500	[thread overview]
Message-ID: <> (raw)

Hello all,

I'm interested in running an analysis of some Scheme source code,
specifically, I'm looking to find what's defined in each file and what
references each file takes on.

I started writing my own analyzer with the match macro, and it looks
something like this:

(define (process-form form)
  (match form
    (['define [name @args] @body]
     (cons name (map process-form body)))
    (['define name value]
    (['let [[foo bar] ...] @body]
     (map process-form body))
    (['if test then else]
     (list (process-form test)
           (process-form then)
           (process-form else)))
    ([procedure @args]
     (cons procedure (map process-form args)))))

Thinking a bit more, rather than doing it myself, I thought maybe I could
reuse the existing machinery that's in Kawa already, i.e.

I think the trick is to get an instance of a Translator for a particular
file, and then call `rewrite` and possibly inspect the resulting Expression
(which ought to be an instance of a ModuleExp?)

(import (class gnu.expr Language NameLookup)
        (class InPort)
        (class gnu.text Lexer)
        (class kawa.lang Translator))

(define (process-file filename)
  (let ((lang (Language:getDefaultLanguage))
        (lexer (language:getLexer (InPort:openFile filename)
    (Translator lang lexer:messages  (NameLookup lang))))

What I have above seems to only result in an empty Translator.

What's the right way to set up the environment?


             reply	other threads:[~2020-12-08 23:49 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-08 23:49 Duncan Mak [this message]
2020-12-09  2:32 ` Duncan Mak
2020-12-09  3:00   ` Duncan Mak
2020-12-09  3:19   ` Per Bothner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='' \ \ \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).