public inbox for kawa@sourceware.org
 help / color / mirror / Atom feed
* Analyzing Scheme source code
@ 2020-12-08 23:49 Duncan Mak
  2020-12-09  2:32 ` Duncan Mak
  0 siblings, 1 reply; 4+ messages in thread
From: Duncan Mak @ 2020-12-08 23:49 UTC (permalink / raw)
  To: kawa mailing list

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]
     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.
https://www.gnu.org/software/kawa/internals/semantic-analysis.html

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 gnu.kawa.io InPort)
        (class gnu.text Lexer)
        (class kawa.lang Translator))

(define (process-file filename)
  (let ((lang (Language:getDefaultLanguage))
        (lexer (language:getLexer (InPort:openFile filename)
(SourceMessages))))
    (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?


-- 
Duncan.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-12-09  3:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-08 23:49 Analyzing Scheme source code Duncan Mak
2020-12-09  2:32 ` Duncan Mak
2020-12-09  3:00   ` Duncan Mak
2020-12-09  3:19   ` Per Bothner

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).