Implementing a language is a real test of programming skill. The code is complex and performance critical. You must master recursion, dynamic arrays, trees, graphs, and hash tables. - Robert Nystrom
This project is a simple interpreter that implements the basics of a limited C-like language. It uses Pratt-Parsing to be able to evaluate expressions using Top Down Operator Precedence instead of context free grammar or Backus Naur Form. This helps us form ast trees to evaluate the expressions with precedence efficiently.
- Basic Syntax Parsing: Handles a subset of C language syntax.
- Expression Evaluation: Supports arithmetic and logical expressions.
- Variable Management: Allows declaration and manipulation of variables.
- Control Structures: Implements basic control flow mechanisms like loops and conditionals.
- Python 3.x: Ensure you have Python installed on your system. You can download it from the official website.
-
Clone the Repository:
git clone https://github.com/CobaltIII/Interpreter-for-C.git
-
Navigate to the Project Directory:
cd Interpreter-for-C
-
Run the Interpreter:
To help with running, for now there is a sample code of Recursive Fibonacci given. Running it would show the output in the stdout of your python terminal.
- Adding a text editor to be able to write your own code in monkey instead of writing a python string
- Deploying on the internet
- interpreter.py: The main entry point for the interpreter.
- lexer.py: Handles lexical analysis, breaking down the input code into tokens.
- parser.py: Parses the tokens and generates the abstract syntax tree (AST).
- evaluator.py: Evaluates the expressions and executes the AST.
- object.py: Contains the various object types used by the interpreter, such as numbers, strings, and booleans.
- builtins.py: Implements built-in functions available in the interpreter.
- Crafting Interpreters - Robert Nystrom
- Writing an interpreter in Go -Thorsten Ball
- Simple but Powerful Pratt Parsing
- Writing compilers and interpreters - Ronald Mak