~ubuntu-branches/ubuntu/quantal/menhir/quantal

« back to all changes in this revision

Viewing changes to src/grammar.ml

  • Committer: Package Import Robot
  • Author(s): Mehdi Dogguy
  • Date: 2012-01-23 20:50:25 UTC
  • mfrom: (1.1.8) (2.1.7 sid)
  • Revision ID: package-import@ubuntu.com-20120123205025-nd325ikf9gmqe1v7
Tags: 20120123.dfsg-1
* New upstream release
  - fixes http://caml.inria.fr/mantis/view.php?id=5462

Show diffs side-by-side

added added

removed removed

Lines of Context:
62
62
        | UndefinedPrecedence ->
63
63
            ()
64
64
        | PrecedenceLevel (_, _, pos1, pos2) ->
65
 
            Error.warning2 pos1 pos2
 
65
            Error.grammar_warning (Positions.two pos1 pos2)
66
66
              (Printf.sprintf "the precedence level assigned to %s is never useful." id)
67
67
    ) Front.grammar.tokens
68
68
 
126
126
  let map f =
127
127
    Misc.mapi n f
128
128
 
 
129
  let iterx f =
 
130
    for nt = start to n - 1 do
 
131
      f nt
 
132
    done
 
133
 
129
134
  let foldx f accu =
130
135
    Misc.foldij start n f accu
131
136
 
178
183
    in
179
184
    match tokens with
180
185
    | [] ->
181
 
        Error.error "no tokens have been declared."
 
186
        Error.error [] "no tokens have been declared."
182
187
    | _ ->
183
188
        Misc.index ("error" :: tokens @ [ "#" ])
184
189
 
623
628
        | None ->
624
629
            ()
625
630
        | Some id ->
626
 
            Error.warningp id "this %prec declaration is never useful."
 
631
            Error.grammar_warning [Positions.position id] "this %prec declaration is never useful."
627
632
    )
628
633
 
629
634
  (* Determining the precedence level of a production. If no %prec
805
810
  let nonempty, _ = compute true in
806
811
  for nt = Nonterminal.start to Nonterminal.n - 1 do
807
812
    if not nonempty.(nt) then
808
 
      Error.warningN
 
813
      Error.grammar_warning
809
814
        (Nonterminal.positions nt)
810
815
        (Printf.sprintf "%s generates the empty language." (Nonterminal.print false nt))
811
816
  done
875
880
  Time.tick "Analysis of the grammar"
876
881
 
877
882
(* ------------------------------------------------------------------------ *)
878
 
(* Compute FOLLOW sets. Unnecessary for us, but requested by a user. *)
 
883
(* Compute FOLLOW sets. Unnecessary for us, but requested by a user. Also,
 
884
   this is useful for the SLR(1) test. Thus, we perform this analysis only
 
885
   on demand. *)
879
886
 
880
 
let () =
881
 
  Error.logG 2 (fun f ->
 
887
let follow : TerminalSet.t array Lazy.t =
 
888
  lazy (
882
889
 
883
890
    let follow =
884
891
      Array.make Nonterminal.n TerminalSet.empty
927
934
      TerminalSet.compare original updated <> 0
928
935
    );
929
936
 
 
937
    follow
 
938
 
 
939
  )
 
940
 
 
941
(* Define an accessor that triggers the computation of the FOLLOW sets
 
942
   if it has not been performed already. *)
 
943
 
 
944
let follow nt =
 
945
  (Lazy.force follow).(nt)
 
946
 
 
947
(* At log level 2, display the FOLLOW sets. *)
 
948
 
 
949
let () =
 
950
  Error.logG 2 (fun f ->
930
951
    for nt = 0 to Nonterminal.n - 1 do
931
952
      Printf.fprintf f "follow(%s) = %s\n"
932
953
        (Nonterminal.print false nt)
933
 
        (TerminalSet.print follow.(nt))
 
954
        (TerminalSet.print (follow nt))
934
955
    done
935
 
 
936
956
  )
937
957
 
938
958
(* ------------------------------------------------------------------------ *)
1000
1020
  let explain_first_rhs (tok : Terminal.t) (rhs : Symbol.t array) (i : int) =
1001
1021
    convert (explain tok rhs i)
1002
1022
 
 
1023
  let follow = follow
 
1024
 
1003
1025
end
1004
1026
 
1005
1027
(* ------------------------------------------------------------------------ *)