## Exercise 1›:

Expressions over binary +
The set of tokens of the language is {+,NUMBER}. The token NUMBER represents unsigned integers, i.e., non-empty sequences of digits. Recall that “1”, “2+3” and “4+5+6+7” are correct expressions, whereas “+”, “6+” and “1 2” are not. The generated AST must correspond to an interpretation of + as a left-associative operator. For example, for input 1+2+3, the resulting AST must be +(+(1,2),3), i.e., as if the implicit parenthesization was (1+2)+3.
Authors: Carles Creus, Guillem Godoy, Nil Mamano / Documentation:
 // In the first problem on parsing we directly propose a solution, in // order to show which is the syntax to represent the grammars. You // just have to uncomment (remove //) the following two lines and // submit: // // exp: NUMBER ('+'^ NUMBER)*; // NUMBER: ('0'..'9')+; // // Note that symbols enclosed in quotes (' or ") are literal tokens, // while identifiers started with a lowercase letter denote variables // and identifiers started with an uppercase letter denote tokens. As // an alternative solution you can uncomment the following three lines: // // exp: num ('+'^ num)*; // num: NUMBER; // NUMBER: ('0'..'9')+; // // In this case, since exp appears first, it is supposed to be the // starting variable. // The available operations are: // X | Y : if the lookahead is in the First set of X or if X is // nullable and the lookahead is in the Follow set of the whole // expression, parse X, otherwise, try to parse Y // X* : while the lookahead is in the First set of X, parse X // X+ : equivalent to (X X*) // X? : equivalent to (X | ) // The available AST construction directives are ^ and !, and must // appear after a token: // ! : the token must not be inserted in the AST // ^ : the token must become the root of the current AST // Finally, in the definition of a token no identifier can be used, the // AST operators ! and ^ are forbidden, and the following two extra // operators might be used: // .. : denotes a range of characters, like '0'..'9' // ~ : denotes the complement of a set of characters, like ~'"' for // all non-double-quote characters, or like ~('0'..'9') for all // non-digits To be able to submit you need to either log in, register, or become a guest.