home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 8 Other / 08-Other.zip / lr.zip / LR.INC < prev    next >
Text File  |  1993-05-15  |  26KB  |  546 lines

  1. /*
  2. ______________________________________________________________________________
  3. LR parser generator data structures
  4. Philip R Brenan,  Transcendental Automation,  1992,  800-FOR-PHIL
  5. ______________________________________________________________________________
  6. */
  7. #ifndef LR_INC
  8. #define LR_INC
  9.  
  10. #include <ctype.h>
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <string.h>
  14. #include "x.inc"
  15. #include "m.inc"
  16. #include "void.inc"
  17. #include "u.inc"
  18. #include "lr_mess.inc"
  19.  
  20. /*
  21. ______________________________________________________________________________
  22. Constants
  23. ______________________________________________________________________________
  24. */
  25. #define lr_chars              256 // Number of characters in the alphabet being parsed
  26. #define lr_chars_1            257 // Above + 1
  27. #define lr_max_key            257 // Maximum keyword length
  28. #define lr_chars_on           '1' // Present
  29. #define lr_chars_off          '2' // Absent
  30. #define lr_reductions          2  // Number of reduction levels
  31.  
  32. #define lr_reduction_primary    0 // Primary reductions
  33. #define lr_reduction_secondary  1 // Secondary reductions
  34.  
  35. #define lr_reduce_normal        0 // Normal reduction
  36. #define lr_reduce_string        1 // String reduction
  37. #define lr_reduce_substr        2 // String component
  38.  
  39. #define lr_repeat_normal        0 // No repetition
  40. #define lr_repeat_start         1 // Start repetition
  41. #define lr_repeat_continue      2 // Continue repetition
  42.  
  43. #define lr_width_nt            16 // Width of a non terminal name
  44. #define lr_width_state          8 // Width of state number
  45.  
  46. #define lr_save_count           1 // More than one area in condensed version
  47. #define lr_save_file            2 // Unable to open save file
  48.  
  49. #define lr_print_states       999 // Maximum number of states to be printed
  50. #define lr_print_width         10 // Step size in parse tree width
  51. #define lr_print_width1       220 // Maximum tree width in printing parse tree
  52. #define lr_print_width2        16 // Maximum width of leaf in printing of parse tree
  53.  
  54. #define lr_char_horiz         196 // Horizontal line
  55. #define lr_char_vert          179 // Vertical line
  56. #define lr_char_cont          195 // T from left side
  57. #define lr_char_end           192 // Lower left corner
  58.  
  59. #define lr_file_code       ".CC"  // Suffix for code file
  60. #define lr_file_error      ".ERR" // Suffix for errors file
  61. #define lr_file_grammar    ".GR"  // Suffix for source grammar
  62. #define lr_file_n          ".N"   // Suffix for non terminal count file
  63. #define lr_file_print      ".LR"  // Suffix for grammar listing file
  64. #define lr_file_parse      ".PRS" // Suffix for parse   listing file
  65. #define lr_file_save       ".LRS" // Suffix for condensed grammar save file
  66. #define lr_file_struct     ".STR" // Suffix for struct files
  67. #define lr_file_text       ".TXT" // Suffix for text input files
  68.  
  69. #define lr_struct_suffix   "_NPS" // LR_PT * structure suffix
  70. #define lr_struct_width       32  // LR_PT * structure name width
  71.  
  72. #define lr_file_chars         257 // Maximum file length name
  73. #define lr_comment_width      80  // Comment width
  74. /*
  75. ______________________________________________________________________________
  76. Structures with forward references
  77. ______________________________________________________________________________
  78. */
  79. struct LR_SPACE;
  80. /*
  81. ______________________________________________________________________________
  82. Structures
  83. ______________________________________________________________________________
  84. */
  85. typedef struct LR
  86.  {
  87. #define lr_LR                                                             \
  88.   char   *name;               /* Name of grammar                        */\
  89.   char   *title;              /* Short description of grammar           */\
  90.   M      *mc;                 /* Memory for condensed version of parser */\
  91.   long    STATES;             /* Number of states                       */\
  92.   long    NTS;                /* Number of non terminals                */\
  93.   long    ACTIONS;            /* Number of actions                      */
  94.  
  95.   lr_LR
  96.   M             *m;           // Memory used by this parse
  97.   struct  LR2   *lr2;         // Condensed version
  98.   struct  LR_S  *start_state; // Start state in the LR(0) automaton
  99.   struct  LR_S  *end_state;   // End   state in the LR(0) automaton
  100.   char          *path;        // Path used for file names
  101.   char          *save_file;   // File to which condensed version was saved
  102.   char          *print_file;  // File to which LR automaton was printed
  103.   char          *struct_file; // File to which LR structures were written
  104.   char          *struct_file_n; // Other file
  105.   char          *code_file;   // Code file
  106.   VOID_PARSE *vp;             // Parse of void language representation of grammar
  107.   VOID_ITEM  *rules;          // Rules      keyword
  108.   VOID_ITEM  *zero;           // Zero       keyword
  109.   VOID_ITEM  *optional;       // Optional   keyword
  110.   VOID_ITEM  *repeat;         // Repeat     keyword
  111.   VOID_ITEM  *choice;         // Choice     keyword
  112.   VOID_ITEM  *ignore;         // Ignore     keyword
  113.   struct VOID_ITEM  *secondary;      // Secondary  keyword
  114.   struct VOID_ITEM  *string;         // String     keyword
  115.   struct VOID_ITEM  *describe;       // Describe   keyword
  116.   struct VOID_ITEM  *save;           // Save       keyword
  117.   struct VOID_ITEM  *print;          // Print      keyword
  118.   struct VOID_ITEM  *printf;         // Print file keyword
  119.   struct VOID_ITEM  *structs;        // Struct     keyword
  120.   struct VOID_ITEM  *code;           // Code       keyword
  121.   char   *grammar;            // Void language representation of grammar
  122.  
  123.   XT      NT;                 // Non terminals LR_NT
  124.   XL      LR_R;               // Rules
  125.   XL      LR_RC;              // Rule components
  126.   XL      STATE;              // States
  127.   XL      LR_A;               // Actions
  128.   XL      LR_At;              // Terminal Actions
  129.  
  130.   long    RS, RCS;            // Number of rules, rule components (rule components only)
  131.   XT      T;                  // Terminals
  132.   long    eS;                 // Number of states removed
  133.   long    eA;                 // Number of actions removed
  134.   long    eAt;                // Number of terminal actions removed
  135.   long    ISTATES;            // Number of identified states
  136.   long    ACTIONS_NT;         // Number of non terminal actions
  137.   long    ACTIONS_T;          // Number of terminal actions
  138.   long    nBUNDLES;           // Number of bundles
  139.   struct  LR_NT *start_nt;    // Start non terminal (first one under RULES keyword)
  140.  
  141.   XT      BUNDLES;            // States by bundle
  142.   struct LR_CONDENSE_COUNT    // Number of duplicates in condensed version
  143.    {long NTs, ts[lr_reductions], REACTIONs;
  144.    } CC;
  145.   struct LR_CONDENSE_SAVE     // Storage occupied by duplicates in condensed version
  146.    {long NTs, ts[lr_reductions], REACTIONs;
  147.    } CS;
  148.  
  149.   long    reuses;             // Size of following area
  150.   long   *reuse;              // Non terminal reuse check
  151.  
  152.   struct  LR_ERRORS           // Errors
  153.    {long  info, severe;       // Number of informational and severe errors detected
  154.     long  name;               // Name keyword missing
  155.     long  title;              // Title keyword missing
  156.     long  rules;              // Rules keyword missing
  157.     long  start_symbol;       // Start symbol missing
  158.     long  parse;              // Parse errors occurred
  159.     long  save;               // Save  errors occurred
  160.     long  terminals;          // Number of invalid terminal specifications (not CHOICE, NOT, MIXED, or SEQUENCE)
  161.     long  non_terminals;      // Number of invalid non terminal specifications (not ZERO, REPEAT, CHOICE, OPTIONAL, SECONDARY)
  162.     long  sec_nts;            // Number of secondary non terminals without terminal RHS
  163.     long  rc_sec_nts;         // Number of rule components specifying secondary for a non terminal whose RHS is non terminal
  164.     long  lhss;               // Number of undefined LHS used on the RHS
  165.     long  rhss;               // Number of defined LHS not used on the RHS
  166.     long  nt_options;         // Invalid non terminal options
  167.     long  optionals;          // Optional non terminals without definitions
  168.     long  secondarys;         // Secondary non terminals without definitions
  169.     long  strings;            // String non terminals without definitions
  170.     long  repeats;            // Repeatable non terminals without definitions
  171.     long  choices;            // Choosable non terminals without definitions
  172.     long  sub_choices;        // First choice non terminal with more than one non termional in each rule
  173.     long  ignores;            // Ignorable non terminals without definitions
  174.     long  zeros;              // Zero non terminals without definitions
  175.     long  str_strs;           // Number of string over string reductions
  176.     long  substr_strs;        // Number of string under substring reductions
  177.     long  normal_substrs;     // Number of substrings under normal reductions
  178.     long  start_substr;       // Start non terminal is a substring reduction
  179.     long  dup_rule_names;     // Number of non unique rule names
  180.     long  zero_productions;   // Number of zero productions
  181.     long  reduces;            // Number of reduce conflicts
  182.     long  mixeds;             // Number of non terminals which mix terminals and non terminals in the same rule
  183.     long  reuses;             // Number of rule components which use a non terminal more than once on the RHS of a rule
  184.     long  no_shift_reduces;   // Number of states containing neither shift nor reduce
  185.  
  186.     struct LR_ERRORS_RS       // Reduce-shift conflict details
  187.      {long   count;           // Number of reduce-shift conflicts
  188.      } reduce_shift;
  189.  
  190.     struct LR_ERRORS_OVERLAP  // Terminal symbol overlap detected
  191.      {long   count;           // Number of errors detected
  192.      } overlap;
  193.  
  194.     struct LR_ERRORS_SECOND   // Secondary, Non secondary conflict
  195.      {long   count;           // Number of errors detected
  196.      } second_conflict;
  197.  
  198.     struct LR_ERRORS_IGNORE   // Ignore, Not ignore conflict
  199.      {long   count;           // Number of errors detected
  200.      } ignore_conflict;
  201.  
  202.     struct LR_ERRORS_ND       // Non deterministic state
  203.      {long   count;           // Number of errors detected
  204.      } non_deter;
  205.  
  206.     struct LR_ERRORS_FINAL    // Unable to locate final state
  207.      {long   count;           // Number of errors detected
  208.      } final;
  209.  
  210.     struct LR_ERRORS_DOUBLED  // Same non terminal transfer to different states
  211.      {long   count;           // Number of errors detected
  212.      } doubled;
  213.    } errors;
  214.   XL              * ERROR;    // Error list
  215.   struct LR_ERROR *PERROR;    // Last error
  216.  } LR;
  217.  
  218. typedef struct  LR_ERROR      // Errors
  219.  {Xl        *error;           // Error list entry
  220.   long      line_number;      // Error line number
  221.   VOID_ITEM *terminal;        // Invalid terminal specification
  222.   VOID_ITEM *non_terminal;    // Invalid non terminal specification
  223.   struct LR_RC *sec_nt;       // Secondary non terminal without terminal RHS
  224.   struct LR_RC *rc_sec_nt;    // Rule components specifying secondary for a non terminal whose RHS is non terminal
  225.   char *lhs;                  // Number of undefined LHS used on the RHS
  226.   char *rhs;                  // Number of defined LHS not used on the RHS
  227.   char *nt_option;            // Invalid non terminal options
  228.   char *optional;             // Optional non terminals without definitions
  229.   char *secondary;            // Secondary non terminals without definitions
  230.   char *string;               // String non terminals without definitions
  231.   char *repeat;               // Repeatable non terminals without definitions
  232.   char *choice;               // Choosable non terminals without definitions
  233.   char *sub_choice;           // First choice non terminal with more than one non termional in each rule
  234.   char *ignore;               // Ignorable non terminals without definitions
  235.   char *zero;                 // Zero non terminals without definitions
  236.   struct LR_RC *str_str;      // Number of string over string reductions
  237.   struct LR_RC *substr_str;   // Number of string under substring reductions
  238.   struct LR_RC *normal_substr;// Number of substrings under normal reductions
  239.   struct LR_R  *dup_rule_name;// Number of non unique rule names
  240.   struct LR_R  *zero_production;// Nunmer of zero productions
  241.   struct LR_S  *reduce1;      // State at which reduce/reduce conflict occurs
  242.   struct LR_R  *reduce2;      // First conflicting reduce-reduce rules
  243.   struct LR_RC *mixed;        // Number of non terminals which mix terminals and non terminals in the same rule
  244.   struct LR_RC *reuse;        // Number of rule components which use a non terminal more than once on the RHS of a rule
  245.   struct LR_S  *no_shift_reduce;// State containing neither shift nor reduce
  246.  
  247.   struct LR_ERROR_RS          // Reduce-shift conflict details
  248.    {struct LR_S *state;       // State with first reduce-shift conflict
  249.     struct LR_A *action;      // Action causing first reduce-shift conflict
  250.     char  *text;              // Text which caused the reduce-shift conflict
  251.    } reduce_shift;
  252.  
  253.   struct LR_ERROR_OVERLAP     // Terminal symbol overlap detected
  254.    {struct LR_RC *rc;         // Rule component causing overlap
  255.     struct LR_S  *s;          // State affected by overlap
  256.    } overlap;
  257.  
  258.   struct LR_ERROR_SECOND      // Secondary, Non secondary conflict
  259.    {struct LR_RC *on, *off;   // Rule component causing conflict
  260.    } second_conflict;
  261.  
  262.   struct LR_ERROR_IGNORE      // Ignore, Not ignore conflict
  263.    {struct LR_RC *on, *off;   // Rule components causing conflict
  264.    } ignore_conflict;
  265.  
  266.   struct LR_ERROR_ND          // Non deterministic state
  267.    {struct LR_RC *rc;         // Rule component causing non determinism
  268.     struct LR_S  *from;       // State at which non determinism was detected
  269.     struct LR_A  *action;     // Existing action
  270.    } non_deter;
  271.  
  272.   struct LR_ERROR_FINAL       // Unable to locate final state
  273.    {struct LR_RC *rc;         // Rule component causing non determinism
  274.     struct LR_S  *from;       // State at which non determinism was detected
  275.    } final;
  276.  
  277.   struct LR_ERROR_DOUBLED     // Same non terminal transfer to different states
  278.    {struct LR_A *action1;     // First  action exiting state with doubled non terminal
  279.     struct LR_A *action2;     // Second action exiting state with doubled non terminal
  280.    } doubled;
  281.  } LR_ERROR;
  282.  
  283. typedef struct LR2            // Condensed LR parser definition
  284.  {lr_LR
  285.   char   *(*separator)(struct LR_SPACE *p, char *c);// Procedure to move over white space
  286.   struct  LR2_S  *start_state;      // Start state in the LR(0) automaton
  287.   struct  LR2_S  *end_state;        // End   state in the LR(0) automaton
  288.   long    Ss, As, Ats, Rs, RCs, NTs;// Objects count by vector
  289.   struct  LR2_S  *S;                // States  vector
  290.   struct  LR2_A  *A;                // Actions vector
  291.   struct  LR2_At *At;               // Terminal actions vector
  292.   struct  LR2_R  *R;                // Rules vector
  293.   struct  LR2_RC *RC;               // Rule components vector
  294.   struct  LR2_NT *NT;               // Non terminals vector
  295.  } LR2;
  296.  
  297. typedef struct LR_NT        // Non terminal
  298.  {
  299. #define lr_NT                                                \
  300.   char   *name;             /* Non terminal symbol name    */\
  301.   char   *describe;         /* Description of non terminal */\
  302.   long    nts;              /* Non terminal number         */\
  303.   long    reduce_action;    /* lr_reduce_* constants       */
  304.  
  305.   lr_NT
  306.   Xt      nt;               // Non terminal tree from LR
  307.   XL      R;                // Rules of which this non terminal is the LHS
  308.   long    refs;             // Number of references to this rule
  309.  
  310.   unsigned zero      : 1;   // Repeat zero or more times
  311.   unsigned repeat    : 1;   // Repeat one or more times
  312.   unsigned choice    : 1;   // Choose one or more
  313.   unsigned optional  : 1;   // Optional non terminal
  314.   unsigned ignore    : 1;   // Do not index this non terminal in the parse tree
  315.   unsigned secondary : 1;   // Secondary non terminal
  316.   unsigned string    : 1;   // String options
  317.   unsigned write     : 1;   // Writable NT
  318.  
  319.   struct  LR_NT *set_substr;// Non terminal which set this non terminal to substring reduction
  320.   long    rc_nts, rc_ts;    // Number of rule component non terminals and terminals
  321.   XT      rule;             // Rule names tree
  322.   long    line_number;      // Source line number
  323.  } LR_NT;
  324.  
  325. typedef    struct LR2_NT    // Condensed non terminal description
  326.  {lr_NT
  327.  } LR2_NT;
  328.  
  329. typedef    struct LR_T  // Terminal symbol
  330.  {char    *value;       // Possible character values of this terminal symbol
  331.   struct   LR_TS  *ts;  // Terminal symbol from which it was derived
  332.   long     position;    // Position within terminal symbol (SEQUENCE option)
  333.  } LR_T;
  334.  
  335.  
  336. typedef    struct LR_TS // Terminal symbol text
  337.  {unsigned sequence : 1;
  338.   unsigned choice   : 1;
  339.   unsigned not      : 1;
  340.   unsigned mixed    : 1;
  341.   char    *value;       // Text associated with this terminal symbol
  342.   VOID_ITEM *v;         // Void language item from which it was derived
  343.  } LR_TS;
  344.  
  345. typedef    struct LR_R  // Rule
  346.  {
  347. #define lr_R                                   \
  348.   char    *rule_name;   /* Rule name         */\
  349.   long     nt;          /* Non terminal count*/
  350.  
  351.   lr_R
  352.   Xl       lr_r;        // Rules in LR
  353.   long     rs;          // Rule number
  354.   long     t;           // Terminal count
  355.   XL       RC;          // Rule components
  356.   Xl       r;           // Rule list
  357.   long     line_number; // Source line number
  358.  } LR_R;
  359.  
  360. typedef    struct LR2_R // Condensed rule
  361.  {lr_R
  362.  } LR2_R;
  363.  
  364. typedef    struct LR_RC // Rule component
  365.  {
  366. #define lr_RC                                                      \
  367.   unsigned choice:1;    /* Local version of non terminal options */\
  368.   unsigned ignore:1;    /* Local version of non terminal options */
  369.  
  370.   lr_RC
  371.   unsigned zero:1;      // Local version of non terminal options
  372.   unsigned repeat:1;    // Local version of non terminal options
  373.   unsigned optional:1;  // Local version of non terminal options
  374.   unsigned secondary:1; // Local version of non terminal options
  375.   LR_NT   *nt;          // Non terminal symbol
  376.   Xl       lr_rc;       // Rule components in LR
  377.   long     rcs;         // Rule component number
  378.   LR_T    *t;           // Terminal symbol
  379.   struct   LR_A *action;// Action associated with this rule component
  380.   Xl       rc;          // Rule component list
  381.   long     line_number;      // Source line number
  382.  } LR_RC;
  383.  
  384.  
  385. typedef    struct LR2_RC    // Condensed Rule component
  386.  {lr_RC
  387.   LR2_NT  *nt;              // Non terminal symbol
  388.  } LR2_RC;
  389.  
  390. typedef    struct LR_S      // State in the LR(0) automaton
  391.  {
  392. #define lr_S                                            \
  393.   long     states;           /* State number          */\
  394.   LR_R    *reduce;           /* Reduce by this rule   */
  395.  
  396.   lr_S
  397.   XT      *NT;               /* Non terminal actions  */
  398.   XT      *t[lr_reductions]; /* Terminal actions tree */
  399.   XT      *REACTION;         /* Reduction actions     */
  400.   Xl       state;            // States list
  401.   XT       BUNDLE;           // Bundle elements from this state by rule component number
  402.   char    *expanded;         // Non terminals already expanded
  403.   struct   LR_S *identify;   // First state with same bundle
  404.   XV      *rc_expanded;      // Vector of expanded rule components
  405.   unsigned complete:1;       // Expansion of this state has been completed
  406.   unsigned required:1;       // State can be reached from start state
  407.   unsigned error:1;          // State needs to be printed to help resolve errors
  408.  } LR_S;
  409.  
  410. typedef    struct LR2_S      // Condensed state
  411.  {lr_S
  412.   XV      *NT;               /* Non terminal actions  */
  413.   XV      *t[lr_reductions]; /* Terminal actions tree */
  414.   XV      *REACTION;         /* Reduction actions     */
  415.  } LR2_S;
  416.  
  417. typedef    struct LR_A       // Action from a state
  418.  {
  419. #define lr_A                                                           \
  420.   char    *k;           /* Reduction state number - key              */\
  421.   unsigned push:1;      /* Number of pushes after a reduction        */\
  422.   unsigned repeat:2;    /* Repeat status                             */
  423.  
  424.   lr_A
  425.   unsigned required:1;  // Action can be reached from start state
  426.   LR_RC   *rc;          // Rule component used to create this action
  427.   LR_S    *to;          // To state
  428.   Xl       lr_a;        // Actions in LR
  429.   LR_S    *from;        // From states
  430.   Xt       action;      // Non terminal action tree in LR_S
  431.   long     actions;     // Action number
  432.  } LR_A;
  433.  
  434. typedef    struct LR2_A // Condensed action
  435.  {lr_A
  436.   LR2_RC  *rc;          // Rule component used to create this action
  437.   LR2_S   *to;          // To state
  438.  } LR2_A;
  439.  
  440. typedef    struct LR_At // Terminal action
  441.  {
  442. #define lr_At                                                          \
  443.   char    *k;           /* Transition character                      */
  444.  
  445.   lr_At
  446.   LR_S    *to;          // To state
  447.   LR_A    *action;      // Action
  448.   Xl       lr_at;       // Actions in LR
  449.   Xt       t;           // Transition index
  450.   unsigned required:1;  // Terminal action required
  451.  } LR_At;
  452.  
  453. typedef    struct LR2_At// Condensed terminal action
  454.  {lr_At
  455.   LR2_S   *to;          // To state
  456.  } LR2_At;
  457.  
  458. typedef    struct LR_B  // Rule component bundle.
  459.  {LR_A    *action;      // Action generated by this bundle element
  460.   LR_A    *reduce;      // Action used to reduce this bundle element
  461.   LR_RC   *rc;          // Rule component generating this bundle element
  462.   Xt       bundle;      // State bundle element, keyed by associated rule component number
  463.   struct   LR_B *n, *p; // Next and previous bundle elements
  464.  } LR_B;
  465.  
  466. typedef struct LR_PT    // Parse tree element
  467.  {char   *t;            // Terminal text
  468.   long    chars, lines; // Amount of spacing between items
  469.   LR2_RC *rc;           // Rule component used to perform reduction
  470.   char   *k;            // Key - parse tree node name
  471.   Xl      Pl;           // Arrival order
  472.   XL      PL;           // Arrival order list
  473.  } LR_PT;
  474.  
  475. typedef struct LR_PS    // Parse stack element
  476.  {LR2_S  *state;        // State
  477.   LR_PT  *pt;           // Parse tree element
  478.   char   *c;            // Character at which this parse stack entry was created
  479.  } LR_PS;
  480.  
  481. typedef struct LR_SPACE // Spacing between items
  482.  {long  chars, lines;   // Intervening characters and new lines
  483.  } LR_SPACE;
  484.  
  485. typedef struct LR_P     // Parse results
  486.  {LR2    *lr;           // LR parser definition
  487.   LR_PT  *parse_tree;   // Parse tree
  488.   M      *m;            // Memory used by the parse
  489.   XT      T;            // Terminals found in the parsed text
  490.   char   *text;         // Text to be parsed
  491.   char   *path;         // Path to be used for file names
  492.   char   *parse;        // File on which parse were printed
  493.   char   *error;        // File on which errors were printed
  494.   long    stack_size;   // Stack size
  495.   long    pts;          // Number of parse tree elements
  496.   LR_SPACE  space;      // Recorded space
  497.   LR_SPACE  space2;     // Unrecorded space
  498.   LR_PS (*stack)[];     // Parse stack
  499.   M      *sm;           // Memory for stack
  500.   LR_PS  *base,         // Base of stack
  501.          *current,      // Current position in stack
  502.          *top;          // Top of stack
  503.   long    errors;       // Error count
  504.   LR2_S  *error_state;  // State in which error was detected
  505.   char   *error_text;   // Position in text at which error was detected
  506.   XT      EXPECTED;     // Expected non terminals at error
  507.   char   *next;         // Next characters
  508.   XV     *V;            // Linearized access to parse tree
  509.  } LR_P;
  510.  
  511. typedef struct LR_RCN   // Parse results
  512.  {LR_RC  *rc;           // Rule component
  513.   struct LR_RCN *next;  // Next rule component in this chain
  514.   long   in;            // In circuit
  515.  } LR_RCN;
  516. /*
  517. ______________________________________________________________________________
  518. Procedures
  519. ______________________________________________________________________________
  520. */
  521. void   lr2_free             (LR2  *lr);
  522. int    lr2_open             (LR2 **lr, char *ds);
  523. LR2   *lr_condense          (LR   *lr);
  524. void   lr_expected          (LR_P *p);
  525. void   lr_free              (LR   *lr);
  526. XV    *lr_linearize_tree    (LR_P *P);
  527. long   lr_locate_string     (LR_P *p,  LR2_S **S, char  **C,   long r);
  528. void   lr_open              (char *NAME, char *grammar, LR **Lr);
  529. void   lr_parse_free        (LR_P *p);
  530. void   lr_parse_open        (LR_P **P, LR2  *lr,  char  *text, char *path, long stack_size);
  531. void   lr_print             (LR   *lr);
  532. void   lr_print_error_text  (FILE *f,  char *c, char *e);
  533. void   lr_print_parse       (LR_P *p);
  534. void   lr_print_parse_tree  (LR_P *p,  LR_PT *pt, FILE *f);
  535. void   lr_print_stack       (LR_P *p);
  536. void   lr_print_state       (LR   *lr, LR_S  *S,  FILE *f);
  537. void   lr_print_terminals   (          LR_PT *P,  FILE *f);
  538. void   lr_reduce            (LR_P *p,  LR2_S **s, char **Sc, char **c);
  539. long   lr_reduce_search     (LR_P *p,  LR2_S *S,  char  *C,  long   i);
  540. void   lr_reduce_state      (LR   *lr, LR_S  *S,  LR_A  *A,  LR_S  *C, LR_S *c, char *text, long l);
  541. int    lr_reduct            (void);
  542. void   lr_relocate          (LR2  *lr, long r);
  543. char  *lr_separator         (LR_SPACE *p, char *c);
  544. void   lr_test              (char *g, char *t);
  545.  
  546. #endif