Giter VIP home page Giter VIP logo

comp's Introduction

COMP

The COMment Processor language written for https://github.com/langjam/jam0001

This language celebrates the multitude of comment syntaxes in programming languages and uses them to encode a simple stack-based interpreter.

Basic Usage

This project requires a recent version of node/npm to be installed (developed on 7.20.3), see https://nodejs.org/en/download/

  • To run tests issue the following command:

npm t

  • To run a script issue the following command, replacing the filename accordingly:

npx ts-node ./lib/comp.ts ./test/resources/singleLine/REM.COMP

  • To run the REPL issue the following command

npx ts-node ./lib/comp.ts

Press Ctrl+C to exit.

Example

REM 1 this is a comment that takes a single argument and put it on the stack
REM 2 arguments are always the first part of a comment
REM 3 the stack is now [1,2,3]
-- this comment takes no arguments and pops a value from the stack, which is now [1,2]
; this should roll so the stack is now [2,1]

# add this command executes a procedure so now the stack is [3]

REM 4
# mul should result in [12]

See test/resources/ for more examples.

Single Line Comments

Comment Origin Function Args
REM BASIC push value
-- Haskell pop -
# Perl call proc name
// C-style duplicate -
; Assembly roll -
% MATLAB swap -

Values

Currently only integers are supported as input although regular JavaScript numbers are used on the stack.

Procedures

When you issue a # comment you can follow that comment with add, sub, mul, or div to perform the given procedure on the top two values.

Future Plans

I didn't get to do everything I originally planned to do with project. Below are some improvements that could be made.

Support More Types

It would be nice to support something other than numbers. Ideally all basic JavaScript types could be supported.

Error Handling

There is none.

User Defined Procedures

I was originally planning on using multi-line comments (like /* */ or <!-- -->) to allow users to define their own procedures but I never got around to it.

Conditionals

Similar to the above I was planning on supporting basic conditionals with multi-line comments as well.

comp's People

Contributors

almibe avatar

Watchers

 avatar  avatar  avatar

comp's Issues

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.