private void ExecutingForm_Shown(object sender, EventArgs e) { var lexemes = _poliz.Select(x => Lexeme.Parse(x)).ToList(); foreach (var lexeme in lexemes) { if (lexeme.Body.StartsWith("m{") && !lexeme.Body.EndsWith(":")) { lexeme.Code = (int)LexemeCodes.LABEL; continue; } if (lexeme.Body == "УПЛ" || lexeme.Body == "БП" || lexeme.Body.EndsWith(":")) { lexeme.Code = (int)LexemeCodes.NOTHING; } } _scope = lexemes.Where(x => x.Is(LexemeCodes.ID)) .Distinct() .ToDictionary(x => x.Body, x => "0"); var token = _cts.Token; Task.Run(() => { for (int i = 0; i < lexemes.Count; i++) { token.ThrowIfCancellationRequested(); ExecuteCommand(lexemes[i], ref i); } WriteConsole("Done"); }, token); }
private void SaveLexeme(string accumulatedLexeme) { if (AllLexemes.Any()) { var last = AllLexemes.Last(); var previous = new[] { LexemeCodes.RIGHT_PARENTHESIS, LexemeCodes.ID, LexemeCodes.CONSTANT }; if (accumulatedLexeme.Length > 1 && accumulatedLexeme.First().IsSign() && previous.Any(x => (int)x == last.Code)) { SaveLexeme(accumulatedLexeme.Substring(0, 1)); SaveLexeme(accumulatedLexeme.Substring(1)); return; } } var lexeme = Lexeme.Parse(accumulatedLexeme); lexeme.Line = lineNumber; if (lexeme.Is(LexemeCodes.CONSTANT)) { AddTo(Constants, lexeme); } if (lexeme.Is(LexemeCodes.ID)) { var exsistingId = AllLexemes.FirstOrDefault(x => x.Body == lexeme.Body); if (exsistingId != null) { lexeme.Code = exsistingId.Code; } else { AddTo(Identificators, lexeme); if (AllLexemes.Count > 0 && AllLexemes.Last().Is(LexemeCodes.LABEL)) { lexeme.Code = (int)LexemeCodes.LABEL_ID; } } } AllLexemes.Add(lexeme); }