Exercise 22:

Expressions over binary + and function calls
The set of tokens of the language is {+,IDENT,NUMBER,(,),,} (mind the last token, which is a comma). The token NUMBER represents unsigned integers, i.e., non-empty sequences of digits. The token IDENT represents function that returns a number. Such tokens are non-empty sequences of alphanumeric characters and underscore, not starting by a digit. Examples of correct expressions are “1+f(2+3)”, “t()”, “g(h(1),2)” and examples of incorrect expressions are “x+0”, “1(m)”, “()+1”, “(y(2))”, etc. The generated AST must correspond to an interpretation of the operator “+” as left-associative. Function calls must be represented by a subtree with a special node named call as root, the function identifier as first child, and another special node named params as second child. The params node has one child for each parameter. Functions can have an arbitrary number of parameters, including 0. For example, for input
x(1,2+3,y())
the resulting AST must be
call(x,params(1,+(2,3),call(y,params())))
Authors: Nil Mamano / Documentation:
To be able to submit you need to either log in, register, or become a guest.