Formal Languages and Translators

From NovaOrdis Knowledge Base
Jump to navigation Jump to search

Internal

Overview

Compiler

Interpreter

Lexical Analysis

Regular Expressions

Finite Automata

Syntax Analysis (Parsing)

TODO Deplete This Parsing

Grammar

Derivation. The leftmost derivation. The rightmost derivation.

Production

Production head

Production body

Terminal

Nonterminal


Backus-Naur Form (BNF)

Extended Backus-Naur Form (EBNF)

Parse Tree

A parse tree is a graphical representation of a derivation.

Each interior node of a parse tree represents the application of a production and it is labeled with the name of the nonterminal that is the head of the production. The children node are labeled, from left to right, by the symbols in the body of the production. While is being constructed, the leaves of a parse tree may represent terminals and nonterminals, which at any moment, if they are read from left to right, they constitute the yield or the frontier of the tree, and it is also referred to as a sentential from of the grammar.

A parse tree does not contain the information that reflects the order in which productions are applied to replace nonterminals. It is customary to produce parse trees by always producing the leftmost (or rightmost) derivation. Each parse tree has associated with it a unique leftmost and an unique rightmost derivation.

Parse trees are sometimes called concrete syntax trees.

(Abstract) Syntax Tree

The abstract syntax tree, also referred to as syntax tree, represents the hierarchical syntactic structure of the parsed content, by depicting significant programming constructs. For example, in case of an expression that involves an operator, the fragment of the syntax tree that represents the expression has a node that represents the operator, and its children represent the operands. In general, any programming construct can be handled by marking up an operator for the construct and treating the semantically meaningful components of that construct as operands.

A syntax tree resembles a parse tree to a certain extent. The difference is that for a syntax tree, the internal nodes represent programming constructs, while for parse tree, the internal nodes represent nonterminals. Many nonterminals of a grammar represent programming constructs, but others are intermediate "helpers" of some sort, for example representing terms, factors or other variations of expressions. Examples of productions that are not represented in a syntax tree are exprterm or ε-productions rest → ε. These helpers are dropped into a syntax three. That is why sometimes a parse tree is called a concrete syntax tree.

Precedence

Associativity

Parser

Top-Down Parser

Bottom-Up Parser

Semantic Analysis