-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
LR1 items:
Lines 10 to 17 in f368fac
| #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone)] | |
| struct LR1Item { | |
| non_terminal_idx: NonTerminalIdx, | |
| production_idx: ProductionIdx, | |
| cursor: usize, | |
| // None => EOF | |
| lookahead: Option<TerminalIdx>, | |
| } |
LR1 sets:
Lines 80 to 84 in f368fac
| fn compute_lr1_closure<A>( | |
| grammar: &Grammar<A>, | |
| first_table: &FirstTable, | |
| items: FxHashSet<LR1Item>, | |
| ) -> BTreeSet<LR1Item> { |
This representation generates a lot of redundant (duplicate) info in states:
1571: {
[LetExpr -> "let" "(" Binder CommaBinder1_Rev ")" "=" SeqExpr "in" SeqExpr|, "("]
[LetExpr -> "let" "(" Binder CommaBinder1_Rev ")" "=" SeqExpr "in" SeqExpr|, "bool"]
[LetExpr -> "let" "(" Binder CommaBinder1_Rev ")" "=" SeqExpr "in" SeqExpr|, "-"]
[LetExpr -> "let" "(" Binder CommaBinder1_Rev ")" "=" SeqExpr "in" SeqExpr|, "-."]
[LetExpr -> "let" "(" Binder CommaBinder1_Rev ")" "=" SeqExpr "in" SeqExpr|, "+"]
[LetExpr -> "let" "(" Binder CommaBinder1_Rev ")" "=" SeqExpr "in" SeqExpr|, "+."]
[LetExpr -> "let" "(" Binder CommaBinder1_Rev ")" "=" SeqExpr "in" SeqExpr|, "*."]
[LetExpr -> "let" "(" Binder CommaBinder1_Rev ")" "=" SeqExpr "in" SeqExpr|, "/."]
[LetExpr -> "let" "(" Binder CommaBinder1_Rev ")" "=" SeqExpr "in" SeqExpr|, "="]
[LetExpr -> "let" "(" Binder CommaBinder1_Rev ")" "=" SeqExpr "in" SeqExpr|, "<>"]
[LetExpr -> "let" "(" Binder CommaBinder1_Rev ")" "=" SeqExpr "in" SeqExpr|, "<="]
[LetExpr -> "let" "(" Binder CommaBinder1_Rev ")" "=" SeqExpr "in" SeqExpr|, "<"]
[LetExpr -> "let" "(" Binder CommaBinder1_Rev ")" "=" SeqExpr "in" SeqExpr|, ">="]
[LetExpr -> "let" "(" Binder CommaBinder1_Rev ")" "=" SeqExpr "in" SeqExpr|, ">"]
[LetExpr -> "let" "(" Binder CommaBinder1_Rev ")" "=" SeqExpr "in" SeqExpr|, ","]
[LetExpr -> "let" "(" Binder CommaBinder1_Rev ")" "=" SeqExpr "in" SeqExpr|, ";"]
[LetExpr -> "let" "(" Binder CommaBinder1_Rev ")" "=" SeqExpr "in" SeqExpr|, "id"]
[LetExpr -> "let" "(" Binder CommaBinder1_Rev ")" "=" SeqExpr "in" SeqExpr|, "int"]
[LetExpr -> "let" "(" Binder CommaBinder1_Rev ")" "=" SeqExpr "in" SeqExpr|, "float"]
}
All of the items in this state have the same production. We can combine all of these items into a single one with a lookahead set:
struct LR1Item {
non_terminal_idx: NonTerminalIdx,
production_idx: ProductionIdx,
cursor: usize,
lookahead: FxHashSet<TerminalIdx>,
}We can either add one more field for whether EOF is a valid lookahead, or we can assign EOF a TerminalIdx.
See #1 for optimizing terminal sets. (FxHashSet<TerminalIdx> in the code above)
Metadata
Metadata
Assignees
Labels
No labels