4

I seldom see static analyzer for functional programming languages, like Racket/Scheme, I even doubt that whether there are any. I would like to write a static analyzer for functional languages, say Scheme/Racket. How should I go about it?

3 Answers 3

6

Yes, there is some work on static analysis of dynamic languages like Scheme. For instance, see the work of Olin Shivers (http://www.ccs.neu.edu/home/shivers/citations.html) and Manuel Serrano (http://www-sop.inria.fr/members/Manuel.Serrano/index-1.html).

2
  • Are there some open source code to download for people to play with?I don't see Onlin Shiver nor the other guy post any for static analyzer stuff?
    – user618815
    Commented Mar 9, 2011 at 19:47
  • I'm sure there's a bunch of code floating around out there. The best pointer for running analysis is probably Matt Might, who just recently published a paper on accelerating 0CFA with GPUs. Commented Mar 10, 2011 at 18:00
6

There's already, e.g., typed racket: http://docs.racket-lang.org/ts-guide/index.html Since valid racket code is valid typed racket, you just have to change the language you're working in. Then, for libraries with typed versions, load those instead of the untyped versions, and certain type errors can get caught statically already. Further type annotations can be added to your own code to get guarantees of type correctness beyond that...

5

First read this paper by Shivers, explaining why there is no static control flow graph available in Scheme.

Might implemented k-CFA in Scheme. Matt Might's site and blog is a good starting point for exploring static analysis of higher-order languages.

I did some static analysis implementations for Scheme in Java as well:

1
  • From the abstract of the Shivers paper: "I present a technique for recovering the control-flow graph of a Scheme program at compile time. " Certainly the static control flow graph isn't obvious, but it does exist. Commented Nov 21, 2019 at 19:29