From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf1-x133.google.com (mail-lf1-x133.google.com [IPv6:2a00:1450:4864:20::133]) by sourceware.org (Postfix) with ESMTPS id DE787395C036 for ; Tue, 8 Dec 2020 23:49:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org DE787395C036 Received: by mail-lf1-x133.google.com with SMTP id b4so859273lfo.6 for ; Tue, 08 Dec 2020 15:49:47 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=hjcUHqIAS0gKbSN+OFLJvS19eyXDoCnYPSyocjvxUys=; b=m1o9e5vR8yK49Jl42B49JbTcVjJ263mdODuB/U4xQUH5O5QkWOZh98XGbzrMPzbdXG COPuCPtnHOo7Gj71rIqV4iPdkiaw6KpzUh/ofeSoLsqF+rFa2ytoh1CucIwVDrZmWjVa kqm0zPpeSOZmjQhs7HLuIVE6skX81dPcM2sfzVf7Russwiq6uNQ6fVpqXYc3fkOEs5o7 wL6ZCs0jo/lJgLalQo4WJNdwwQbMfEH7+daCG6IQGMBjYxdKORzzpfCC0OwOUI/lyg3U qExy6PB3v8TQIj0zlRn3rEVx3/IOw/oH1kAy5UvQ/dJOWXVfMooXShO+Lw9Qo0/JWzK1 4CKg== X-Gm-Message-State: AOAM530AIbpaRUv3Cysz0DiE+NsLw2GGZi1drfIq43LJhJEe38v8/L0e uIE18irmzzpaTX7zuoqSI+7dE8je8WFt6406fGXnI1FQ9xnn4A== X-Google-Smtp-Source: ABdhPJyrmlCGWMioNsQrgNloVokHiJGwEfvo7d6hEgGws8oZOpVAlZADg0Jq97EEh4UGtQMmQqGvU2xjfn/I1spHeMc= X-Received: by 2002:a19:c508:: with SMTP id w8mr24034lfe.658.1607471386204; Tue, 08 Dec 2020 15:49:46 -0800 (PST) MIME-Version: 1.0 From: Duncan Mak Date: Tue, 8 Dec 2020 18:49:08 -0500 Message-ID: Subject: Analyzing Scheme source code To: kawa mailing list X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, HTML_MESSAGE, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: kawa@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Kawa mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 08 Dec 2020 23:49:49 -0000 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.