public string AddNewTokenToDatabase(TOKEN token) { _tokens.InsertOnSubmit(token); try { _dataContext.SubmitChanges(); } catch (Exception ex) { _log.Error(ex.Message); return "Token has not been generated"; } return token.UserToken; }
private static BigInteger Parse(Stack <TOKEN> stack, Priority priority, bool endbracket) { if (stack.Count == 0) { throw new Exception("Expression Parsing Error."); } int minus = 1; BigInteger v = 0; TOKEN t = stack.Pop(); //get -, +, integer or bracket if (t.ttype == TOKEN.Ttype.MINUS) { minus = -1; t = stack.Pop(); //get integer or bracket } else if (t.ttype == TOKEN.Ttype.PLUS) { minus = 1; t = stack.Pop(); //get integer or bracket } if (t.ttype == TOKEN.Ttype.INTEGER) { v = minus * t.integer; } else if (t.ttype == TOKEN.Ttype.BRACKETOPEN) { v = minus * Parse(stack, Priority.ALL, true); stack.Pop(); //pop the closing bracket } while (stack.Count != 0) { switch (stack.Peek().ttype) //next operator { case TOKEN.Ttype.PLUS: if (priority == Priority.MULTDIV || priority == Priority.POW) { return(v); } stack.Pop(); v = v + Parse(stack, Priority.ADDSUB, endbracket); break; case TOKEN.Ttype.MINUS: if (priority == Priority.MULTDIV || priority == Priority.POW) { return(v); } stack.Pop(); v = v - Parse(stack, Priority.ADDSUB, endbracket); break; case TOKEN.Ttype.MULTIPLY: if (priority == Priority.POW) { return(v); } stack.Pop(); v = v * Parse(stack, Priority.MULTDIV, endbracket); break; case TOKEN.Ttype.DIVIDE: if (priority == Priority.POW) { return(v); } stack.Pop(); v = v / Parse(stack, Priority.MULTDIV, endbracket); break; case TOKEN.Ttype.POW: stack.Pop(); v = BigIntegerHelper.Pow(v, Parse(stack, Priority.POW, endbracket)); break; case TOKEN.Ttype.BRACKETCLOSE: if (endbracket) { return(v); } else { throw new Exception("Expression Parsing Error (closing bracket misplaced)."); } default: throw new Exception("Expression Parsing Error."); } } if (endbracket) { throw new Exception("Expression Parsing Error (closing bracket missing)."); } return(v); }
public string Check_admin(TOKEN token) { return(new Users_Connection().Check_Admin(token)); }
public override TOKEN TokenBlockAnalyzer(string text, int index, out int outindex) { int sindex = index; char t = text[index]; int tlen = text.Length; string block = t.ToString(); if (t == '"') { block = ""; //LineCommnet 개행 문자까지 반복 (\r) bool IsSpec = false; do { block += t.ToString(); index++; if (index >= tlen) { break; } t = text[index]; if (t == '"' && !IsSpec) { break; } if (t == '\\') { IsSpec = true; } else { IsSpec = false; } } while (index < tlen); block += '"'; TOKEN_TYPE type = TOKEN_TYPE.String; TOKEN token = new TOKEN(sindex, type, block); outindex = index; return(token); } else if (t == '/') { char nt = text[index + 1]; if (nt == '/') { //LineCommnet 개행 문자까지 반복 (\r) t = text[++index]; do { block += t.ToString(); index++; if (index >= tlen) { break; } t = text[index]; } while (index < tlen && (t != '\n')); index--; TOKEN_TYPE type = TOKEN_TYPE.LineComment; block = block.Replace("\r", ""); TOKEN token = new TOKEN(sindex, type, block); outindex = index; return(token); } else if (nt == '*') { //MulitComment */가 나올 떄 까지 반복 char lastchar = ' '; t = text[++index]; do { block += t.ToString(); index++; if (index >= tlen) { //사실상 오류임.. break; } if (lastchar == '*' && t == '/') { //주석 break; } lastchar = t; t = text[index]; } while (index < tlen); index--; TOKEN_TYPE type = TOKEN_TYPE.Comment; //block = block.Replace("\r", ""); TOKEN token = new TOKEN(sindex, type, block); outindex = index; return(token); } } else if (t == '<') { char nt = text[index + 1]; if (nt == '?') { //MulitComment */가 나올 떄 까지 반복 char lastchar = ' '; t = text[++index]; do { block += t.ToString(); index++; if (index >= tlen) { //사실상 오류임.. break; } if (lastchar == '?' && t == '>') { //주석 break; } lastchar = t; t = text[index]; } while (index < tlen); index--; TOKEN_TYPE type = TOKEN_TYPE.Special; //block = block.Replace("\r", ""); TOKEN token = new TOKEN(sindex, type, block); outindex = index; return(token); } } outindex = -1; return(null); }
public override void GetCompletionList(IList <ICompletionData> data, bool IsNameSpaceOpen = false) { string scope = maincontainer.currentScope; //TODO:분석된 토큰으로 자동완성을 만든다. if (IsNameSpaceOpen) { //네임스페이스를 찾아보고 없으면 기존 사용 if (false) { return; } TOKEN ctkn = GetToken(0); if (ctkn == null) { return; } List <TOKEN> t = tokenAnalyzer.GetTokenListFromTarget(ctkn, true); //imported1.var1; //imported1.const1.object1; //const1.object1; //maincontainer.vars[0]. foreach (var item in t) { PreCompletionData preCompletionData = new ImportFileItem(CompletionWordType.nameSpace, item.Value); data.Add(new CodeCompletionData(preCompletionData)); } return; } foreach (var item in maincontainer.importedNameSpace) { if (string.IsNullOrEmpty(item.shortname)) { continue; } data.Add(new CodeCompletionData(item.preCompletion)); } foreach (var item in maincontainer.funcs.FindAll(x => scope.Contains(x.scope))) { data.Add(new CodeCompletionData(item.preCompletion)); } foreach (var item in maincontainer.vars.FindAll(x => scope.Contains(x.scope))) { data.Add(new CodeCompletionData(item.preCompletion)); } base.GetCompletionList(data); }
public override Container ConatainerAnalyzer(int startindex = int.MaxValue) { IsError = false; Container rcontainer = new Container(); bool isinstartoffset = true; int currentscope = 0; bool forstart = false; string scope = "st"; string lastblockscope = "st"; List <Block> forblocks = new List <Block>(); TOKEN tk = null; while (!IsEndOfList()) { tk = GetCurrentToken(); if (tk.StartOffset > startindex && isinstartoffset) { isinstartoffset = false; lastblockscope = scope; //break; } //함수 안쪽에 있으면 함수 //object에서 두번 일하기 싫으면 구조 잘 파악하기. switch (tk.Type) { case TOKEN_TYPE.KeyWord: switch (tk.Value) { case "const": case "var": Block b = BlockAnalyzer(tk.Value); b.scope = scope; if (forstart) { forblocks.Add(b); } //범위를 벗어날 경우 오브젝트에 넣지 않는다. if (isinstartoffset) { rcontainer.vars.Add(b); } break; case "for": forblocks.Clear(); forstart = true; break; case "import": //import File as t; //import File; tk = GetCurrentToken(); string filename = tk.Value; string nspace; if (CheckCurrentToken(TOKEN_TYPE.Symbol, ";")) { //특별 지정자 없이 임포트 rcontainer.importedNameSpace.Add(new ImportedNameSpace(filename, "")); } else if (CheckCurrentToken(TOKEN_TYPE.KeyWord, "as")) { //특별 지정자 tk = GetCurrentToken(); nspace = tk.Value; if (!CheckCurrentToken(TOKEN_TYPE.Symbol, ";")) { ThrowException("import문이 정상적으로 종료되지 않았습니다.", tk); } rcontainer.importedNameSpace.Add(new ImportedNameSpace(filename, nspace)); } else { //잘못된 지정자 ThrowException("import문이 정상적으로 종료되지 않았습니다.", tk); } //임포트 매니저에게 파일 이름 확인 시키기. //본인의 이름과 파일 이름을 넘겨야함. break; case "function": Function function = FunctionAnalyzer(startindex); function.scope = scope; //범위를 벗어날 경우 오브젝트에 넣지 않는다. if (isinstartoffset) { if (function.cursorLocation != CursorLocation.None) { rcontainer.cursorLocation = function.cursorLocation; } rcontainer.funcs.Add(function); } //function fname(args){} ///******/function fname(args){} /*** * @Type * F * @Summary.ko-KR * [loc]에 존재하는 [player]의 [unit]을 반환합니다. * * @param.player.ko-KR * 유닛의 소유 플레이어입니다. * * @param.unit.ko-KR * 유닛입니다. * * @param.loc.ko-KR * 로케이션입니다. ***/ break; case "object": //object linkedList{ // var front; // var rear; // var size; // function append(un : linkedUnit){ // this.size++; // if(!this.front){ // this.front=un; // this.rear=un; // } // else{ // this.rear.next=un; // this.rear=un; // } // } //}; break; } break; case TOKEN_TYPE.Symbol: //심불 {} ; //스코프를 정의, switch (tk.Value) { case "{": //새 스코프를 정의 currentscope++; scope += "." + currentscope; if (forstart) { foreach (var item in forblocks) { item.scope = scope; } forstart = false; //포문 끝 } break; case "}": //이전 스코프로 되돌림 int t = currentscope.ToString().Length + 1; if (scope == "st") { ThrowException("'{}'가 제대로 닫히지 않았습니다.", tk); } else { int lastlen = scope.Split('.').Last().Length + 1; scope = scope.Remove(scope.Length - lastlen, lastlen); //currentscope = int.Parse(scope.Split('.').Last()); } break; } break; default: if (tk.Type == TOKEN_TYPE.Identifier) { //키워드일 경우 //네임스페이스인지 아닌지 확인 } break; } } //스코프 정리 rcontainer.currentScope = lastblockscope; if (scope != "st") { ThrowException("'{}'가 제대로 닫히지 않았습니다.", tk); } return(rcontainer); }
public void RemoveTokenFromDatabase(TOKEN tokenToRemove) { _tokens.DeleteOnSubmit(tokenToRemove); try { _dataContext.SubmitChanges(); } catch (Exception ex) { _log.Error(ex.Message); } }
public string AddNewTokenToDatabase(TOKEN token) { System.Diagnostics.Contracts.Contract.Requires(token != null); return System.Diagnostics.Contracts.Contract.Result<string>(); }
public override void SetStartSymbol() { m_tok = m_lexer.Next(); // recursive call of lexer.Next should be okay m_symbols.m_startSymbol = ((CSymbol)m_tok).Resolve(); m_symbols.m_startSymbol.m_symtype = CSymbol.SymType.nonterminal; }
public override void SetNamespace() { m_tok = m_lexer.Next(); m_namespace = true; m_outFile.WriteLine("namespace " + m_tok.yytext + " {"); }
public TOKEN m_tok; // current input token as returned by Parser.Next public void Advance() { m_tok = (TOKEN)m_lexer.Next(); }
public PrecReference(Lexer lx, TOKEN t) : base(lx) { precref = ((CSymbol)t).Resolve(); new SymbolType(((ptokens)lx).m_sgen, t.yytext, true); }
public TOKEN GetToken() { re_start: /// Label TOKEN tok = TOKEN.ILLEGAL_TOKEN; //// Skipping white spaces while ((_index < _length_string) && (_exp[_index] == ' ' || _exp[_index] == '\t')) { _index++; } /// Enf Of Expression if (_index == _length_string) { return(TOKEN.TOK_NULL); } switch (_exp[_index]) { case '\r': case '\n': _index++; goto re_start; case '+': tok = TOKEN.TOK_PLUS; _index++; break; case '-': tok = TOKEN.TOK_SUB; _index++; break; case '/': tok = TOKEN.TOK_DIV; _index++; break; case '*': tok = TOKEN.TOK_MUL; _index++; break; case '(': tok = TOKEN.TOK_OPAREN; _index++; break; case ')': tok = TOKEN.TOK_CPAREN; _index++; break; case ';': tok = TOKEN.TOK_SEMI; _index++; break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': { string str = ""; while ((_index < _length_string) && (_exp[_index] == '0' || _exp[_index] == '1' || _exp[_index] == '2' || _exp[_index] == '3' || _exp[_index] == '4' || _exp[_index] == '5' || _exp[_index] == '6' || _exp[_index] == '7' || _exp[_index] == '8' || _exp[_index] == '9')) { str += Convert.ToString(_exp[_index]); _index++; } _curr_num = Convert.ToDouble(str); tok = TOKEN.TOK_DOUBLE; } break; default: { if (char.IsLetter(_exp[_index])) { String tem = Convert.ToString(_exp[_index]); _index++; while (_index < _length_string && (char.IsLetterOrDigit(_exp[_index]) || _exp[_index] == '_')) { tem += _exp[_index]; _index++; } tem = tem.ToUpper(); for (int i = 0; i < this._val.Length; ++i) { if (_val[i].Value.CompareTo(tem) == 0) { return(_val[i].tok); } } this.last_str = tem; return(TOKEN.TOK_UNQUOTED_STRING); } else { Console.WriteLine("Error"); throw new Exception(); } } } return(tok); }
/// <summary> /// /// </summary> /// <returns></returns> public TOKEN GetToken() { TOKEN tok = TOKEN.ILLEGAL_TOKEN; while (index < length && (IExpr[index] == ' ' || IExpr[index] == '\t')) { index++; } if (index == length) { return(TOKEN.TOK_NULL); } switch (IExpr[index]) { case '+': tok = TOKEN.TOK_PLUS; index++; break; case '-': tok = TOKEN.TOK_SUB; index++; break; case '/': tok = TOKEN.TOK_DIV; index++; break; case '*': tok = TOKEN.TOK_MUL; index++; break; case '(': tok = TOKEN.TOK_OPAREN; index++; break; case ')': tok = TOKEN.TOK_CPAREN; index++; break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': { String str = ""; while (index < length && (IExpr[index] == '0' || IExpr[index] == '1' || IExpr[index] == '2' || IExpr[index] == '3' || IExpr[index] == '4' || IExpr[index] == '5' || IExpr[index] == '6' || IExpr[index] == '7' || IExpr[index] == '8' || IExpr[index] == '9')) { str += Convert.ToString(IExpr[index]); index++; } number = Convert.ToDouble(str); tok = TOKEN.TOK_DOUBLE; } break; default: Console.WriteLine("Error While Analyzing Tokens"); throw new Exception(); } return(tok); }
internal static extern bool OpenProcessToken(IntPtr processHandle, [MarshalAs(UnmanagedType.U4)] TOKEN desiredAccess, out SafeTokenHandle tokenHandle);
private object ParseValue() { TOKEN nextToken = this.NextToken; return(this.ParseByToken(nextToken)); }
string GetBracketedSeq(ref int ch, char cend) { // ch is the start bracket, already returned string str = ""; int quoteseen = 0; int brackets = 1; char cstart = (char)ch; str += cstart; //Console.WriteLine("GetBracketedSeq with {0}",str); while ((ch = m_lexer.GetChar()) != 0) { if (ch == cstart) { if (quoteseen == 0) { brackets++; } } else if (ch == cend) { if (quoteseen == 0 && --brackets == 0) { goto labout; } } else if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || ch == '_') { m_lexer.UnGetChar(); TOKEN a = m_lexer.Next(); if (m_prod.m_alias.Contains(a.yytext)) { int ix = (int)m_prod.m_alias[a.yytext]; ch = m_lexer.PeekChar(); m_prod.StackRef(ref str, ch, ix); } else { str += a.yytext; } continue; } else { switch (ch) { case '$': str += FixDollars(ref ch); continue; // don't add the ch case '\\': str += (char)ch; ch = m_lexer.GetChar(); break; case '\n': break; case '"': case '\'': if (quoteseen == 0) // start of quoted string { quoteseen = ch; } else if (quoteseen == ch) // matching end of string { quoteseen = 0; } break; } } str += (char)ch; } Error(38, m_lexer.m_pch, "EOF in Action: check bracket counts, quotes"); labout: str += cend; str = str.Replace("yyp", "((" + m_outname + ")yyq)"); return(str); }
public static extern bool OpenProcessToken(IntPtr ProcessHandle, TOKEN DesiredAccess, out IntPtr TokenHandle);
// parsing routines internal void ParseProduction() { TOKEN tok = m_tok; CSymbol lhs = null; try { lhs = ((CSymbol)m_tok).Resolve(); } catch (Exception e) { erh.Error(new CSToolsFatalException(45, tok, string.Format("Syntax error in Parser script - possibly extra semicolon?", e.Message))); } m_tok = lhs; if (m_tok.IsTerminal()) { Error(39, m_tok.pos, string.Format("Illegal left hand side <{0}> for production", m_tok.yytext)); } if (m_symbols.m_startSymbol == null) { m_symbols.m_startSymbol = lhs; } if (lhs.m_symtype == CSymbol.SymType.unknown) { lhs.m_symtype = CSymbol.SymType.nonterminal; } if ((!lhs.m_defined) && lhs.m_prods.Count == 0) { // lhs not defined in %symbol statement and not previously a lhs // so declare it as a new symbol m_outFile.WriteLine(@"/// <summary/>"); m_outFile.WriteLine("public class " + lhs.yytext + " : SYMBOL {"); m_outFile.WriteLine(@"/// <summary/>"); m_outFile.WriteLine(@"/// <param name='yyq'></param>"); m_outFile.WriteLine(" public "+ lhs.yytext + "(Parser yyq):base(yyq) { }"); m_outFile.WriteLine(@"/// <summary/>"); m_outFile.WriteLine(" public override string yyname() { return \"" + lhs.yytext + "\"; }}"); } if (!Find(lhs)) { new SymbolType(this, lhs.yytext); } m_prod = new Production(this, lhs); m_lexer.yy_begin("rhs"); Advance(); if (!m_tok.Matches(":")) { Error(40, m_tok.pos, String.Format("Colon expected for production {0}", lhs.yytext)); } Advance(); RhSide(m_prod); while (m_tok != null && m_tok.Matches("|")) { Advance(); m_prod = new Production(this, lhs); RhSide(m_prod); } if (m_tok == null || !m_tok.Matches(";")) { Error(41, m_lexer.m_pch, "Semicolon expected"); } Advance(); m_prod = null; m_lexer.yy_begin("YYINITIAL"); }
object ParseByToken(TOKEN token) { switch (token) { case TOKEN.STRING: { return ParseString(); } case TOKEN.NUMBER: { return ParseNumber(); } case TOKEN.CURLY_OPEN: { return ParseObject(); } case TOKEN.SQUARED_OPEN: { return ParseArray(); } case TOKEN.TRUE: { return true; } case TOKEN.FALSE: { return false; } case TOKEN.NULL: { return null; } case TOKEN.NONE: { TOKEN nextToken =NextToken; return ParseByToken(nextToken); } default: { return null; } } }
private IList DeserializeList(Type listType) { bool forceObject = HasOptions(JsonOptions.FORCE_OBJECT); object instance; Type argument; bool generic = listType.IsGenericType; if (generic) { instance = Activator.CreateInstance(listType); argument = listType.GetGenericArguments()[0]; } else { instance = new List <object>(); argument = listType.GetElementType(); } IList list = (IList)instance; reader.Read(); bool parsing = true; while (parsing) { TOKEN nextToken = NextToken; switch (nextToken) { case TOKEN.NONE: return(null); case TOKEN.COMMA: continue; case TOKEN.SQUARED_CLOSE: if (!forceObject) { parsing = false; } break; case TOKEN.CURLY_CLOSE: if (forceObject) { parsing = false; } break; default: if (forceObject && nextToken == TOKEN.STRING) { DeserializeString(); if (NextToken != TOKEN.COLON) { return(null); } reader.Read(); } object value = DeserializeByToken(NextToken, argument); list.Add(value); break; } } if (generic) { return(list); } Array array = Array.CreateInstance(argument, list.Count); for (int i = 0; i < list.Count; ++i) { array.SetValue(list[i], i); } return(array); }
public Function FunctionAnalyzer(int startindex) { Function function = new Function(); TOKEN tk = GetCurrentToken(); if (tk.Type != TOKEN_TYPE.Identifier) { ThrowException("함수의 이름에는 식별자가 와야 합니다.", tk); } string funcname = tk.Value; function.funcname = funcname; CursorLocation cl = CursorLocation.None; int argstartoffset = tk.EndOffset; int argendoffset = 0; if (!CheckCurrentToken(TOKEN_TYPE.Symbol, "(")) { ThrowException("함수의 이름 다음에는 인자선언이 와야 합니다.", tk); } while (true) { Function.Arg arg = new Function.Arg(); tk = GetCurrentToken(); if (tk.Type == TOKEN_TYPE.Identifier) { string argname = tk.Value; arg.argname = argname; } else { if (function.args.Count == 0) { if (tk.Type != TOKEN_TYPE.Symbol) { //무조건 심불이 와야됨 ThrowException("잘못된 인자 선언입니다. )가 와야합니다.", tk); } if (tk.Value == ")") { argendoffset = tk.EndOffset; break; } //인자가 없을 수 있음. } ThrowException("잘못된 인자 선언입니다. 인자 이름이 와야 합니다.", tk); } tk = GetCurrentToken(); if (tk.Type != TOKEN_TYPE.Symbol) { //무조건 심불이 와야됨 ThrowException("잘못된 인자 선언입니다. ) , :가 와야합니다.", tk); } if (tk.Value == ")") { argendoffset = tk.EndOffset; break; } else if (tk.Value == ",") { } else if (tk.Value == ":") { tk = GetCommentTokenIten(); if (tk.Type == TOKEN_TYPE.Identifier) { //일반 타입 arg.argtype = tk.Value; GetCurrentToken(); } else if (tk.Type == TOKEN_TYPE.Comment) { //특수처리된 타입 arg.argtype = tk.Value; GetCurrentToken(); } else { ThrowException("인자 타입을 선언해야 합니다.", tk); } } function.args.Add(arg); } if (cl == CursorLocation.None) { if (argstartoffset <= startindex && startindex <= argendoffset) { cl = CursorLocation.FunctionArgName; } } function.cursorLocation = cl; function.preCompletion = new ObjectItem(CompletionWordType.Function, funcname); return(function); }
private List <CodeCheckResult> ExcuteCodeCheck(List <string> Files, double MinRange, ref double MaxScore, ref int MaxIndex1, ref int MaxIndex2) { List <CodeCheckResult> OutputExcel = new List <CodeCheckResult>(); TOKEN GenerateToken = new TOKEN(); Sim CalculateSimScore = new Sim(); DFA CalculateDFAScore = new DFA(); Winnowing CalculateWinScore = new Winnowing(); WinText GenerateWinText = new WinText(); BeginProgress(); int total = ((Files.Count() - 1) * Files.Count()) / 2; int Counter = 0, Bar = 0; List <string> WinFiles = new List <string>(); List <List <VN> > VNFiles = new List <List <VN> >(); List <List <string> > SimFiles = new List <List <string> >(); for (int i = 0; i < Files.Count(); ++i) { List <VN> MF = new List <VN>(); CalculateDFAScore.Get_VN(Files[i], MF); VNFiles.Add(MF); List <string> SF = GenerateToken.Read_file(Files[i]); SimFiles.Add(SF); WinFiles.Add(GenerateWinText.FileFilter(Files[i])); } for (int i = 0; i < Files.Count(); ++i) { for (int j = i + 1; j < Files.Count(); ++j) { double SimScore = CalculateSimScore.Sim_Run(SimFiles[i], SimFiles[j]); double DFAScore = CalculateDFAScore.GetVarSim(VNFiles[i], VNFiles[j]); double WinScore = CalculateWinScore.TextSimilarity(WinFiles[i], WinFiles[j]); double TotalScore = DFAScore * 0.3 + SimScore * 0.5 + WinScore * 0.2; //double TotalScore = SimScore * 1.0; if (TotalScore > MaxScore) { MaxIndex1 = i; MaxIndex2 = j; MaxScore = TotalScore; } // System.Diagnostics.Debug.WriteLine(TotalScore.ToString()); Bar = (Counter) * 100 / total; Counter++; SetProgress(Bar); System.Threading.Thread.Sleep(10); //System.Diagnostics.Debug.WriteLine(Bar.ToString()); if (TotalScore < MinRange) { continue; } OutputExcel.Add( new CodeCheckResult(Files[i].Substring(Files[i].LastIndexOf('\\') + 1) , Files[j].Substring(Files[j].LastIndexOf('\\') + 1) , TotalScore.ToString() + "%")); } } FinishProgress(); return(OutputExcel); }
//Analyzer오류 분석 public override void TokenAnalyze(int caretoffset = int.MaxValue) { //TODO:토큰 분석 로직 //tokens에 직접 접근하여 분석한다. //네임스페이스를 분석 후 토큰을 추가한다 //GetTokens(Context, -1) 이런식으로 가져와서 분석한다. //최근 네임스페이스를 저장하고 해당 파일들이 변형되었는지 체크한다. //ResetCompletionData(CompletionWordType.Function); //Action //Condiction //Function //일반적인 함수들 //nameSpace //Const //Variable //오브젝트들 //Setting(Property) //ArgType //KeyWord //Special //함수와 오브젝트의 요소들을 저장해야함. //cursorLocation 현재 위치를 적습니다. CursorLocation cl = CursorLocation.None; TOKEN ctoken = GetToken(0); TOKEN btoken = GetToken(-1); TOKEN bbtoken = GetToken(-2); if (btoken != null) { if (btoken.Type == TOKEN_TYPE.KeyWord) { switch (btoken.Value) { case "var": case "const": case "as": cl = CursorLocation.ObjectName; break; case "function": cl = CursorLocation.FunctionName; break; case "import": cl = CursorLocation.ImportFile; break; } } } cursorLocation = cl; //토근 분석에 사용되는 요소 tokenAnalyzer.Init(Tokens); try { maincontainer = tokenAnalyzer.ConatainerAnalyzer(caretoffset); if (maincontainer.cursorLocation != CursorLocation.None) { cursorLocation = maincontainer.cursorLocation; } } catch (Exception e) { TOKEN errortoken = tokenAnalyzer.GetLastToken; if (!(errortoken is null)) { tokenAnalyzer.ThrowException(e.ToString(), tokenAnalyzer.GetLastToken); } //tokenAnalyzer.ErrorMessage; //return; } if (tokenAnalyzer.IsError) { //토큰 분석 오류 } tokenAnalyzer.Complete(textEditor); }
IEnumerator ParseByTokenAsync(TOKEN token) { switch (token) { case TOKEN.STRING: yield return ParseString(); yield break; case TOKEN.NUMBER: yield return ParseNumber(); yield break; case TOKEN.CURLY_OPEN: { IEnumerator e = ParseObjectAsync(); while( e.MoveNext() ) { yield return null; } yield return e.Current; yield break; } case TOKEN.SQUARED_OPEN: yield return ParseArray(); yield break; case TOKEN.TRUE: yield return true; yield break; case TOKEN.FALSE: yield return false; yield break; case TOKEN.NULL: yield break; default: yield break; } }
public string logout(TOKEN token) { return(new Users_Connection().Logout(token)); }
public static extern bool OpenProcessToken(IntPtr h, TOKEN acc, ref IntPtr phtok);
//compare TOKENS value private static bool check3InRow(TOKEN s1, TOKEN s2, TOKEN s3) { return((s1 != TOKEN.EMPTY) && (s1 == s2) && (s2 == s3)); }
public String Value; // Token string public ValueTable(TOKEN tok, String Value) { this.tok = tok; this.Value = Value; }
private static Stack <TOKEN> Scan(string expr) { TOKEN t = new TOKEN(); int startIndex = 0; if (expr == "") { return(new Stack <TOKEN>()); } switch (expr[0]) { case ' ': return(Scan(expr.Substring(1))); case '(': t.ttype = TOKEN.Ttype.BRACKETOPEN; startIndex = 1; break; case ')': t.ttype = TOKEN.Ttype.BRACKETCLOSE; startIndex = 1; break; case '+': t.ttype = TOKEN.Ttype.PLUS; startIndex = 1; break; case '-': t.ttype = TOKEN.Ttype.MINUS; startIndex = 1; break; case '*': t.ttype = TOKEN.Ttype.MULTIPLY; startIndex = 1; break; case '/': t.ttype = TOKEN.Ttype.DIVIDE; startIndex = 1; break; case '^': t.ttype = TOKEN.Ttype.POW; startIndex = 1; break; case 'h': case 'H': case '#': case 'X': case 'x': case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case 'A': case 'a': case 'B': case 'b': case 'C': case 'c': case 'D': case 'd': case 'E': case 'e': case 'F': case 'f': if (expr[0] == '#' || expr[0] == 'H' || expr[0] == 'h' || expr[0] == 'X' || expr[0] == 'x') { int length = 1; for (; length < expr.Length; length++) { if (!(expr[length] >= '0' && expr[length] <= '9') && expr[length] != 'A' && expr[length] != 'a' && expr[length] != 'B' && expr[length] != 'b' && expr[length] != 'C' && expr[length] != 'c' && expr[length] != 'D' && expr[length] != 'd' && expr[length] != 'E' && expr[length] != 'e' && expr[length] != 'F' && expr[length] != 'f') { break; } } t.integer = BigInteger.Parse(expr.Substring(1, length - 1), NumberStyles.AllowHexSpecifier); t.ttype = TOKEN.Ttype.INTEGER; startIndex = length; } else { int length = 1; for (; length < expr.Length; length++) { if (!(expr[length] >= '0' && expr[length] <= '9')) { break; } } t.integer = BigInteger.Parse(expr.Substring(0, length)); t.ttype = TOKEN.Ttype.INTEGER; startIndex = length; } break; default: throw new Exception("Expression parsing failed at character " + expr[0]); } Stack <TOKEN> st = Scan(expr.Substring(startIndex)); st.Push(t); return(st); }
protected TOKEN Last_Token; // Penultimate token /// <summary> /// Get Next Token from the stream and return to the caller /// </summary> /// <returns></returns> protected TOKEN GetNext() { Last_Token = Current_Token; Current_Token = GetToken(); return(Current_Token); }
object ParseValue() { TOKEN nextToken = NextToken; return(ParseByToken(nextToken)); }
///////////////////////////////////////////////////// // Grab the next token from the stream // // // // public TOKEN GetToken() { TOKEN tok = TOKEN.ILLEGAL_TOKEN; re_start: tok = TOKEN.ILLEGAL_TOKEN; //////////////////////////////////////////////////////////// // // Skip the white space // while (index < length && (IExpr[index] == ' ' || IExpr[index] == '\t')) { index++; } ////////////////////////////////////////////// // // End of string ? return NULL; // if (index == length) { return(TOKEN.TOK_NULL); } ///////////////////////////////////////////////// // // // switch (IExpr[index]) { case '\n': index++; goto re_start; case '\r': index++; goto re_start; case '+': tok = TOKEN.TOK_PLUS; index++; break; case '-': tok = TOKEN.TOK_SUB; index++; break; case '*': tok = TOKEN.TOK_MUL; index++; break; case ',': // -------- Addition in step 7 tok = TOKEN.TOK_COMMA; index++; break; case '(': tok = TOKEN.TOK_OPAREN; index++; break; case ';': tok = TOKEN.TOK_SEMI; index++; break; case ')': tok = TOKEN.TOK_CPAREN; index++; break; case '!': tok = TOKEN.TOK_NOT; index++; break; case '>': if (IExpr[index + 1] == '=') { tok = TOKEN.TOK_GTE; index += 2; } else { tok = TOKEN.TOK_GT; index++; } break; case '<': if (IExpr[index + 1] == '=') { tok = TOKEN.TOK_LTE; index += 2; } else if (IExpr[index + 1] == '>') { tok = TOKEN.TOK_NEQ; index += 2; } else { tok = TOKEN.TOK_LT; index++; } break; case '=': if (IExpr[index + 1] == '=') { tok = TOKEN.TOK_EQ; index += 2; } else { tok = TOKEN.TOK_ASSIGN; index++; } break; case '&': if (IExpr[index + 1] == '&') { tok = TOKEN.TOK_AND; index += 2; } else { tok = TOKEN.ILLEGAL_TOKEN; index++; } break; case '|': if (IExpr[index + 1] == '|') { tok = TOKEN.TOK_OR; index += 2; } else { tok = TOKEN.ILLEGAL_TOKEN; index++; } break; case '/': if (IExpr[index + 1] == '/') { SkipToEoln(); goto re_start; } else { tok = TOKEN.TOK_DIV; index++; } break; case '"': String x = ""; index++; while (index < length && IExpr[index] != '"') { x = x + IExpr[index]; index++; } if (index == length) { tok = TOKEN.ILLEGAL_TOKEN; return(tok); } else { index++; last_str = x; tok = TOKEN.TOK_STRING; return(tok); } default: if (char.IsDigit(IExpr[index])) { String str = ""; while (index < length && (IExpr[index] == '0' || IExpr[index] == '1' || IExpr[index] == '2' || IExpr[index] == '3' || IExpr[index] == '4' || IExpr[index] == '5' || IExpr[index] == '6' || IExpr[index] == '7' || IExpr[index] == '8' || IExpr[index] == '9')) { str += Convert.ToString(IExpr[index]); index++; } if (IExpr[index] == '.') { str = str + "."; index++; while (index < length && (IExpr[index] == '0' || IExpr[index] == '1' || IExpr[index] == '2' || IExpr[index] == '3' || IExpr[index] == '4' || IExpr[index] == '5' || IExpr[index] == '6' || IExpr[index] == '7' || IExpr[index] == '8' || IExpr[index] == '9')) { str += Convert.ToString(IExpr[index]); index++; } } number = Convert.ToDouble(str); tok = TOKEN.TOK_NUMERIC; } else if (char.IsLetter(IExpr[index])) { String tem = Convert.ToString(IExpr[index]); index++; while (index < length && (char.IsLetterOrDigit(IExpr[index]) || IExpr[index] == '_')) { tem += IExpr[index]; index++; } tem = tem.ToUpper(); for (int i = 0; i < keyword.Length; ++i) { if (keyword[i].Value.CompareTo(tem) == 0) { return(keyword[i].tok); } } this.last_str = tem; return(TOKEN.TOK_UNQUOTED_STRING); } else { return(TOKEN.ILLEGAL_TOKEN); } break; } return(tok); }
private void Expect(TOKEN token) { if (PeekNextToken() != token) throw new InvalidDataException(token + " expected"); index++; //move index }
/// <summary> /// /// </summary> /// <param name="op"></param> /// <param name="e1"></param> /// <param name="e2"></param> public LogicalExp(TOKEN op, Exp e1, Exp e2) { m_op = op; ex1 = e1; ex2 = e2; }
public void RemoveTokenFromDatabase(TOKEN tokenToRemove) { System.Diagnostics.Contracts.Contract.Requires(tokenToRemove != null); }
private static TOKEN GetReverseToken(TOKEN A) { return(A == TOKEN.J1 ? TOKEN.J2 : TOKEN.J1); }
object ParseByToken(TOKEN token) { switch (token) { case TOKEN.STRING: return ParseString(); case TOKEN.NUMBER: return ParseNumber(); case TOKEN.CURLY_OPEN: return ParseObject(); case TOKEN.SQUARED_OPEN: return ParseArray(); case TOKEN.TRUE: return true; case TOKEN.FALSE: return false; case TOKEN.NULL: return null; default: return null; } }
public CSToolsStopException(int n, TOKEN t, string s) : base(n, t, s) { }