Avoid non-deterministic set iteration order when handling conflicts

This commit is contained in:
Max Brunsfeld 2019-08-13 15:57:42 -07:00
parent 56ce4e5d50
commit 5e04daf483
4 changed files with 23 additions and 8 deletions

View file

@ -132,7 +132,7 @@ impl<'a> ParseTableBuilder<'a> {
) -> Result<()> {
let mut terminal_successors = HashMap::new();
let mut non_terminal_successors = HashMap::new();
let mut lookaheads_with_conflicts = HashSet::new();
let mut lookaheads_with_conflicts = TokenSet::new();
for (item, lookaheads) in &item_set.entries {
if let Some(next_symbol) = item.symbol() {
@ -229,7 +229,7 @@ impl<'a> ParseTableBuilder<'a> {
.insert(symbol, next_state_id);
}
for symbol in lookaheads_with_conflicts {
for symbol in lookaheads_with_conflicts.iter() {
self.handle_conflict(
&item_set,
state_id,

View file

@ -149,6 +149,21 @@ impl TokenSet {
vec.set(other.index, true);
}
pub fn remove(&mut self, other: &Symbol) {
let vec = match other.kind {
SymbolType::NonTerminal => panic!("Cannot store non-terminals in a TokenSet"),
SymbolType::Terminal => &mut self.terminal_bits,
SymbolType::External => &mut self.external_bits,
SymbolType::End => {
self.eof = false;
return;
}
};
if other.index < vec.len() {
vec.set(other.index, false);
}
}
pub fn insert_all_terminals(&mut self, other: &TokenSet) -> bool {
let mut result = false;
if other.terminal_bits.len() > self.terminal_bits.len() {

View file

@ -1,11 +1,11 @@
Unresolved conflict for symbol sequence:
'[' identifier • identifier
'[' identifier • ']'
Possible interpretations:
1: '[' (array_repeat1 identifier) • identifier
2: '[' (array_type_repeat1 identifier) • identifier
1: '[' (array_repeat1 identifier) • ']'
2: '[' (array_type_repeat1 identifier) • ']'
Possible resolutions:

View file

@ -1,11 +1,11 @@
Unresolved conflict for symbol sequence:
_program_start '[' identifier • identifier
_program_start '[' identifier • ']'
Possible interpretations:
1: _program_start '[' (array_repeat1 identifier) • identifier
2: _program_start '[' (array_type_repeat1 identifier) • identifier
1: _program_start '[' (array_repeat1 identifier) • ']'
2: _program_start '[' (array_type_repeat1 identifier) • ']'
Possible resolutions: