Mimir:Draft1 Chapter9

From Openitware
Jump to: navigation, search

Back to Table of Contents


Contents

Chapter TODOs

  • quote
  • content
  • summary
  • exercises

Chapter 9: Grammars

"QUOTE HERE" - Author

Introduction to Grammars

Grammars are used to completely specify syntax rules of languages. The structure imposed by a grammar gives a systemic way of processing expressions.

A grammar consists of four main pieces identifiers, terminals, non-terminals, and production rules. A grammar must contain at least one rule and this rule must have an identifier. Identifiers distinguish rules from other rules, while also acting as a reference for the rule. They must begin with either an alpha character or an underscore. Following can be either an alpha, a numeric, or an underscore. Non-terminals are symbols that are used to write out the grammar. They can be expanded and are represented in < >. Terminals are symbols that appear in the language generated by the grammar. They are written exactly as they are, inside single quotes ' '. Production Rules are composed of of a non-terminal followed by ::= followed by a combination terminal &/or non-terminal.


The main notation used to represent grammars is Backus-Naur Form or BNF for short. This notation looks a lot like HTML and is used to describe the structure of a language.


Additional meta-symbols of BNF are:

::=    means "is defined as"
 |      means "or"

Identifiers

Identifiers distinguish rules from other rules, while also acting as a reference for the rule.

Terminals

Terminals are symbols that appear in the language generated by the grammar.

They are written exactly as they are, inside single quotes ' '.

Non-Terminals

Non-terminals are symbols that are used to write out the grammar. They can be expanded and are represented in < >.

Production rules

Production Rules are composed of of a non-terminal followed by ::= followed by a combination terminal &/or non-terminal.

Summary

A quick summary of the chapter should go here

Key Terms

A list of key terms should go here. This should be created using some sort of glossary type plugin.

Problem Sets

A list of practice problems