FixedSymTable

Struct FixedSymTable 

Source
pub struct FixedSymTable { /* private fields */ }
Expand description

Stores the names of the terminal and nonterminal symbols used by a parser.

Terminals are defined in the lexicon. They have two parts to their name:

  • the identifier in the lexicon
  • the source string they represent (optional)

For example:

Plus : '+';
...
ID    : [a-zA-Z][a-zA-Z_0-9]*;

If Arrow’s token ID is 0 and ID’s is 24,

t[0] = ("Plus".to_string(), Some("+".to_string()));
t[24] = ("ID".to_string(), None);

Nonterminals are defined in the grammar, and possibly completed by new ones when the rules are adapted to the target parser. For example, recursive rules are transformed for LL(1) parsers, which usually adds extra rules.

expr: expr Plus term | term;

If expr is 0 and term is 1,

nt[0] = "expr".to_string();
nt[1] = "term".to_string();
nt[2] = "expr_1".to_string(); // generated when removing the left recursion

Implementations§

Source§

impl FixedSymTable

Source

pub fn new(t: Vec<(String, Option<String>)>, nt: Vec<String>) -> Self

Source

pub fn get_terminals(&self) -> impl Iterator<Item = &(String, Option<String>)>

Source

pub fn get_num_t(&self) -> usize

Source

pub fn get_nonterminals(&self) -> impl Iterator<Item = &String>

Source

pub fn get_num_nt(&self) -> usize

Trait Implementations§

Source§

impl Clone for FixedSymTable

Source§

fn clone(&self) -> FixedSymTable

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FixedSymTable

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl SymInfoTable for FixedSymTable

Source§

fn is_token_data(&self, token: TokenId) -> bool

Does Symbol::T(token) hold lexer string data? Read more
Source§

fn is_symbol_t_data(&self, symbol: &Symbol) -> bool

Is symbol a terminal holding lexer string data? Read more
Source§

fn is_symbol_t_fixed(&self, symbol: &Symbol) -> bool

Source§

fn get_t_str(&self, token: TokenId) -> String

Source§

fn get_t_name(&self, token: TokenId) -> String

Source§

fn get_nt_name(&self, var: VarId) -> String

Source§

fn get_name(&self, symbol: &Symbol) -> String

Gets the symbol’s name: the nonterminal identifier, the terminal identifier, or “ε”, “$”, …
Source§

fn get_str(&self, symbol: &Symbol) -> String

Gets the symbol’s representation string: the nonterminal identifier, the terminal string value (if it exists), or “ε”, “$”, …
Source§

fn get_name_quote(&self, symbol: &Symbol) -> String

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.