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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
//! rustlr is a parser generator that can create LALR(1) as well as full
//! LR(1) parsers. It is also capable of recognizing operator precedence and
//! associativity declarations that allows the use of some ambiguous grammars.
//! Parsers also have optional access to *external state* information that allows
//! them to recognize more than just context-free languages. Rustlr implements
//! methods of error recovery similar to those found in other LR generators.
//! For error reporting, however, rustlr parsers can run in
//! *training mode*, in which, when a parse error is encountered, the human
//! trainer can augment the parser's state transition table with an
//! appropriate error message. The augmented parser is automatically saved.
//! See the [RuntimeParser::parse_train] function.
//!
//! The parser can generate a full
//! LR(1) parser given the ANSI C grammar in
//! approximately 2-4 seconds on contemporary processors.
//!
//! A [`detailed tutorial`](<https://cs.hofstra.edu/~cscccl/rustlr_project/>)
//! is being prepared that will explain the
//! format of grammars and how to generate and use parsers for several sample
//! languages.
//!
//!
//! Most of the items
//! exported by this crate are only required by the parsers that are generated,
//! and does not form an API. The
//! user needs to provide a grammar and a lexical analyzer that implements
//! the [Lexer] trait. Only a simple lexer that returns individual characters
//! in a string ([charlexer]) is provided.
//! The examples in the tutorial use
//! [basic_lexer](<https://docs.rs/basic_lexer/0.1.2/basic_lexer/>), which was written by
//! the same author but other tokenizers can be easily adopted
//! as well, such as [scanlex](<https://docs.rs/scanlex/0.1.4/scanlex/>).
//!
//! Example
//!
//! Given [this grammar](<https://cs.hofstra.edu/~cscccl/rustlr_project/calculator.grammar>), with file name "calculator.grammar",
//!```\ignore
//! rustlr calculator.grammar lr1
//!```
//! generates a LR(1) parser as
//! [a rust program](<https://cs.hofstra.edu/~cscccl/rustlr_project/calculatorparser.rs>).
//! This program includes a make_parser function, which can be used as in
//!
//!```ignore
//! let mut scanner = Exprscanner::new(&sourcefile);
//! let mut parser1 = make_parser();
//! let absyntree = parser1.parse(&mut scanner);
//!```
//! Here, Exprscanner is a structure that must implement the [Lexer] trait
//! required by the generated parser.
//!
//! A relatively self-contained example, containing both a grammar and code for
//! using its generated parser, is found
//! [here](<https://cs.hofstra.edu/~cscccl/rustlr_project/cpm.grammar>).
//!
//!
//use std::default::Default;
use *;
use *;
pub use *;
use *;
use *;
pub use *;
//mod enhancements;
//pub use enhancements::*;
pub use ;
//pub use enhancements::{ParseValue,ParseResult,Enhanced_Lexer};
pub use ;
////// main function, called from main with command-line args
/// this is the only function that can invoke the parser generator externally,
/// without running rustlr (rustlr::main) directly.
/// It expects to find a file of the form grammarname.grammar.
/// The option argument that can currently only be "lr1" or "lalr". It generates
/// a grammar in a file named grammarnameparser.rs.
///
/// Example:
///
/// Given the grammar called [test1.grammar](<https://cs.hofstra.edu/~cscccl/rustlr_project/test1.grammar>),
///```ignore
/// rustler("test1","lalr");
///```
/// would generate
///[this parser](<https://cs.hofstra.edu/~cscccl/rustlr_project/test1parser.rs>).
/// Since this grammar is small enought (requiring less than 16 LALR states), the
/// generated parser is readable, which is appropriate for testing. For larger
/// grammars, the parser generator switches to a binary representation.
//rustler