"Fossies" - the Fresh Open Source Software Archive

Member "gentle-97/USAGE" (20 Aug 1998, 2806 Bytes) of package /linux/misc/old/gentle-97.tar.gz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 
    2    GENTLE 97
    3 
    4 
    5    USAGE
    6    -----
    7 
    8 
    9    Go to directory `examples/calc' which contains a specification
   10    of a simple calculator and a script to process this specification.
   11 
   12    Here is the Gentle specification of the calculator (file `calc.g') :
   13 
   14 
   15 	 'root' expression(-> X) print(X)
   16 
   17 	 'nonterm' expression(-> INT)
   18 
   19 	    'rule' expression(-> X): expr2(-> X)
   20 	    'rule' expression(-> X+Y): expression(-> X) "+" expr2(-> Y)
   21 	    'rule' expression(-> X-Y): expression(-> X) "-" expr2(-> Y)
   22 
   23 	 'nonterm' expr2(-> INT)
   24 
   25 	    'rule' expr2(-> X): expr3(-> X)
   26 	    'rule' expr2(-> X*Y): expr2(-> X) "*" expr3(-> Y)
   27 	    'rule' expr2(-> X/Y): expr2(-> X) "/" expr3(-> Y)
   28 
   29 	 'nonterm' expr3(-> INT)
   30 
   31 	    'rule' expr3(-> X): Number(-> X)
   32 	    'rule' expr3(-> - X): "-" expr3(-> X)
   33 	    'rule' expr3(-> + X): "+" expr3(-> X)
   34 	    'rule' expr3(-> X): "(" expression(-> X) ")"
   35 
   36 	 'token' Number(-> INT)
   37 
   38 
   39    Here is a script to process this specification (file `build') :
   40    
   41 
   42 	 GENTLE=../../gentle/gentle
   43 	 GRTS=../../gentle/grts.o
   44 	 REFLEX=../../reflex/reflex
   45 	 LIB=../../lib
   46 	 LEX=lex
   47 	 YACC=yacc
   48 	 CC=cc
   49 
   50 	 $GENTLE calc.g
   51 	 $REFLEX
   52 	 $LEX gen.l
   53 	 $YACC gen.y
   54 
   55 	 $CC -o calc \
   56 	    calc.c \
   57 	    lex.yy.c \
   58 	    y.tab.c \
   59 	    $LIB/errmsg.o \
   60 	    $LIB/main.o \
   61 	    $GRTS
   62 
   63 	 calc testfile
   64 
   65 
   66    This script creates and invokes the simple desk calculator `calc'.
   67 
   68    Here the command
   69 
   70 	 $GENTLE calc.g
   71 
   72    invokes the Gentle compiler, this translates the specification
   73    `calc.g' into a C file `calc.c'. In addition it generates some
   74    files `gen.*' the user does not have bother about.
   75 
   76    The command
   77 
   78 	 $REFLEX
   79 
   80    invokes the program `reflex'. This creates a specification for
   81    the scanner generator Lex (out of files created by `gentle' and files
   82    provided by the user such as `Number.t'.
   83 
   84    The commands
   85 
   86 	 $LEX gen.l
   87 	 $YACC gen.y
   88 
   89    invoke the scanner generator Lex and the parser generator Yacc
   90    respectively.
   91 
   92    Finally the C compiler creates the program `calc':
   93 
   94 	 cc -o calc       \
   95 	    calc.c        \
   96 	    lex.yy.c      \
   97 	    y.tab.c       \
   98 	    $LIB/errmsg.o \
   99 	    $LIB/main.o   \
  100 	    $GRTS
  101 
  102    `lex.yy.c' and `y.tab.c' are C files created by Lex and Yacc.
  103    `$LIB/errmsg.o' and `$LIB/main.o' are modules from the
  104    user library, they provide an error message routine and and
  105    main function that invokes the code create by the Gentle compiler 
  106    (a user may use these components as they are or may adapt them
  107    according to his or her needs).
  108 
  109    If `testfile' contains the line
  110 
  111 	 2+3*4
  112 
  113    then the command
  114 
  115 	 calc testfile
  116 
  117    emits `14' .
  118 
  119    Refer to the manual `Getting Started' for a discussion of this
  120    example and further details on how to generate a compiler.
  121 
  122    Take a look at the `Gentle Primer' for an introduction to the
  123    Gentle compiler description language.
  124