Target Language Compiler | ![]() ![]() |
Output Streams
The typical "Hello World" example is rather simple in the target language. Type the following in a file named hello.tlc
%selectfile STDOUT Hello, World
To run this Target Language Compiler program, type
tlc hello.tlc
This simple program demonstrates some important concepts underlying the purpose (and hence the design) of the Target Language Compiler. Since the primary purpose of the Target Language Compiler is to generate code, it is output (or stream) oriented. It makes it easy to handle buffers of text and output them easily. In the above program, the %selectfile
directive tells the Target Language Compiler to send any following text that it does not recognize to the standard output device. All syntax that the Target Language Compiler recognizes begins with the %
character. Since Hello, World
is not recognized, it is sent directly to the output. You could just as easily change the output destination to be a file.
%openfile foo = "foo.txt" %openfile bar = "bar.txt" %selectfile foo This line is in foo. %selectfile STDOUT Line has been output to foo. %selectfile bar This line is in bar. %selectfile NULL_FILE This line will not show up anywhere. %selectfile STDOUT About to close bar. %closefile bar %closefile foo
Note that you can switch between buffers to display status messages. The semantics of the three directives, %openfile
, %selectfile
, and %closefile
are given in the Compiler Directives table.
![]() | Code Generation Concepts | Variable Types | ![]() |