Project Language

In the course project you will build a compiler and IDE for the ChocoPy language. Quoting from the ChocoPy website:

ChocoPy is a programming language designed for classroom use in undergraduate compilers courses. ChocoPy is a restricted subset of Python 3, which can easily be compiled to a target such as RISC-V. The language is fully specified using formal grammar, typing rules, and operational semantics. ChocoPy is used to teach CS 164 at UC Berkeley. ChocoPy has been designed by Rohan Padhye and Koushik Sen, with substantial contributions from Paul Hilfinger.

At a glance, ChocoPy is:

Familiar: ChocoPy programs can be executed directly in a Python (3.6+) interpreter. ChocoPy programs can also be edited using standard Python syntax highlighting.

Safe: ChocoPy uses Python 3.6 type annotations to enforce static type checking. The type system supports nominal subtyping.

Concise: A full compiler for ChocoPy be implemented in about 12 weeks by undergraduate students of computer science. This can be a hugely rewarding exercise for students.

Expressive: One can write non-trivial ChocoPy programs using lists, classes, and nested functions. Such language features also lead to interesting implications for compiler design.

Bonus: Due to static type safety and ahead-of-time compilation, most student implementations outperform the reference Python implementation on non-trivial benchmarks.

The ChocoPy Reference Manual

The ChocoPy reference manual is the authority on the definition of the syntax and semantics of ChocoPy. Start reading the document to understand the language design.

ChocoPy Example Programs

You can find examples of ChocoPy programs at https://github.com/cs164berkeley.

References

  • Proceedings of the 2019 ACM SIGPLAN Symposium on SPLASH-E 2019 [pdf, doi, bib, researchr, ]
    ChocoPy is a programming language designed for teaching an undergraduate course on programming languages and compilers. ChocoPy is a restricted subset of Python 3.6, using static type annotations to enforce compile-time type safety. ChocoPy is fully specified using formal grammar, typing rules, and operational semantics. Valid ChocoPy programs can be executed in a standard Python interpreter, producing results consistent with ChocoPy semantics. A major component of CS164 at UC Berkeley is the project: students develop a full compiler for ChocoPy, targeting RISC-V, in about twelve weeks. In other exercises, students extend the syntax, type system, and formal semantics to support additional features of Python. In this paper, we outline (1) the motivations for creating the ChocoPy project, (2) salient features of the language, (3) the resources provided to students to develop their compiler, (4) some insights gained from teaching two semesters of ChocoPy-based courses by different instructors. Our assignment resources are available for re-use by other instructors and institutions.
  • (editor).
    https://chocopy.org/ 2019 [bib, researchr]