Skip to content

sipi/Interpreter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Interpreter

Generic interpreter for java

Simple example

code:

import pi.interpreter.Environment;
import pi.interpreter.Interpreter;
import pi.interpreter.commands.Command;

public class Main {
	
	private static class MyCmd implements Command {

		private static final String LABEL = "mycmd";
		
		@Override
		public String getLabel() {
			return LABEL;
		}

		@Override
		public int exec(String[] args, Environment env) {
			env.out.println("Hello world !");
			return 0;
		}

		@Override
		public String manual() {
			return "This is a man page.";
		}

		@Override
		public String syntax() {
			return "This is command syntax description";
		}

		@Override
		public String shortDescription() {
			return "This is a short description of this command";
		}
		
	};
	
	public static void main(String[] args) {
		Interpreter ui = new Interpreter();
		ui.setBanner("    Hello world !\n" +
					 "=======================================");
		ui.addCmd(new MyCmd());
		ui.start();
	}
	
};

result:

   Hello world !
=======================================
> mycmd
Hello world !
> man mycmd
This is a man page
> help
Commands :
   alias       creates an alias
   cd          change current directory
   echo        print into the output
   env         display environment variables
   exit        exit the interpreter
   help        displays help
   let         set the value of an environment variable
   ls          display current directory
   man         open a command manual
   pwd         
   mycmd       This is a short description of this command
> 

About

Generic interpreter for java

Resources

Stars

Watchers

Forks

Packages

No packages published