private static string CreateErrorMessage(ET errorType, Id errorId, byte errorColumn, int errorLine) { string[] codes = SourceCode.Split((char)TT.LF); HIDebug.Assert(codes.Length > errorLine); return(string.Format(Id.ErrorFormat.ToText(), codes[errorLine], "".PadLeft(errorColumn), errorType, errorId.ToText(), errorLine + 1)); }
public Symbol(Token token) { HIDebug.AssertEqual(token.Type, TT.Identifier); if (symbols.TryGetValue(token.Text, out _)) { throw new HIException(ET.NameError, Id.NameAlreadyDefined, token); } Token = token; symbols[token.Text] = this; }
public Token(TT type, string identifier, byte column, int line) { HIDebug.Assert(type == TT.Identifier || type == TT.String); Type = type; Column = column; Line = line; if (type == TT.Identifier && Keyword.Find(identifier, out KT keywordType)) { Type = TT.Keyword; KeywordType = keywordType; } else { StringId = strings.Count; strings.Add(identifier); } }
public override long Visit() { long leftValue = Left.Visit(); long rightValue = Right.Visit(); switch (Operator.Type) { case TT.Plus: return(leftValue + rightValue); case TT.Minus: return(leftValue - rightValue); case TT.Mul: return(leftValue * rightValue); case TT.Div: if (rightValue == 0) { throw new HIException(ET.ZeroDivisionError, Id.DivisionByZero, Operator.Column); } return(leftValue / rightValue); } HIDebug.Fail(Operator.Type, Id.InvalidOperator.ToText()); return(0); }
public IntegerNode(Token integerToken) { HIDebug.AssertEqual(integerToken.Type, TT.Integer); Integer = integerToken; }
public StringNode(Token stringToken) { HIDebug.AssertEqual(stringToken.Type, TT.String); str = stringToken; }