• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/11

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

11 Cards in this Set

  • Front
  • Back

Context Free Grammar

A context free grammar consists of non-terminals and terminals

Non-terminal

defined by a string of terminals and non-terminals

Parsing

Parsing is the process of determining how a sentence was generated by the grammar.



The result is a Parse Tree

Type 3

Regular



The left-hand side of a production rule is a single non-terminal
The right-hand side of a production rule is either
a single terminal
a single non-terminal followed by a terminal or a terminal followed by a single non-terminal (but not both in the same grammar)
Type 3 grammars can be expressed as regular expressions.
Type 3 languages can be recognized by a deterministic finite-state automata.


Type 2

Context Free



The left-hand side of a production rule is a single non-terminal
The right-hand side of a production rule is a sequence of terminals and non-terminals
Type 2 languages can be recognized by a non-deterministic push-down automata (NP hard)
A sub-set of the type 2 languages can be recognized by a deterministic push-down automata (e.g. a computer program that is either recursive or uses a stack).


Type 1

Context Sensitive



The left-hand side of a production rule consists of a sequence of terminals and non-terminals that contains at least one non-terminal.
The right hand side is the same sequence with the designated non-terminal replaced by a non-empty sequence of terminals and non-terminals.
e.g. The production rule established a context in which the designated non-terminal can be expanded, and the context is preserved.
Recognizing a type 1 language is NP hard. However, since programming languages are context sensitive, compilers are possible, but the context sensitivity is not part of the language’s formal definition.


Type 0

Phrase Structured



There is no restriction on either the left-hand side or the right-hand side of a production rule.
Type 0 languages are equivalent to computer programs.
A general-purpose recognizer is not possible.


Recursive Decent Parsing

Given a context-free grammar one can construct a parser as follows:
Define a method for each non-terminal
This method tries to match each of its choices to the input by looking at the next input token.
If there is a match, the method captures the input token and returns true.
If no match, the method leaves the input stream alone and returns false.


Lexer

The Lexer parses the input into tokens.
It recognizes that sub-set of the grammar that is regular (e.g. type-3).
The lexer generator lex (flex) which is part of Unix (GNU) is regular-expression based.
A Lexer can also be generated using recursive-decent parsing.


Parse Tree

records how a sentence is derived from the grammar.

Abstract Syntax Tree

tree that shows the structure of the sentence.
The internal nodes are terminals or artificial nodes
The leaves are terminals.