Giter Site home page Giter Site logo

programming_language_compiler_design's Introduction

Programming Language Compiler Design

This project takes insipiration from Python, Haskell, and MATLAB to create an interpreter for a toy programming language. The language supports most basic modern programming language features including functions, loops, conditional statements, dynamic variable assignment, runtime library, and basic implementations of recursion and some backtracking.

Prerequisites

Before running the file, make sure to have SymPy installed and Python in order to run the sample code successfully.

Testing Sample Code

The file run.py has the following flags defined in order to see the process or run the sample code file, labeled sample_code.ma:

  1. --file is to use a user defined file (optional)
  2. --lexer is to view lexer streams as the lexing process is running
  3. --run is to run the parser and evaluate the sample code if a file is not provided.

Files

Lexer

The lexer is defined in Lexer.py and holds definitions of reserved tokens and keywords using regular expressions. It uses the lex module in the PLY library.

Parser

The parser is defined in Parser.py and holds syntax definition using the Backus-Naur form (BNF) that will be evaluated by the yacc module in the PLY library. Each definition in the parser is used together with class defined nodes that will build the abstract syntax tree (AST) while syntax parsing.

Math Functions

The library of math functions is defined in math_functions.py and holds definitions for the built-in math functions.

Abstract Syntax Tree

The AST class is defined in AST.py and has two main sections: code interpretation and processing and AST nodes. The former is implemented based on the class name of each node and recursively does a postorder traversal to visit each node until the tree is evaluated.

Current Features

Supported Features

  1. Functions (simple implementations of functions)
  2. Lists with indexing and slicing similar to Numpy
  3. Dynamically typed variables
  4. For and While Loops
  5. Conditional statements including if and else statements and switch case statements
  6. Built-in functions
    1. Mathematical functions: integration, differentiation, trigonometric functions, Maximum and Minimum (accepts any data type)

For a more descriptive syntax and guideline on how the language is structured see the sample code.

programming_language_compiler_design's People

Contributors

susanto-tm avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

uamhforever

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.