/** * 토큰열을 분석하여 접미형 단항 연산 구문 요소를 추출한다. * * @param tokens * @param lineNumber * @return */ public static SuffixSyntax analyze(List <Token> tokens, int lineNumber) { int indexOfLpo = TokenTools.indexOfLpo(tokens); int depth = 0; foreach (int i in Enumerable.Range(0, tokens.Count)) { if (tokens[i].type == Type.ShellOpen) { depth++; } else if (tokens[i].type == Type.ShellClose) { depth--; } } // 껍데기가 온전히 닫혀 있는지 검사한다. if (depth > 0) { Debug.reportError("Syntax error", "insert \")\" to complete Expression", lineNumber); return(null); } if (depth < 0) { Debug.reportError("Syntax error", "delete \"(\"", lineNumber); return(null); } return(new SuffixSyntax(tokens[indexOfLpo], tokens.GetRange(0, indexOfLpo))); }
/** * 토큰열이 이항 연산자 구문 패턴과 일치하는지 확인한다. * * @param tokens * @return */ public static bool match(List <Token> tokens) { int indexOfLPO = TokenTools.indexOfLpo(tokens); if (indexOfLPO < 0) { return(false); } if (!tokens[indexOfLPO].isPrefix() && !tokens[indexOfLPO].isSuffix()) { return(true); } return(false); }
/** * 토큰열을 분석하여 캐스팅 구문 요소를 추출한다. * * @param tokens * @param lineNumber * @return */ public static CastingSyntax analyze(List <Token> tokens, int lineNumber) { int indexOfLpo = TokenTools.indexOfLpo(tokens); // 캐스팅 대상이 없다면 if (tokens.Count <= indexOfLpo + 1) { Debug.reportError("Syntax error", "Cannot find casting target.", lineNumber); return(null); } List <Token> target = tokens.GetRange(0, indexOfLpo); string castingType = tokens[indexOfLpo + 1].value; return(new CastingSyntax(target, castingType)); }
/** * 토큰열이 캐스팅 구문 패턴과 일치하는지 확인한다. * * @param tokens * @return */ public static bool match(List <Token> tokens) { int indexOfLPO = TokenTools.indexOfLpo(tokens); if (indexOfLPO < 0) { return(false); } if (tokens[indexOfLPO].type != Type.As) { return(false); } return(true); }
/** * 토큰열이 속성 선택문 구문 패턴과 일치하는지 확인한다. * * @param tokens * @return */ public static bool match(List <Token> tokens) { int indexOfLpo = TokenTools.indexOfLpo(tokens); if (indexOfLpo < 0) { return(false); } // 도트가 가장 최하위 연산자이면, 즉 도트를 제외하고 다른 연산자가 없을 때 if (tokens[indexOfLpo].type == Type.Dot) { return(true); } return(false); }
/** * 토큰열을 분석하여 이항 연산자 구문 요소를 추출한다. * * @param tokens * @param lineNumber * @return */ public static InfixSyntax analyze(List <Token> tokens, int lineNumber) { int indexOfLpo = TokenTools.indexOfLpo(tokens); int depth = 0; foreach (int i in Enumerable.Range(0, tokens.Count)) { if (tokens[i].type == Type.ShellOpen) { depth++; } else if (tokens[i].type == Type.ShellClose) { depth--; } } // 껍데기가 온전히 닫혀 있는지 검사한다. if (depth > 0) { Debug.reportError("Syntax error", "insert \")\" to complete Expression", lineNumber); return(null); } if (depth < 0) { Debug.reportError("Syntax error", "delete \"(\"", lineNumber); return(null); } // 연산자 취득 Token _operator = tokens[indexOfLpo]; // 좌항과 우항 List <Token> left = tokens.GetRange(0, indexOfLpo); List <Token> right = tokens.GetRange(indexOfLpo + 1, tokens.Count - (indexOfLpo + 1)); return(new InfixSyntax(_operator, left, right)); }
/** * 토큰열이 함수 호출 구문 패턴과 일치하는지 확인한다. * * @param tokens * @return */ public static bool match(List <Token> tokens) { int indexOfLpo = TokenTools.indexOfLpo(tokens); // 어떠한 유효 연산자라도 있을 경우 함수 호출이 아님 if (indexOfLpo >= 0) { return(false); } // 최소 길이 조건 확인 if (tokens.Count < 3) { return(false); } // 첫 토큰이 ID이고 두 번째 토큰이 ShellOpen이면 조건 만족 if (tokens[0].type != Type.ID || tokens[1].type != Type.ShellOpen) { return(false); } return(true); }