ANIL is a statically typed programming language, inspired by Python and C++, that can be embedded within C source files.
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.
Fig: The generated C code from the second __contains__
method in the first screenshot.
- C compiler.
- Python.
- clang-format(Recommended).
- Open preprocess_2.py.
- Uncomment one of the
source_file = "FILE_NAME*.c"
line. - Run
python preprocess_2.py
Alternatively, you can specify the filename directly by running:
python preprocess_2.py --filename examples\FILE_NAME*.c
- This will generate a FILE_NAME*_generated.c file. Compile the generated c file using a C compiler and execute the generated executable.
- 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 implementin
operator (e.gvalue 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.
-
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.
-
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:
- To learn about compiler development.
- To build a self-compiling compiler.
- To implement features I find interesting and cool.