private static bool ParseTenaryIf(Parser.ParseContext context) { context.BpOrder.Push(TokenType.TernaryIf); ValidateTokenOrder(context, TokenType.TernaryIf); Element element = new ElementTernaryOperator(TokenType.TernaryIf); context.LastTokenType = TokenType.TernaryIf; while (context.Stack.Count > 0) { Element lastElement = context.Stack.Pop(); if (lastElement.Type == TokenType.OpenParenthesis) { context.Stack.Push(lastElement); break; } else { context.Ouput.Push(lastElement); } } context.Stack.Push(element); context.Ouput.Push(element); context.TokenPosition++; return(true); }
private static bool ParseTernaryElse(Parser.ParseContext context) { if (context.BpOrder.Count == 0 || context.BpOrder.Pop() != TokenType.TernaryIf) { throw new ELException("Invalid token at position " + context.TokenPosition); } ValidateTokenOrder(context, TokenType.TernaryElse); Element element = new ElementTernaryOperator(TokenType.TernaryElse); while (context.Stack.Count > 0) { Element lastElement = context.Stack.Pop(); if (lastElement.Type == TokenType.TernaryIf) { break; } else { context.Ouput.Push(lastElement); } } context.Ouput.Push(element); context.TokenPosition++; return(true); }