view doc/misc/html/examples/hw.html @ 24:a4899cdfc2d6 default tip

Obfuscate the regexps to strip off the IBM compiler's copyright banners. I don't want bots scanning github to think they're real copyright notices because that could cause real problems.
author David A. Holland
date Mon, 13 Jun 2022 00:40:23 -0400
parents 13d2b8934445
children
line wrap: on
line source

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE>Hello World!</TITLE>
</HEAD>


<BODY BGCOLOR="#ffffff" BACKGROUND="tilbl6h.gif"
 TEXT="#000000" LINK="#0033CC"
 VLINK="#CC0033" ALINK="#CC0099">

<P>
<IMG ALIGN="right" SRC="../images/agrsl6c.gif" ALT="AnaGram"
         WIDTH=124 HEIGHT=30 >
<BR CLEAR="all">
Back to <A HREF="../index.html">Index</A>
<P>
<IMG ALIGN="bottom" SRC="../images/rbline6j.gif" ALT="----------------------"
        WIDTH=1010 HEIGHT=2  >
<P>


<H1>Hello, World!</H1>

<IMG ALIGN="bottom" SRC="../images/rbline6j.gif" ALT="----------------------"
        WIDTH=1010 HEIGHT=2  >

<P>
<H2>Introduction</H2>
<P>
          Hello, world! has become the traditional first program to
          try in a new programming language. This directory provides
          two instances of "Hello, world!" The first, <tt>hw1</tt>, uses C. The
          second, <tt>hw2</tt>, uses C++.
<P>

<H2>Hello, world! using C &nbsp;&nbsp;-&nbsp;&nbsp; HW1.SYN</H2>
          <tt>hw1</tt> accepts a single newline character as input and then
          prints the "Hello, world!" message on stdout.
<P>
          Every grammar must have a single token, the grammar token,
          to which the entire grammar finally condenses. The default
          name for this token is "grammar", which is used here.
<P>
          AnaGram productions use an arrow ( <CODE>-&gt;</CODE> ) to separate the
          token or tokens being described, on the left, from their
          descriptions, on the right. <tt>hw1</tt> consists of a single
          production, defining the token "grammar" to consist of a
          single newline character.
<P>
          The right hand side of a production is called a "grammar
          rule" and in the general case consists of a series of rule
          elements separated by commas. Following the rule on the same
          line, introduced by an equal sign, there may be a "reduction
          procedure", C code to be executed when the rule is
          identified in the input stream. Here there is one rule
          element and the reduction procedure consists of a single C
          expression, followed by a semicolon.
<P>
          Note that AnaGram permits comments in accordance with the
          rules for C comments. AnaGram comments, like C comments, do
          not ordinarily nest. However, you may set the "nest
          comments" configuration switch to allow nesting.
<P>
          When AnaGram builds a parser, it will provide defaults for
          all important aspects of the parser which you do not
          specify. In <tt>hw1</tt>, there is no specification of input, so the
          parser will be set up to read characters one at a time from
          stdin.
<P>
          If a syntax file contains no embedded C, AnaGram will
          automatically provide a main program to call the parser.
          Thus this simple grammar suffices to describe a complete
          program.
<P>

<H2>Testing HW1</H2>
          To test <tt>hw1</tt>, run AnaGram and build a parser using
          <tt>hw1.syn</tt>.
          The name of the output source file will be <tt>hw1.c</tt>.
          Compile and link the
          parser with your C compiler. Then run it from the command line
          and press Enter.
          The "Hello, world!" message should appear on your screen.
<P>

<H2>Hello, world! using C++ &nbsp;&nbsp;-&nbsp;&nbsp; HW2.SYN</H2>
          <tt>hw2</tt> is a step up in complexity. <tt>hw2</tt>
          creates a C++ program
          instead of C, and uses stream I/O to write the famous
          message.
<P>
          The first complexity is the requirement to tell AnaGram to
          output a file with a C++ name rather than a C name. 
         <!--
          Of
          course, this is a frill, since you could probably have
          compiled it anyway. 
         -->
          The <b>parser file name</b> configuration
          parameter specifies that the name of the parser file should
          be the same as the name of the syntax file, but with the
          extension <tt>.cpp</tt>.
<P>
          The second complexity is the need to provide an #include
          statement for <tt>iostream.h</tt> to get a definition of
          <tt>cout</tt>. <tt>hw1</tt> 
          did not need to include <tt>stdio.h</tt>, since the parser
          always has 
          an <CODE>#include</CODE> statement for <tt>stdio.h</tt> to
          support the default
          input procedures. To provide an <CODE>#include</CODE>
          statement, we need a
          block of embedded C.
<P>
          Since we have a block of embedded C, AnaGram will not create
          a main program automatically. So we add a main program which
          does nothing but call the parser. The parser name is set (by
          default) to <tt>hw2</tt>.
<P>
          Note also that in addition to C style comments, AnaGram also
          supports C++ style comments.
<P>

<H2>Testing HW2</H2>
          To test <tt>hw2</tt>, build a parser using <tt>hw2.syn</tt>,
          just as you did
          for <tt>hw1</tt>. This time the name of the parser file will be
          <tt>hw2.cpp</tt>. Compile and link the parser with your C++ compiler.
          Then run it from the command line and press Enter. The
          "Hello, world!" message
          should appear on your screen.
</P>

<BR>
<IMG ALIGN="bottom" SRC="../images/rbline6j.gif" ALT="----------------------"
      WIDTH=1010 HEIGHT=2 >
<P>
<IMG ALIGN="right" SRC="../images/pslrb6d.gif" ALT="Parsifal Software"
                WIDTH=181 HEIGHT=25>
<BR CLEAR="right">
<P>
Back to <A HREF="../index.html">Index</A>
<P>
<ADDRESS><FONT SIZE="-1">
                  AnaGram parser generator - examples<BR>
                  Hello World!<BR>
                  Copyright &copy; 1993-1999, Parsifal Software. <BR>
                  All Rights Reserved.<BR>
</FONT></ADDRESS>

</BODY>
</HTML>