Commit 999a4c82 authored by POTTIER Francois's avatar POTTIER Francois
Browse files

A little cleanup.

parent 795f5b53
...@@ -424,7 +424,9 @@ let current fact = ...@@ -424,7 +424,9 @@ let current fact =
1. If [fact.lookahead] is a real terminal symbol [z] (i.e., not [any]), 1. If [fact.lookahead] is a real terminal symbol [z] (i.e., not [any]),
then [z] does not cause an error in the current state [current fact]. then [z] does not cause an error in the current state [current fact].
It would be useless to consider a fact that violates this property; It would be useless to consider a fact that violates this property;
this cannot possibly lead to a successful reduction. this cannot possibly lead to a successful reduction. In practice,
this refinement allows reducing the number of facts that go through
the queue by a factor of two.
2. [fact.lookahead] is [any] iff the current state [current fact] is 2. [fact.lookahead] is [any] iff the current state [current fact] is
solid. This sounds rather reasonable (when a state is entered solid. This sounds rather reasonable (when a state is entered
...@@ -464,11 +466,6 @@ module Q = LowIntegerPriorityQueue ...@@ -464,11 +466,6 @@ module Q = LowIntegerPriorityQueue
let q = let q =
Q.create() Q.create()
(* We never insert into the queue a fact that immediately causes an error,
i.e., a fact such that [causes_an_error (current fact) fact.lookahead]
holds. In practice, this convention allows reducing the number of facts
that go through the queue by a factor of two. *)
(* In principle, there is no need to insert the fact into the queue if [T] (* In principle, there is no need to insert the fact into the queue if [T]
already stores a comparable fact. We could perform this test in [add]. already stores a comparable fact. We could perform this test in [add].
However, a quick experiment suggests that this is not worthwhile. The run However, a quick experiment suggests that this is not worthwhile. The run
...@@ -477,7 +474,7 @@ let q = ...@@ -477,7 +474,7 @@ let q =
significantly. *) significantly. *)
let add fact = let add fact =
(* [fact.lookahead] can be [any] *) (* [fact.lookahead] can be [any], but cannot be [error] *)
assert (non_error fact.lookahead); assert (non_error fact.lookahead);
assert (invariant1 fact); assert (invariant1 fact);
assert (invariant2 fact); assert (invariant2 fact);
...@@ -487,26 +484,26 @@ let add fact = ...@@ -487,26 +484,26 @@ let add fact =
(* Construct the [star] of every state [s]. Initialize the priority queue. *) (* Construct the [star] of every state [s]. Initialize the priority queue. *)
let () = let () =
(* For every state [s]... *)
Lr1.iter (fun s -> Lr1.iter (fun s ->
(* If the trie rooted at [s] is nontrivial...*)
match Trie.star s with match Trie.star s with
| Some trie -> | None ->
(* TEMPORARY weird *) ()
| Some position ->
(* ...then insert an initial fact into the priority queue. *)
(* In order to respect invariants 1 and 2, we must distinguish two
cases. If [s] is solid, then we insert a single fact, whose
lookahead assumption is [any]. Otherwise, we must insert one
initial fact for every terminal symbol [z] that does not cause
an error in state [s]. *)
let word = W.epsilon in
if is_solid s then if is_solid s then
add { add { position; word; lookahead = any }
position = trie;
word = W.epsilon;
lookahead = any
}
else else
foreach_terminal_not_causing_an_error s (fun z -> foreach_terminal_not_causing_an_error s (fun z ->
add { add { position; word; lookahead = z }
position = trie;
word = W.epsilon;
lookahead = z
}
) )
| None ->
()
) )
(* ------------------------------------------------------------------------ *) (* ------------------------------------------------------------------------ *)
...@@ -993,6 +990,7 @@ let () = ...@@ -993,6 +990,7 @@ let () =
(with different lookahead tokens) (report all of them?) (with different lookahead tokens) (report all of them?)
warn if --list-errors is set AND the grammar uses [error] warn if --list-errors is set AND the grammar uses [error]
control verbose output control verbose output
measure the cost of assertions
remove $syntaxerror? remove $syntaxerror?
how do we maintain the list of error messages when the grammar evolves? how do we maintain the list of error messages when the grammar evolves?
implement a naive semi-algorithm that enumerates all input sentences, implement a naive semi-algorithm that enumerates all input sentences,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment