Menu

FirstCompiler

Tom Harwood

First Example Compiler

The first compiler compiles a very simple expression-oriented language to MIPS assembly language. The resulting programs can be run by QtSpim.

Language Definition

  • Definitions
    int x = 4;
  • Assignments
    x = y;
  • print Pseudo-Statement
    print x;

The Compiler

The source code for this compiler is in JBurg distributions 1.20 and later; the paths shown here are relative to BaseJBurgDirectory/docs/tutorial. To build the tutorial, use Apache ant.

This compiler has only four components:

  • Driver (src/jburg/tutorial/first/Main.java)
    The driver invokes the front end parser and code generator.
  • Front End grammar (src/jburg/tutorial/first/first.g)
    The lexical analyzer and source code parser.
  • Code Generator grammar (src/jburg/tutorial/first/first.jbg)
    The instruction selector and code generator.
  • StringTemplate manager and template library (src/jburg/tutorial/common/TemplateManager.java and src/templates/MIPS.stg)
    MIPS/SPIM assembly language snippets are found in the .stg file; TemplateManager is a convenience wrapper over the StringTemplateGroup API.

| Compiler Overview | Front End | Code Generator | Templates |


Related

Wiki: FirstCodeGenerator
Wiki: FirstFrontEnd
Wiki: Tutorial
Wiki: TutorialCompilerTemplates

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.