uniblab icon

Looking up words in our dict stack

uniblab | PRO | 12/05/20 12:56:53 AM UTC | 0 ⭐ | 2450 👁️ | Never ⏰ | []
C# |

620 B

|

None

|

0 👍

/

0 👎

private static Type FindWord( System.String word ) {
    Type output = null;
 
    Type probe;
    var stack = theDictStack;
    System.Collections.Generic.IDictionary<System.String, Type> dict;
    while ( !stack.IsEmpty && ( null == output ) ) {
        dict = stack.Peek();
        if ( dict.TryGetValue( word, out probe ) ) {
            output = probe;
            break;
        }
        stack = stack.Pop();
    }
 
    if ( null == output ) {
        if ( word.StartsWith( "(" ) ) {
            output = Type.CreateString( word );
        } else if ( word.StartsWith( "/" ) ) {
            output = Type.CreateLiteral( word );
        } else {
            output = Type.AsNumber( word );
        }
    }
 
    return output;
}

Comments