Skip to content
Snippets Groups Projects
Verified Commit 737a50bc authored by Jamie Willis's avatar Jamie Willis Committed by Jamie Willis
Browse files

provided examples and support documentation for 2024-2025 WACC project

parents
No related branches found
No related tags found
No related merge requests found
Showing
with 283 additions and 0 deletions
File added
File added
# attempt to read into a boolean variable
# Output:
# #semantic_error#
# Exit:
# 200
# Program:
begin
bool b = true ;
read b ;
println b
end
# Attempting to access an array with an invalid complex expression
# Thanks to Ethan Range, Fawwaz Abdullah, Robbie Buxton, and Edward Hartley
# Output:
# #semantic_error#
# Exit:
# 200
# Program:
begin
int[] a = [1, 2];
int b = a[1 - "horse"];
int c = a[!false]
end
\ No newline at end of file
# Attempting to access an array with a non-integer index.
# Thanks to Ethan Range, Fawwaz Abdullah, Robbie Buxton, and Edward Hartley
# Output:
# #semantic_error#
# Exit:
# 200
# Program:
begin
int[] a = [1, 2];
int b = a["horse"]
end
# Indexing an array to get sub-arrays, but going too far.
# Thanks to Ethan Range, Fawwaz Abdullah, Robbie Buxton, and Edward Hartley
# Output:
# #semantic_error#
# Exit:
# 200
# Program:
begin
int[] a = [1, 2];
int[] b = [3, 4];
int[][] ab = [a, b];
int[] sameAsA = ab[0];
int oops = sameAsA[0][1]
end
\ No newline at end of file
# Too much indexing!
# Thanks to David Pan
# Output:
# #semantic_error#
# Exit:
# 200
# Program:
begin
int[] a = [1];
println a[1][2]
end
# Attempting to array-index an undefined identifier.
# Thanks to Ethan Range, Fawwaz Abdullah, Robbie Buxton, and Edward Hartley
# Output:
# #semantic_error#
# Exit:
# 200
# Program:
begin
char c = horse[2]
end
# Attempting to mix types in an array literal.
# Thanks to Ethan Range, Fawwaz Abdullah, Robbie Buxton, and Edward Hartley
# Output:
# #semantic_error#
# Exit:
# 200
# Program:
begin
char five() is
begin return '5' end
end
char f = call five();
int[] a = [1, f]
end
# Arrays should not be covariant
# Thanks to Nathaniel Burke
# Output:
# #semantic_error#
# Exit:
# 200
# Program:
begin
char[][] acs = [] ;
string[] bad = acs
end
# It shouldn't be possible to index strings (wrong side of the type relaxation)
# Output:
# #semantic_error#
# Exit:
# 200
# Program:
begin
string str = "hello world";
char x = str[0]
end
# Trying to assign the wrong array dimension to a variable, or non-matching pairs.
# Thanks to Ethan Range, Fawwaz Abdullah, Robbie Buxton, and Edward Hartley
# Output:
# #semantic_error#
# Exit:
# 200
# Program:
begin
int[] a = [1, 2];
int[][] aa = [a, a];
int[] b = aa
end
# Accessing too many array indices.
# Thanks to Ethan Range, Fawwaz Abdullah, Robbie Buxton, and Edward Hartley
# Output:
# #semantic_error#
# Exit:
# 200
# Program:
begin
int[] a = [1, 2];
int oops = a[1][2][3]
end
# Array was given wrong type.
# Thanks to Ethan Range, Fawwaz Abdullah, Robbie Buxton, and Edward Hartley
# Output:
# #semantic_error#
# Exit:
# 200
# Program:
begin
int[] should_be_int_array = ['a', 'b', 'c']
end
# tries to exit using a character
# Output:
# #semantic_error#
# Exit:
# 200
# Program:
begin
exit 'a'
end
# exit with non-int - this should be an invalid program!
# Output:
# #semantic_error#
# Exit:
# 200
# Program:
begin
char x = 'f' ;
exit x
end
# trying to return from the main program
# Output:
# #semantic_error#
# Exit:
# 200
# Program:
begin
return 42 ;
println "should not get here"
end
# Returning from the main body is forbidden.
# Thanks to Ethan Range, Fawwaz Abdullah, Robbie Buxton, and Edward Hartley
# Output:
# #semantic_error#
# Exit:
# 200
# Program:
begin
while true do
return 3
done;
if true then
return 4
else
return 5
fi;
begin
return 6
end
end
# expresission type mismatch int->bool
# Output:
# #semantic_error#
# Exit:
# 200
# Program:
begin
bool b = 1 || 1
end
# expresission type mismatch bool->int
# Output:
# #semantic_error#
# Exit:
# 200
# Program:
begin
int b = 15 + 6 || 19
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment