Git Product home page Git Product logo

mycompiler's Introduction

MyComplier

A new compiler that can compile natural languages. Support simple arithmetic options based on numbers and floats. A file with natural language will be compiled as assembly code (x86_64 with FPU) and calculate results.

1. Concrete Syntax

<expr>:
      | let <bindings> in <expr>
      | if <expr>: <expr> else: <expr>
      | <decls> in <expr>
      | <binop-expr>
<binop-expr>:
            | IDENTIFIER
            | NUMBER
            | FLOAT
            | true
            | false
            | !<binop-expr>
            | <prim1>(<expr>)
            | <expr> <prim2> <expr>
            | IDENTIFIER(<exprs>)
            | IDENTIFIER()
            | (<expr>)
<prim1>:
       | add1 | sub1
       | print | isbool | isnum | isfloat
       | cos | sqrt
<prim2>:
       | + | - | * | / | //
       | < | > | <= | >=
       | ==
       | && | ||
<decls>:
       | <decls> and <decl>
       | <decl>
<decl>:
      | def IDENTIFIER(<ids>): <expr>
      | def IDENTIFIER(): <expr>
<ids>:
     | IDENTIFIER
     | IDENTIFIER, <ids>
<exprs>:
       | <expr>
       | <expr>, <exprs>
<bindings>:
          | IDENTIFIER = <expr>
          | IDENTIFIER = <expr>, <bindings>

2. Usage

To install rustc, run

sudo apt-get install rustc

To run the code, run

cargo run

To compile a program and emit assembly code to stdout use

snake INPUT_FILE

To compile a program, link it and run the produced binary use

snake --run INPUT_FILE

To run the reference interpreter use

snake --interp INPUT_FILE

To see this usage message run

snake --help

3. Test

To test the examples in ./examples/, run

cargo test

To add new tests, add new mk_test! and mk_fail_test! in ./tests/examples.rs

4. Additional information

See in ./new_proposal.pdf

mycompiler's People

Contributors

xinyaoqiu avatar

Watchers

 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.