This site uses cookies only for the purpose of identifying user sessions.
This is required to properly register actions.
Expressions over binary + and indexed access with brackets
The set of tokens of the language is
{+,IDENT,NUMBER,[,]}. The token
NUMBER represents unsigned integers, i.e., non-empty sequences of
digits. The token IDENT represents variable identifiers, which can be an
array or have a numeric value. Such tokens are non-empty sequences of
alphanumeric characters and underscore, not starting by a digit. Examples of
correct expressions are “1+a[2]”, “x[1+y]”,
“z[w[4]+5]”, “a[i][0]” and examples of incorrect expressions
are “1[]”, “[]+2”, “k[3]+”, etc. The generated AST
must correspond to an interpretation of the operator + as
left-associative. Array access must be represented by a subtree with the symbol
[ as root, the array as first child and the index as second child. Note
that the implicit parenthesization of “a[1][2]” is
“(a[1])[2]”. Identifiers have at least one index. For example, for
input
1+2+a1[3+4][a2[5]]
the resulting AST must be
+(+(1,2),[([(a1,+(3,4)),[(a2,5)))
Authors: Carles Creus, Pau Fernández, Nil Mamano
/
Documentation: