Headline

A tree representing the grammatical structure of text

Description

We explain the concept by means of an illustrative example.

Illustration

See the illustrations of abstract and concrete syntax for simple intuitions.

A more profound illustration follows.

Consider the following context-free grammar; we label the productions for convenience:

[literal] expression ::= literal
[binary] expression ::= "(" expression op expression ")"
[plus] op ::= "+"
[times] op ::= "*"

We assume that literals are integers as in sequences of digits.

Now consider this input:

((4 * 10) + 2)

A parsing algorithm would basically accept the input string, as it is an element of the language generated by the grammar; see also the parsing problem. In addition, an actual parser would also represent the grammar-based structure of the input string by a parse tree. We represent the parse tree for the input string here as a prefix term such that we use production labels as function symbols:

binary(
  "(",
  binary(
    "(",
    literal("4"),
    times("*"),
    literal("10"),
    ")",
  ),
  plus("+"),
  literal("2"),
  ")",
)  

That is, each non-leaf node in the tree corresponds to a production label and each leaf node is a terminal. Further, each non-leaf node has as many branches as the underlying production has symbols in the right-hand side sequence. We assume that the branches are ordered in the same way as the underlying right-hand side and the subtrees are parse trees for the symbols in the right-hand side. A parse tree for a given nonterminal is rooted by a production with the nonterminal on the left-hand side.

The parse tree shown above is a concrete syntax tree in that it captures even the terminals of the derivation. We may also remove those symbols to arrive at an abstract syntax tree. Thus:

binary(
  binary(
    literal("4"),
    times,
    literal("10")
  ),
  plus,
  literal("2")
)  


Ralf Lämmel edited this article at Sat, 20 Jun 2020 14:08:03 +0200
Compare revisions Compare revisions

User contributions

    This user never has never made submissions.

    User edits

    Syntax for editing wiki

    For you are available next options:

    will make text bold.

    will make text italic.

    will make text underlined.

    will make text striked.

    will allow you to paste code headline into the page.

    will allow you to link into the page.

    will allow you to paste code with syntax highlight into the page. You will need to define used programming language.

    will allow you to paste image into the page.

    is list with bullets.

    is list with numbers.

    will allow your to insert slideshare presentation into the page. You need to copy link to presentation and insert it as parameter in this tag.

    will allow your to insert youtube video into the page. You need to copy link to youtube page with video and insert it as parameter in this tag.

    will allow your to insert code snippets from @worker.

    Syntax for editing wiki

    For you are available next options:

    will make text bold.

    will make text italic.

    will make text underlined.

    will make text striked.

    will allow you to paste code headline into the page.

    will allow you to link into the page.

    will allow you to paste code with syntax highlight into the page. You will need to define used programming language.

    will allow you to paste image into the page.

    is list with bullets.

    is list with numbers.

    will allow your to insert slideshare presentation into the page. You need to copy link to presentation and insert it as parameter in this tag.

    will allow your to insert youtube video into the page. You need to copy link to youtube page with video and insert it as parameter in this tag.

    will allow your to insert code snippets from @worker.