1.2. Action language : An imperative syntax

[Warning]Text not verified for kermeta 2

Th action language of Kermeta is an imperative language for modeling, with a basic syntax inspired from Eiffel. Code is statically type checked, and execution is made by a compiler in its version 2.x. The previous version of Kermeta (up to 1.x) were executed thanks to an interpreter.

1.2.1.  First Program

Even if it is not very useful in our context, since it doesn't show the really interresting structures of the language, here is the traditional " Hello world " example you can find in every programming book.

Example 1.1. MainClass.kmt

package helloworld;

using kermeta::standard             // shorthand for standard types
using kermeta::io::StdIO => stdio   // shorthand to kermeta::io::StdIO

class HelloworldExample
{
    operation sayHello() is
    do
        stdio.writeln("Hello world, ...")
    end
}

Example 1.2. hello.kp

KermetaProject "hello"
	groupId = "my.group"
	defaultMainClass = "helloworld::HelloworldExample"
	defaultMainOperation = "sayHello"
	sources = {
		require "${project.baseUri}/src/main/kmt/MainClass.kmt"
	}
	dependencies = {
		//default dependency to kermeta framework (try first in eclipse plugin, then look into maven repository)
		dependency "library.core" ="platform:/plugin/org.kermeta.language.library.core",
		                           "mvn:org.kermeta.language/language.library.core/2.0.4"
	}

1.2.2. Classic features

Kermeta language includes usual statements like blocks and loops, comments, etc

do
    // a loop for getting a text from an user
    var s : kermeta::standard::String
    from var found : kermeta::standard::Boolean init false
    until found
    loop
        s := stdio.read("Enter a text:\n --> ")
        if s.size > 0 then
            found := true
        else
            stdio.writeln("ERROR - Empty text!")
        end
    end
    stdio.writeln("\n You entered: " + s)
end

1.2.3. Corresponding sections in the Reference chapter

All these "classic" imperative features and their syntaxes are described in Chapter 2, Reference . More precisely in