1.2 The Anatomy of an HLA Program


1.2 The Anatomy of an HLA Program

A typical HLA program takes the form shown in Figure 1-1.

click to expand
Figure 1-1: Basic HLA Program.

pgmID in the template above is a user-defined program identifier. You must pick an appropriate, descriptive name for your program. In particular, pgmID would be a horrible choice for any real program. If you are writing programs as part of a course assignment, your instructor will probably give you the name to use for your main program. If you are writing your own HLA program, you will have to choose an appropriate name for your project.

Identifiers in HLA are very similar to identifiers in most high level languages. HLA identifiers may begin with an underscore or an alphabetic character, and may be followed by zero or more alphanumeric or underscore characters. HLA's identifiers are case neutral. This means that the identifiers are case sensitive insofar as you must always spell an identifier exactly the same way in your program (even with respect to upper and lower case). However, unlike case sensitive languages like C/C++, you may not declare two identifiers in the program whose name differs only by alphabetic case.

A traditional first program people write, popularized by Kernighan and Ritchie's The C Programming Language is the Hello World program. This program makes an excellent concrete example for someone who is learning a new language. Listing 1-1 presents the HLA Hello World program.

Listing 1-1: The Hello World Program.

start example
 program helloWorld; #include( "stdlib.hhf" ); begin helloWorld;     stdout.put( "Hello, World of Assembly Language", nl ); end helloWorld; 
end example

The #include statement in this program tells the HLA compiler to include a set of declarations from the stdlib.hhf (Standard Library, HLA header file). Among other things, this file contains the declaration of the stdout.put code that this program uses.

The stdout.put statement is the print statement for the HLA language. You use it to write data to the standard output device (generally the console). To anyone familiar with I/O statements in a high level language, it should be obvious that this statement prints the phrase "Hello, World of Assembly Language." The nl appearing at the end of this statement is a constant, also defined in stdlib.hhf, that corresponds to the newline sequence.

Note that semicolons follow the program, begin, stdout.put, and end statements.[1] Technically speaking, a semicolon does not follow the #include statement. It is possible to create include files that generate an error if a semicolon follows the #include statement, so you may want to get in the habit of not putting a semicolon here.

The #include is your first introduction to HLA declarations. The #include itself isn't actually a declaration, but it does tell the HLA compiler to substitute the file stdlib.hhf in place of the #include directive, thus inserting several declarations at this point in your program. Most HLA programs you will write will need to include one or more of the HLA Standard Library header files (stdlib.hhf actually includes all the Standard Library definitions into your program).

Compiling this program produces a console application. Running this program in a command window prints the specified string and then control returns back to the command line interpreter (or shell in UNIX terminology).

HLA is a free-format language. Therefore, you may split statements across multiple lines if this helps to make your programs more readable. For example, you could write the stdout.put statement in the Hello World program as follows:

 stdout.put (     "Hello, World of Assembly Language",     nl ); 

Another item you'll see appearing in sample code throughout this text is that HLA automatically concatenates any adjacent string constants it finds in your source file. Therefore, the statement above is also equivalent to:

 stdout.put (     "Hello, "     "World of Assembly Language",     nl ); 

Indeed, nl (the newline) is really nothing more than a string constant, so (technically) the comma between the nl and the preceding string isn't necessary. You'll often see the above written as:

 stdout.put( "Hello, World of Assembly Language" nl ); 

Notice the lack of a comma between the string constant and nl; this turns out to be perfectly legal in HLA, though it only applies to certain constants; you may not, in general, drop the comma. A later chapter will explain in detail how this works. This discussion appears here because you'll probably see this "trick" employed by sample code prior to the formal explanation.

[1]Technically, from a language design point of view, these are not all statements. However, this chapter will not make that distinction.




The Art of Assembly Language
The Art of Assembly Language
ISBN: 1593272073
EAN: 2147483647
Year: 2005
Pages: 246
Authors: Randall Hyde

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net