-
Notifications
You must be signed in to change notification settings - Fork 7
Home
Welcome to Gold! This page is intended as an introduction to Gold, presenting examples about the different features of the language
Gold is Domain Specific Language (DSL) intended for the mathematical definition of graph structures like automata and Turing machines. To this purpose Gold offers a mathematical declarative syntax to be as close as possible as pencil-and-paper definitions
Sets can be defined in different ways according to the intended use and ergonomics. In general, sets can be defined using their explicit representation, as
Definition in Gold | Explanation | |
---|---|---|
Explicit |
{1, 2, 3, 4} {"A", "B", "C"}
|
Defines a set of four Number elements Defines a set of three String elements |
Range |
(1..4) ("A".."Z")
|
Defines a set of four Number elements (from 1 to 4) Defines a set of all capital String letters |
All structures used in Java can be re-used from Gold. That is, we are able to use arrays
, lists
, maps
, etc
In Gold, control structures are always defined as a block of instructions starting with the structure name and closing with an end
Conditionals are expressed as if-then-else structures. Conditionals have the same behavior and restrictions than conditionals in Java. In Gold the conditions are not required to be enclosed between parenthesis. The following code snippet shows an example of a conditional.
if var in Set1 then
Set = Set \ {var}
elseif var in Set2 then
Set = Set U {var}
else
Set2 = Set U {var}
end
Loop are expressed as for-loops declaring the loop variable and the range of the loop from the initial index to the final index, as shown in the following snippet
for i := 1 to 10 do
println("Counter: " + i)
end
This example will print the string message ten times, varying the value of i in the range 1 <= i <= 10
Functions are defined as "mathematical functions", that is they should have a result (return value).
Functions, and in general all structures, are the limited by the function start (with the word function
) and an end
.
As an example the function to calculate the maximum between two numbers would be as follows:
function max(x, y) : Int
if x > y then
return x
else
return y
end
end