aspect26 / trufflepascal Goto Github PK
View Code? Open in Web Editor NEWYear project - Pascal interpreter written in Java using Truffle API
Year project - Pascal interpreter written in Java using Truffle API
Since the class contains no actual JUnit tests, it shall be marked with @Ignore.
Readln and Writeln buitin subroutines are a TP extension. They are not supported by wirth's standard
When the two parsers and grammar files (for Wirth and TP) are separated, move reference passing to TP only
Rename numericLiteral to integerLiteral in pascal.atg
Implement Graph unit:
Implement work with files.
Implement Dos unit:
move primitive descriptors to its own file
the same with builtin procedure descriptors (even enums maybe)
Implement goto statement and labels.
The simpleMultipleRead test suggests that only new-line character is a separator for multiple arguments in the readln()
procedure. However, the code readln(i, j);
for two integers shall read two numbers on both inputs: 42 24
and 42\n24
.
Implement string unit:
Implement Pascal sets and set operations.
Implement passing subroutine arguments by reference.
from wirth's standard:
program = program-heading ';' program-block '.'.
program-block = block.
program-heading = 'program' identifier [ '(' program-parameter-list ')' ] .
program-parameter-list = identifier-list.
EDIT:
this includes binding of file names/paths to file type variables, example:
program copy (f, g);
var f, g : file of char;
c: char;
begin
reset(f) ; rewrite(g);
while not eof(f) do begin
read(f, c); write(g, c);
end;
end.
execution:
trupple copy.pas alpha.txt bravo.txt
Wirth's pascal:
Where a commentary shall be any sequence of characters and separations of lines, containing neither } nor *), the construct
( '{' | '(' ) commentary ( ')' | '}' )
shall be a comment if neither the { nor the (* occurs within a character-string or within a commentary.
NOTES
1 A comment may thus commence with { and end with ), or commence with ( and end with }.
2 The sequence (*) cannot occur in a commentary even though the sequence {) can.
Turbo Pascal:
comment beginnig with { must end with } and comment beginnig with (* must end with *).
Implement type checking during compilation time:
Implement pointers
It is not possible to define a custom type which is a subrange
There is currently a problem with negative array idnexing.
@Test
public void stringDoubleQuotesTwoTimes() {
test("program quoting; begin writeln('''', '''') end.", "''");
}
The test program prints '', ''
instead of ''
.
Create two separate parsers: one for wirth's pascal and the second one for turbo pascal
Implement Type statements.
LocalIdentifiersTable of subroutines doesn't contain types defined in the parent lexical scope
TP has extended constants
Implement >< operator for sets for TP extension
Currently, the unit tests expects CR-LF line endings for input. The standard does not explicitly state that there is only one kind of line ending. It would be nice if all CR, LF and CR+LF would be supported (as in FreePascal).
The generated build/Trupple.jar
shall be a standalone JAR, i.e. there ought to be packaged all the cz.cuni.mff.d3s.trupple
classes. On the other hand, the JUnit related JARs are not really necessary there.
Character sequence '' in string shall represent ' character in string.
block = label-declaration-part constant-definition-part type-definition-part
variable-declaration-part procedure-and-function-declaration-part
statement-part.
label-declaration-part = [ 'label' label { ',' label } ' ;' ].
constant-definition-part = [ 'const' constant-definition ' ;' { constant-definition ';' } ].
type-definition-part = [ 'type' type-definition ' ;' { type-definition ';' } ].
variable-declaration-part = [ 'var' variable-declaration ' ;' { variable-declaration ';' } ].
procedure-and-function-declaration-part = { ( procedure-declaration
| function-declaration ) ';' }.
It would be nice if the project would follow a more standardized source code organization.
The src
should be split into src
and src-test
: that would simplify compilation of Trupple with and without tests (alternative naming is src/java
and src/test-java
, or src/main
and src/test
). And the lib
folder can be a top-level one.
Classpath is missing in the <junit>
task:
diff --git a/build.xml b/build.xml
index 3be40df..e265e95 100644
--- a/build.xml
+++ b/build.xml
@@ -67,6 +67,7 @@
<fileset dir="${lib.dir}">
<include name="**/*.jar"/>
</fileset>
+ <pathelement location="${build.dir}"/>
</classpath>
<batchtest todir="${reports.dir}">
Implement crt unit:
File handling procedures (Pre-requisite: #4 ):
Dynamic allocation procedures (Pre-requisite: #5 ):
Arithmetic functions (Pre-requisite: none ):
Transfer functions (Pre-requisite: none ):
Ordinal functions (Pre-requisite: none ):
Boolean functions (Pre-requisite: #4 ):
expression is not a statement duh...
program main;
begin
5;
end.
is not supported in wirth's pascal nor turbo pascal
The simplest program in standard Pascal is not runnable:
program Hello;
begin
writeln('Hello, World!');
end.
$ java -cp build/:Trupple.jar cz.cuni.mff.d3s.trupple.compiler.CompilerMain Hello.pas
-- line 1 col 1: invalid Pascal
Errors while parsing source file, the code cannot be interpreted...
The current unit tests force the developer to inherit from JUnitTest
and then uses an overloaded method to actually execute the test.
Following snippet builds the test a bit more slowly but it clearly states what are the individual strings (note that newlines are added automatically to individual arguments of the setSource
to decrease occurrences of the escape sequences). The first test uses fluent interface to make the code more compact.
@Test
public void copy() {
TruppleTest
.create()
.setSource(
"program copy;",
"var i : integer;",
"begin readln(i); writeln(i); end."
)
.setInput("42");
.expectsOutput("42");
.run();
}
@Test
public void simpleUnit() {
TruppleTest test = new TruppleTest();
test.addImport(
"UNIT math;",
"",
"INTERFACE",
"",
"function add(a,b:integer): integer;",
/* etc. */
);
test.setStandard("tp6");
test.setSource(
"uses math;",
"begin",
" write(add(3,5));",
"end."
);
test.expectsOutput("8");
test.run();
}
The compiler shall support flag which specifies the Pascal standard that will be used during the interpretation (e.g.: --std=turbo)
NOTE: break is not supported by original standard
from standard:
The required constant-identifiers shall be as specified in 6.4.2.2 and 6.7.2.2.
http://www.pascal-central.com/iso7185.html#6.4.2.2 Required simple-types
http://www.pascal-central.com/iso7185.html#6.7.2.2 Arithmetic operators
Fix bugs in custom units:
subrange-type = constant '..' constant.
Examples:
1..100
-10..+10
red..green
'0'..'9'
donst forget to upgrade tests for Sets
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.