CSCE 121 Grammar
Jump to navigation
Jump to search
Grammars are chains of logic rules that can be used to interpret data:
- LHS → RHS
Way to apply rules:
- start with a particular Left Hand Side
- continually replace using rules until you're stuck
Applications
Mostly used in artificial intelligence
- Expert Systems (medicine)
- Logic programming
- Interpret natural languages
- Interpret programming languages
- Other data: music, dance, RNA structure, 2D graphics
Example
Describe all strings of parentheses that are balanced:
( )( ) | OK |
( ( ) ) | OK |
( ( ) ) ) | NOT OK |
( ( ) ( ) ) | OK |
( ) ) ( | NOT OK |
Rules
- S → ( S )
- S → S S
- S → empty string
Going top-down picking rules at randomgenerates a string of parentheses that will be balanced