public WSOperation(string _name, OperatorChars _operatorChar, List <string> _aliaces = null) : base(_name, _aliaces) { OperatorChar = Operators[_operatorChar]; }
public WSStateOperation(string _name, OperatorChars _operatorChar, List <string> _aliaces = null) : base(_name, _operatorChar, _aliaces) { }
/// <summary> /// Scans a token. /// </summary> void ScanToken() { var c = source.Peek(); // Test for whitespace if (char.IsWhiteSpace(source.Peek())) { // Skip the whitespace source.SkipWhitespace(); return; } // Test for hexadecimal number if (source.See(2) && source.Peeks(2) == "0x") { // Read a hexadecimal number ReadHexNumber(); return; } // Test for decimal number if (char.IsDigit(c)) { // Read a decimal number ReadNumber(); return; } // Test for single-character operator if (OperatorChars.Contains(c.ToString())) { // Read an operator ReadOperator(); return; } // Build key-value-pairs of characters and their // corresponding token classes. var dict = new Dictionary <char, TokenClass> { { '{', TokenClass.OpenBrace }, { '}', TokenClass.CloseBrace }, { '(', TokenClass.OpenParen }, { ')', TokenClass.CloseParen }, { '[', TokenClass.OpenBracket }, { ']', TokenClass.CloseBracket }, { ';', TokenClass.Semicolon }, { ':', TokenClass.Colon }, { ',', TokenClass.Comma } }; // Test for those characters if (dict.ContainsKey(c)) { // Skip if advancing is possible if (source.See()) { source.Skip(); } // Add the lexeme lexemes.Add(new Lexeme(dict[c], source, c)); return; } // Test for other stuff switch (c) { case '#': // Skip a character source.Skip(); // Read a comment line var comment = source.ReadLine(); // Test if the line cotnains source analysis hints if (comment.TrimStart().StartsWith("analysis", StringComparison.Ordinal)) { // Parse the source analysis hint var parts = comment.Trim().Split(' '); if (parts.Length != 3) { break; } var action = parts[1].Trim(); var name = parts[2].Trim(); // Add the source analysis hint lexemes.Add(new Lexeme(TokenClass.SourceAnalysisHint, source, $"{action}:{name}")); } break; case '\'': case '"': case '`': // Read a string ReadString(); break; default: // Test for binary string if (source.See() && c == 'b' && (source.Peek(1) == '\"' || source.Peek(1) == '\'')) { // Read a binary string ReadBinaryString(); break; } // Test for identifier if (char.IsLetter(c) || c == '_') { // Read an identifier ReadIdentifier(); break; } // The token was not handled by any of the above code; Throw an exception throw new Exception($"Unexpected token: '{c}' at {source.Location}."); } }