README: snacc compiler source code - Mike Sample 92
----------------------------------------------------


Compiling the snacc compiler
----------------------------

The snacc source code can be compiled with ANSI and non-ANSI C compilers.
Define the __USE_ANSI_C__ symbol as necessary (See snacc_config.h).

Three makefiles are used to compile snacc snacc/src/makefile,
snacc/src/back_ends/c_gen/makefile, and
snacc/src/back_ends/c++_gen/makefile.  If you change one, you may have
to change the others.  Typing make in snacc/src should compile snacc
and put it in snacc/bin.

If you use lex, you should change the YYLMAX value in the lex
generated lex.yy.c file from its measly default value (200 or so) to
something like 2048.  YYLMAX is the longest token that the lexical
analyzer can match.  I found this problem when snacc choked on the
DESCRIPTION field of an OBJECT-TYPE macro that was longer than 200
characters.  GNU flex does not have this problem (and seems to produce
smaller code than the old lex).

Compiling asn1.yacc with bison or yacc will produce 61 shift/reduce
errors and 2 reduce/reduce errors.  These are mostly due to the macros
that are parsed.  The reduce/reduce errors result from type or value
lists in some macros - the a "NULL" value and "NULL" type are both
represented by "NULL" - don't worry about this ambiguity.  Bizzare
syntax errors that arise from these shift-reduce errors can be
handled by separating types/values with semi-colons.

The length of generated files' names will be truncated to match your
system has the posix "pathconf" routine.  If it does not the maximum
file length will be set at 14 chars.  If you want to change this, 
modify the "MakeBaseFileName" routine in
snacc/src/back_ends/c_gen/str_util.c or use the -mf cmd line option.

snacc has been successfully installed on SPARCs, HP700s, RS 6000s, and
MIPS machines.  You may have to fiddle with system include files.

Outline of what snacc does
--------------------------

The snacc compiler uses yacc and lex (or bison/flex) parser To produce
an attributed parse tree for an ASN.1 source file.  The main steps of
the snacc are (see main() in snacc.c):


1. parse USEFUL types module (if given on command line with -u option)
     related src:  snacc.c asn1.lex asn1.yacc asn1module.h

2. parse the ASN.1 source file(s)
     related src:  snacc.c asn1.lex asn1.yacc asn1module.h

3. link import and local type references to the type proper 
   definitions in the parsed modules (including useful types module).
     related src:  link_types.c

4. do parsing for OBJECT IDENTIFIER values. Simple recursive descent
   parser.  Could be expanded to handle more complex values.
     related src:  val_parser.c     

5. link any value references (some may be internal to OBJECT IDENTIFIERs)
     related src:  link_values.c

6. process macros - change type definitions in the macros to separate
                    type definitions and do systemd dependent processing. 
     related src:  do_macros.c

7. normalize types and values - eg swap COMPONENTS OF and SELECTION types
                   for actual types/field. (and more)
     related src:  normalize.c

8. mark recursive type and report any recursion related errors.
    (e.g. empty recursive types A ::= B  B ::= A )
     related src:  recursive.c

9. check for sematic errors in each ASN.1 module.
     related src:  err_chk.c

10. fill in the C or C++ type and routine naming information.
   (done before dependency sorting so the sorter can make
    decisions on the basis of whether a type is ref'd by pointer
    (last resort))
     related src:  back_ends/c++_gen/cpp_types.c
                   back_ends/c++_gen/cpp_rules.c
                   back_ends/c_gen/types_info.c
                   back_ends/c_gen/rules.c

11. do type dependency sorting. Ordered from least dependent
    to most dependent.  Saves some irritations in the C/C++ code.
     related src:  dependency.c

12. Generate C/C++ .h and .c/.C files
     related src:  snacc.c back_ends/*

