Commit 807531e8 authored by Mark Wheelhouse's avatar Mark Wheelhouse
Browse files

provided examples and support documentation for 2021 WACC project

parents
File added
This diff is collapsed.
# attempt to read into a boolan variable
# Output:
# #semantic_error#
# Exit:
# 200
# Program:
begin
bool b = true ;
read b ;
println b
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
# 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
# expresission type mismatch bool->int
# Output:
# #semantic_error#
# Exit:
# 200
# Program:
begin
int x = true + false
end
# evaluating less-than on references
# Output:
# #semantic_error#
# Exit:
# 200
# Program:
begin
pair(int,int) x = newpair(1,2) ;
println x;
pair(int,int) y = newpair(2,3) ;
println y;
println x < y
end
# expresission type mismatch bool->int
# Output:
# #semantic_error#
# Exit:
# 200
# Program:
begin
int b = 1 + 2 + true + 4 + 5
end
# program performs boolean operations on arrays
# Output:
# #semantic_error#
# Exit:
# 200
# Program:
begin
int[] x = [1,2];
int[] y = [3,4];
println x > y
end
# element access is not permitted for strings
# Output:
# #semantic_error#
# Exit:
# 200
# Program:
begin
string str = "hello world!" ;
println str ;
str[0] = 'H' ;
println str
end
# functions cannot access global variables
# Output:
# #semantic_error#
# Exit:
# 200
# Program:
begin
int f() is
x = -1 ;
return 0
end
int x = 5 ;
int y = call f() ;
println x
end
# tries to assign to a function
# Output:
# #semantic_error#
# Exit:
# 200
# Program:
begin
int f() is
return 3
end
f = 2
end
# function parameter misuse
# Output:
# #semantic_error#
# Exit:
# 200
# Program:
begin
int f(int x) is
bool b = x && true ;
return 0
end
int x = call f(0)
end
# function call type mismatch
# Output:
# #semantic_error#
# Exit:
# 200
# Program:
begin
int f() is
return 0
end
bool b = call f() ;
println b
end
# function parameter type mismatch
# Output:
# #semantic_error#
# Exit:
# 200
# Program:
begin
int f(int x) is
return x
end
bool b = true ;
int x = call f(b)
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment