public static new EXPRESSION parse(Token first, iSCOPE context) { EXPRESSION result; Token token = (first != null) ? first : get(); switch (token.code) { case TokenCode.Plus: case TokenCode.Minus: case TokenCode.Tilde: forget(); EXPRESSION second = UNARY.parse(null, context); result = new UNARY(token, second); result.setSpan(token.span, second.span); break; case TokenCode.New: forget(); UNIT_REF unitRef = UNIT_REF.parse(null, false, context); result = new NEW(unitRef); result.setSpan(token.span, unitRef.span); break; default: result = POWER.parse(token, context); break; } return(result); }
/// <summary> /// /// </summary> /// <returns></returns> public static new EXPRESSION parse(Token first, iSCOPE context) { EXPRESSION result = null; Token token = (first == null) ? get() : first; Token begin = token; switch (token.code) { case TokenCode.This: forget(); UNIT unit = Context.unit(); if (unit == null) { // Error message! result = new THIS(null); } else { result = new THIS(unit); result.setSpan(token); } break; case TokenCode.Return: if (!ENTITY.weAreWithinEnsure) { break; } forget(); ROUTINE routine = Context.routine(); if (routine == null) { } // error else { result = new RETURN_EXPR(routine); result.setSpan(token); } break; case TokenCode.Old: forget(); result = EXPRESSION.parse(null, context); Span end = result.span; OLD old = new OLD(result); result.parent = old; result = old; result.setSpan(begin.span, end); break; case TokenCode.If: result = CONDITIONAL.parse(context); break; case TokenCode.LParen: forget(); Span start_tuple = token.span; result = EXPRESSION.parse(null, context); token = get(); if (token.code == TokenCode.Comma) { // Seems to be a tuple forget(); TUPLE_EXPR tuple = new TUPLE_EXPR(); tuple.add(result); while (true) { EXPRESSION expr = EXPRESSION.parse(null, context); tuple.add(expr); token = get(); if (token.code != TokenCode.Comma) { break; } forget(); } result = tuple; } end = expect(TokenCode.RParen).span; result.setSpan(token.span, end); break; case TokenCode.Identifier: if (first == null) { forget(); ////// perhaps the same condition should be added for all cases? } DECLARATION d = Context.find(token); if (d == null) { result = new UNRESOLVED(context, new IDENTIFIER(token)); } else { result = new REFERENCE(d); } Token token2 = get(); if (token2.code == TokenCode.LBracket) { UNIT_REF unitRef = UNIT_REF.parse(token, false, context); result = new NEW(unitRef); result.setSpan(unitRef.span); } else { result.setSpan(token); } break; case TokenCode.Integer: case TokenCode.Real: case TokenCode.String: case TokenCode.Character: result = new LITERAL(token.value, token.span, token.code); result.setSpan(token); forget(); break; default: return(null); } // result.setSpan(token); return(result); }