Formal languages Flashcards

1
Q

PDA

A

We want to find other representation of a context free language in order to solve the membership problem efficiently.

The problem is that with context free languages if they are complex, the tools become less and less efficient, some languages aren’t even feasible to manipulate.

Pushdown automaton: finite state automaton with stack memory structure:

{Q, Σ, Γ, 𝛿, q0, Z0, F}

  • Q: finite (non-𝛆) set of states
  • Σ: alphabet of input symbols
  • Γ: alphabet of stack symbols (the two alphabet could be overlapped, fully, partially or none at all)
  • 𝛿: transition function
    • different domain compared to the NFA definition
    • 𝛿: Q x (Σ ∪ {𝛆}) x Γ → 𝒫({(p, 𝛾) | p ∈ Q; 𝛾 ∈ Γ*})
      • p is the new state
      • 𝛾: 0 or more symbols are pushed to the stack
  • q0: start state (q0 ∈ Q)
  • Z0: start stack symbol (Z0 ∈ Γ)
  • F: set of final states (F ⊆ Q)

A language is accepted by a final state by the PDA.

A language is accepted by empty stack.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

NFA

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Equations tricks

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Context-free languages venn diagram

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

LL(1) grammars

A

A grammar is said to be LL(1) if its predictive parsing table has no multily-defined entries:

  • whenever A → 𝛂 | β then
    • First(𝛂) ⋂ First(β) = ∅
    • at most one of 𝛂 and β is nullable
    • if 𝛂 is nullable then First(β) ⋂ Follow(A) = ∅

No ambiguos or left-recursive grammar can be LL(1).

LL(1) parser:

  • scans the input from left to right (L)
  • constructs a leftmost derivation (L)
  • uses 1 lookahead input symbols in making parsing decisions.

The class of languages that can be parsed with LL(1) parsers a proper subset off the deterministic CFL’s.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

SA: left recursive grammars

A
  • a production like A → A 𝛂 is called left-recursive
  • a grammar is left recursive if it can generate a derivation A => *A 𝛂
  • a left-recursive gramma can cause a top-down parer to go into an infinite loop

Replacing left-recursive productions:

A → A 𝛂 | β ===

  • A → β R
  • R → 𝛂 R | 𝛆
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

SLR

A

SLR parsing tables for the same languages are much smaller respect to LR(1) parsing tables (several hundred states) but can contain conflicts.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

LR

A
  • LR(0) parser
    • scans the input from left to right (L)
    • constructs a rightmost derivation in reverse (R)
    • uses 0 lookahead input symbols in making parsing decisions
    • parsable langagues are a subset of deterministc CFL’s
      • LR(1) parser
    • scans the input from left to right (L)
    • constructs a rightmost derivation in reverse (R)
    • uses 1 lookahead symbols in making parsing decisions
    • parsable languages are exactly the calss of deterministic CFL’s
    • parsing tables can be very large (several thousand states) for grammars generating common programming languages
  • A grammar is LR(0) if the table generated by lr0Table(G) doesn’t include conflicts
    • non-ambiguos
  • A grammar is LR(1) if the table generated by lr1Table(G) doesn’t include conflicts
    • LR(1) grammars are non-ambiguos.
      *
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

LALR(1) parsing

A
  • Look-Ahead LR parser is a simplified version of a canonical LR parser, to parse (separate and analyze) a text according to a set of production rules specified by a formal grammar
  • LALR(1) parsing tables have the same states of SLR tables and can conveniently express most programming languages

Core:

  • two LR(1) items have the same core if they are identical except for the lookahead symbols

Union:

  • a set of LALR(1) items is the union of sets of LR(1) items having the same core.

Conflicts:

  • merging state with common cores can never produce shift/reduce conflict which was not present n one of the original states.
  • merging may produce reduce/reduce conflicts
  • class of parsable languages is a proper subset of the deterministic CFL’s
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Predictive parsing

A
  • backtracking can be avoided if it is possible to detect wich rule among A → 𝛂1 | 𝛂2 | … | 𝛂n has to be applied, by considering the current input symbol.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly