Code Monkey home page Code Monkey logo

expr's Introduction

Expr

Expr is a very simple integer expression calculator. Its grammar is as follows:

identifier := [A-Za-z_] [A-Za-z_0-9]*
variable := identifier
decimal_literal := [0-9]+
hex_literal := '0x' [0-9A-Fa-f]+
binary_literal := '0b' [0-1]+
octal_literal := '0o' [0-7]+
literal := decimal_literal | hex_literal | binary_literal | octal_literal
binary_op := '+' | '-' | '*' | '/' | '%' |
            '<<' | '>>' |
            '==' | '!=' | '<' | '>' | '<=' | '>=' |
            '&&' | '||' |
            '&' | '|' | '^'
unary_op := '!' | '~'
brackets := '(' atom ')'
unary := unary_op atom
function_call := itentifier brackets
atom := brackets | unary | literal | function_call
expr := atom ( binary_op atom )*

Very standard with two exceptions:

  1. There is no unary + or -.
  2. Function calls always take exactly 1 argument.

The only supported types are bool and u64. There is no type coersion.

All arithmetic operations are checked and cause an error on over/underflow. Shift overflows (e.g. 1 << 100) are allowed and result in 0.

Operator meaning and precedence is the same as in Rust, with the exception of ~ which is used for bitwise not (Rust uses ! for both logical and bitwise not).

expr's People

Contributors

timmmm avatar

Stargazers

Chris Heimpel avatar Márk Bartos avatar Doug Coleman avatar  avatar  avatar

Watchers

 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.