Exercise 21:

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
the resulting AST must be
Authors: Carles Creus, Pau Fernández, Nil Mamano / Documentation:
To be able to submit you need to either log in, register, or become a guest.