Created
April 19, 2016 01:54
-
-
Save JeOam/fe78ab80482c6d411455db09d0e3dbd2 to your computer and use it in GitHub Desktop.
Compilers Notes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Author
JeOam
commented
Apr 19, 2016
Definition of Grammars
A context-free grammar has four components:
- A set of terminal symbols, sometimes referred to as "tokens." The terminals are the elementary symbols of the language defined by the grammar.
- A set of nonterminals, sometimes called "syntactic variables." Each nonterminal represents a set of strings of terminals, in a manner we shall describe.
- A set of productions, where each production consists of a nonterminal, called the head or left side of the production, an arrow, and a sequence of terminals and/or nonterminals, called the body or right side of the produc tion. The intuitive intent of a production is to specify one of the written forms of a construct; if the head nonterminal represents a construct, then the body represents a written form of the construct.
- A designation of one of the nonterminals as the start symbol.
Formally, given a context-free grammar, a parse tree according to the grammar is a tree with the following properties:
- The root is labeled by the start symbol.
- Each leaf is labeled by a terminal or by €
- Each interior node is labeled by a nonterminal.
-
- If A is the nonterminal labeling some interior node and Xl , X2 , • • • , Xn are the labels of the children of that node from left to right, then there must be a production
A -> XIX2···Xn
. Here, XI,X2,... ,Xn each stand for a symbol that is either a terminal or a nonterminal. As a special case, ifA -> €
is a production, then a node labeled A may have a single child labeled €.
- If A is the nonterminal labeling some interior node and Xl , X2 , • • • , Xn are the labels of the children of that node from left to right, then there must be a production
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment