Exercise 25:

Parenthesized expressions over unary signs and not, binary +, -, *, /, ^, <, >, =, and and or, function calls, indexed access and field access
The set of tokens of the language is {+,-,*,/,<,>,=,not,and,or,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 identifiers, variables, and field identifiers. Such tokens are non-empty sequences of alphanumeric characters and underscore, not starting by a digit. A function can receive an arbitary number of arguments, possibly 0, enclosed in parentheses and separated by commas. A variable can be an array indexable with [], a struct with fields accessible with . or a numeric value. An arbitrary expression, including the value returned by a function call, an array elemement or a a struct field, is considered a variable itself, and therefore can be any of the aformentioned things (but not function names). Thus, semantically nonsensical expressions such as 1[2] or (not 3).field must be accepted. Function parameters and array indices can be arbitrary expressions, whereas a struct field is always an IDENT.

Examples of correct expressions are and examples of incorrect expressions are The generated AST must correspond to an interpretation of all of the following: Note that expressions such as “not 1”, “1 < (not 2=2)”, “1 + (2<3)” and “1.m + (1+2)[_variable1] + 3()” may be semantically nonsensical, but are syntactically correct and should be recognized. For example, for input
myfunc(not 1-2 or 3<k).mem
the resulting AST must be
.(((myfunc,params(or(-(not(1),2),<(3,k)))),mem)
Authors: Carles Creus, Nil Mamano / Documentation:
To be able to submit you need to either log in, register, or become a guest.