Set Lang
Set Lang
Types:
int – like in C
Literals:
dddd - integer value
Variable Definitions:
int <var> [, <var> … ] -- Define one or more int variables
str <var> [, <var> … ] -- Define one or more str variables
set <var> [, <var> … ] -- Define one or more set variables
collection <var> [, <var> … ] -- Define one or more collection variables
Operations:
+, - , *, / – for int, as in C
() – parenthesis, as in C
= – Assignment to variable
Conditions:
>, <, >=, <=, == -- for int: numeric compare; for string lexicographic compare
<set>
<collection> -- Empty ➔ False; otherwise ➔ True
! -- Not
Control
if (<condition>) <sentencet> | <blockt> Execute <sentencet> or <blockt> if
[else <sentencef> | <blockf>] <condition> is true. Otherwise, (optional)
execute <sentencef> or <blockf> instead
while (<condition) <sentence> | <block> Execute <sentence> or <block> repeatedly,
while <condition> is true.
for (<var> : <set> | <collection>) Iterator: execute <sentence> or <block> for
<sentence> | <block> each element in <set> or <collection>
Input/Output
input <prompt-value> <var>; Output the <prompt-value> and input reply into variable <var>.
If <var> is a <set> or <collection>, accept a comma-separated
list (if just hit “Enter” ➔ empty set/collection)
output "<string>" [<expression>]; Output <string> and then (optionaly) Evaluate and Output
<expression>
Example Program 1:
collection class, highGradeStudents, lowGradeStudents, avgGradeStudents;
set grades, gradesHigh;
int grd;
str student;
class = {"Rafi_Suisa", "Tamar_Even", "Avi_Maoz", "Eli_Kamer", "Shlomit_Raz",
"Haim_Mizrachi", "Moshe_Samocha", "Tali_Raban", "Sharon_Tal", "Gal_Elbaz"};
gradesHigh = [];
highGradeStudents = {};
for (student:class)
{
output "Grade for:" student;
input ">" grd;
grades = grades + grd;
if (grd >= 90])
{
gradesHigh = gradesHigh + grd;
highGradeStudents = highGradeStudents + student;
}
}
if (gradesHigh)
{
output "Number of top grades:" |gradesHigh|;
output "Top Grades are:" gradesHigh;
output "High Grade Students are:" highGradeStudents
}
output "Companies that sell hardware & software:" software & hardware;
collection highSW;
highSW = software & highTech;
if (highSW == software)
output "All software companies are high-tech companies:" highSW;
else
output "Not all software companies are high-tech companies:" highSW;
output "Companies that sell Hardware but not Gaming Software:" hardware – (software & gaming)
Program Run
Companies that sell hardware & software: {Microsoft, Apple, Google}
Not all software companies are high-tech companies: {Apple, Oracle, Microsoft, Amdocs, Google,
PayPal, OpenAI, Sap}
Now all software companies are high-tech companies: {Apple, Oracle, Microsoft, Playtika, Amdocs,
Google, PayPal, OpenAI, Sap}
Companies that do software or hardware: {PayPal, Google, Playtika, Nice, Apple, Oracle, Nucor,
Microsoft, Amdocs, Nvidia, Cummins, Sony, OpenAI, Sap}
Companies that sell Hardware but not Gaming Software: {Sony, Nucor, Nvidia, Cummins, Nice}