Giter Club home page Giter Club logo

deci.vm's Introduction

deci.vm

deci.vm - simple proof-of-concept interpreter uses IEC61131-3 ST like-ish programming language as basis for its syntax.

Dependencies

  1. C++ compiler with C++11 support
  2. CMake 3.5
  3. GNU Bison 3.0.4
  4. Flex 2.6.4

Platform

Theoreticaly, code can be compiled and run on any platform, where one can build code using modern C++11 compiler, but Windows lacks decent Flex/GNU Bison version, so no luck there. I'll include a copy of generated code to use when no Flex/GNU Bison available in some future releases.

API

Library has several distinct parts:

  • classes implementing any/variant pattern:
    • value_t - basic abstract class;
    • nothing_t - singleton class implements NULL-class patter;
    • number_t - double precision IEEE 754 number;
    • string_t - byte string;
    • array_t - sequence container, elements stored contiguously;
    • reference_t - can reference to other objects and keeps count;
    • dictionary_t - unordered associative container;
    • function_t - abstract class implements execution capabilities;
  • classes implementing virtual machine (VM):
    • stack_t - implements VM execution context, which consists of defined variables and stack itself;
    • vm_t - simple wrapper, when called tries to execute function on top of its stack;
    • program_t - class implements user-defined interpretable code;
    • binop_t - template implements basic function of two arguments;
    • unrop_t - template implements basic function of single argument;
  • standard library of functions to use with user-defined code:
    • sum_t - A + B;
    • sub_t - A - B ;
    • mul_t - A * B;
    • div_t - A / B;
    • ls_t - A < B;
    • gr_t - A > B;
    • le_t - A <= B;
    • ge_t - A >= B;
    • eq_t - A == B;
    • neq_t - A != B;
    • or_t - A || B;
    • and_t - A && B;
    • xor_t - A ^ B;
    • pow_t - pow(A, B);
    • mod_t - A%B;
    • not_t - !A;
    • neg_t - -A;
    • print_t - print to stdout;
  • ST language compiler
    • deci_scanner_t - lexer class, body of get_next_token function generated by Flex from "iec61131.l";
    • parser_t - parser class, class declaration/definition generated by GNU BISON from "iec61131.y";
    • ast_item_t - interface class implementing single AST branch/leaf, method Generate writes compiled code for program_t to interpret;
    • ast_number_t - numeric constant leaf;
    • ast_identifier_t - some text nonterminal symbol in program;
    • ast_arg_list_t - list of arguments divied by comma;
    • ast_postfix_t - postfix operation (mainly function calls);
    • ast_binary_t - infix binary operation;
    • ast_unary_t - prefix unary operation;
    • ast_return_t - operation which dumps unassigned expression results;
    • ast_set_t - operation set new variable value;
    • ast_t - sequence of ast_item_t elements;
    • ast_if_t - if/else/end_if statement;
    • ast_for_t - for/end_for statement;
    • ast_while_t - while/end_while statement;
    • ast_repeat_t - repeat/end_repeat statement;

Test Code

  1. basic_test - small obsolete code to test deci::program_t assembler
  2. values_test - small unfinished code to test deci::value_t derived classes
  3. compile_test - simple REPL iterpreter, or non-interactive interpreter of program given in test arguments list.

Build

mkdir stage
cd stage
cmake ../
cmake --build ./

Run Interpreter

./stage/compile_test ./test/prog.st

Run REPL

./stage/compile_test

>> 123 + 321;
444

deci.vm's People

Contributors

masscry avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

hyatt-zhong

deci.vm's Issues

Keyword "Function"

Simple iec61131 execution block, which can be called from other places.

Function do not save inner context between calls.

Tags

Tags are used to implement bindings between automated object and ST code.

Keyword "Exit"

for, while, repeat blocks can be ended using Exit keyword

Comments

Single line comments: // comments
Multi-line comments: /* /, ( *)

"Case" statement

Selection statement.

case a of
1: do_foo;
2: do_bar;
esle:
do_foobar;
end_case;

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.