-
Notifications
You must be signed in to change notification settings - Fork 154
Term Grouping
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 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:
- The term containing the
3
term, the/
term, and the4
term - The term containing the
2
term, the-
term, and group term #1 - The overall "root" group term containing the
1
term, the+
term, and group term #2.
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
").
A number term is a term representing a numeric literal.
A variable term is a term representing a variable.
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.