Git Product home page Git Product logo

naereen / minipy-interpreter-in-ocaml Goto Github PK

View Code? Open in Web Editor NEW
2.0 3.0 0.0 1.33 MB

My local copy of files from https://github.com/LaurentMazare/LaurentMazare.github.io/tree/master/minipy, whose code is there https://github.com/LaurentMazare/ocaml-minipy

Home Page: https://perso.crans.org/besson/publis/MiniPy/editor.html

License: Apache License 2.0

Makefile 1.43% JavaScript 3.13% HTML 45.30% CSS 50.14%
minipython-interpreter ocaml js-of-ocaml ocaml-interpreter python-interpreter ace-editor bootstrap toplevel repl

minipy-interpreter-in-ocaml's Introduction

My local copy of OCaml MiniPy

A Naive (OCaml) interpreter for a (minimalist subset of a) Python like language.

Try the interpreter online or use the editor (these rely on js_of_ocaml).

This is a work in progress, most of the supported features are only partially implemented.


Screenshots

Here is an example of using the MiniPy OCaml console, to define a sum function. It shows that a lot of basic construct of the Python language are supported, but almost no functions from the standard library are available:

Screenshot showing the use of MiniPy OCaml console (console.html)

Here is a second example, using the MiniPy OCaml editor, loaded with one of the example files, showing a Eratosthene Sieve to detect prime numbers:

Screenshot showing the use of MiniPy OCaml editor (editor.html)

Here is a third and last example, using the MiniPy OCaml editor, loaded with one of the example files, showing the prime decompositions of integers. I added a few comments (# blabla) to show some features supported by MiniPy:

Screenshot showing the use of MiniPy OCaml editor (editor.html)


Details about this local copy

Where is it hosted on my website?

On my websites, it is as https://perso.crans.org/besson/publis/MiniPy/ and https://besson.link/publis/MiniPy/.

Where do the files come from?

License ?

Apache-2.0 License Copyright 2020 by LaurentMazare.


Documentation of supported features

See https://github.com/LaurentMazare/ocaml-minipy#supported-features

Supported Features

  • Python values:
    • Boolean.
    • Integer (represented with arbitrary precision!).
    • Float.
    • String.
    • List/Tuple.
  • Function definitions (with keyword arguments, ...), nested function definition.
  • Variable assignments with tuple/list destructuring and assignements to a list element.
  • Augmented assignments +=, -=, etc.
  • Control flow:
    • Loops: while and for loops, with support for break and continue.
    • If conditionals with elif and else.
  • Expressions:
    • Unary and binary operators, comparisons.
    • Ternary if operator.
    • Attributes, e.g. x.foo.
    • Subscripts, e.g. x[foo].
    • Lambdas, lambda.
    • List comprehensions (only for lists, no support for dict/set).
  • Built-ins print, range.
  • Dictionaries.
  • Delete operator, del.
  • REPL example, javascript version with js-of-ocaml.
  • Starred expressions.
  • Basic object system.
  • Exceptions, try/with blocks, raise.
  • with blocks.
  • (Class) Inheritance.

Not implemented yet

  • Sets.
  • Slices, e.g. x[12:15].
  • Generators, yield.
  • Module system, import.
  • Type annotations.
  • Bytecode compilation/interpreter.

minipy-interpreter-in-ocaml's People

Contributors

naereen avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  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.