-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasics.rs
38 lines (31 loc) · 1.11 KB
/
basics.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
use liblet::grammar::grammar;
use liblet::production::production;
use liblet::symbol::symbol;
extern crate liblet;
fn main() {
// simple grammar construction by string
// you can specify a grammar by simply writing its productions
// in the form LHS -> RHS | ...
// the start symbol is the non terminal symbol in the first encountered production
// which is, in this case, "Sentence"
let g = grammar(
"
Sentence -> Name | List End
List -> Name | Name , List
Name -> tom | dick | harry
, Name End -> and Name
",
);
// prints out the grammar
// it will show the n, t and s symbols and the productions
println!("{}", g);
// you can also construct symbols from string directly
// check out the documentation to know which kind of strings/chars
// are accepted
let symbol = symbol("MySymbol");
println!("My symbol: {}", symbol);
// you can also construct productions from string directly
// specifying the left and right hand sides
let production = production("A", "B");
println!("My production: {}", production);
}