Giter Site home page Giter Site logo

building-my-programming-language's Introduction

Yeep Programming Language

This is a simple programming language interpreter for basic arithmetic operations. The interpreter includes a lexer, parser, and abstract syntax tree (AST) nodes for performing arithmetic operations.

Getting Started

  1. Create a file called yeep.py.
  2. Copy the provided code into the file.
  3. Run the file with Python3 using the command python3 yeep.py.
  4. Type in an expression (e.g., 2 + 2) and press enter.
  5. The interpreter will print the result of the expression.

Tokens

  • TT_PLUS: Represents the plus operator '+'
  • TT_MINUS: Represents the minus operator '-'
  • TT_DIV: Represents the division operator '/'
  • TT_MUL: Represents the multiplication operator '*'
  • TT_LPAREN: Represents the left parenthesis '('
  • TT_RPAREN: Represents the right parenthesis ')'
  • TT_INT: Represents an integer number
  • TT_FLOAT: Represents a floating-point number
  • TT_EOF: Represents the end of the file

Classes

  • Tokens: Represents a token with a type and optional value
  • Lexer: Converts source code into tokens
  • NumberNode: Represents a number in the AST
  • BinOpNode: Represents a binary operation in the AST
  • UnaryOpNode: Represents a unary operation in the AST
  • VarAccessNode: Represents a variable access in the AST
  • Parser: Converts tokens into an AST
  • Error: Base class for different types of errors
  • IllegalCharError: Represents an error for encountering an illegal character
  • InvalidSyntaxError: Represents an error for encountering invalid syntax
  • ExpectedTokenError: Represents an error for expecting a specific token
  • Position: Represents the position of a character in the source code

Usage Example

# Example usage in the shell
import yeep

while True:
    text = input("yeep >> ")
    result = yeep.run("<stdin>", text)

    if isinstance(result, tuple):
        ast, error = result
        if error:
            print(error.as_string())
        else:
            print(ast)

building-my-programming-language's People

Contributors

syipmong avatar

Stargazers

 avatar

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.