Giter Site home page Giter Site logo

pythonlike's Introduction

#this is a python like script language written in java using antlr4

build antlr parser/lexers:

java -jar libs/antlr4-4.8-1-complete.jar -visitor -no-listener PythonLike.g4 -o src/com/sainttheana/pythonlike/antlr4/

run test:

make run

example code:

def main(args):
    testMethod(args[0])
    testObject()
    testWhile()
    testForeach(args)
    testFor(args)

def testMethod(in):
    print(in)
    
def testObject():
    import org.json.JSONObject
    json=new JSONObject()
    json.put("hello","world")
    print(json.toString())

def print(in):
    import java.lang.System
    System.out.println(in)

def testWhile():
    i=0
    while(i<10):
        print(i)
        i++
    while(i<20):
        print(i)
        i+=1

def testForeach(args):
    for(arg:args):
        print(arg)

def testFor(args):
    argSize=arraySize(args)
    for(i=0;i<argSize;i+=1){
        print(args[i])
    }
    for(i=0;i<argSize;i++){
        print(args[i])
    }

def arraySize(array):
    import java.lang.reflect.Array
    return Array.getLength(array);

use of interpretor

ANTLRInputStream input = new ANTLRInputStream(new FileInputStream("test.py"));
PythonLikeLexer lexer = new PythonLikeLexer(input);
CommonTokenStream tokens = new CommonTokenStream(lexer);
PythonLikeParser parser = new PythonLikeParser(tokens);
ParseTree tree = parser.program();
Interpretor  y = new Interpretor();
y.visit(tree);
y.callFunction("main",((Object)k));

pythonlike's People

Contributors

saint-theana 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.