Case Study

JC-Plus Programming Language

A custom programming language compiler written in Java that adds class-based inheritance, subtyping, and bounds-checked arrays to the C programming language.

javaccompiler-designprogramming-languages

App in Action

JC-Plus compiler pipeline
JC-Plus compiler pipeline
JC-Plus language design
JC-Plus language design
JC-Plus security buffer overflow prevention
JC-Plus security buffer overflow prevention

Project Details

Duration
4 Months
Role
Compiler Engineering
Platform
JVM / Command Line
Technology
Java, C, Compiler Design

Problem / Approach / Result

The Problem

C lacks modern safety and object-oriented features

C is a powerful low-level language, but it lacks modern features like object-oriented programming, type-safe inheritance, and automatic bounds checking for arrays -- the latter being a well-known source of security vulnerabilities. Developers need these higher-level constructs without sacrificing C's performance and portability.

  • C has no native support for classes, inheritance, or polymorphism
  • Unchecked array access is one of C's most dangerous security vulnerabilities
  • No subtyping system means no type-safe code reuse across related types
  • Bridging high-level OOP concepts with low-level C requires a compilation strategy
The Approach

Design a new language with a multi-stage compiler targeting C

JC+ was designed to bring higher-level programming constructs to a C-like language while compiling down to standard C. The compiler follows a traditional multi-stage pipeline -- lexer, parser, typechecker, and code generator -- each implemented as a distinct Java module.

  • Defined class-based inheritance with instance variables, constructors, and methods
  • Implemented a full subtyping system for polymorphic behavior and type-safe reuse
  • Added runtime bounds-checked arrays to prevent buffer overflow vulnerabilities
  • Built a four-stage compiler pipeline -- Lexer, Parser, Typechecker, Code Generator
  • Targeted C as the output language to leverage existing C toolchains and portability
The Result

A working compiler that bridges OOP and systems programming

A complete, functional compiler that translates JC+ source code into valid C programs. The language combines the expressiveness of object-oriented languages with C's performance, proving that high-level features can compile down cleanly to procedural constructs.

  • Working compiler with 106 commits across the development cycle
  • Class-based inheritance with Java-style extends keyword
  • Full subtyping allowing subclass instances wherever a superclass is expected
  • Runtime bounds checking eliminates C's most common security vulnerability class
  • Complete control flow support including if/else, while loops, and break statements

Key Features

Class-Based Inheritance

Define classes with instance variables, constructors, and methods that extend other classes using Java-style inheritance.

Subtyping System

Full subtyping allowing subclass instances wherever a superclass is expected, enabling polymorphic behavior.

Bounds-Checked Arrays

Runtime bounds checking prevents out-of-bounds reads and writes -- addressing C's most dangerous security vulnerability.

Multi-Stage Compiler

Traditional pipeline with lexer, parser, typechecker, and code generator -- each as a distinct module.

Built-In Types & Expressions

Integer types, void, array types, arithmetic and comparison operators, method calls, and object instantiation.

Control Flow

Full support for if/else conditionals, while loops with break statements, return statements, and block-scoped grouping.

Architecture

HIGH-LEVEL ARCHITECTURESOURCE CODEJC+ Program (.jc)Class DefinitionsLEXERTokenizerToken StreamPARSERRecursive DescentAST ConstructionTYPECHECKERSubtype ValidationInheritance RulesCODE GENERATORC TranslationBounds ChecksC OUTPUTCompiled C programs via standard toolchains
Source Code

JC+ source files containing class definitions with inheritance, methods, and bounds-checked arrays.

Lexer

Custom tokenizer breaks JC+ source into typed tokens including keywords, identifiers, operators, and literals.

Parser

Recursive descent parser builds an Abstract Syntax Tree from the token stream, enforcing grammar rules.

Typechecker

Type system validates subtyping relationships, method signatures, and inheritance hierarchies for correctness.

Code Generator

Translates the typed AST into valid C code, injecting runtime bounds checks for array access safety.

Key Metrics

106
Commits
Across the development cycle
4
Compiler Stages
Lexer, Parser, Types, CodeGen
OOP
Paradigm
Class-based inheritance
Safe
Arrays
Runtime bounds checking

Tech Stack

Implementation
Java

Compiler implementation language for all pipeline stages

Target
C

Output language for compiled JC+ programs

Lexer
Custom Tokenizer

Tokenizes JC+ source into typed token streams

Parser
Recursive Descent

AST construction from token streams

Type System
Type Theory

Subtyping rules and type inference implementation