home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / ada / library / napp / pp_exe.exe / arc / PRETTY_P.DOC < prev    next >
Text File  |  1988-05-27  |  74KB  |  1,990 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.           The  source  code  and  data  files  for GSFC Ada Standard Pretty 
  9.           Printer is in the public domain,  but  NASA  does  request  to be 
  10.           notified of  how many  copies are  made to  encourage funding for 
  11.           similar development for the  public  domain.    Therefore, please 
  12.           fill out this page and return it to:  
  13.             
  14.                     Ada Pretty Printer Notification  
  15.                     c/o Ms. Elisabeth Brinker -- Code 522
  16.                     Data Systems Applications Branch  
  17.                     Goddard Space Flight Center 
  18.                     Greenbelt, Maryland 20771-0001  
  19.             
  20.           ----------------------------------------------------------------- 
  21.  
  22.             
  23.                     Ada Pretty Printer Notification  
  24.                          Version 1.1  
  25.             
  26.             
  27.           Name ____________________________________________________________ 
  28.  
  29.           Address _________________________________________________________ 
  30.             
  31.           _________________________________________________________________ 
  32.             
  33.           _________________________________________________________________ 
  34.             
  35.             
  36.             
  37.           Copies ___________________      Modified Copies _________________ 
  38.  
  39.             
  40.            _  
  41.           |_|  I would like information regarding any modifications since  
  42.                version 1.1  
  43.             
  44.             
  45.           Comments ________________________________________________________ 
  46.             
  47.           _________________________________________________________________ 
  48.             
  49.           _________________________________________________________________ 
  50.  
  51.           _________________________________________________________________ 
  52.             
  53.           _________________________________________________________________ 
  54.             
  55.           _________________________________________________________________ 
  56.             
  57.           _________________________________________________________________ 
  58.             
  59.           _________________________________________________________________ 
  60.    
  61.  
  62.  
  63.  
  64.                      Data Systems Technology Laboratory Series  DSTL-88-003
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.                     National Aeronautics and Space Administration 
  87.                         Goddard Space Flight Center Standard 
  88.  
  89.                                  Ada Pretty Printer 
  90.  
  91.  
  92.  
  93.  
  94.  
  95.                                     May 1988
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.             
  103.                                       FOREWORD
  104.  
  105.  
  106.           NASA/GSFC Standard  Ada Pretty  Printer is  a publication  of the
  107.           Data Systems  Technology Division  of the  Mission Operations and
  108.           Data Systems  Directorate, the National Aeronautics and Space Ad-
  109.           ministration, Goddard Space Flight Center (NASA/GSFC).
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.                                 The principal author 
  118.                                  of this document is
  119.  
  120.  
  121.                                    Allyn M. Shell
  122.                                          of
  123.                                    AdaCraft, Inc.
  124.                               (a Maryland Corporation)
  125.  
  126.  
  127.  
  128.                               Work was accomplished for
  129.  
  130.                           Data Systems Technology Division
  131.                                         under
  132.                            Purchase Order Number S-89844-D
  133.             
  134.  
  135.  
  136.           Single copies of this document may be obtained by writing to:
  137.  
  138.                            Ms. Elisabeth Brinker
  139.                            Code 522
  140.                            NASA/Goddard Space Flight Center
  141.                            Greenbelt, Maryland 20771
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.                                       ABSTRACT
  149.  
  150.  
  151.           This documentation  contains a User Guide describing installation
  152.           and limitations of the NASA/GSFC Ada  Pretty Printer  tool.  Con-
  153.           tained in  the Appendix  is a  description of how the source code
  154.           for the Pretty Printer  is structured  and guidelines  for source
  155.           code modification  and reuse.   This  documentation was completed
  156.           together with Version 1.1  of the  software tool,  which provides
  157.           significant  enhancements  to expand  the tool's  usefulness in a
  158.           software development environment.
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.                              Goddard Space Flight Center 
  166.                              Standard Ada Pretty Printer 
  167.  
  168.             
  169.           Table of Contents:  
  170.             
  171.           1. Background 
  172.             
  173.           2. Installation for IBM AT and Compatibles From Executable 
  174.             
  175.           3. Installation From Source Code 
  176.             
  177.           4. Normal Use With Single File 
  178.             
  179.           5. Multiple Files and Batch Mode  
  180.             
  181.           6. The Output Files  
  182.  
  183.           7. Modifying Default File Names 
  184.  
  185.           8. Optional Parameters  
  186.  
  187.           9. Pragmas and Creating a Specialized Pretty Printer 
  188.  
  189.           10. Error Messages  
  190.  
  191.           11. Limitations and Known Problems 
  192.  
  193.           Appendix 
  194.  
  195.               Ada Pretty Printer Code Documentation 
  196.  
  197.               Ada Pretty Printer Notification 
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.  
  207.  
  208.  
  209.  
  210.  
  211.  
  212.  
  213.  
  214.  
  215.  
  216.  
  217.  
  218.                                                                           1 
  219.  
  220.  
  221.  
  222.  
  223.  
  224.                              Goddard Space Flight Center 
  225.                              Standard Ada Pretty Printer 
  226.    
  227.           1.   Background
  228.                   
  229.           This project  began in  early 1986  as an Ada learning project in
  230.           the Simulations Operations Control Center (SOC)  at Goddard Space
  231.           Flight Center,  where the tool's author was being groomed as "The
  232.           Ada Expert" for the SOC.  Through the process of  writing a parse
  233.           table generator and Ada syntax file, he was able to learn many of
  234.           the intricacies of Ada he might have otherwise missed in years of
  235.           development projects. 
  236.  
  237.           The tool's author, Mr. Allyn M. Shell, joined the Ada Users Group
  238.           at GSFC and subsequently became a charter member of the Ada Stan-
  239.           dards Committee, a working committee of the Ada Users Group.  The
  240.           standards implemented in the tool are directly taken from the Ada
  241.           Style Guide  (Software Engineering Laboratory Series  SEL-87-002)
  242.           produced by the Standards Committee.
  243.  
  244.           In January  of 1988  NASA selected  AdaCraft, Inc.  to update and
  245.           document the Pretty Printer  code that Mr. Shell wrote.  The code
  246.           has been released to the public domain.  Enhancements are encour-
  247.           aged, and  NASA would  like to  know what  was done.  If some en-
  248.           hancements require changes to the syntax  or directives, there is
  249.           a parse table generator associated  with the Pretty Printer which
  250.           operates on the VAX / VMS.  This program can be acquired from the
  251.           Data Systems  Applications Branch of GSFC.  (See  notification at
  252.           end of  document for address.)   It will require  modification to
  253.           make it usable on an IBM AT.
  254.            
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.                    
  270.                   
  271.  
  272.  
  273.  
  274.  
  275.  
  276.  
  277.  
  278.                                                                           2 
  279.  
  280.  
  281.  
  282.  
  283.  
  284.                              Goddard Space Flight Center 
  285.                              Standard Ada Pretty Printer 
  286.  
  287.           2.   Installation  for  IBM  AT  and  Compatibles  from  Archived 
  288.                Executable: 
  289.             
  290.           AT must have extended RAM with driver=vdisk.sys in the config.sys 
  291.           file  (vdisk.sys  comes  with  IBM's DOS).  Otherwise, use PP.exe 
  292.           alone (expanded memory helps). 
  293.             
  294.           INSTALLATION: After making a backup floppy, do the DOS commands  
  295.           designated in the left column starting from the root directory.  
  296.             
  297.              MD Pretty   |   Act_Tab1.DIO    Act_Tab2.DIO    DirecTab.DIO 
  298.              CD Pretty   |   Heap.COM        Load_PP.BAT     PP.EXE 
  299.              A:PP_Exe    |   Pretty_P.DOC    Pretty_P.EXE    Pretty_P.EXT  
  300.                                    
  301.           Your directory should include the  files  on  the  right.   Print 
  302.           Pretty_P.DOC.   If your  RAM is not D: then you will need to edit 
  303.           Load_PP.BAT to designate the correct drive number.   
  304.  
  305.           The Alsys compiler routines are  assumed  to  be  present  by the 
  306.           Load_PP.BAT file  but are  not necessary.   If you have the Alsys 
  307.           compiler routines, Heap.COM can be deleted.  Add C:\Pretty to the 
  308.           path in  your AutoExec.BAT file.  If you expect to use the Pretty 
  309.           Printer frequently,  include the  Load_PP call  (without the Heap 
  310.           call) before any Alsys\StartUp call in the AutoExec.BAT file.  
  311.             
  312.           EXECUTION: 
  313.           with RAM: 
  314.                 Load_PP      (This only needs to be done once per session.) 
  315.                 Pretty_Print  
  316.  
  317.           without RAM: 
  318.                 PP 
  319.  
  320.           On the  prompt enter  file name.   The  last two  letters will be 
  321.           changed to -PP for the formatted  source  file  and  -SR  for the 
  322.           status report. 
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336.  
  337.                                                                           3 
  338.  
  339.  
  340.  
  341.  
  342.  
  343.                              Goddard Space Flight Center 
  344.                              Standard Ada Pretty Printer 
  345.  
  346.           3.   Installation From Source Code:  
  347.             
  348.           Compilation command  lists are provided for Vax / VMS and IBM AT. 
  349.           Users of other machines should determine  whether the VAX_Parse_- 
  350.           Tables can be compiled on their systems.  If the VAX_Parse_Tables 
  351.           will compile then they should be used.  Edit the appropriate com- 
  352.           mand list.   If  necessary create  the Ada library.  Then compile 
  353.           and link the source code using the edited command list.   
  354.  
  355.           Copy the  executable module  into the  appropriate directory, and 
  356.           if you  have not used the VAX_Parse_Tables, you will have to copy 
  357.           the action tables and directives  table  to  the  same directory. 
  358.           These are the files:  Act_Tab1.DAT  Act_Tab2.DAT  DirecTab.DAT 
  359.  
  360.           Note: These  tables are necessary only for the first execution of 
  361.           the Pretty Printer and can be deleted after  the first  run.  The 
  362.           Pretty Printer  will generate  Direct_IO versions of these tables 
  363.           with .DIO designations.  All of the .DIO files or all of the .DAT 
  364.           files must  be present  for the Pretty Printer to initialize.  If 
  365.           modifications are  made to  the source  code that  do not include 
  366.           changes to  the parse tables, the original .DIO files can be used 
  367.           with the new load module of the Pretty Printer. 
  368.  
  369.           If modifications are made to the  syntax or  directives using the 
  370.           parse table  generator then the parse tables and parse keys files 
  371.           will both need to be recompiled along with their dependent units. 
  372.           The .DIO  files will also need to be renamed so that the new .DAT 
  373.           will be installed. 
  374.  
  375.  
  376.  
  377.  
  378.  
  379.  
  380.  
  381.  
  382.  
  383.  
  384.  
  385.  
  386.  
  387.  
  388.  
  389.  
  390.  
  391.  
  392.  
  393.  
  394.  
  395.  
  396.                                                                           4 
  397.  
  398.  
  399.  
  400.  
  401.  
  402.                              Goddard Space Flight Center 
  403.                              Standard Ada Pretty Printer 
  404.  
  405.           4.   Normal Use with Single File: 
  406.  
  407.           To execute the Pretty Printer simply invoke the  executable modu- 
  408.           le.  On the VAX this would be:  Run Pretty_Print 
  409.           On an IBM AT this would be: Pretty_Print 
  410.  
  411.           Note: Execution  of the Pretty Printer on an IBM AT or Compatible 
  412.           will require copying the .EXT file to RAM  and assignment  of the 
  413.           name Ada_Heap.DTA  to the  free space  in RAM.   This can be done 
  414.           using the Load_PP.BAT file which is included. 
  415.  
  416.           The Pretty Printer will  prompt for  the name  of the  file to be 
  417.           formatted and will return several simple messages. For Example: 
  418.  
  419.  
  420.                C> Pretty_Print 
  421.                Ada File? > FileName.Ada 
  422.                FileName.APP created 
  423.                FileName.ASR created 
  424.  
  425.  
  426.           The  Ada  file  FileName.Ada  was formatted according to the GSFC 
  427.           Standard Ada Style and  written to  the FileName.APP  file with a 
  428.           statistics report  written to  the FileName.ASR file.  See Output 
  429.           Files section for examples. 
  430.  
  431.           Note: Since output file names are simply modified versions of the 
  432.           input file  name less  the last two characters, distinctions bet- 
  433.           ween files made by differences in the extension may be lost. (For 
  434.           instance a declaration and corresponding body called Package1.ADA 
  435.           and Package1.ADB will both  produce output  files with  the names 
  436.           Package1.APP and Package1.ASR.) Also file names with single char- 
  437.           acter extensions will raise  exceptions  in  some implementations 
  438.           because the period of the intended extension will be deleted. 
  439.  
  440.           Some  error  messages  may  also  appear at the terminal.  If the 
  441.           message is related to a parse error then the source code does not 
  442.           conform  to  the  Ada  LRM.    In this case the -PP file will not 
  443.           contain a formatted version of the source file.  Instead, it will 
  444.           be a  copy of  the original file with very simple error messages. 
  445.           Often one parse error will produce  several error  messages; some 
  446.           of  which  may  be  much  later  in the code where later parts of 
  447.           nested constructs appear. 
  448.  
  449.           Another kind of message that appears  at the  terminal is  a flag 
  450.           that is displayed for violations of the Style Guide which are not 
  451.           violations of Ada.  These are included for NASA's use. 
  452.  
  453.  
  454.  
  455.                                                                           5 
  456.  
  457.  
  458.  
  459.  
  460.  
  461.                              Goddard Space Flight Center 
  462.                              Standard Ada Pretty Printer 
  463.  
  464.           5.   Multiple Files and Batch Mode: 
  465.  
  466.           The Pretty Printer will take a list of files and format each file 
  467.           on the list. Each file will produce two output files named in the 
  468.           same manner as for the single file.   A statistics  totals report 
  469.           is also produced named the Stat_Tot.RPT file. 
  470.  
  471.           To format a list of files: 
  472.  
  473.           Prepare the  list to  be formatted  with one  file name per line. 
  474.           The name may be preceded  by  blanks  (no  tab  characters).   If 
  475.           anything  else  follows  on  the  line there must be at least one 
  476.           blank space immediately after the name. 
  477.  
  478.           To execute a list of files: 
  479.  
  480.           Indicate the input file is a list by placing an  "at" sign before 
  481.           the file name. 
  482.  
  483.  
  484.                C> Pretty_Print 
  485.                Ada File? > @NameList.Ada 
  486.                Pretty Print -- File_1.APP  
  487.                File_1.APP created 
  488.                File_1.ASR created 
  489.                Pretty Print -- File_2.APP  
  490.                File_2.APP created 
  491.                File_2.ASR created 
  492.                Stat_Tot.Rpt created 
  493.  
  494.  
  495.           To execute the Pretty Printer in Batch mode: 
  496.  
  497.           The first  word of the first line in the files list should be the 
  498.           word "batch".  This word must be all lower case and must  be sep- 
  499.           arated from  anything following  by at  least one  blank.  If the 
  500.           output file for the terminal responses is to  be named,  the name 
  501.           must appear on the same line after the word "batch" and separated 
  502.           before and behind by one  or  more  spaces  (no  tab characters). 
  503.           Everything that  appears on this line after the first blank space 
  504.           following the output file name will be considered a comment. 
  505.  
  506.           For batch processing this  list file  must be  named Files_In.LST 
  507.           and must  be in  the directory  starting the batch job.  When the 
  508.           batch job  is completed  this file  should be  renamed because it 
  509.           will cause  normal execution of the Pretty Printer to execute the 
  510.           same list file and overwrite the output file.   This  may cause a 
  511.           loss of  the existing  output file even if the execution is stop- 
  512.           ped. 
  513.  
  514.                                                                           6 
  515.  
  516.  
  517.  
  518.  
  519.  
  520.                              Goddard Space Flight Center 
  521.                              Standard Ada Pretty Printer 
  522.  
  523.  
  524.           If the Storage_Error exception is raised while a list of files is 
  525.           being formatted, execution will be stopped at that file, an error 
  526.           message will appear at the terminal  or in  the output  file, and 
  527.           the  Statistics  Totals  Report  will  be generated for all files 
  528.           prior to the one causing the Storage_Error.  
  529.  
  530.           Note: Files having parse  errors will  not produce  a unit status 
  531.           report nor add statistics to the total. 
  532.  
  533.  
  534.  
  535.  
  536.  
  537.  
  538.  
  539.  
  540.  
  541.  
  542.  
  543.  
  544.  
  545.  
  546.  
  547.  
  548.  
  549.  
  550.  
  551.  
  552.  
  553.  
  554.  
  555.  
  556.  
  557.  
  558.  
  559.  
  560.  
  561.  
  562.  
  563.  
  564.  
  565.  
  566.  
  567.  
  568.  
  569.  
  570.  
  571.  
  572.  
  573.                                                                           7 
  574.  
  575.  
  576.  
  577.  
  578.  
  579.                              Goddard Space Flight Center 
  580.                              Standard Ada Pretty Printer 
  581.  
  582.           6.   The Output Files: 
  583.  
  584.           The two  primary output  files are  the Formatted Source File and 
  585.           the Statistics Report.  The Formatted  Source File  will have the 
  586.           same source  code as the original source file but the format will 
  587.           be according to the Ada Style Guide (Version  1.1).   A sample of 
  588.           the Statistics Report follows: 
  589.  
  590.                Statistics for file named => FileName.Ada 
  591.                Description                        Amount 
  592.                ----------------------------------------- 
  593.                Units                                   1 
  594.                Lines                                  69 
  595.                  Lines_of_Code                   17 
  596.                  Comment_Lines                   42 
  597.                  Blank_Lines                     10 
  598.                  Right_Comments                   6 
  599.                Open_Semicolons                        10 
  600.                Enclosed_Semicolons                     1 
  601.                Maximum_Indentation                     2 
  602.                ----------- Code - Statistics ----------- 
  603.                with_clause                             1 
  604.                use_clause                              1 
  605.                body_stub                               1 
  606.                procedure_body                          1 
  607.                  parameter_spec  (fn & proc)      2 
  608.                call_statement                          1 
  609.                assignment_statement                    3 
  610.                if_statement                            2 
  611.                  elsif_clause                     1 
  612.                ----------------------------------------- 
  613.  
  614.           The code  statistics correspond to the number of parse tree nodes 
  615.           for the selected constructs. (Details such as identifier  and op- 
  616.           erator counts  are not included.) The open and enclosed semicolon 
  617.           counts are provided to determine  how  the  semicolons  are being 
  618.           counted by  others providing  Ada code.  (Enclosed semicolons are 
  619.           those that appear within  parenthesis  as  between  the parameter 
  620.           declarations in the formal part of a subprogram declaration.) The 
  621.           maximum indentation is provided to give a rough  estimate of unit 
  622.           complexity.    The  parameter_spec  count  includes all parameter 
  623.           specifications in procedure, function, and entry declarations and 
  624.           accept statements.   The  amount for the procedure body, function 
  625.           body, package body, package spec, etc. will include the item that 
  626.           is the compilation unit as well as any enclosed units.  The other 
  627.           reported items are self explanatory. 
  628.  
  629.           Note: When the source code contains parse errors this report will 
  630.           not be generated. 
  631.  
  632.                                                                           8 
  633.  
  634.  
  635.  
  636.  
  637.  
  638.                              Goddard Space Flight Center 
  639.                              Standard Ada Pretty Printer 
  640.  
  641.           7.   Modifying Default File Names: 
  642.  
  643.           The default  file names  can be  changed by making changes in the 
  644.           FileNams.Ada file and recompiling this file and its dependencies. 
  645.           The files which can be modified this way are: 
  646.  
  647.              Action_Table_One : constant String := "Act_Tab1.Dat"; 
  648.              Action_Table_Two : constant String := "Act_Tab2.Dat"; 
  649.              Directives_Table : constant String := "Directab.Dat"; 
  650.              Productions_Table : constant String := "Prodtabl.Dat"; 
  651.  
  652.              Direct_Action_Table_One : constant String := "Act_Tab1.DIO"; 
  653.              Direct_Action_Table_Two : constant String := "Act_Tab2.DIO"; 
  654.              Direct_Directives_Table : constant String := "Directab.DIO"; 
  655.              Direct_Productions_Table : constant String := "Prodtabl.DIO"; 
  656.  
  657.              Input_Files_List : constant String := "Files_In.Lst"; 
  658.              Output_List : constant String := "PPoutput.lst"; 
  659.              Status_Totals_Report : constant String := "Stat_Tot.Rpt"; 
  660.  
  661.           Note: The  first eight files named here are not used when the VAX 
  662.           Parse Tables are used. 
  663.  
  664.  
  665.  
  666.  
  667.  
  668.  
  669.  
  670.  
  671.  
  672.  
  673.  
  674.  
  675.  
  676.  
  677.  
  678.  
  679.  
  680.  
  681.  
  682.  
  683.  
  684.  
  685.  
  686.  
  687.  
  688.  
  689.  
  690.  
  691.                                                                           9 
  692.  
  693.  
  694.  
  695.  
  696.  
  697.                              Goddard Space Flight Center 
  698.                              Standard Ada Pretty Printer 
  699.  
  700.           8.   Optional Parameters: 
  701.  
  702.           The Pretty Printer contains many controls that are parameterized. 
  703.           Any  of  these  parameters  can be overridden by pragma Form_Set. 
  704.           These parameters include the following: 
  705.  
  706.              type Format_Type is (NASA_STANDARD, SPECIAL); 
  707.              Pretty_Print_Format : Format_Type := NASA_STANDARD; 
  708.  
  709.              Page_Width : Natural := 80; 
  710.              Right_Comment_Column : Natural := 40; 
  711.  
  712.              Colon_Offset : Natural := 15; 
  713.              Value_Offset : Natural := 15; 
  714.              Assign_Offset : Natural := 15; 
  715.  
  716.           The following parameters can also be overridden by  pragma Form_- 
  717.           Set, but  they only  apply when the Pretty_Print_Format is set to 
  718.           SPECIAL.  
  719.  
  720.              Indentation : Natural := 3; 
  721.              Using_Half_Indentation : Boolean := TRUE; 
  722.                 -- not recommended for Indentation < 3 
  723.              Using_Reverse_Indentation : Boolean := TRUE; 
  724.                 -- for loop names, block names, and labels 
  725.  
  726.              type Cases is (UPPER_CASE, CAPITALIZE_FIRST, LOWER_CASE);      
  727.              Types_Case : Cases := CAPITALIZE_FIRST; 
  728.              Enumeration_Case : Cases := UPPER_CASE; 
  729.              Identifier_Case : Cases := CAPITALIZE_FIRST; 
  730.  
  731.              Using_Echeloned_Declarations : Boolean := FALSE; 
  732.              Using_Echeloned_Assigns : Boolean := FALSE; 
  733.  
  734.              Using_Colon_Alinement : Boolean := FALSE; 
  735.              Using_Value_Alinement : Boolean := FALSE; 
  736.              Using_Assign_Alinement : Boolean := FALSE; 
  737.              Using_Pointer_Alinement : Boolean := FALSE; 
  738.  
  739.           The  offset  parameters  in  the  third  group  are used with the 
  740.           "using" flags  in the  last group.   The  Colon_Offset is aligned 
  741.           measuring from  the beginning  of the identifier that it follows. 
  742.           The Value_Offset is for  the assignment  in a  declaration and is 
  743.           aligned  measuring  from  the  colon.    The Assign_Offset is for 
  744.           assignment statement and is aligned measuring  from the beginning 
  745.           of the statement. 
  746.  
  747.           The half  indentation will cause the "when" clause of case state- 
  748.           ments, exception handlers, and  variant parts  of record declara- 
  749.  
  750.                                                                          10 
  751.  
  752.  
  753.  
  754.  
  755.  
  756.                              Goddard Space Flight Center 
  757.                              Standard Ada Pretty Printer 
  758.  
  759.           tions and  the "record" of the record declarations to be indented 
  760.           only half of a normal  indentation  level  so  that  the enclosed 
  761.           portion of the construct will be indented one level. 
  762.  
  763.           The reverse  indentation applies  to labels  (which should not be 
  764.           used according to the Ada Style  Guide)  and  to  loop  and block 
  765.           names.  The reverse indentation causes them to stick out from the 
  766.           surrounding lines of code as in the Ada  LRM rather  than the Ada 
  767.           Style Guide. 
  768.  
  769.           The capitalization  parameters can be set for upper_case, lower_- 
  770.           case, or capitalize_first.   Capitalize_First  simply  means that 
  771.           the first  letter of each word is capitalized.  A words in an Ada 
  772.           identifier must be separated by an  underline to  be capitalized. 
  773.           The one exception to this rule is: if an identifier ends with _IO 
  774.           then the 'O' is also capitalized.  The  capitalization parameters 
  775.           can  be  overridden  for  individual  identifiers by using pragma 
  776.           Form. 
  777.  
  778.           An echeloned declaration is  one with  the colon  indented on the 
  779.           line following  the identifier.   An echeloned assign is one with 
  780.           the assignment indented on the  line  following  the  colon. (The 
  781.           echeloned  assign  flag  is  not  considered unless the echeloned 
  782.           declaration flag is TRUE.) 
  783.  
  784.  
  785.  
  786.  
  787.  
  788.  
  789.  
  790.  
  791.  
  792.  
  793.  
  794.  
  795.  
  796.  
  797.  
  798.  
  799.  
  800.  
  801.  
  802.  
  803.  
  804.  
  805.  
  806.  
  807.  
  808.  
  809.                                                                          11 
  810.  
  811.  
  812.  
  813.  
  814.  
  815.                              Goddard Space Flight Center 
  816.                              Standard Ada Pretty Printer 
  817.  
  818.           9.   Pragmas and Creating a Specialized Pretty Printer: 
  819.  
  820.           The Pretty Printer recognizes  four  pragmas.    They  are pragma 
  821.           Form_Set,  pragma  Form,  pragma  Format_Off, and Format_On. (The 
  822.           pragmas are all case insensitive.) 
  823.  
  824.                pragma Form_Set (Parameter_Name => Value); 
  825.  
  826.           The Form_Set pragma will set any  of the  parameters mentioned in 
  827.           the last  section.   The pragma  can appear  anywhere in the file 
  828.           being formatted and effects the formatting of the entire file and 
  829.           any other files which may follow immediately during the execution 
  830.           of the Pretty Printer.  This  pragma requires  both the parameter 
  831.           name and  new value.   It  can have  multiple pairs  of names and 
  832.           values, but it cannot continue over to a second line.   There may 
  833.           be as many pragma Form_Set statements in a file as desired.  When 
  834.           the same parameter is set more than once the last setting will be 
  835.           in force  throughout the  file being formatted.  One exception to 
  836.           the parameter name requirement is the Pretty_Print_Format parame- 
  837.           ter.   The value SPECIAL or NASA_STANDARD may be used without the 
  838.           parameter name, but the value must be the first setting listed in 
  839.           the pragma. 
  840.  
  841.           Note: Settings  of the  parameters remain  in effect throughout a 
  842.           series of formats done using a  list  of  files  starting  at the 
  843.           beginning of the file in which they appear.  This allows lists of 
  844.           files to be formatted  uniformly without  individual editing, but 
  845.           it will require that parameters be reset after an individual file 
  846.           in a list is formatted (in the next file) if they are meant to be 
  847.           in effect  only for that one file.  A recommended procedure is to 
  848.           place all such files at the end of any list of files  to be form- 
  849.           atted  with  the  pragma  reset  files between them.  Files which 
  850.           contain only pragmas will be  flagged  as  having  a  parse error 
  851.           (since they  do not  contain a  unit), but the parameters will be 
  852.           set.  Because the parse error is raised,  a pragma  file will not 
  853.           affect the total statistics. 
  854.  
  855.                pragma Form (Identifier); 
  856.  
  857.           The Form  pragma allows  the capitalization  for individual iden- 
  858.           tifiers to be overridden.   The  capitalization used  will be the 
  859.           first form  appearing in  the file  (which may not necessarily be 
  860.           the one in the pragma).   The pragma  can appear  anywhere in the 
  861.           file  being  formatted  and  affects the formatting of the entire 
  862.           file.  This pragma can  have  multiple  identifiers  separated by 
  863.           commas,  but  it  cannot  continue  over  to a second line.  This 
  864.           pragma does not carry over to subsequent files. 
  865.  
  866.  
  867.  
  868.                                                                          12 
  869.  
  870.  
  871.  
  872.  
  873.  
  874.                              Goddard Space Flight Center 
  875.                              Standard Ada Pretty Printer 
  876.  
  877.  
  878.                pragma Format_Off; 
  879.                pragma Format_On; 
  880.  
  881.           The Format_On and Format_Off pragmas allow portions of  a file to 
  882.           be excluded  from the  automatic indentation and spacing controls 
  883.           that the Pretty Printer performs.   This allows  tables and lists 
  884.           which have  been indented  and spaced  for clarity  to be left in 
  885.           their original clear form.   These  pragmas take  effect at their 
  886.           positions in the file.  The enclosed code will all be adjusted by 
  887.           the same number of spaces as the first line after the pragma. 
  888.  
  889.           Note: Both pragmas in a given pair must  appear at  places in the 
  890.           code  that  have  the  same  indentation  level. (This means, for 
  891.           example, that the pragmas cannot  be  used  to  enclose  only the 
  892.           condition line(s) of an if construct.) 
  893.  
  894.           Creating a Specialized Pretty Printer: 
  895.  
  896.           By setting  the parameters  in the Pretty_Printer_Parameters unit 
  897.           to the  preferred values  and recompiling,  the user  can set the 
  898.           Pretty Printer to the preferred local standard.   If the Pretty_- 
  899.           Print_Format is set to NASA_Standard, the Special settings can be 
  900.           obtained simply by using one pragma statement: 
  901.  
  902.                pragma Form_Set (Special);  
  903.  
  904.           If the  Pretty_Print_Format is  set to Special, the NASA_Standard 
  905.           can still be obtained by: 
  906.  
  907.                pragma Form_Set (NASA_Standard);  
  908.  
  909.  
  910.  
  911.  
  912.  
  913.  
  914.  
  915.  
  916.  
  917.  
  918.  
  919.  
  920.  
  921.  
  922.  
  923.  
  924.  
  925.  
  926.  
  927.                                                                          13 
  928.  
  929.  
  930.  
  931.  
  932.  
  933.                              Goddard Space Flight Center 
  934.                              Standard Ada Pretty Printer 
  935.  
  936.           10.  Error Messages: 
  937.  
  938.           Error messages can appear in several places.  They can  be in the 
  939.           terminal's output  listing or the same output when sent to a file 
  940.           by the batch processing mode or they can appear in  the formatted 
  941.           source code  file.  The error messages sent to the output listing 
  942.           or output file include: 
  943.  
  944.                Parse Error Encountered in Line 20 
  945.  
  946.                  ** this file contains goto_statement ** 
  947.  
  948.                  ** Storage_Error raised ** 
  949.  
  950.                  ** exception raised ** 
  951.  
  952.           When the "parse error"  message  appears  in  the  output listing 
  953.           there  will  be  a  corresponding  error  message in the -PP file 
  954.           (which will not be formatted) at  the designated  line which will 
  955.           look like: 
  956.  
  957.                -- PARSE ERROR => @@^$^@ 
  958.  
  959.           Where  the  thing  after  the  => indicates the unparsable token. 
  960.           Often this error message will appear several times  after a given 
  961.           line that  will not  parse because  the parser  will try to start 
  962.           parsing again with an  unrecognizable piece  of code.   When this 
  963.           happens the  last error  message line  following a  given line of 
  964.           code will be the one that  was  generated  first,  and  the token 
  965.           that is  designated will  be the  one on which the parser failed. 
  966.           Error messages will also appear at the end of any  construct that 
  967.           enclosed the original error. 
  968.  
  969.           The "file  contains" message  is not  actually an error.  It is a 
  970.           flag designating Ada code that does not adhere  to the  Ada Style 
  971.           Guide.   Not all violations of the Ada Style Guide are identified 
  972.           in this utility. (Some simply cannot be checked  and other checks 
  973.           were not attempted.) 
  974.  
  975.           The file  causing a  storage error in a list of files will be the 
  976.           last file processed because  the pointers  for the  data base are 
  977.           controlled  rather  than  recovered.   Therefor, the space is un- 
  978.           usable for any  other  purpose  and  would  only  cause continual 
  979.           storage  errors.    However,  the  totals  report is prepared and 
  980.           printed to a file (after  the  buffers  are  released  by closing 
  981.           the file being processed), but the totals report will not include 
  982.           statistics on the file that caused the storage error. 
  983.  
  984.  
  985.  
  986.                                                                          14 
  987.  
  988.  
  989.  
  990.  
  991.  
  992.                              Goddard Space Flight Center 
  993.                              Standard Ada Pretty Printer 
  994.  
  995.           11.  Limitations and Known Problems: 
  996.  
  997.           Three limitations and known problems are  enumerated in  the fol- 
  998.           lowing paragraphs. 
  999.  
  1000.           One limitation  which will  affect many  people is that the input 
  1001.           source code is limited to 80 columns.  This extension is one very 
  1002.           desirable enhancement for which there simply was not enough time. 
  1003.           Correction can be made by editing the code  and inserting  a line 
  1004.           break  between  any  two  tokens  in  the long line before pretty 
  1005.           printing. 
  1006.  
  1007.           One known problem occurs when the  Pretty Printer  appends to the 
  1008.           end of  a line  of code  from the  following line.  Sometimes the 
  1009.           spacing is not even.  This can be  corrected simply  by rerunning 
  1010.           the Pretty Printer using the -PP file as the input file. 
  1011.  
  1012.           Another known problem occurs when a "begin" is followed by a "--" 
  1013.           which is followed by an end of line  with nothing  but space bet- 
  1014.           ween them.  A parse error is generated because the Pretty Printer 
  1015.           is looking for a  syntactic comment.   This  can be  corrected by 
  1016.           editing the code and either removing the singular "--" or insert- 
  1017.           ing something after it before pretty printing. 
  1018.  
  1019.  
  1020.  
  1021.  
  1022.  
  1023.  
  1024.  
  1025.  
  1026.  
  1027.  
  1028.  
  1029.  
  1030.  
  1031.  
  1032.  
  1033.  
  1034.  
  1035.  
  1036.  
  1037.  
  1038.  
  1039.  
  1040.  
  1041.  
  1042.  
  1043.  
  1044.  
  1045.                                                                          15 
  1046.  
  1047.  
  1048.  
  1049.  
  1050.                                     Appendix          
  1051.  
  1052.           Ada Pretty Printer Code Documentation
  1053.  
  1054.           1.   Introduction to Code
  1055.           2.   Package Tokens and a Description of the Data Structure
  1056.           3.   Scan
  1057.           4.   Parse_Ada
  1058.           5.   Format
  1059.           6.   Print
  1060.           7.   Status_Report
  1061.           8.   Restart
  1062.           9.   Dump
  1063.           10.  Pretty_Print
  1064.           11.  Token
  1065.           12.  Source_Line
  1066.           13.  Page
  1067.           14.  Symbol_Text_Record
  1068.           15.  Symbol_Table_Entry
  1069.           16.  Parse_Tree_Node
  1070.           17.  List_Record
  1071.           18.  Reusable Code
  1072.  
  1073.           Ada Pretty Printer Notification
  1074.  
  1075.  
  1076.  
  1077.  
  1078.  
  1079.  
  1080.  
  1081.  
  1082.  
  1083.  
  1084.  
  1085.  
  1086.  
  1087.  
  1088.  
  1089.  
  1090.  
  1091.  
  1092.  
  1093.  
  1094.  
  1095.  
  1096.  
  1097.  
  1098.  
  1099.  
  1100.  
  1101.  
  1102.  
  1103.  
  1104.                                                                          16
  1105.  
  1106.  
  1107.  
  1108.  
  1109.                                     Appendix
  1110.  
  1111.  
  1112.           1.   Introduction to Code:
  1113.  
  1114.           The Pretty Printer is built around a complex data structure which
  1115.           is declared in package Tokens.   This data  structure is composed
  1116.           of seven interconnected record structures.  These include Source-
  1117.           _Line, Token,  Symbol_Table_Entry,  Parse_Tree_Node,  and several
  1118.           others which  will be  described in  detail in the following sec-
  1119.           tions.   Use of  this data  structure is  available through seven
  1120.           major  routines.    These  routines  are Scan, Parse_Ada, Format,
  1121.           Print, Status_Report,  Restart, and  Dump which  are described in
  1122.           the following  sections.   Several other units are also described
  1123.           which include the main routine, Pretty_Print,  and several routi-
  1124.           nes which could be reusable such as Reserved_Words_Package.
  1125.  
  1126.           ----------------------------------------------------------------
  1127.  
  1128.  
  1129.  
  1130.  
  1131.  
  1132.  
  1133.  
  1134.  
  1135.  
  1136.  
  1137.  
  1138.  
  1139.  
  1140.  
  1141.  
  1142.  
  1143.  
  1144.  
  1145.  
  1146.  
  1147.  
  1148.  
  1149.  
  1150.  
  1151.  
  1152.  
  1153.  
  1154.  
  1155.  
  1156.  
  1157.  
  1158.  
  1159.  
  1160.  
  1161.  
  1162.  
  1163.                                                                          17 
  1164.  
  1165.  
  1166.  
  1167.  
  1168.                                     Appendix
  1169.  
  1170.           2.   Package  Tokens  and  a  General  Description  of  the  Data
  1171.                Structure:
  1172.  
  1173.           As described in the Introduction, the  data structure  in package
  1174.           Tokens is  the heart  of the Pretty Printer.  Package Tokens con-
  1175.           tains more than the data structure.  It contains the objects that
  1176.           serve as  the hooks on which the data structure network hangs and
  1177.           a large number of the subroutines that serve  the data structure.
  1178.  
  1179.           The data  structure is  made up  of records  with access pointers
  1180.           that serve to make the records both self  recursive and intercon-
  1181.           necting. These records are: 
  1182.  
  1183.                record name          accessed by             points into
  1184.                ------------------   --------------------    -----------
  1185.           1.   Token                Token_Pointer           (1) 2 5 6 7
  1186.           2.   Source_Line          Source_Line_Pointer     1 (2)
  1187.           3.   Page                 Page_Pointer
  1188.           4.   Symbol_Text_Record   Symbol_Text_Pointer     3 (4)
  1189.           5.   Symbol_Table_Entry   Symbol_Table_Pointer    1 4 (5) 
  1190.           6.   Parse_Tree_Node      Parse_Tree_Pointer      1 (6)
  1191.           7.   List_Record          List_Pointer            (7)
  1192.  
  1193.           The first  group of objects that provide access to this structure
  1194.           is the group of  objects and  subroutines that  control the freed
  1195.           records.   They are  First_Free_X, Last_Free_X, Blank_X, function
  1196.           New_X, and procedure Free_X where _X is the record name.
  1197.  
  1198.           The next group of objects that  provide access  to this structure
  1199.           is the  group of  objects that  serve as the roots of the tables,
  1200.           tree structures, and cross reference lists.  They  include Start-
  1201.           er (the root for the Source_Line and Token structure), Reserved_-
  1202.           Table (Symbol_Table for reserved words), Table  (Symbol_Table for
  1203.           other tokens  organized by token kind), First_Rule (cross refere-
  1204.           nce for parse rules),  and Parse_Tree  (root of  the Parse Tree).
  1205.           Many of  the cross  reference linkages  are in the records of the
  1206.           data structure.  
  1207.  
  1208.           The next group of objects that  provide access  to this structure
  1209.           is the group of objects that serve as the current position point-
  1210.           ers used in the  utilities.   These include  Current_Line, Last_-
  1211.           Line, Current_Token, Current_Page, Page_Pos, and Last_Rule.  Also
  1212.           Error_In_Code provides an inter-routine flag.
  1213.  
  1214.           Several objects also  appear  in  the  Tokens  package  which are
  1215.           primarily for the parse table generator (which uses the same data
  1216.           structure).   These include  Kind_Of_Scan, Class_Is_Open, Produc-
  1217.           tion, Defn_Count, and Class_Count.
  1218.  
  1219.           The Tokens  package also  includes one other package declaration,
  1220.           the State_Stack_Package.  This package is used only in the Parse-
  1221.           _Ada routine,  but it  is included here because of implementation
  1222.           considerations.
  1223.                                                                          18
  1224.  
  1225.  
  1226.  
  1227.                                     Appendix
  1228.  
  1229.           The Tokens  package declares  two categories  of subroutines, the
  1230.           data structure  utility routines  and the  visible routines.  The
  1231.           utility routines can be accessed only by the visible routines and
  1232.           other utility  routines.   For descriptions of these routines see
  1233.           the descriptions in the documentary comments  with the subroutine
  1234.           declarations.    The  visible  routines, Scan, Parse_Ada, Format,
  1235.           Print, Status_Report, Restart, and  Dump,  are  described  in the
  1236.           following sections.   Two  visible routines are not provided with
  1237.           the rest of this code.  They are  Generate_Tables and  Edit.  The
  1238.           Generate_Tables  code  contains  more  units than the rest of the
  1239.           Pretty Printer code but is not used directly in the  Pretty Prin-
  1240.           ter.   The code  can be  obtained by  contacting NASA.   The Edit
  1241.           routine was  the original  objective of  the development project,
  1242.           but  has  not  been  developed  yet.  Both of these routines have
  1243.           stubs in the delivered code.
  1244.  
  1245.           ----------------------------------------------------------------
  1246.  
  1247.           3.   Scan:
  1248.  
  1249.           This routine performs a lexical scan  of  Ada  source  code  or a
  1250.           properly formatted  syntax file.   The products of this procedure
  1251.           are the source line, token, and symbol table data structures used
  1252.           by all the other routines in this package.
  1253.  
  1254.           This routine  will read the source file and scan through the file
  1255.           one character at a time identifying  the tokens  and creating the
  1256.           symbol text  and symbol  table entries.  The symbol table entries
  1257.           will all be cross referenced during the scan routine.  
  1258.  
  1259.           Some of the more important routines used in  the scan  are Read_-
  1260.           Line, Add_Line, Start_Identifier, Finish_Identifier, Check_Reser-
  1261.           ved,  Start_Number,  Start_Symbol,  Start_String,  Start_Comment,
  1262.           Start_Comment_Word,  Add_New_Token,  Update_Source_Line, Add_To_-
  1263.           Symbol_Table,   Add_Symbol_Text,    Add_Symbol_Table_Entry,   and
  1264.           Assign_Cross_Reference.   The Read_Line  routine is fairly intui-
  1265.           tive but it does contain the call to  Add_Line which  creates the
  1266.           Source_Line data structure.  The Start_XX routines along with the
  1267.           Scan routine itself do  the actual  character by  character iden-
  1268.           tifying of  tokens.  The Add_XX routines build the named parts of
  1269.           the data structure.  And the other routines named serve to inter-
  1270.           connect the data structure.
  1271.  
  1272.           ----------------------------------------------------------------
  1273.  
  1274.           4.   Parse_Ada:
  1275.  
  1276.           This procedure  parses the internal tokens data structure made   
  1277.           by the Scan routine and produces an internal parse table data    
  1278.           structure used  by the  Format, Status_Report, and Dump routines.
  1279.           The parse procedure used is a simple LR parse.  
  1280.  
  1281.                                                                          19
  1282.  
  1283.  
  1284.  
  1285.                                     Appendix
  1286.  
  1287.           The Parse_Ada routine is the only routine using the State_Stack_-
  1288.           Package.   The parse  tables are generated by the Generate_Tables
  1289.           routine which can also be obtained from NASA.  The  action tables
  1290.           are compressed  with the  table position  being determined by the
  1291.           modulus of the table  length and  the conflict  jump being deter-
  1292.           mined by  the multiple  of the  table length  as divided into the
  1293.           uncompressed table position (called  Unique in  the code).   Com-
  1294.           ments  are  handled  by  creating individual parse trees for each
  1295.           comment and attaching them to the first non comment token for the
  1296.           line that  they are  in. (Left  comments are  attached to the EOL
  1297.           token.) This routine also  does some  minimal error  recovery and
  1298.           places error  messages in  the source  line and token data struc-
  1299.           ture.  
  1300.  
  1301.           Some of the more important routines used in Parse_Ada are Assign-
  1302.           _Key_Values,   Push_State_Stack,   Pop_Top_Node,  Attach_Comment,
  1303.           Error_Fix, and Add_Error_Comment.   The Assign_Key_Values routine
  1304.           identifies the individual tokens and gives them keys.  These keys
  1305.           determine the action to be taken  by the  parser.   Every non EOL
  1306.           or EOF token is given a parse node as its initial sub-parse-tree.
  1307.           The Push_State_Stack and Pop_Top_Node  routines enter  and remove
  1308.           the  sub-parse-trees  and  states  from  the  state  stack.   The
  1309.           Attach_Comment routine handles comments as described above (which
  1310.           would not  be necessary if the parser was reused as the front end
  1311.           of a compiler).  To reuse this code as an  incremental parser the
  1312.           final  assignment  to  the  Parse_Tree would simply be changed to
  1313.           whatever parse node was the father of the code being incremental-
  1314.           ly parsed.  The Error_Fix simply takes the sub-parse-trees in the
  1315.           state stack as well as any unidentifiable tokens  that follow and
  1316.           collects them  as sons under a single error node.  The parse con-
  1317.           tinues with the first token it expects to recognize.
  1318.  
  1319.           ----------------------------------------------------------------
  1320.  
  1321.           5.   Format:
  1322.  
  1323.           The Format routine modifies the capitalization, spacing, position
  1324.           of line  breaks and indentation in the source line and token data
  1325.           structure to correspond to the designated  pretty print standard.
  1326.           The  formatting  process  simply  takes the directives which were
  1327.           attached to the parse nodes during parsing and moves them  to the
  1328.           appropriate tokens.   Tt then modifies the data structure accord-
  1329.           ing to the directives and parameter settings.
  1330.  
  1331.           Some of the more  important routines  used in  the Format routine
  1332.           are  Set_Pragma_Parameters, Identify_Parameter, Standardize_Para-
  1333.           meters,   Standardize_Case,   Verify_Syntactic_Comments,   Move_-
  1334.           Actions_To_Tokens,     Select_Pretty_Print_Action,    EOL_Action,
  1335.           Action_# (where # is  the  directive  number), Set_Token_Spacing,
  1336.           Format_Right_Comment, and  Format_Left_Comment.  The Set_Pragma_-
  1337.           Parameters, Identify_Parameter, Standardize_Parameters, and other
  1338.           Set_XX routines  (where XX  is the  name of  a parameter) are all
  1339.  
  1340.                                                                          20
  1341.  
  1342.  
  1343.  
  1344.  
  1345.                                     Appendix
  1346.  
  1347.           associated with the settings of parameters  in the Pretty_Print_-
  1348.           Parameters package.   The  Standardize_Case routine  and its sub-
  1349.           routines modify the capitalization  of  the  various identifiers.
  1350.           (The reserved  words will  always be  in lower case.)  The Move_-
  1351.           Actions_To_Tokens actually moves the  action directives  from the
  1352.           parse tree  where they  are attached  during the parse and attach
  1353.           them to the individual tokens where they act.  The other routines
  1354.           all perform  the action  functions to  format the Source_Line and
  1355.           Token data structure by  adjusting the  location of  line breaks,
  1356.           indentation and token spacing.
  1357.  
  1358.           ---------------------------------------------------------------- 
  1359.  
  1360.           6.   Print:
  1361.  
  1362.           This  procedure  produces  a  formatted source code file from the
  1363.           internal the Source_Line and Token data structure.   The routines
  1364.           are Print  and Print_Token.   The Print routine coordinates which
  1365.           lines are printed, and  the  Print_Token  prints  the  spaces and
  1366.           display text of a token.
  1367.  
  1368.           ----------------------------------------------------------------
  1369.  
  1370.           7.   Status_Report:
  1371.  
  1372.           This routine  produces a  status report on statement counts for a
  1373.           specified file or for the totals  from  a  list  of  files.   The
  1374.           subroutines  are  Calculate_Counts, Sum_Counts, Print_Counts, and
  1375.           Print_Totals.   These  routines  are  the  primary  users  of the
  1376.           Status_Data package.   The statistics are gathered primarily from
  1377.           the cross reference counts of parse  tree node  types.   Some are
  1378.           calculated using  the relationships  of nodes  in the parse tree.
  1379.           The Parse_Keys package  and  the  Syntax.Dat  file  will  be very
  1380.           valuable to  anyone who  wants to modify the selection of statis-
  1381.           tics.
  1382.  
  1383.           ----------------------------------------------------------------
  1384.  
  1385.           8.   Restart:
  1386.  
  1387.           This routine resets the variables of  this package  to their ini-
  1388.           tial state.   The  hooks for  the data structures are cleared and
  1389.           the individual records  are  released  to  their  free  lists for
  1390.           reuse.    Note:  Since  the  data structure is controlled, once a
  1391.           storage error occurs the data structure  is corrupted  and can no
  1392.           longer be properly recovered. 
  1393.  
  1394.           The major subroutines of this routine are Free_All_Symbol_Tables,
  1395.           Free_All_Source_Lines_And_Tokens, Free_Parse_Tree, and the Free_X
  1396.           routines of  the Tokens package (where X is a data record struct-
  1397.           ure).  These routines  traverse the  data structures  and release
  1398.           the records to their various free lists.
  1399.  
  1400.                                                                          21
  1401.  
  1402.  
  1403.  
  1404.                                     Appendix
  1405.  
  1406.           9.   Dump:
  1407.  
  1408.           This routine  will dump  the internal token and parse data struc-
  1409.           tures into files.  This routine and its Dump_XX and Print_XX rou-
  1410.           tines were  written as part of the debug reporting for the Gener-
  1411.           ate_Tables routine, but they are included  here because  they may
  1412.           be helpful  to anyone  wanting a better look into the data struc-
  1413.           ture. They will need to be rewritten slightly for your individual
  1414.           purposes.
  1415.  
  1416.           ---------------------------------------------------------------- 
  1417.  
  1418.           10.  Pretty_Print:
  1419.  
  1420.           The main routine of the Pretty Printer guides the flow of control
  1421.           through the routines discussed above.  The Pretty  Printer opera-
  1422.           tes two main paths, one for single file processing, the other for
  1423.           a list of files.  
  1424.  
  1425.           This routine starts by checking for the presence of a file called
  1426.           Files_In.LST to  determine if  batch processing is in effect.  If
  1427.           it is present and the first  word  is  "batch"  then  the default
  1428.           output is  reset to  the filename indicated.  If the Files_In.LST
  1429.           file is not present then a prompt is sent to  the user  to desig-
  1430.           nate the  file to  be formatted.   If the filename entered by the
  1431.           user is not prefaced by an  "at" sign,  then the  processing path
  1432.           for the  single file  is executed.  Otherwise the processing path
  1433.           for the list of file is executed.  
  1434.  
  1435.  
  1436.  
  1437.  
  1438.  
  1439.  
  1440.  
  1441.  
  1442.  
  1443.  
  1444.  
  1445.  
  1446.  
  1447.  
  1448.  
  1449.  
  1450.  
  1451.  
  1452.  
  1453.  
  1454.  
  1455.  
  1456.  
  1457.  
  1458.                                                                          22
  1459.  
  1460.  
  1461.  
  1462.  
  1463.                                     Appendix
  1464.  
  1465.           11.  Token:
  1466.  
  1467.             type TOKEN_KIND is
  1468.               ( UNKNOWN, RESERVED_WORD, IDENTIFIER, NUMERIC_LITERAL, 
  1469.                 CHARACTER_LITERAL, STRING_LITERAL, COMMENT_WORD, SPECIAL,
  1470.                 OPERATOR, OTHER );
  1471.  
  1472.             type TOKEN_POINTER is access TOKEN;
  1473.  
  1474.             type TOKEN is
  1475.               record
  1476.                 Number             : INTEGER              := 0;
  1477.                 Line               : SOURCE_LINE_POINTER  := null;
  1478.                 Spaces             : INTEGER              := 0;
  1479.                 Column             : INTEGER              := 0;
  1480.                 Next               : TOKEN_POINTER        := null;
  1481.                 Kind               : TOKEN_KIND           := UNKNOWN;
  1482.                 Symbol             : SYMBOL_TABLE_POINTER := null;
  1483.                 Rule               : INTEGER              := 0;
  1484.                 Construct_Position : NATURAL              := 0;
  1485.                 Directive          : NATURAL              := 0;
  1486.                 Dir_List           : LIST_POINTER         := null;
  1487.                 X_Ref_Next         : TOKEN_POINTER        := null;
  1488.                 Parse              : PARSE_TREE_POINTER   := null;
  1489.               end record;
  1490.  
  1491.           This data structure record  is the  focus of  the pretty printer.
  1492.           It  provides  connections  to  every  other data structure either
  1493.           directly or indirectly. (See list  in  Section  2.)    Most Token
  1494.           records are created during the Scan routine.  Others are added by
  1495.           the Format routine.  As they are added to the  data structure the
  1496.           text from  the original  source file that the token represents is
  1497.           placed in the symbol  table with  the appropriate  references and
  1498.           cross references  in the  Token record.  In the Parse_Ada routine
  1499.           each Token record receives a Parse_Tree_Node record as  its indi-
  1500.           vidual connection  to the  parse tree.   At  the beginning of the
  1501.           Format routine the action directives are  collected and  added to
  1502.           the Dir_List  in parse tree order and are acted on in source line
  1503.           order.  The Print routine creates  the formatted  source code for
  1504.           output from  the Token  records.   And the  Restart routine frees
  1505.           them for reuse.
  1506.  
  1507.           The individual components are used as follows:
  1508.  
  1509.           Number : identifies the order of the tokens and is  used only for
  1510.                debug purposes.
  1511.  
  1512.           Line : points to the Source_Line record to which the Token record
  1513.                currently belongs.
  1514.  
  1515.  
  1516.  
  1517.                                                                          23
  1518.  
  1519.  
  1520.  
  1521.  
  1522.                                     Appendix
  1523.  
  1524.           Spaces : designate the number of  spaces in  front of  the Token.
  1525.                This value  is modified  by the  Format routine  to make the
  1526.                code pretty. 
  1527.  
  1528.           Column : designates the position from  the beginning  of the line
  1529.                of code  of the last character of the preceding token in the
  1530.                line.
  1531.  
  1532.           Next : points to the next Token record.
  1533.  
  1534.           Kind : categorizes the token. (See  the Token_Kind  type declara-
  1535.                tion.)  SPECIAL includes EOF, EOL, etc.
  1536.  
  1537.           Symbol :  points to  the Symbol_Table  record which points to the
  1538.                Symbol_Text record which points to the Page and  Position on
  1539.                the  page  containing  the  token's  text string.  This text
  1540.                string has its capitalization modified by the Format routine
  1541.                to make the code pretty. 
  1542.  
  1543.           Rule : is used only in the Generate_Tables routine.
  1544.  
  1545.           Construct_Position : is used only in the Generate_Tables routine.
  1546.  
  1547.           Directive : is used only in the Generate_Tables routine.
  1548.  
  1549.           Dir_List :  points to  the head of the List records which contain
  1550.                the action directives.
  1551.  
  1552.           X_Ref_Next : points to the  next  Token  record  having  the same
  1553.                symbol.
  1554.  
  1555.           Parse :  points to  the Parse_Tree_Node  that is attached to this
  1556.                Token.
  1557.  
  1558.           ----------------------------------------------------------------
  1559.  
  1560.           12.  Source_Line:
  1561.  
  1562.             type SOURCE_LINE_POINTER is access SOURCE_LINE;
  1563.  
  1564.             type SOURCE_LINE is
  1565.               record
  1566.                 Line_No      : INTEGER              := 0;
  1567.                 First_Token  : TOKEN_POINTER        := null;
  1568.                 Last_Token   : TOKEN_POINTER        := null;
  1569.                 Token_Count  : NATURAL              := 0;
  1570.                 Prior        : SOURCE_LINE_POINTER  := null;
  1571.                 Next         : SOURCE_LINE_POINTER  := null;
  1572.               end record;
  1573.  
  1574.           Most of the Source_Line  records are  generated by  the Scan rou-
  1575.  
  1576.                                                                          24
  1577.  
  1578.  
  1579.  
  1580.  
  1581.                                     Appendix
  1582.  
  1583.           tine.   Others are  added by  the Format routine to make the code
  1584.           pretty.  The combination of  the  Source_Line  records  and Token
  1585.           records corresponds very closely to the source code.  
  1586.  
  1587.           The individual components are used as follows:
  1588.  
  1589.           Line_No :  identifies the  order of  the source lines and is used
  1590.                primarily for debug purposes.  The Print routine will accept
  1591.                a range  of line  numbers for  printing.   Note: because the
  1592.                Format  routine  does  not  completely  renumber  the lines,
  1593.                ranges can  get misrepresented  if the  lines are not renum-
  1594.                bered first.  Therefore, if  you  reuse  the  code  to print
  1595.                portions of code by line number be sure to renumber first.
  1596.  
  1597.           First_Token : points to the first Token record in the line.
  1598.  
  1599.           Last_Token : points to the last Token record in the line.
  1600.  
  1601.           Token_Count : indicates the number of Token records in the line.
  1602.  
  1603.           Prior : points to the prior Source_Line record.
  1604.  
  1605.           Next : points to the next Source_Line record both in the Source_-
  1606.                Line structure and in the free list.
  1607.           ----------------------------------------------------------------
  1608.  
  1609.           13.  Page:
  1610.  
  1611.             type PAGE_POINTER is access PAGE;
  1612.  
  1613.             subtype PAGE is
  1614.               STRING (1 .. Page_Size);
  1615.  
  1616.             Page_Pos  : NATURAL  := 0;
  1617.  
  1618.           The Page array is used to hold both a display and a match copy of
  1619.           the  symbol  text.    The  match  copy  is always all lower case.
  1620.           Literals will have only  one copy  since they  are never compared
  1621.           for a  match.   And reserved words have only one copy since their
  1622.           display form and match form are always the same (all lower case).
  1623.           This array is the target of the Source_Text pointers.
  1624.  
  1625.           Since this  is an array the free list is maintained by a separate
  1626.           array of pointers.
  1627.  
  1628.           ----------------------------------------------------------------
  1629.  
  1630.  
  1631.  
  1632.  
  1633.  
  1634.  
  1635.                                                                          25
  1636.  
  1637.  
  1638.  
  1639.  
  1640.                                     Appendix
  1641.  
  1642.           14.  Symbol_Text_Record:
  1643.  
  1644.             type SYMBOL_TEXT_POINTER is access SYMBOL_TEXT_RECORD;
  1645.  
  1646.             type SYMBOL_TEXT_RECORD is
  1647.               record
  1648.                 Page  : PAGE_POINTER         := null;
  1649.                 Pos   : NATURAL              := 0;
  1650.                 Len   : NATURAL              := 0;
  1651.                 Next  : SYMBOL_TEXT_POINTER  := null;
  1652.               end record;
  1653.  
  1654.           The Symbol_Text record designates the Page  and the  position and
  1655.           length of the text on the page.  This record structure is pointed
  1656.           at by the Symbol_Table record.
  1657.  
  1658.           The individual components are used as follows:
  1659.  
  1660.           Page : points to the page containing the text.
  1661.  
  1662.           Pos : references the starting position of the  first character of
  1663.                the text.
  1664.  
  1665.           Len : indicates the number of characters in the text.
  1666.  
  1667.           Next : is used by the free list.
  1668.  
  1669.           ----------------------------------------------------------------
  1670.  
  1671.           15.  Symbol_Table_Entry:
  1672.  
  1673.             type CAP_TYPE is
  1674.               ( NORMAL, ENUMERATION, TYPE_SUBTYPE, SPECIAL );
  1675.  
  1676.             type SYMBOL_TABLE_POINTER is access SYMBOL_TABLE_ENTRY;
  1677.  
  1678.             type SYMBOL_TABLE_ENTRY is
  1679.               record
  1680.                 Key          : NATURAL               := 0;
  1681.                 Match        : SYMBOL_TEXT_POINTER   := null;
  1682.                 Display      : SYMBOL_TEXT_POINTER   := null;
  1683.                 Cap          : CAP_TYPE              := NORMAL;
  1684.                 Prior        : SYMBOL_TABLE_POINTER  := null;
  1685.                 Next         : SYMBOL_TABLE_POINTER  := null;
  1686.                 Lesser       : SYMBOL_TABLE_POINTER  := null;
  1687.                 Greater      : SYMBOL_TABLE_POINTER  := null;
  1688.                 Count        : NATURAL               := 0;
  1689.                 X_Ref_First  : TOKEN_POINTER         := null;
  1690.                 X_Ref_Last   : TOKEN_POINTER         := null;
  1691.               end record;
  1692.  
  1693.  
  1694.                                                                          26
  1695.  
  1696.  
  1697.  
  1698.  
  1699.                                     Appendix
  1700.  
  1701.             type SYMBOL_TABLE_HEADER is
  1702.               record
  1703.                 First  : SYMBOL_TABLE_POINTER  := null;
  1704.                 Head   : SYMBOL_TABLE_POINTER  := null;
  1705.                 Last   : SYMBOL_TABLE_POINTER  := null;
  1706.               end record;
  1707.  
  1708.             type SYMBOL_TABLE_ARRAY is
  1709.               array (TOKEN_KIND)
  1710.                 of SYMBOL_TABLE_HEADER;
  1711.  
  1712.           The Symbol_Table_Entry  record is created by the Scan routine for
  1713.           each unmatched token found in the  source code.   The Symbol_Text
  1714.           records are  created at the same time, and so are the Page entri-
  1715.           es.  When a matching token symbol entry is found  it is  added to
  1716.           the cross reference list of the matched Symbol_Table_Entry.  Each
  1717.           Symbol_Table_Entry is part of  a Symbol_Table  which is organized
  1718.           in two  ways, an alphabetical list and a binary tree.  These both
  1719.           start with a Symbol_Table_Header  which  contains  the  first and
  1720.           last entry  of the  alphabetical list  and the head (root) of the
  1721.           binary tree.  The binary tree is created  by order  of appearance
  1722.           in  the  source  code.  (No  special balancing is done to improve
  1723.           speed.)
  1724.  
  1725.           The individual components are used as follows:
  1726.  
  1727.           Key : is assigned and used in the Parse_Ada routine.   These Keys
  1728.                can be found in the Parse_Keys package. 
  1729.  
  1730.           Match :  points to the Symbol_Text record used for comparisons in
  1731.                the binary search.
  1732.  
  1733.           Display : points to the Symbol_Text  record which  is modified by
  1734.                the Format routine to make the code pretty and which is used
  1735.                by the Print routine.
  1736.  
  1737.           Cap : designates the form of capitalization to be used.  (See the
  1738.                Cap_Type.)   When the Form pragma is used, the Special value
  1739.                is assigned.  Otherwise,  the capitalization  is modified in
  1740.                the  Format  routine  according to the parameters designated
  1741.                for the capitalization type.
  1742.  
  1743.           Prior : points to the prior Symbol_Table_Entry in  the alphabetic
  1744.                list.
  1745.  
  1746.           Next :  points to  the next  Symbol_Table_Entry in the alphabetic
  1747.                list.  This component is also used by the free list.
  1748.  
  1749.           Lesser : points to the  prior  Symbol_Table_Entry  in  the binary
  1750.                tree.
  1751.  
  1752.  
  1753.                                                                          27
  1754.  
  1755.  
  1756.  
  1757.  
  1758.                                     Appendix
  1759.  
  1760.           Greater  :  points  to  the next Symbol_Table_Entry in the binary
  1761.                tree.
  1762.  
  1763.           Count :  indicates the  number of  tokens in  the cross reference
  1764.                list.
  1765.  
  1766.           X_Ref_First :  points to  the first  token in the cross reference
  1767.                list.
  1768.  
  1769.           X_Ref_Last : points to the  last  token  in  the  cross reference
  1770.                list.
  1771.  
  1772.           ----------------------------------------------------------------
  1773.  
  1774.           16.  Parse_Tree_Node:
  1775.  
  1776.             type PARSE_TREE_POINTER is access PARSE_TREE_NODE;
  1777.  
  1778.             type PARSE_TREE_NODE is
  1779.               record
  1780.                 Number     : NATURAL             := 0;
  1781.                 Rule       : NATURAL             := 0;
  1782.                 Rule_Next  : PARSE_TREE_POINTER  := null;
  1783.                 Pp_Dir     : NATURAL             := 0;
  1784.                 Token      : TOKEN_POINTER       := null;
  1785.                 Father     : PARSE_TREE_POINTER  := null;
  1786.                 Brother    : PARSE_TREE_POINTER  := null;
  1787.                 Comment    : PARSE_TREE_POINTER  := null;
  1788.                 Sons       : NATURAL             := 0;
  1789.                 First_Son  : PARSE_TREE_POINTER  := null;
  1790.                 Last_Son   : PARSE_TREE_POINTER  := null;
  1791.               end record;
  1792.  
  1793.  
  1794.           The Parse_Tree_Node record is the second most important member of
  1795.           the data structure.  This record provides the direct link between
  1796.           the Ada  Syntax and the code, and it is the avenue for taking the
  1797.           action directives that are associated with the Syntax and attach-
  1798.           ing them  to the  tokens.  The Parse Tree is a simple tree struc-
  1799.           ture with each node having only one father and either  a token or
  1800.           a sub-parse-tree  as a  subordinate.  The first level of any sub-
  1801.           parse-tree can have zero  to  many  sons.    Each Parse_Tree_Node
  1802.           designates  its  own  immediate  next  Brother node in this first
  1803.           level of sons.  All the brothers will  designate the  same Father
  1804.           node.   The Parse  Tree is created by the parser in the Parse_Ada
  1805.           routine. (The Parse Tree could alternately be created  by select-
  1806.           ing  syntax  structures  in  a  language sensitive editor.  Since
  1807.           this was the originally intended product the Parse_Tables package
  1808.           and  the  related  data  files  already contain the data to build
  1809.           these constructs directly.)
  1810.  
  1811.  
  1812.                                                                          28
  1813.  
  1814.  
  1815.  
  1816.  
  1817.                                     Appendix
  1818.  
  1819.           The individual components are used as follows:
  1820.  
  1821.           Number : indicates the  order of  the Parse_Tree_Nodes.   This is
  1822.                primarily for debug purposes.  
  1823.  
  1824.           Rule :  designates the  Syntax rule  associated with a sub-parse-
  1825.                tree.  This corresponds to the Parse Keys  in the Parse_Keys
  1826.                package and  to the Key in the Token record.  It is assigned
  1827.                as the parser performs its reduce step.  
  1828.  
  1829.           Rule_Next : points  to  the  next  Parse_Tree_Node  in  the cross
  1830.                reference list for the rule indicated.
  1831.  
  1832.           Pp_Dir :  is the action directive associated with the given posi-
  1833.                tion of the father node's rule.   The  values for  this com-
  1834.                ponent are  provided in  the Directives table of the Parse_-
  1835.                Tree package or the associated data file.  
  1836.  
  1837.           Token : points to the Token record that  is associated  with this
  1838.                node.  The Token component will always be null when the node
  1839.                has one or more son nodes.
  1840.  
  1841.           Father : points to the father node of the parse tree.
  1842.  
  1843.           Brother : points to the next  brother  node  of  the  parse tree.
  1844.                This component is also used by the free list.
  1845.  
  1846.           Comment :  points to  a special  sub-parse-tree which  is a right
  1847.                comment.  This will  usually only  be used  when there  is a
  1848.                token record subordinate.
  1849.  
  1850.           Sons : indicates the number of son nodes in the sub_parse_tree.
  1851.  
  1852.           First_Son : points to the first son node of the sub_parse_tree.
  1853.  
  1854.           Last_Son : points to the last son node of the sub_parse_tree.
  1855.  
  1856.           ----------------------------------------------------------------
  1857.  
  1858.           17.  List_Record:
  1859.  
  1860.             type LIST_POINTER is access LIST_RECORD;
  1861.  
  1862.             type LIST_RECORD is
  1863.               record
  1864.                 Ref   : NATURAL       := 0;
  1865.                 Next  : LIST_POINTER  := null;
  1866.               end record;
  1867.  
  1868.           The  last  record  structure  used  in  the data structure of the
  1869.           pretty printer is the List record.  This is simply a list that is
  1870.  
  1871.                                                                          29
  1872.  
  1873.  
  1874.  
  1875.  
  1876.                                     Appendix
  1877.  
  1878.           recursive.   The only  use in the Pretty Printer is for attaching
  1879.           multiple directives  to a  given token.  (It is  used for several
  1880.           other kinds of lists in the Generate_Tables routine.)
  1881.  
  1882.           The individual components are used as follows:
  1883.  
  1884.           Ref : designates the reference value of the action directive.
  1885.  
  1886.           Next :  points to  the next  List record.  This component is also
  1887.                used by the free list.
  1888.  
  1889.           ----------------------------------------------------------------
  1890.           18.  Reusable Code:
  1891.  
  1892.           Not only can the code be used for  readily modifiable  Ada pretty
  1893.           printer, but  with reasonably little modification this code could
  1894.           be used for any  language syntax  by generating  the parse tables
  1895.           using  the  associated  Generate_Tables  routine.   Similarly the
  1896.           code can be used as a basis for development of  a language sensi-
  1897.           tive editor.   Or  it could  even be  used as  the front end of a
  1898.           compiler.
  1899.  
  1900.           Some individual components which  might be  reusable individually
  1901.           include the package Reserved_Words, the procedure Lower_Case, and
  1902.           the procedure Next_Prime.
  1903.  
  1904.  
  1905.  
  1906.  
  1907.  
  1908.  
  1909.  
  1910.  
  1911.  
  1912.  
  1913.  
  1914.  
  1915.  
  1916.  
  1917.  
  1918.  
  1919.  
  1920.  
  1921.  
  1922.  
  1923.  
  1924.  
  1925.  
  1926.  
  1927.  
  1928.  
  1929.  
  1930.                                                                          30
  1931.  
  1932.  
  1933.  
  1934.  
  1935.  
  1936.  
  1937.           The  source  code  and  data  files  for GSFC Ada Standard Pretty 
  1938.           Printer is in the public domain,  but  NASA  does  request  to be 
  1939.           notified of  how many  copies are  made to  encourage funding for 
  1940.           similar development for the  public  domain.    Therefore, please 
  1941.           fill out this page and return it to:  
  1942.             
  1943.                     Ada Pretty Printer Notification  
  1944.                     c/o Ms. Elisabeth Brinker -- Code 522
  1945.                     Data Systems Applications Branch  
  1946.                     Goddard Space Flight Center 
  1947.                     Greenbelt, Maryland 20771-0001  
  1948.             
  1949.           ----------------------------------------------------------------- 
  1950.  
  1951.             
  1952.                     Ada Pretty Printer Notification  
  1953.                          Version 1.1  
  1954.             
  1955.             
  1956.           Name ____________________________________________________________ 
  1957.  
  1958.           Address _________________________________________________________ 
  1959.             
  1960.           _________________________________________________________________ 
  1961.             
  1962.           _________________________________________________________________ 
  1963.             
  1964.             
  1965.             
  1966.           Copies ___________________      Modified Copies _________________ 
  1967.  
  1968.             
  1969.            _  
  1970.           |_|  I would like information regarding any modifications since  
  1971.                version 1.1  
  1972.             
  1973.             
  1974.           Comments ________________________________________________________ 
  1975.             
  1976.           _________________________________________________________________ 
  1977.             
  1978.           _________________________________________________________________ 
  1979.  
  1980.           _________________________________________________________________ 
  1981.             
  1982.           _________________________________________________________________ 
  1983.             
  1984.           _________________________________________________________________ 
  1985.             
  1986.           _________________________________________________________________ 
  1987.             
  1988.           _________________________________________________________________ 
  1989.  
  1990.