A Pascal Interpreter written in Java. kPascal is intended to be used as either a command-line Java interpreter, or as an embedded Pascal engine inside J2EE applications.
<groupId>com.khubla.kpascal</groupId>
<artifactId>kpascal</artifactId>
<version>1.1.0</version>
<packaging>jar</packaging>
kPascal is distributed until the GPL v3. For more information please see the GPL.
kPascal uses Antlr. The Pascal grammar is here
Using a file:
FileInputStream fileInputStream = new FileInputStream("myprogram.pas");
Interpreter interpreter = new Interpreter();
interpreter.run(fileInputStream);
Using a string:
String myProgram = "program HelloWorld; begin writeln('hello'); end."
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(myProgram.getBytes());
Interpreter interpreter = new Interpreter();
interpreter.run(byteArrayInputStream);
kPascal uses System.in
and System.out
as the console by default. However, it is possible to provide your own input and output IO streams.
public void runPascalProgram(InputStream pascalInputStream, InputStream consoleIn, PrintStream consoleOut){
Interpreter interpreter = new Interpreter(consoleIn, consoleOut);
interpreter.run(programInputStream);
}
java -jar kpascal.jar --file=myprogram.pas