Lesson 2: Create and run an EGL program

In this lesson, you will learn how to create and run a simple EGL program.

  1. Click your EGL project to select it.
  2. Click File > New > EGL Source File. You will use the contents of this file to generate a working "Hello World" program. The New EGL Source File window opens, with the Source folder already set to Hello\EGLSource.
  3. Enter a package name such as hello. A package is both a folder and a unifying concept for a group of files that share resources. If you are only going to have one package in your project, there is no problem in using the same name for both.
  4. Enter an EGL source file name such as helloMain. EGL will add the file extension .egl for you, because all EGL source files end with that extension. Note also that EGL by convention uses "camel case" for file, function, variable, and other names. This style capitalizes each word in the name except the first, and omits the spaces between words, allowing you to use names that are long enough and complex enough to document their contents.
    New EGL Source File window filled in
  5. Click Finish.
  6. The workbench displays the new helloMain.egl file in the EGL editor. Note that it has already included the package name for you, in the line of code package hello;.
  7. Highlight the text that says //Put EGL Source File Contents Here and replace it with the following line of code, exactly as it is written here:
    program helloMain type BasicProgram

    Moving down the elemental structure of the EGL application, a program falls below a package, representing, in most cases, the solution to a single business problem. EGL has different types of programs, of which BasicProgram is the simplest.

    Note also that the name of your program must match the name of the EGL file, minus the .egl extension. If you named your file helloMain.egl, your program must be named helloMain. In most cases, EGL is not case sensitive, but for programs (and other major types of EGL part called generatable parts), the case of the program name must match the case of the file name.

  8. Leave a blank line, then on a new line (indented, if you want to follow common style), type this code:
      function main()
    A program consists of one or more functions, which are comparable to atoms—they are the fundamental building blocks of EGL logic. All function declarations are followed by parentheses, which in some cases hold data passed in or out of the function. Every program must have one and only one main() function.
  9. On another new line (indented again), type:
    writeStdOut("Hello, Cleveland!");
    Here the function performs its actual work. In this case, it is calling another function, one named writeStdOut(). This function exists in a library named sysLib, a system library of functions that you get free with EGL. You can call its functions from any other EGL function, and most of the time (you will learn about the rare exceptions later) you will not need to explicitly point to the library for EGL to be able to find the function.

    The writeStdOut() function takes a single argument (the piece of data in the parentheses). In this case the argument is a literal string of characters, and writeStdOut() has the job of displaying this string, on a line by itself, wherever EGL thinks the standard output should go. By default, that would be in the workbench's console window. That window is associated with one of the tabs in the lower right of the default workbench screen.

    The line of code, which represents a complete thought, ends with a semicolon.

  10. On another new line, with the current indentation, type:
    end
    EGL is smart enough to figure out that this end statement refers to the main() function declaration, so it should match the indentation of that declaration. Other languages use braces or other contrivances to mark blocks of code; EGL, being closer to natural language, simply matches the word end with the beginning of a block.
  11. Then on another new line, with the current indentation, type:
    end
    Again, EGL knows this end refers back to the program declaration, so it matches the indentation of that opening declaration.
  12. Press CTRL+S to save the file. Your finished program should look like the following example:
    Completed EGL program
  13. Press CTRL+G. CTRL + G will generate a native language version of the file. In this case, EGL generates a Java™ version of your EGL program. Your generation results will appear in a tabbed window directly below the editor in the default workbench configuration. The EGL Generation Results view looks like this:
    The EGL Generation Results view shows that your project has generated with no errors.

    In the Project Explorer view, you can now see the file Hello\Java Resources\hello\helloMain.java. Double-click the file name if you want to display the contents in the editor and see the considerable quantity of Java code that resulted from your one-line EGL function.

  14. Right click the file name Hello\Java Resources\hello\helloMain.java in the Navigator view, and from the resulting option window click Run > Java Application.
  15. After a moment, the lettering on the Console view's tab turns bold, indicating that it has messages.
  16. Switch to the Console view by clicking its tab. The Console view displays the message from your program.
    Console view showing the message "Hello, Cleveland!"
This message in the Console view demonstrates that this simple program works.