Formal Language

Context-Free Language

A context-free grammar is a four-tuple where:

  • is a finite set of non-terminal symbols
  • is a finite set of terminal symbols (the alphabet)
  • is a finite set of productions, also called rules
  • is the start non-terminal

Each production in is of the form , where is a non-terminal symbol and is a sequence of terminal and non-terminal symbols.

The language generated by the grammar is

A language is context-free if there exists a context-free grammar that generates it. There may be multiple grammars that generate the same language.

Convention for CS241E

So much notation, it’s actually so confusing.

  • In the rest of this module, we will use the convention that:
  • variables , and always refer to terminal symbols in
  • variables and always refer to non-terminal symbols in
  • variables , and always refer to terminal or non-terminal symbols in
  • variables , and always refer to sequences of terminal symbols from , i.e. to words, and
  • variables , and always refer to sequences of terminal or non-terminal symbols from

After we do this Parsing, we move up by doing Parsing, we move up by doing Context-Sensitive Analysis, since a valid Lacs program is not only context free, but context-sensitive, because we need to make sure about type checking and name resolution.