Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
menhir
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
10
Issues
10
List
Boards
Labels
Milestones
Merge Requests
3
Merge Requests
3
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Container Registry
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
POTTIER Francois
menhir
Commits
79c2b979
Commit
79c2b979
authored
Mar 20, 2017
by
POTTIER Francois
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removed fix.patch.
parent
f03ba64a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
0 additions
and
138 deletions
+0
-138
attic/fix.patch
attic/fix.patch
+0
-138
No files found.
attic/fix.patch
deleted
100644 → 0
View file @
f03ba64a
Index: grammar.ml
===================================================================
--- grammar.ml (revision 128)
+++ grammar.ml (working copy)
@@ -273,6 +273,15 @@
)
)
+ type property =
+ t
+
+ let bottom =
+ empty
+
+ let is_maximal _ =
+ false
+
end
(* Maps over terminals. *)
@@ -787,18 +796,60 @@
);
property, symbol_has_property
-let () =
+let nonempty =
let nonempty, _ = compute true in
for nt = Nonterminal.start to Nonterminal.n - 1 do
if not nonempty.(nt) then
Error.warningN
(Nonterminal.positions nt)
(Printf.sprintf "%s generates the empty language." (Nonterminal.print false nt))
- done
+ done;
+ nonempty
let (nullable : bool array), (nullable_symbol : Symbol.t -> bool) =
compute false
+let rhs basecase nt get =
+ (* disjunction over all productions for this nonterminal *)
+ Production.foldnt nt false (fun prod accu ->
+ accu ||
+ let rhs = Production.rhs prod in
+ (* conjunction over all symbols in the right-hand side *)
+ Array.fold_left (fun accu symbol ->
+ accu && match symbol with
+ | Symbol.T _ ->
+ basecase
+ | Symbol.N nt ->
+ get nt
+ ) true rhs
+ )
+
+module NONEMPTY =
+ Fix.Make
+ (Maps.PersistentMapsToImperativeMaps(NonterminalMap))
+ (Boolean)
+ (struct
+ type variable = Nonterminal.t
+ type property = bool
+ let rhs = rhs true
+ end)
+
+module NULLABLE =
+ Fix.Make
+ (Maps.PersistentMapsToImperativeMaps(NonterminalMap))
+ (Boolean)
+ (struct
+ type variable = Nonterminal.t
+ type property = bool
+ let rhs = rhs false
+ end)
+
+let () =
+ for nt = Nonterminal.start to Nonterminal.n - 1 do
+ assert (nonempty.(nt) = NONEMPTY.get nt);
+ assert (nullable.(nt) = NULLABLE.get nt)
+ done
+
(* ------------------------------------------------------------------------ *)
(* Compute FIRST sets. *)
@@ -840,6 +891,54 @@
TerminalSet.compare original updated <> 0
)
+module FIRST =
+ Fix.Make
+ (Maps.PersistentMapsToImperativeMaps(NonterminalMap))
+ (TerminalSet)
+ (struct
+ type variable = Nonterminal.t
+ type property = TerminalSet.t
+
+ let rhs nt first =
+
+ let first_symbol = function
+ | Symbol.T tok ->
+ TerminalSet.singleton tok
+ | Symbol.N nt ->
+ first nt
+ in
+
+ let nullable_first_rhs (rhs : Symbol.t array) (i : int) : bool * TerminalSet.t =
+ let length = Array.length rhs in
+ assert (i <= length);
+ let rec loop i toks =
+ if i = length then
+ true, toks
+ else
+ let symbol = rhs.(i) in
+ let toks = TerminalSet.union (first_symbol symbol) toks in
+ if nullable_symbol symbol then
+ loop (i+1) toks
+ else
+ false, toks
+ in
+ loop i TerminalSet.empty
+ in
+
+ (* union over all productions for this nonterminal *)
+ Production.foldnt nt TerminalSet.empty (fun prod accu ->
+ let rhs = Production.rhs prod in
+ let _, toks = nullable_first_rhs rhs 0 in
+ TerminalSet.union toks accu
+ )
+
+ end)
+
+let () =
+ for nt = Nonterminal.start to Nonterminal.n - 1 do
+ assert (TerminalSet.equal first.(nt) (FIRST.get nt))
+ done
+
(* ------------------------------------------------------------------------ *)
(* Dump the analysis results. *)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment