A research C# compiler

David R. Hanson, Todd A. Proebsting

Research output: Contribution to journalArticle

5 Scopus citations

Abstract

C# is the new flagship language in the Microsoft .NET platform. C# is an attractive vehicle for language design research not only because it shares many characteristics with Java, the current language of choice for such research, but also because it is likely to see wide use. Language research needs a large investment in infrastructure, even for relatively small studies. This paper describes a new C# compiler designed specifically to provide that infrastructure. The overall design is deceptively simple. The parser is generated automatically from a possibly ambiguous grammar, accepts C# source, perhaps with new features, and produces an abstract syntax tree, or AST. Subsequent phases - dubbed visitors - traverse the AST, perhaps modifying it, annotating it or emitting output, and pass it along to the next visitor. Visitors are specified entirely at compilation time and are loaded dynamically as needed. There is no fixed set of visitors, and visitors are completely unconstrained. Some visitors perform traditional compilation phases, but the more interesting ones do code analysis, emit non-traditional data such as XML, and display data structures for debugging. Indeed, most usage to date has been for tools, not for language design experiments. Such experiments use source-to-source transformations or extend existing visitors to handle new language features. These approaches are illustrated by adding a statement that switches on a type instead of a value, which can be implemented in a few hundred lines. The compiler also exemplifies the value of dynamic loading and of type reflection.

Original languageEnglish (US)
Pages (from-to)1211-1224
Number of pages14
JournalSoftware - Practice and Experience
Volume34
Issue number13
DOIs
StatePublished - Nov 10 2004
Externally publishedYes

Keywords

  • .NET
  • Abstract syntax trees;
  • C# programming language
  • Compiler architecture
  • Object-oriented programming
  • Visitor pattern

ASJC Scopus subject areas

  • Software

Fingerprint Dive into the research topics of 'A research C# compiler'. Together they form a unique fingerprint.

  • Cite this