-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- bump version to 2.5.0 - add lookahead predefined variable to reduce action - add README about GLR parser - add(parser) %glr syntax - invalid non-terminal now returns InvalidTerminalError, no unreachable - add(core) Parser and Context trait - fix(core) add `allow_conflict` option to grammar builder
- Loading branch information
Showing
32 changed files
with
2,012 additions
and
886 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[package] | ||
name = "glr" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
rusty_lr = { path = "../../rusty_lr", features = ["fxhash"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
pub mod parser; | ||
// pub mod parser_expanded; | ||
|
||
fn main() { | ||
let p = parser::EParser::new(); | ||
let mut c = p.begin(); | ||
|
||
let input = "1+2*3+4"; | ||
for ch in input.chars() { | ||
println!("feed: {}", ch); | ||
match p.feed(&mut c, ch) { | ||
Ok(_) => { | ||
println!("nodes: {}", c.current_nodes.nodes.len()); | ||
} | ||
Err(e) => { | ||
println!("Error: {:?}", e); | ||
break; | ||
} | ||
} | ||
} | ||
println!("feed eof"); | ||
match p.feed(&mut c, '\0') { | ||
Ok(_) => { | ||
println!("nodes: {}", c.current_nodes.nodes.len()); | ||
} | ||
Err(e) => { | ||
println!("Error: {:?}", e); | ||
} | ||
} | ||
|
||
println!("{}", c.accept()); | ||
|
||
// for mut n in c.current_nodes.nodes.into_iter() { | ||
// loop { | ||
// println!("{}", n.state()); | ||
// if let Some(par) = n.parent() { | ||
// n = std::rc::Rc::clone(par); | ||
// } else { | ||
// break; | ||
// } | ||
// } | ||
// println!("---"); | ||
// } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use rusty_lr::lr1; | ||
|
||
lr1! { | ||
%glr; | ||
%tokentype char; | ||
%start E; | ||
%eof '\0'; | ||
|
||
%left [plus star]; | ||
|
||
%token plus '+'; | ||
%token star '*'; | ||
%token zero '0'; | ||
%token one '1'; | ||
%token two '2'; | ||
%token three '3'; | ||
%token four '4'; | ||
%token five '5'; | ||
%token six '6'; | ||
%token seven '7'; | ||
%token eight '8'; | ||
%token nine '9'; | ||
|
||
Digit(char): ch=[zero-nine] { println!("Digit: {}", ch); ch }; | ||
|
||
E(i32) : E plus e2=E { println!("Plus"); E + e2 } | ||
| E star e2=E { println!("Star"); E * e2 } | ||
| Digit { println!("D2E"); Digit as i32 - '0' as i32 } | ||
; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.