public Token(uint line, uint column, Token_Type type, string value) { this.line = line; this.column = column; this.type = type; this.value = value; }
public Token(Token_Type Type, float Value, int precedence) { this.Type = Type; this.Value = (float)Value; this.Precedence = precedence; SetOperatorString(Type); }
private void parse_letter() { do { append_char_to_builder(); }while (is_letter(next_char)); string s = builder.ToString(); builder.Clear(); token_type = keywords.Contains(s)? Token_Type.Keyword : operators.Contains(s)? Token_Type.Operator : (s == "true" || s == "false")? Token_Type.Boolean : (s == "null")? Token_Type.Null : Token_Type.Name; builder.Append(s); }
static Node <Token> tokenize_split(Code code, Node <Token> rest, Token_Type type, Location loc, char end) { bool unbreak = true; code.shift(); int start = code.index(); int trans_time = 0; while (code.noEnd() && unbreak) { char c = code.current(); if (c == end) { String str = code.substr(start, code.index()); if (trans_time != 0) { str = Util.stringFromEscape(str, end, trans_time); } rest = Node <Token> .extend( new Token(str, type, loc), rest ); code.shift(); unbreak = false; } else { if (c == '\\') { trans_time++; code.shift(); } code.shift(); } } if (unbreak) { throw new LocationException(loc, "³¬³ö·¶Î§ÈÔδ½áÊø"); } return(rest); }
private void parse_number() { do { append_char_to_builder(); }while (is_digit(next_char)); if (next_char == '.' && is_digit(next_next)) { do { append_char_to_builder(); }while (is_digit(next_char)); token_type = Token_Type.Decimal; } else { token_type = Token_Type.Integer; } }
bool MatchToken(Token_Type tp) { return(token.type == tp); }
private void begin_parse() { if (is_letter(next_char)) { parse_letter(); // name, keyword, boolean(true, false), null, operator(and, or, not...) } else if (is_digit(next_char)) { parse_number(); // integer or decimal } else { switch (next_char) { // 括号 case '(': case ')': case '[': case ']': case '{': case '}': { append_char_to_builder(); token_type = Token_Type.Bracket; } break; case '+': case '-': // 加减号或正负号 { append_char_to_builder(); token_type = Token_Type.Operator; } break; case '*': case '/': case '^': case '.': case '&': case '|': case '~': { append_char_to_builder(); token_type = Token_Type.Operator; } break; case '>': case '<': { append_char_to_builder(); // >, < if (next_char == '=') { append_char_to_builder(); // >=, <= } token_type = Token_Type.Operator; } break; case '=': { append_char_to_builder(); if (next_char == '>') // => { append_char_to_builder(); token_type = Token_Type.Arrow; } else if (next_char == '=') // == { append_char_to_builder(); token_type = Token_Type.Operator; } else { token_type = Token_Type.Assignment; // = } } break; case '!': { append_char_to_builder(); if (next_char == '=') // != { append_char_to_builder(); token_type = Token_Type.Operator; } else { throw new Exception(); } } break; case ':': { append_char_to_builder(); token_type = Token_Type.Colon; } break; case ';': { append_char_to_builder(); token_type = Token_Type.Semicolon; } break; case ',': { append_char_to_builder(); token_type = Token_Type.Comma; } break; case -1: token_type = Token_Type.Terminator; break; default: throw new Exception(); } } }
public Token(Token_Type tp, string le, double d, FuncPtr fp) { type = tp; lexico = le; value = d; funcPtr = fp; }
private void SetOperatorString(Token_Type input) { switch (input) { case Token_Type.Null: Operator_String = null; break; case Token_Type.Constant: Operator_String = "*-c"; break; case Token_Type.String: Operator_String = "*-s"; break; case Token_Type.Cell: Operator_String = "*-d"; break; case Token_Type.Add: Operator_String = "+"; break; case Token_Type.Subtract: Operator_String = "-"; break; case Token_Type.Multiply: Operator_String = "*"; break; case Token_Type.Divide: Operator_String = "/"; break; case Token_Type.Exponent: Operator_String = "^"; break; case Token_Type.LessThan: Operator_String = "<"; break; case Token_Type.GreaterThan: Operator_String = ">"; break; case Token_Type.Function: Operator_String = (string)this.Value; break; case Token_Type.LeftParen: Operator_String = "("; break; case Token_Type.RightParen: Operator_String = ")"; break; case Token_Type.Range: Operator_String = ":"; break; case Token_Type.SheetReferenceStart: Operator_String = ""; break; default: Operator_String = ""; break; } }
public Token(Token_Type Type, float Value) { this.Type = Type; this.Value = (float)Value; SetOperatorString(Type); }
public Token(Token_Type Type, string Value) { this.Type = Type; this.Value = (string)Value; SetOperatorString(Type); }
public Token() { //null constructor Type = Token_Type.Null; }
public CToken() { m_str = ""; m_token = Token_Type.Token_Unknown; }
public CToken(string _str) { m_str = _str; m_token = Token_Type.Token_Unknown; }
public Token(String value, Token_Type type, Location loc) { this.value = value; this.type = type; this.loc = loc; }