Git Product home page Git Product logo

jvmbasic's Introduction

CI Codacy Badge

jvmBASIC

A BASIC to JVM bytecode compiler

jvmBASIC is a bytecode compiler which is capable of consuming a BASIC file (.bas) and producing a JVM .class file. The JVM class file exposes a public class named after the input file and a public method "program()" which contains the generated bytecode. The generated .class file also exposes a "void main()" method which enables the BASIC program to be run from the command line.

In order to use the generated .class file from Java code, the public class members "inputStream" and "outputStream" must be set, in order for the BASIC program to consume input and produce output.

Maven Coordinates

jvmBasicCC

<groupId>com.khubla.jvmbasic</groupId>
<artifactId>jvmbasicc</artifactId>
<version>2.4.0</version>
<packaging>jar</packaging>

jvmBasicRT

<groupId>com.khubla.jvmbasic</groupId>
<artifactId>jvmbasicrt</artifactId>
<version>2.4.0</version>
<packaging>jar</packaging>

License

jvmBASIC is distributed until the GPL v3. For more information please see the GPL.

Modules

The modules are:

  • jvmBasicc - The jvmBASIC compiler
  • jvmBasicrt - the jvmBASIC runtime library
  • jvmBasicwww - A simple web server that uses BASIC programs to generate HTML over HTTP
  • jvmBasicmojo - A maven mojo that compiles all .bas files found at /src/main/basic to .class files
  • examples - a simple directory of examples
  • demo - a simple .BAS program which can be compiled to produce a .jar and run to produce output

The Implementation

Notes on the implementation

  • The Parser and Lexer are created by ANTLR via an ANTLR grammar.
  • The generated bytecode is created by ObjectWeb ASM
  • Currently screen functions such as "CLEAR" are not implemented
  • Math functions and string functions are implemented in the jvmBasic runtime jar "jvmbasicrt.jar"
  • BASIC types are implemented by the class "Value" in jvmbasicrt.jar

Running an example

  • build jvmBASIC: mvn clean package install
  • use the script run_bas.sh to run an example:
sh run_bas.sh hellojvmBASIC.bas

The output should look very much like:

shrek:jvmBASIC tom$ sh run_bas.sh hellojvmBASIC.bas 
Running BASIC file hellojvmBASIC.bas
khubla.com jvmBASIC Compiler
Compiling: /Users/tom/projects/jvmBASIC/hellojvmBASIC.bas
added manifest
adding: hellojvmBASIC.class(in = 1402) (out= 740)(deflated 47%)
19:17:44.698 [main] INFO com.khubla.jvmbasic.jvmbasicrt.ExecutionContext - pushing String: '"hello from jvmBASIC"'
19:17:44.701 [main] INFO com.khubla.jvmbasic.jvmbasicrt.ExecutionContext - popping hello from jvmBASIC
hello from jvmBASIC
shrek:jvmBASIC tom$ 

Using jvmBASICC

jvmbasicc.jar is the jvmBASIC compiler. The only required parameter is -file, which is used to specify an input file. For example to compile "myprogram.bas" to bytecode:

java -jar jvmbasicc.jar -file myprogram.bas

This will produce "jvmbasicc.class"

Once jvmbasicc.class has been combined into a jar file, the file "jvmbasicrt.jar" must be on the class path order order to run the generated code.

Running java -jar jvmbasicc.jar will produce help output, which will show all the commandline options.

The generated bytecode

Inspecting the generated bytecode

To view the generated class at the command line, use javap. For example to view the generated output for "bottlesofbeer.bas" type

javap botttlesofbeer

to produce more verbose output from javap use

javap -c bottlesofbeer

The grammar

The ANTLR grammar is at

https://github.com/teverett/jvmBASIC/blob/master/jvmbasicc/src/main/antlr4/com/khubla/jvmbasic/jvmbasicc/antlr/jvmBasic.g4

There is an excellent ANTLR grammar editor here:

ANTLRWorks

Once you have created the grammar you need, recompile jvmBasicc:

mvn clean package

If you wish to use jvmBasicMojo, you will have to install the generated jvmBasic compiler:

mvn clean package install

Running the Examples

The examples are standard maven builds, and require the jvmBASIC maven mojo "jvmBasicmojo". In order for the examples to work propertly jvmbasicc.jar, jvmbasicrt.jar and jvmbasicmojo.jar must all have been compiled and installed. The easiest way to do this is to run this command from the root jvmBasic directory

mvn clean package install

To use the jvmBasic maven moojo from the command line:

mvn clean jvmbasic:jvmbasic jar:jar

This will build the BASIC files, and produce a jar that can be run from the command line. jvmbasicrt.jar must be on the command line.

jvmBASIC WWW

jvmBASIC WWW is a very simple web server that produces HTML output from BASIC files. To run it use a command line similar to this:

java -jar target/jvmbasicwww.jar -sourcedir www -classdir www/classfiles/ -port 8080

The basic files to compile are the directory specified by -sourcedir and the generated classes are in the directory specified by -classdir. The HTTP port to bind is specified by -port. The default page is served by INDEX.bas.

to run the example use:

sh run.sh and point your browser to http://localhost:8080/

jvmbasic's People

Contributors

dependabot[bot] avatar teverett avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jvmbasic's Issues

DepShield encountered errors while building your project

The project could not be analyzed because of build errors. Please review the error messages here. Another build will be scheduled when a change to a manifest file* occurs. If the build is successful this issue will be closed, otherwise the error message will be updated.

This is an automated GitHub Issue created by Sonatype DepShield. GitHub Apps, including DepShield, can be managed from the Developer settings of the repository administrators.

* Supported manifest files are: pom.xml, package.json, package-lock.json, npm-shrinkwrap.json, Cargo.lock, Cargo.toml, main.rs, lib.rs, build.gradle, build.gradle.kts, settings.gradle, settings.gradle.kts, gradle.properties, gradle-wrapper.properties, go.mod, go.sum

[DepShield] (CVSS 9.8) Vulnerability due to usage of ch.qos.logback:logback-classic:1.1.7

Vulnerabilities

DepShield reports that this application's usage of ch.qos.logback:logback-classic:1.1.7 results in the following vulnerability(s):


Occurrences

ch.qos.logback:logback-classic:1.1.7 is a transitive dependency introduced by the following direct dependency(s):

ch.qos.logback:logback-classic:1.1.7

ch.qos.logback:logback-classic:1.1.7

ch.qos.logback:logback-classic:1.1.7

com.khubla.jvmbasic:jvmbasicc:2.4.0-SNAPSHOT
        └─ ch.qos.logback:logback-classic:1.1.7

com.khubla.jvmbasic:jvmbasicrt:2.4.0-SNAPSHOT
        └─ ch.qos.logback:logback-classic:1.1.7

com.khubla.jvmbasic:jvmbasicrt:2.4.0-SNAPSHOT
        └─ ch.qos.logback:logback-classic:1.1.7

This is an automated GitHub Issue created by Sonatype DepShield. Details on managing GitHub Apps, including DepShield, are available for personal and organization accounts. Please submit questions or feedback about DepShield to the Sonatype DepShield Community.

[DepShield] (CVSS 9.8) Vulnerability due to usage of ch.qos.logback:logback-core:1.1.7

Vulnerabilities

DepShield reports that this application's usage of ch.qos.logback:logback-core:1.1.7 results in the following vulnerability(s):


Occurrences

ch.qos.logback:logback-core:1.1.7 is a transitive dependency introduced by the following direct dependency(s):

ch.qos.logback:logback-classic:1.1.7
        └─ ch.qos.logback:logback-core:1.1.7

ch.qos.logback:logback-classic:1.1.7
        └─ ch.qos.logback:logback-core:1.1.7

ch.qos.logback:logback-classic:1.1.7
        └─ ch.qos.logback:logback-core:1.1.7

com.khubla.jvmbasic:jvmbasicc:2.4.0-SNAPSHOT
        └─ ch.qos.logback:logback-classic:1.1.7
              └─ ch.qos.logback:logback-core:1.1.7

com.khubla.jvmbasic:jvmbasicrt:2.4.0-SNAPSHOT
        └─ ch.qos.logback:logback-classic:1.1.7
              └─ ch.qos.logback:logback-core:1.1.7

com.khubla.jvmbasic:jvmbasicrt:2.4.0-SNAPSHOT
        └─ ch.qos.logback:logback-classic:1.1.7
              └─ ch.qos.logback:logback-core:1.1.7

This is an automated GitHub Issue created by Sonatype DepShield. Details on managing GitHub Apps, including DepShield, are available for personal and organization accounts. Please submit questions or feedback about DepShield to the Sonatype DepShield Community.

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.