syntax.mli 2.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
(* Terminals and nonterminal symbols are strings. Identifiers
   (which are used to refer to a symbol's semantic value) are
   strings. A file name is a string. *)

type terminal =
    string

type nonterminal =
    string 

type symbol =
    string 

type identifier = 
    string 

type filename = 
    string

20
(* A trailer is a source file fragment. *)
21 22

type trailer =
23
    Stretch.t
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50

(* Objective Caml semantic actions are represented as stretches. *)

type action =
    Action.t

type token_associativity = 
    LeftAssoc 
  | RightAssoc
  | NonAssoc
  | UndefinedAssoc

type precedence_level = 
    UndefinedPrecedence 

  (* Items are incomparable when they originate in different files. A
     brand of type [Mark.t] is used to record an item's origin. The
     positions allow locating certain warnings. *)

  | PrecedenceLevel of Mark.t * int * Lexing.position * Lexing.position
                                    
type token_properties =
    {
	       tk_filename      : filename;
	       tk_ocamltype     : Stretch.ocamltype option;
	       tk_position	: Positions.t;
      mutable  tk_associativity : token_associativity;
51
      mutable  tk_precedence    : precedence_level;
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
      mutable  tk_is_declared   : bool; 
    }

type parameter = 
  | ParameterVar of symbol Positions.located
  | ParameterApp of symbol Positions.located * parameters

and parameters = 
    parameter list

type declaration =

    (* Raw Objective Caml code. *)

  | DCode of Stretch.t

    (* Raw Objective Caml functor parameter. *)

  | DParameter of Stretch.ocamltype (* really a stretch *)

    (* Terminal symbol (token) declaration. *)

  | DToken of Stretch.ocamltype option * terminal

    (* Start symbol declaration. *)

  | DStart of nonterminal 

    (* Priority and associativity declaration. *)

  | DTokenProperties of terminal * token_associativity * precedence_level

    (* Type declaration. *)

  | DType of Stretch.ocamltype * parameter

88
(* A [%prec] annotation is optional. A production can carry at most one.
89
   If there is one, it is a symbol name. See [ParserAux]. *)
90 91

type branch_prec_annotation =
92 93
    symbol Positions.located option

94 95 96 97
(* A "production level" is used to solve reduce/reduce conflicts. It reflects
   which production appears first in the grammar. See [ParserAux]. *)

type branch_production_level =
98
  | ProductionLevel of Mark.t * int
99 100

type producer =
101
    identifier Positions.located * parameter
102 103 104 105 106 107

type parameterized_branch =
    { 
      pr_branch_position	   : Positions.t;
      pr_producers		   : producer list;
      pr_action			   : action; 
108
      pr_branch_prec_annotation    : branch_prec_annotation;
109
      pr_branch_production_level   : branch_production_level
110 111 112 113 114 115 116 117 118 119 120 121
    }

type parameterized_rule =
    {
      pr_public_flag	   : bool;
      pr_inline_flag	   : bool;
      pr_nt		   : nonterminal;
      pr_positions	   : Positions.t list;
      pr_parameters	   : symbol list;
      pr_branches	   : parameterized_branch list;
    }