Involves lanugages recognized by Turing Machines; covered elsewhere
These are effectively anything that's computable
Chomsky Hierarchy:
L(RE) subset L(CFG) subset L(CSG) subset all Formal Lanugages
"All formal languages": ones for which there exist a Turing Machine; also known as a "Turing Complete" languages
EBNF vs. BNF
Do we have to have EBNF?
Theorem: For every EBNF grammar G, there is a BNF grammar G' that recognized the same strings
Suppose we have a production A -> a y? b
It can be rewritten as
A -> a A' B
A' -> y | epsilon
EBNF is easier
Easier to prove results with BNF
Other ways
Railroad Diagrams
Grammars | CS 3040
Date
09/21/2022
Topic
Grammars
Professor
Dr. Hasker
Week
3
Ambiguous Grammars
More than one parse tree
More than one derivation sequence is not enough!
Multiple parse trees = multiple structural interpretations
Example:
Expr -> Expr Op Expr
Expr -> [0-9]+
Op -> 'x' | '*' | '-' | '/'
Apply to 3 - 4 / 5
Fix: Separate different operator types using Expression/Term/Factor grammar from earlier…
Allow (+|-) in Expression
Allow (* | /) in Term, but then…
Meta-meta-level Languages
Textbook: Discusses using CFGs to specify CFGs
Shows that CFGs are powerful
A common standard for programming languages through the 80s and 90s: if a language is powerful, one should be able to write the compiler in that language
00s and beyond: there is no real difference in power, just expressiveness
The only people who care about the compiler's language are those who are maintaining the compiler
Get the job done
Challenge with using CFGs to specify CFGs: notation like ':' can either be a part of a grammar rule or a meta-symbol
Haskell?
Can be a "pure functional" programming language - no side-effects
Easier to reason about - don't have to worry calling a method changes some data at random
Easier to parallelize - each node can compute its own result without other nodes being able to change data the nodes depends on
Type system will help us determine which are pure functions
Sophisticated type system - one of the most powerful