Advertisement
uniblab

Looking up words in our dict stack

Dec 4th, 2020
1,400
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.62 KB | None | 0 0
  1. private static Type FindWord( System.String word ) {
  2.     Type output = null;
  3.  
  4.     Type probe;
  5.     var stack = theDictStack;
  6.     System.Collections.Generic.IDictionary<System.String, Type> dict;
  7.     while ( !stack.IsEmpty && ( null == output ) ) {
  8.         dict = stack.Peek();
  9.         if ( dict.TryGetValue( word, out probe ) ) {
  10.             output = probe;
  11.             break;
  12.         }
  13.         stack = stack.Pop();
  14.     }
  15.  
  16.     if ( null == output ) {
  17.         if ( word.StartsWith( "(" ) ) {
  18.             output = Type.CreateString( word );
  19.         } else if ( word.StartsWith( "/" ) ) {
  20.             output = Type.CreateLiteral( word );
  21.         } else {
  22.             output = Type.AsNumber( word );
  23.         }
  24.     }
  25.  
  26.     return output;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement