Skip to content
/ ANIL Public

ANIL(A Nice Intermediate Language) Python & C++ inspired programming language that transpiles to C and can be embedded within C source files.

Notifications You must be signed in to change notification settings

AnilBK/ANIL

Repository files navigation

A Nice Intermediate Language(ANIL)

ANIL is a statically typed programming language, inspired by Python and C++, that can be embedded within C source files.

ss1

Fig: ANIL functions written in C and ANIL respectively. The first function written in C is the general implementation for the __contains__ method whereas the second function written in ANIL is template specialization for String class.

ANIL generates appropriate C code, which is then compiled using a C compiler.

ss2

Fig: The generated C code from the second __contains__ method in the first screenshot.

Requirements:

  • C compiler.
  • Python.
  • clang-format(Recommended).

Usage

  1. Open preprocess_2.py.
  2. Uncomment one of the source_file = "FILE_NAME*.c" line.
  3. Run
python preprocess_2.py

Alternatively, you can specify the filename directly by running:

python preprocess_2.py --filename examples\FILE_NAME*.c
  1. This will generate a FILE_NAME*_generated.c file. Compile the generated c file using a C compiler and execute the generated executable.

Features:

  • Classes: Example 1 Example 2
  • Templates & Function Overloading: Example
  • Macros: Example
  • Compile-Time Reflection: Example 1
  • Annotations: Example 1 WebSever Example
  • Standard Library: See Lib/. Shows mixing of C code and ANIL.
  • Dunder methods:
    • __init__ : To implement constructors.
    • __del__ : To implement destructors.
    • __getitem__ : To get an item at a specified index (e.g. obj[index]).
    • __setitem__ : To set an item at a specified index (e.g. obj[index] = value).
    • __reassign__ : To implement reassignment (e.g. obj = value).
    • __add__ : To implement addition.
    • __contains__ : To implement in operator (e.g value in list).
    • len : To get total number of items. It is used along with __getitem__ to implement iterators.

The examples in examples/ and Lib/ folder shows all different features of ANIL. Right now, these examples serve as documentation for the language.

Project Structure

Directories

  • Bootstrap: Implementation of the compiler in ANIL itself. Files in this directory uses all (advanced) features available in the language.

  • examples: Demonstrations of various language features and usage of the standard library.

  • Lib: Standard Library.

Individual Files

  • preprocess_2.py: The actual compiler and code generator.

  • batch_compile.py: Compiles all the ANIL files one by one. Used to verify if the changes made to the compiler doesn't break existing functionality.


Note

This is my first ever compiler project.
I created this compiler for the following reasons:

  1. To learn about compiler development.
  2. To build a self-compiling compiler.
  3. To implement features I find interesting and cool.

About

ANIL(A Nice Intermediate Language) Python & C++ inspired programming language that transpiles to C and can be embedded within C source files.

Resources

Stars

Watchers

Forks

Releases

No releases published