GithubHelp home page GithubHelp logo

macthomasengineering / mteeval-b4x-library Goto Github PK

View Code? Open in Web Editor NEW
10.0 1.0 3.0 150 KB

B4X Expression Compiler and Eval Library

License: Other

Batchfile 0.18% Java 28.43% VBA 29.87% FreeBasic 41.52%
b4a java b4x compiler visual-basic android ios

mteeval-b4x-library's Introduction

MteEVAL - B4X Expression Compiler and Eval Library

MteEVAL is a library for compiling and evaluating expressions at runtime. Expressions are converted to bytecode and then executed on demand with a simple virtual machine.

There are four editions of the library: Android (B4A), iOS (B4i), Java (B4J), JavaS2 (B4A/B4J).

JavaS2 is our stage 2 performance edition of the library in native Java.

See Anywhere Software to learn more about B4A, B4i, and B4J cross-platform development tools.

Application

Creating expressions at runtime is a powerful tool allowing calculations and program flow to be modified after installation, which otherwise would require a physical update or a custom build of an application. For example, any application designed to manage a sales compensation plan could benefit from runtime expressions, where the end-user may want to customize the plan's formulas by team members, product mixes and sales goals.

Codeblocks

MteEVAL implements a single class named Codeblock. MteEVAL's codeblock adopts the syntax from the venerable 1990's xBase compiler Clipper 5 where the construct began. Codeblocks start with an open brace, followed by an optional parameter list between pipes, then the expression, and end with a closing brace.

{|<parameters>|<expression>}

Examples

You only need to compile a Codeblock once. Once compiled you can evaluate it as many times as needed, all while supplying different arguments.

Example 1: Codeblock without parameters

Dim cb as Codeblock
cb.Initialize
cb.Compile( "{||5 + 3}" )
Result = cb.Eval           'Result=8

Example 2: Codeblock with parameters

Dim cb as Codeblock
cb.Initialize
cb.Compile( "{|length,width|length*width}" )
Area = cb.Eval2( Array( 3, 17 ) )    'Area=51

When evaluating a Codeblock with parameters, use the Eval2 method.

Example 3: Codeblock compile, eval and repeat

Dim cb as Codeblock
cb.Initialize
cb.Compile( "{|sales,r1,r2| r1*sales + iif( sales > 100000, (sales-100000)*r2, 0 ) }" )
Commission1 = cb.Eval2( Array( 152000, .08, .05 ) )    'Commission1=14760
Commission2 = cb.Eval2( Array( 186100, .08, .07 ) )    'Commission2=20915
Commission3 = cb.Eval2( Array( 320000, .08, .05 ) )    'Commission3=36600

Operator support

The library supports C/Java style operators along side a growing list of B4X native functions.

  • Math operators: +-*/%
  • Relational: > < >= <= != ==
  • Logical: || && !
  • Bitwise: << >> & ^ |
  • Assignment: =
  • Functions: abs(), ceil(), floor(), iif(), if(), min(), max(), sqrt(), power(), round()
  • Trig Functions: acos(), acosd(), asin(), asind(), atan(), atand(), cos(), cosd(), sin(), sind(), tan(), tand()

Linking to your project

  • To use the Android or Java editions, add the .JAR and .XML files to your Additional Libraries folder and check the MteEVAL library in the Libraries Manager of the IDE.
  • For iOS, copy the modules Codeblock.bas, Codegen.bas, PCODE.bas, and Run.bas to your project folder or place them in the Shared Modules folder. Then add the modules to the project through the IDE.

mteeval-b4x-library's People

Contributors

macthomasengineering avatar waffle-iron avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

mteeval-b4x-library's Issues

Add support for trig functions

Add support for trig functions including ACos(), ACosD(), ASin(), ASinD(), ATan(), ATanD(), Cos(), CosD(), Sin(), SinD(), Tan(), TanD()

Add variable assignments

Add support for assigning value to variables passed as parameters.

For example:
cb As Codeblock
cb.Compile ("{|a,b,c| (a=5, b=a+c)}")
result = cb.Eval2( Array( 0, 0, 33) ) ' result = 38

Codeblocks cannot be nested.

Codeblocks share the same software CPU, stack, and var memory. Executing nested Codeblocks could yield unpredictable results.

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.