Skip to content

Term Grouping

Dave DeLong edited this page Sep 13, 2015 · 1 revision

Grouping happens following tokenization and is when tokens are organized hierarchically by parenthetical level.

This is accomplished by a simple LL(1) recursive descent parser. Tokens are organized into terms, of which there are several kinds.

Group terms

Group terms are the representation of a parenthetical group and all of the terms inside of it. For example, given the string "1 + (2 - (3 / 4))", there are three group terms:

  1. The term containing the 3 term, the / term, and the 4 term
  2. The term containing the 2 term, the - term, and group term #1
  3. The overall "root" group term containing the 1 term, the + term, and group term #2.

Function term

A function term is a specialized group term. Like the group term, it can have "subterms", but it also has a property denoting the name of the function. For example, if we have the string "sin($x) + $x", the function term will be the term containing the first $x variable, plus the name of the function ("sin").

Number term

A number term is a term representing a numeric literal.

Variable term

A variable term is a term representing a variable.

Operator term

An operator term is a term representing one of the built-in operators.

During tokenization, we created operator tokens for opening and closing parentheses. An operator term does not represent those particular tokens, since parentheses are represented with group terms and function terms.

Clone this wiki locally