Beispiel #1
0
        public static string GetLexeme(this TokenCode value)
        {
            FieldInfo fieldInfo = value.GetType().GetField(value.ToString());

            if (fieldInfo == null)
            {
                return(null);
            }
            var attribute = (LexemeAttribute)fieldInfo.GetCustomAttribute(typeof(LexemeAttribute));

            return(attribute.Text);
        }
Beispiel #2
0
        public static Token expect(TokenCode code)
        {
            Token token = get();

            if (token.code == code)
            {
                forget(); return(token);
            }
            // Else error: token 'code' expected but not found
            error(token, "not-found", code.ToString());
            return(null);
        }