public Lexem(LexemType type, LexemLocation start, LexemLocation end, string value = null) { Type = type; Value = value; StartLocation = start; EndLocation = end; }
public bool Store(LexemType type, string content) { char character; LexemState state; if (content.Length > 0) { character = content[0]; if (!this.branches.TryGetValue (character, out state)) { state = new LexemState (); this.branches[character] = state; } return state.Store (type, content.Substring (1)); } else if (this.type == LexemType.None) { this.type = type; return true; } return false; }
public Lexem(LexemType type, int line, int offset, int total, string file, string data = "") { Type = type; Line = line; Offset = offset; TotalOffset = total; File = file; Data = data; }
protected bool TryExtract(List<CodeLexem> res, ref SourcePart text, string lex, LexemType type) { if (text.StartsWith(lex)) { res.Add(new CodeLexem(type, CutString(ref text, lex.Length))); return true; } return false; }
/// <summary>Unknown if not command</summary> public LexemType ParseCommand() { Lexem lexem = lexems[0]; LexemType type = lexem.Type; if (type == LexemType.AddCmd || type == LexemType.ListCmd || type == LexemType.RemoveCmd) { return(type); } return(LexemType.Unknown); }
public OperatorCompareNode(LexemType type) { switch (type) { case LexemType.Equal: case LexemType.NotEqual: case LexemType.Less: case LexemType.LessEqual: case LexemType.Greater: case LexemType.GreaterEqual: ComparisonType = type; break; default: throw new NotImplementedException(); } }
protected string GetLexem(string s, int startIdx, int endIdx, LexemType lexemType) { string lexem = GetLexem(s, startIdx, endIdx); if (lexemType == null || lexemType != LexemType.QuotedConstant) { return(lexem); } // remove first and last chars string constant = lexem.Substring(1, lexem.Length - 2); // replace "" with " return(constant.Replace("\"\"", "\"")); }
public ExecutionAndCount ParseExecutionAndCount() { for (int i = 2; i < lexems.Count; i++) { if (lexems[i].Type == LexemType.Execute) { LexemType executionType1 = lexems[i + 2].Type; if (executionType1 == LexemType.Always || executionType1 == LexemType.Once) { int count = ParseCount(i + 2); return(new ExecutionAndCount(executionType1, LexemType.Unknown, LexemType.Unknown, count)); } else if (executionType1 == LexemType.Per) { LexemType executionType2 = lexems[i + 4].Type; if (executionType2 == LexemType.Day || executionType2 == LexemType.Player) { int count = ParseCount(i + 4); return(new ExecutionAndCount(LexemType.Per, executionType2, LexemType.Unknown, count)); } else if (executionType2 == LexemType.Game) { if (lexems[i + 6].Type == LexemType.Day) { int count2 = ParseCount(i + 6); return(new ExecutionAndCount(LexemType.Per, LexemType.Game, LexemType.Day, count2)); } int count = ParseCount(i + 4); return(new ExecutionAndCount(LexemType.Per, LexemType.Game, LexemType.Unknown, count)); } } else { int count = ParseCount(i); return(new ExecutionAndCount(LexemType.Unknown, LexemType.Unknown, LexemType.Unknown, count)); } } else if (lexems[i].Type == LexemType.StartBrace) { break; } } return(new ExecutionAndCount()); }
private void ParseXmlKeyWord(ICollection<CodeLexem> res, ref SourcePart text, LexemType type) { var index = text.IndexOfAny(XmlEndOfTerm); if (index <= 0) return; var delimiterIndex = text.IndexOf(XmlNamespaceDelimeter); if (delimiterIndex > 0 && delimiterIndex < index) { res.Add(new CodeLexem(type, CutString(ref text, delimiterIndex))); res.Add(new CodeLexem(LexemType.Symbol, CutString(ref text, 1))); res.Add(new CodeLexem(type, CutString(ref text, index - delimiterIndex - 1))); return; } res.Add(new CodeLexem(type, CutString(ref text, index))); }
protected void TryExtractTo(List<CodeLexem> res, ref SourcePart text, string lex, LexemType type, string except = null) { var index = text.IndexOf(lex); if (except != null) { while (index >= 0 && text.Substring(0, index + 1).EndsWith(except)) { index = text.IndexOf(lex, index + 1); } } if (index < 0) return; LineBreaks(res, ref text, index + lex.Length, type); }
public bool Move(char character, out LexemType type) { if (this.State != null) { this.State = this.State.Follow (character); if (this.State != null && this.State.Type != LexemType.None) { type = this.State.Type; return true; } } type = LexemType.None; return false; }
public bool Move(char character, out LexemType type) { if (this.State != null) { this.State = this.State.Follow(character); if (this.State != null && this.State.Type != LexemType.None) { type = this.State.Type; return(true); } } type = LexemType.None; return(false); }
protected bool GetCondition(LexemType lexemType, string s, int startIdx, ref int endIdx, ref Conditions conditions) { string lexem = GetLexem(s, startIdx, endIdx).ToLower(); if (lexemType == LexemType.Name) { int idx = Array.IndexOf(nameConds, lexem); if (idx >= 0) { conditions = enumNameConds[idx]; return(true); } } if (lexemType == LexemType.Delimiter) { // read all available delimiters... GetAllDelimiters(s, endIdx, out endIdx); lexem = GetLexem(s, startIdx, endIdx); int idx = Array.IndexOf(delimiterConds, lexem); if (idx < 0) { if (lexem == "!") { int newEndIdx; Conditions innerConditions = Conditions.Equal; LexemType newLexemType = GetLexemType(s, endIdx, out newEndIdx); if (GetCondition(newLexemType, s, endIdx, ref newEndIdx, ref innerConditions)) { endIdx = newEndIdx; conditions = innerConditions | Conditions.Not; return(true); } } return(false); } conditions = enumDelimConds[idx]; return(true); } return(false); }
protected void LineBreaks(List <CodeLexem> res, ref SourcePart text, int to, LexemType type) { while (text.Length > 0 && to > 0) { var index = text.IndexOf("\n"); if (index >= to) { res.Add(new CodeLexem(type, CutString(ref text, to))); return; } if (index != 0) { res.Add(new CodeLexem(type, CutString(ref text, index))); } res.Add(new CodeLexem(LexemType.LineBreak, CutString(ref text, 1))); to -= index + 1; } }
protected void LineBreaks(List<CodeLexem> res, ref SourcePart text, int to, LexemType type) { while (text.Length > 0 && to > 0) { var index = text.IndexOf("\n"); if (index >= to) { res.Add(new CodeLexem(type, CutString(ref text, to))); return; } if (index != 0) { res.Add(new CodeLexem(type, CutString(ref text, index))); } res.Add(new CodeLexem(LexemType.LineBreak, CutString(ref text, 1))); to -= index + 1; } }
protected QueryNode ParseCondition(string input, int startIdx, out int endIdx) { IQueryValue leftValue = ParseInternal(input, startIdx, out endIdx); int nextEndIdx; Conditions conditions = Conditions.Equal; LexemType nextLexemType = GetLexemType(input, endIdx, out nextEndIdx); if (!GetCondition(nextLexemType, input, endIdx, ref nextEndIdx, ref conditions)) { throw new RelExParseException( String.Format("Invalid syntax (position: {0}, expression: {1})", startIdx, input)); } IQueryValue rightValue = ParseInternal(input, nextEndIdx, out endIdx); QueryNode node; if (IsNullValue(rightValue)) { if ((conditions & Conditions.Equal) != 0) { node = new QueryConditionNode(leftValue, Conditions.Null | (conditions & ~Conditions.Equal), null); } else { throw new RelExParseException( String.Format("Invalid syntax - such condition cannot be used with 'null' (position: {0}, expression: {1})", startIdx, input)); } } else { node = new QueryConditionNode(leftValue, conditions, rightValue); } return(node); }
private void ParseSingle(LexemType type, string value, string expected) { if (this.lexer.Current.Type != type || this.lexer.Current.Content != value) throw new UnexpectedException (this.lexer, expected); this.lexer.Next (LexerMode.BLOCK); }
public StaticLexemDefenition(string representation, LexemType type) : base(representation, type) { }
private object ProcessOperator(Lexem oper, Lexem leftValue, Lexem rightValue, ref LexemType lt) { if (oper.Content.ToString() == "]") { lt = LexemType.Variable; return Storage.GetVariable(leftValue.Content.ToString(), rightValue); } return Helper.Calculate(oper, leftValue, rightValue, ref lt); }
public StaticLexemDefinition(string repr, LexemType type) { Representation = repr; Type = type; }
public LexemDefenition(T representation, LexemType type) { Representation = representation; Type = type; }
/// <summary> /// Метод, запускающий процесс анализа лексем. /// </summary> /// <returns></returns> public List <LexemDataCell> DoAnalysis() { if (FullText.Equals(string.Empty)) { return(null); } LexemTable = new List <LexemDataCell>(); int numOfStr = 1; for (int point = 0; point < FullText.Length; point++) { (bool isSuccess, StringBuilder value)result; if (FullText[point] == '\n') { numOfStr += 1; continue; } if (FullText[point] == ' ' | FullText[point] == '\t') { continue; } result = TryIdentificator(ref point); if (result.isSuccess) { point -= 1; LexemType type = LexemType.Identificator; if (IsKeyWord(result.value)) { type = LexemType.Key_Word; } // Сообщим обработчикам, что найден идентификатор NotifyAboutIdentificator?.Invoke(result.value.ToString()); AddCell(numOfStr, result.value.ToString(), type); continue; } result = TryStringConstant(ref point); if (result.isSuccess) { point -= 1; AddCell(numOfStr, result.value.ToString(), LexemType.Char_Constant); continue; } result = TryNumberconstant(ref point); if (result.isSuccess) { point -= 1; AddCell(numOfStr, result.value.ToString(), LexemType.Number_Constant); continue; } if (FullText[point] == ':' & (point < FullText.Length - 1)) { if (FullText[point + 1] == '=') { AddCell(numOfStr, ":=", LexemType.Assignment_Symbol); point += 1; continue; } } if (Splitters.Contains(FullText[point])) { AddCell(numOfStr, FullText[point].ToString(), LexemType.Splitter); continue; } if (Conditions.Contains(FullText[point])) { AddCell(numOfStr, FullText[point].ToString(), LexemType.Condition_Symbol); continue; } } return(LexemTable); }
public Lexem(LexemType type, string data = "") { Type = type; Data = data; }
private Lexema GetNextInternal() { StringBuilder sb = new StringBuilder(); LexemType e = LexemType.Unknown; bool stop = false; bool skipChar = false; q = 0; while (!stop && i < mInput.Length) { char c = mInput[i]; switch (q) { case 0: if (Char.IsLetter(c) || c == '_') // | c=='#') { q = 1; e = LexemType.NotTerminal; } else if (Char.IsDigit(c)) { q = 2; e = LexemType.IntNumber; } else if (c == ':') { q = 3; } else if (c == ',' || c == '|' || c == ';') { q = 4; e = LexemType.Operation; } else if (c == '+' || c == '-') { q = 4; e = LexemType.AddOp; } else if (c == '*' || c == '%') { q = 4; e = LexemType.MulOp; } else if (c == '/') { q = 7; skipChar = true; } else if (c == '(') { q = 4; e = LexemType.LeftBr; } else if (c == ')') { q = 4; e = LexemType.RightBr; } else if (c == '"') { q = 5; skipChar = true; e = LexemType.Terminal; } else if (Char.IsPunctuation(c) || c == '<' || c == '>' || c == '=') { q = 4; e = LexemType.Sign; } else { skipChar = true; e = LexemType.Unknown; } break; case 1: //letter if (!(char.IsDigit(c) || char.IsLetter(c) || c == '_' || c == '-')) { stop = true; skipChar = true; } break; case 2: //digits if (!char.IsDigit(c)) { stop = true; skipChar = true; } break; case 3: //:= if (c == '=') { q = 4; e = LexemType.IsSign; } else { e = LexemType.Sign; stop = true; //!!! here no skip char } break; case 4: stop = true; skipChar = true; break; case 5: //" if (c == '\\') { skipChar = true; q = 11; } if (c == '"') { skipChar = true; q = 6; } break; case 6: if (c == '"') { q = 5; } else { skipChar = true; stop = true; } break; case 7: if (c == '*') { q = 8; skipChar = true; } else if (c == '/') { q = 10; skipChar = true; } else { sb.Append('/'); e = LexemType.MulOp; stop = true; skipChar = true; } break; case 8: //waiting * in */ if (c == '*') { q = 9; } skipChar = true; break; case 9: //waiting / in */ if (c == '/') { q = 0; } else { q = 8; } skipChar = true; break; case 10: //waiting end of line after // skipChar = true; break; case 11: //waiting r, n, \ after \ in "" if (c == 'n') { sb.Append("\r\n"); skipChar = true; } q = 5; break; default: //exit states throw new LexerInternalException("unknown state", mInput, q, i); } if (!stop) { i++; } if (!skipChar) { sb.Append(c); } else { skipChar = false; } } if (q == 5) { throw new GrammarSyntaxException("Illegal termial symbol, \" expected", mInput); } return((e == LexemType.Unknown) ? null : new Lexema(sb.ToString(), e, this)); }
public DynamicLexemDefinition(string sig, LexemType type) { Signature = new Regex(sig, RegexOptions.Compiled); Type = type; }
public LexemMatch(LexemType type, string content) { this.content = content; this.type = type; }
private byte GetPriority(LexemType s) { switch (s) { case LexemType.RBracket: case LexemType.LBracket: return 0; case LexemType.And: case LexemType.Or: case LexemType.Equals: case LexemType.NotEquals: case LexemType.Greater: case LexemType.Lower: case LexemType.GreaterEquals: case LexemType.LowerEquals: return 2; case LexemType.Plus: case LexemType.Minus: return 3; case LexemType.Multiply: case LexemType.Divide: return 4; case LexemType.UnarMinus: return 5; default: return 6; } }
private Lexem NextChar(LexemType type) { Lexem lexem; lexem = new Lexem (type, this.last.ToString ()); this.Read (); return lexem; }
private void ParseExpected(LexemType type, string value, string expected) { if (this.lexer.Current.Type != type || this.lexer.Current.Content != value) throw this.Raise (expected); this.lexer.Next (LexerMode.Block); }
protected bool GetCondition(LexemType lexemType, string s, int startIdx, ref int endIdx, ref Conditions conditions) { string lexem = GetLexem(s, startIdx, endIdx).ToLower(); if (lexemType==LexemType.Name) { int idx = Array.IndexOf(nameConds, lexem); if (idx>=0) { conditions = enumNameConds[idx]; return true; } } if (lexemType==LexemType.Delimiter) { // read all available delimiters... GetAllDelimiters(s, endIdx, out endIdx); lexem = GetLexem(s, startIdx, endIdx); int idx = Array.IndexOf(delimiterConds, lexem); if (idx<0) { if (lexem=="!") { int newEndIdx; Conditions innerConditions = Conditions.Equal; LexemType newLexemType = GetLexemType(s, endIdx, out newEndIdx); if (GetCondition(newLexemType, s, endIdx, ref newEndIdx, ref innerConditions)) { endIdx = newEndIdx; conditions = innerConditions|Conditions.Not; return true; } } return false; } conditions = enumDelimConds[idx]; return true; } return false; }
public CodeLexem(LexemType type, string text) { Text = text; Type = type; }
protected string GetLexem(string s, int startIdx, int endIdx, LexemType lexemType) { string lexem = GetLexem(s, startIdx, endIdx); if (lexemType==null || lexemType!=LexemType.QuotedConstant) return lexem; // remove first and last chars string constant = lexem.Substring(1, lexem.Length-2); // replace "" with " return constant.Replace( "\"\"", "\"" ); }
/// <summary> /// Appends a new lexem to the list. /// </summary> private void addLexem(LexemType type, LexemLocation loc) { Lexems.Add(new Lexem(type, loc, default(LexemLocation))); }
public Lexem(string _name, LexemType _type, LexemDataType _datatype, string _data) { name = _data; data = _data; type = _type; datatype = _datatype; }
public Lexema(string aText, LexemType aType, Lexer aLexer) { Text = aText; Type = aType; mLexer = aLexer; }
public List <Lexem> GetAst(string expr) { List <Lexem> lexems = new List <Lexem>(); string acc = ""; bool readingId = false; LexemType nextType = LexemType.Constant; for (int i = 0; i < expr.Length; ++i) { char c = expr[i]; if (char.IsWhiteSpace(c)) { continue; } else if (char.IsLetter(c)) { if (!readingId) { nextType = LexemType.Identifier; readingId = true; } if (c == '.') { throw new Exception("Unexpected char!"); } acc += c; } else if (char.IsDigit(c)) { if (!readingId) { nextType = LexemType.Constant; readingId = true; } acc += c; } else if (c == '.' && readingId && nextType == LexemType.Constant) { acc += '.'; } else if (char.IsLetterOrDigit(c)) { acc += c; } else if ((c == '+' || c == '-') && (i > 0 && (expr[i - 1] == '+' || expr[i - 1] == '-')) && char.IsDigit(expr[i + 1]) && !readingId) { nextType = LexemType.Constant; readingId = true; acc += c; } else if (c == '(' || c == ')' || c == '+' || c == '-' || c == '*' || c == '/' || c == '^') { if (readingId) { readingId = false; if (c == '(' && nextType == LexemType.Identifier) { nextType = LexemType.Function; } else if (c != '(' && nextType == LexemType.Identifier) { nextType = LexemType.Variable; } lexems.Add(new Lexem { Value = acc, Type = nextType }); acc = ""; } lexems.Add(new Lexem { Value = c.ToString(), Type = LexemType.Operator }); } else if (c == ',') { if (readingId) { readingId = false; if (c == '(' && nextType == LexemType.Identifier) { nextType = LexemType.Function; } else if (c != '(' && nextType == LexemType.Identifier) { nextType = LexemType.Variable; } lexems.Add(new Lexem { Value = acc, Type = nextType }); acc = ""; } lexems.Add(new Lexem { Value = c.ToString(), Type = LexemType.Delimier }); } } if (acc != "" && nextType == LexemType.Identifier) { nextType = LexemType.Variable; lexems.Add(new Lexem { Value = acc, Type = nextType }); } else { lexems.Add(new Lexem { Value = acc, Type = nextType }); } return(lexems); }
public RegexLexemDefinition(string regex, LexemType type) { Regex = new Regex(@"\G" + regex, RegexOptions.Compiled); Type = type; }
public void Reset(LexemType type) { this.content.Length = 0; this.type = type; }
private object ProcessOperator(Lexem oper, Lexem leftValue, Lexem rightValue, ref LexemType lt) { if (oper.Content.ToString() == "]") { lt = LexemType.Variable; return(Storage.GetVariable(leftValue.Content.ToString(), rightValue)); } return(Helper.Calculate(oper, leftValue, rightValue, ref lt)); }
/// <summary> /// Detect constant value overflow in lexems /// </summary> /// <param name="value">Constant value</param> /// <param name="type">Constant type</param> /// <returns></returns> public bool DetectOverflow(string value, LexemType type) { try { if(type == LexemType.IntLiteral) RetrieveInt(value, false); if (type == LexemType.FloatLiteral) RetrieveFloat(value, false); if (type == LexemType.ComplexLiteral) RetrieveComplex(value, false); return false; } catch { return true; } }
public PListLexem(string val, LexemType type, CharPosition Position) { this.Value = val; this.Type = type; this.Position = Position; }
protected object EvaluateObject(object currentObj, string s, int startIdx, out int endIdx) { LexemType lexemType = GetLexemType(s, startIdx, out endIdx); // stop if (lexemType == LexemType.Stop) { endIdx = s.Length - 1; return(null); } startIdx = endIdx; // indexer if ((lexemType & LexemType.DelimiterOpenBracket) == LexemType.DelimiterOpenBracket) { ArrayList indexerParamsList = new ArrayList(); do { // read arg lexemType = GetLexemType(s, startIdx, out endIdx); if ((lexemType & LexemType.String) == LexemType.String) { indexerParamsList.Add(GetLexem(lexemType, s, startIdx, endIdx)); startIdx = endIdx; lexemType = GetLexemType(s, startIdx, out endIdx); } else { OnEvalError("expected indexer argument", s, startIdx); } // read delim startIdx = endIdx; // param list is finished ? if ((lexemType & LexemType.DelimiterCloseBracket) == LexemType.DelimiterCloseBracket) { break; } if ((lexemType & LexemType.DelimiterComma) != LexemType.DelimiterComma) { OnEvalError("expected ']' or ','", s, startIdx); } } while (true); try { return(EvaluateObjectIndexer(currentObj, indexerParamsList)); } catch (Exception ex) { OnEvalError("cannot evaluate indexer", s, startIdx); } } // property if ((lexemType & LexemType.DelimiterDot) == LexemType.DelimiterDot) { lexemType = GetLexemType(s, startIdx, out endIdx); // 'this' object ? if (lexemType == LexemType.Stop) { return(currentObj); } // expected property name if (lexemType != LexemType.String) { OnEvalError("expected property name", s, startIdx); } string propertyName = GetLexem(lexemType, s, startIdx, endIdx); startIdx = endIdx; return(EvaluateObjectProperty(currentObj, propertyName)); } OnEvalError("expected property or indexer", s, startIdx); return(null); }
public StaticLexemDefinition(string sig, LexemType type, bool is_id = false) { Signature = sig; Type = type; IsIdentifier = is_id; }
//строки разбираются на числа и слова. Пробелы расцениваются как разделители, но не считаются лексемами. private static List <DtLexem> StrToLexem(string str) { List <DtLexem> res = new List <DtLexem>(); string s = str.Trim(); if (s.Length == 0) { return(res); } DtLexem l = null; for (int i = 0; i < s.Length; i++) { char c = s[i]; if (c == ' ') { if (l != null) { res.Add(l); l = null; } continue; } LexemType lt = GetLexemType(c); if (lt == LexemType.Symbol) { if (l != null) { res.Add(l); } l = new DtLexem(); l.Type = lt; l.Lexem = c.ToString(); continue; } if (l == null) { l = new DtLexem(); l.Type = lt; l.Lexem = c.ToString(); } else { if (l.Type == lt) { l.Lexem += c; } else { if (l != null) { res.Add(l); } l = new DtLexem(); l.Type = lt; l.Lexem = c.ToString(); } } } if (l != null) { res.Add(l); } return(res); }
public DynamicLexemDefenition(string representation, LexemType type) : base(new Regex(representation, RegexOptions.Compiled), type) { }
public Lexem(object content, LexemType tokenType, int startPos) { this.LexemType = tokenType; this.Content = content; this.Position = startPos; }
public ExecutionAndCount(LexemType ex1 = LexemType.Unknown, LexemType ex2 = LexemType.Unknown, LexemType ex3 = LexemType.Unknown, int count = 0) { Execution1 = ex1; Execution2 = ex2; Execution3 = ex3; Count = count; }
public ShortAssignmentNode(LexemType opType, NodeBase expr) { _operatorType = opType; _assignmentOperator = OperatorLookups[opType]; Expression = expr; }
private void ParseXmlKeyWord(ICollection <CodeLexem> res, ref SourcePart text, LexemType type) { var index = text.IndexOfAny(XmlEndOfTerm); if (index <= 0) { return; } var delimiterIndex = text.IndexOf(XmlNamespaceDelimeter); if (delimiterIndex > 0 && delimiterIndex < index) { res.Add(new CodeLexem(type, CutString(ref text, delimiterIndex))); res.Add(new CodeLexem(LexemType.Symbol, CutString(ref text, 1))); res.Add(new CodeLexem(type, CutString(ref text, index - delimiterIndex - 1))); return; } res.Add(new CodeLexem(type, CutString(ref text, index))); }
public Lexem(LexemType type, string content) { this.Content = content; this.Type = type; }
/// <summary> /// Добавляет значение в таблицу лексем /// </summary> /// <param name="numOfStr">Номер строки в файле, где написано слово</param> /// <param name="lexem">Лексема</param> /// <param name="lexType">Тип лексемы. См. перечисление LexemType</param> internal void AddCell(int numOfStr, string lexem, LexemType lexType) { LexemTable.Add(new LexemDataCell(numOfStr, lexem, lexType)); }
protected LexemType GetLexemType(string s, int startIdx, out int endIdx) { LexemType lexemType = LexemType.Unknown; endIdx = startIdx; while (endIdx < s.Length) { int delimIdx = Array.IndexOf(delimiters, s[endIdx]); if (delimIdx >= 0) { if (lexemType == LexemType.Unknown) { endIdx++; return(delimetersLexemType[delimIdx]); } if (lexemType != LexemType.QuotedString) { return(lexemType); } } else if (Char.IsLetterOrDigit(s[endIdx])) { if (lexemType == LexemType.Unknown) { lexemType = LexemType.String; } } else if (s[endIdx] == charQuote) { if (lexemType == LexemType.Unknown) { lexemType = LexemType.QuotedString | LexemType.String; } else { if ((lexemType & LexemType.QuotedString) == LexemType.QuotedString) { // check for "" combination if (((endIdx + 1) < s.Length && s[endIdx + 1] != charQuote)) { endIdx++; return(lexemType); } else if ((endIdx + 1) < s.Length) { endIdx++; // skip next quote } } } } else if (Char.IsControl(s[endIdx]) && lexemType != LexemType.Unknown && (lexemType & LexemType.QuotedString) != LexemType.QuotedString) { return(lexemType); } // goto next char endIdx++; } if (lexemType == LexemType.Unknown) { return(LexemType.Stop); } if ((lexemType & LexemType.QuotedString) == LexemType.QuotedString) { OnEvalError("Unterminated constant", s, startIdx); } return(lexemType); }
protected bool GetGroupType(LexemType lexemType, string s, int startIdx, ref int endIdx, ref GroupType groupType) { string lexem = GetLexem(s, startIdx, endIdx).ToLower(); if (lexemType==LexemType.Name) { int idx = Array.IndexOf(nameGroups, lexem); if (idx<0) return false; groupType = enumGroups[idx]; return true; } if (lexemType==LexemType.Delimiter) { // read all available delimiters... GetAllDelimiters(s, endIdx, out endIdx); lexem = GetLexem(s, startIdx, endIdx); int idx = Array.IndexOf(delimiterGroups, lexem); if (idx<0) return false; groupType = enumGroups[idx]; return true; } return false; }
public void ParseValType() { if (Type == LexemType.Number) { if (!int.TryParse(Lexem, out Value)) { Type = LexemType.Word; ValType = ValueType.Other; Value = -1; return; } if (Lexem.Length <= 2) { ValType = ValueType.Number2; } else if (Lexem.Length == 4) { ValType = ValueType.Number4; } else { ValType = ValueType.Other; } } if (Type == LexemType.Symbol) { ValType = ValueType.Symbol; } if (Type == LexemType.Word) { if (Lexem.Length == 1) { ValType = ValueType.Symbol; } else { string s2 = Lexem.ToLower(); int m = 0; if (s2 == "jan" || s2 == "january" || s2 == "янв" || s2 == "января" || s2 == "январь") { m = 1; } else if (s2 == "feb" || s2 == "february" || s2 == "фев" || s2 == "февраль" || s2 == "февраля") { m = 2; } else if (s2 == "mar" || s2 == "march" || s2 == "мар" || s2 == "мрт" || s2 == "март" || s2 == "марта") { m = 3; } else if (s2 == "apr" || s2 == "april" || s2 == "апр" || s2 == "апрель" || s2 == "апреля") { m = 4; } else if (s2 == "may" || s2 == "may" || s2 == "май" || s2 == "мая") { m = 5; } else if (s2 == "jun" || s2 == "june" || s2 == "июнь" || s2 == "июн" || s2 == "июня") { m = 6; } else if (s2 == "jul" || s2 == "july" || s2 == "июл" || s2 == "июль" || s2 == "июля") { m = 7; } else if (s2 == "aug" || s2 == "august" || s2 == "авг" || s2 == "август" || s2 == "августа") { m = 8; } else if (s2 == "sep" || s2 == "sept" || s2 == "september" || s2 == "сен" || s2 == "сент" || s2 == "сентябрь" || s2 == "сентября") { m = 9; } else if (s2 == "oct" || s2 == "october" || s2 == "окт" || s2 == "октябрь" || s2 == "октября") { m = 10; } else if (s2 == "nov" || s2 == "november" || s2 == "нояб" || s2 == "нбр" || s2 == "ноя" || s2 == "ноябрь" || s2 == "ноября") { m = 11; } else if (s2 == "december" || s2 == "dec" || s2 == "дек" || s2 == "декабрь" || s2 == "декабря") { m = 12; } if (m > 0) { Value = m; ValType = ValueType.MonthWord; } else { ValType = ValueType.Other; } } } }
public Lexem(LexemType type, string value) { this.Type = type; this.Value = value; }
public Lexeme(string text, LexemType type) { Text = text; this.type = type; }
public ShortAssignmentNode(LexemType opType, NodeBase expr) { _OperatorType = opType; _AssignmentOperator = OperatorLookups[opType]; Expression = expr; }