Git Product home page Git Product logo

1y-language's Introduction

1lang Interpreter

简体中文版本

This project is a custom interpreter written in Go, implementing the Lexer, Parser, AST (Abstract Syntax Tree), and Evaluator.

The project is inspired by Thorsten Ball's book "Writing An Interpreter In Go". Building on the original implementation, new keywords and feature modifications have been added to meet the characteristics of modern programming languages.

Now Supported Features

  • Variable assignment and reference
  • Function definition and call
  • Arithmetic operations
  • Conditional statements
  • Loop statements [While]
  • Array operations
  • Importing external modules
  • Comments

Current Issues

  • Error reporting lacks line and column information

Future Work

  • Macro system

Example Usage

You can learn this new language using a simple example:

const filter = fn(arr, f) {
  let iter = fn(arr, acc) {
    if (len(arr) == 0) {
      acc;
    } else {
      let x = first(arr);
      let restArr = rest(arr);
      if (f(x)) {
        iter(restArr, push(acc, x));
      } else {
        iter(restArr, acc);
      }
    }
  };
  iter(arr, []);
};

const quick_sort = fn(arr) {
  if (len(arr) <= 1) {
    arr;
  } else {
    let pivot = first(arr);
    let restArr = rest(arr);
    let less = filter(restArr, fn(x) { x <= pivot });
    let greater = filter(restArr, fn(x) { x > pivot });
    concat(quick_sort(less), [pivot], quick_sort(greater));
  }
};

quick_sort([3, 6, 8, 10, 1, 2, 1]);

REPL and File Execution Support

To run the interpreter in REPL mode or to execute a file, use the following command:

go run main.go -f <file_path> -t

t is an optional parameter that enables the time measurement of the execution process.

This project aims to provide a learning platform for building interpreters and understanding the intricacies of programming language design. Contributions and feedback are welcome!

1y-language's People

Contributors

okysu avatar

Stargazers

Kenji Mouri (Qi Lu) avatar  avatar

Watchers

 avatar

1y-language's Issues

[Feature Request] Update to Type System

  • Floating point and integer types merged into a single numeric type
  • Support for using "." to quickly create floating point numbers
  • Support for scientific notation

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.