Esempio n. 1
0
 //------------------------------------------------------------
 /// <summary>
 /// 指定のトークンの種類であることを期待する。
 /// 期待通りであればトークンを次に進めtrueを返す。
 /// 期待通りでなければ指定のエラーを設定しfalseを返す。
 /// </summary>
 /// <param name="kind"></param>
 /// <param name="errorKind"></param>
 /// <returns></returns>
 bool expectToken(Token.Kind aKind, ErrorKind aErrorKind)
 {
     if (currentToken().Value != aKind)
     {
         setErrorKind(aErrorKind);
         return(false);
     }
     nextToken();
     return(true);
 }
Esempio n. 2
0
 void Expect(Token.Kind kind)
 {
     if (nextToken.kind == kind)
     {
         Next();
     }
     else
     {
         throw new SyntaxErrorException("saw " + nextToken.kind.ToString() + " where " +
                                        kind.ToString() + " was expected");
     }
 }
Esempio n. 3
0
        public static bool IsLiteral(Token.Kind kind)
        {
            switch (kind)
            {
            case Token.Kind.Integer:
            case Token.Kind.Float:
            case Token.Kind.Boolean:
            case Token.Kind.String:
            case Token.Kind.Null:
            case Token.Kind.Binary:
                return(true);

            default: return(false);
            }
        }
Esempio n. 4
0
        protected bool ExpectOptional(List <Token> tokens, ref int index, Token.Kind kind)
        {
            if (index >= tokens.Count)
            {
                throw new ParserException(tokens.Last(), ParserException.Kind.EndOfStream);
            }

            var token = tokens[index];

            if (token.kind == kind)
            {
                index++;
                return(true);
            }

            return(false);
        }
Esempio n. 5
0
        protected string ExpectValue(List <Token> tokens, ref int index, Token.Kind kind, ParserException.Kind exception)
        {
            if (index >= tokens.Count)
            {
                throw new ParserException(tokens.Last(), ParserException.Kind.EndOfStream);
            }

            var token = tokens[index];

            if (token.kind != kind)
            {
                throw new ParserException(token, exception);
            }

            index++;
            return(token.text);
        }
Esempio n. 6
0
        private void BreakIntoTokens(List <Token> tokens, ref string s, ref int baseIndex, ref int index, Token.Kind kind = Token.Kind.Invalid)
        {
            if (s.Length > 0)
            {
                var token = kind != Token.Kind.Invalid ? new Token(kind, s, baseIndex) : Tokenize(s, baseIndex);
                tokens.Add(token);
                s = "";
            }

            baseIndex = index;
        }
Esempio n. 7
0
 //------------------------------------------------------------
 // コンストラクタ。
 public FirstTokenTestRecipe(string aCode, Token.Kind aTokenKind)
 {
     Code      = aCode;
     TokenKind = aTokenKind;
 }
Esempio n. 8
0
 /// <summary>
 /// Gets the <see cref="ParseRule"/> for a given kind of token.
 /// </summary>
 /// <param name="kind">The kind of token that is associated with the desired <see cref="ParseRule"/></param>
 /// <returns>The <see cref="ParseRule"/> associated with the given kind of token.</returns>
 private static ParseRule GetRule(Token.Kind kind)
 {
     return(parseRules[(int)kind]);
 }