Peter Valchev's CPSC510 Compiler Project

University of Calgary, Winter 2006, course website
Instructor: Robin Cockett ICT652

Welcome, this is my compiler project webpage.


I have decided to work on a subset of the C programming language, targetting the SPARC architecture (version 8). An example of such a subset is Small-C. However it is a bit too "stripped", lacking support for structs for example. My plan is to look at it and implement some subset of C (with smallc as a possible reference), adding support for features as time permits. In fact I started with the complete ANSI C grammar and that was a mistake, but the front-end supports much of ANSI C. The backend supports more limited things even though once again the IR is actually complete, the actual assembly generation is not finished. Through some quick hacks it is now able to compile 'hello world' and other small programs into SPARC assembly.

I used OpenBSD as my development platform running on a SPARCStation 20 to actually test things when it came to the assembly. The GNU Assembler is used to produce binaries. will probably be used.

Required things:

  • Formal description of language grammar
  • Semantic checks: arrays, switch() must have an integer as argument (detect string as invalid); check that variables/functions are declared before use and error out
  • Backend: the syntax tree is converted into an IR and unrolled so there are no embedded statements, basically near three address code to facilitate easy assembly generation. No register allocation is done unfortunately but some assembly ad-hoc code generation is in very beginning stages (basically I ran out of time but made a few small programs work).
  • Test programs used
  • Presentations: Final, m3, m2


  • Final presentation coming up (will be here)
  • Test files (more than 15 of them) are here
  • Milestone 3 (HTML)
  • Presentation coming up (HTML, magicpoint file)...
  • Still trying to resolve bugs into my AST/parser, but it is built with semantic analysis in mind, just not complete.
  • Small test files: test1.c test2.c
  • Start this webpage. Reading books and various sources to get a good idea of the design.
  • Milestones/Schedule:

  • Jan 12-16: Establish what I'm going to do.
  • End of January: Syntax description, begin work on scanner/parser
  • End of February: scanning/parsing hopefully sorted out
  • Feb 27-March 2: An initial report - semantic analyzer being worked on (now "front end" hopefully close to done)
  • March 21-24: Halfway report - front end done, explain IR code generation (hopefully and work on the back end
  • April 18-20: Final report - code generation done (maybe some optimizations); Present final project, explain state of things.

    References/Links that will be useful:


  • flex - fast lexical analyzer generator
  • yacc - an LALR(1) parser generator

    SPARC documentation:

  • The SPARC Architecture Manual Version 8
  • SPARC Architecture, Assembly Language Programming, and C / Richard P. Paul, 2nd ed. ISBN 0-13-025596-3

    Other documentation:

  • ANSI C Yacc grammar
  • ANSI C grammar, Lex specification
  • NMI, the most featured smallc website
  • smallc description
  • SmallC for AVR

    Misc books:

  • Compiler Construction: Principles and Practice / Kenneth C. Louden. ISBN 0-534-93972-4
  • The Dragon Book
  • Modern Compiler Implementation, Andrew Appel

    Contact me: