Skip to main content

FirstFollowSets

Struct FirstFollowSets 

Source
pub struct FirstFollowSets<'a> {
    pub grammar: &'a ContextFreeGrammar,
    pub first: Vec<HashSet<Option<usize>>>,
    pub follow: Vec<HashSet<Option<usize>>>,
}
Expand description

Computes FIRST and FOLLOW sets for a context-free grammar.

Fields§

§grammar: &'a ContextFreeGrammar

The grammar.

§first: Vec<HashSet<Option<usize>>>

FIRST sets: nonterminal index → set of (Option<terminal_index>) None represents ε.

§follow: Vec<HashSet<Option<usize>>>

FOLLOW sets: nonterminal index → set of (Option<terminal_index>) None represents end-of-input ($).

Implementations§

Source§

impl<'a> FirstFollowSets<'a>

Source

pub fn compute(grammar: &'a ContextFreeGrammar) -> Self

Compute FIRST and FOLLOW sets for the grammar.

Source

pub fn get_first(&self, nt: usize) -> &HashSet<Option<usize>>

Get FIRST set for a nonterminal.

Source

pub fn get_follow(&self, nt: usize) -> &HashSet<Option<usize>>

Get FOLLOW set for a nonterminal.

Source

pub fn is_nullable(&self, nt: usize) -> bool

Check if a nonterminal is nullable (ε ∈ FIRST(nt)).

Auto Trait Implementations§

§

impl<'a> Freeze for FirstFollowSets<'a>

§

impl<'a> RefUnwindSafe for FirstFollowSets<'a>

§

impl<'a> Send for FirstFollowSets<'a>

§

impl<'a> Sync for FirstFollowSets<'a>

§

impl<'a> Unpin for FirstFollowSets<'a>

§

impl<'a> UnsafeUnpin for FirstFollowSets<'a>

§

impl<'a> UnwindSafe for FirstFollowSets<'a>

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.