Skip to main content

Ll1Table

Struct Ll1Table 

Source
pub struct Ll1Table {
    pub table: HashMap<(usize, Option<usize>), usize>,
    pub n_nonterms: usize,
    pub n_terms: usize,
}
Expand description

An LL(1) parsing table for a given grammar.

Fields§

§table: HashMap<(usize, Option<usize>), usize>

For each (nonterminal, terminal) pair, the production index to use. The terminal None represents end-of-input.

§n_nonterms: usize

Number of nonterminals.

§n_terms: usize

Number of terminals.

Implementations§

Source§

impl Ll1Table

Source

pub fn new(n_nonterms: usize, n_terms: usize) -> Self

Create an empty LL(1) table.

Source

pub fn set(&mut self, nt: usize, term: Option<usize>, prod: usize)

Set the production for (nonterminal, terminal).

Source

pub fn get(&self, nt: usize, term: Option<usize>) -> Option<usize>

Look up the production for (nonterminal, terminal).

Source

pub fn is_conflict_free(&self) -> bool

Check if the table is conflict-free (no cell has more than one production). Since we use a HashMap, each cell has at most one entry by construction.

Source

pub fn entry_count(&self) -> usize

Count the number of filled table entries.

Source

pub fn build(grammar: &ContextFreeGrammar, sets: &FirstFollowSets<'_>) -> Self

Build an LL(1) table from a grammar and its FIRST/FOLLOW sets.

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> 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, 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.