Esempio n. 1
0
 private Entity ScanEntity(LexerToken token, InfixNotation notation, int inputs)
 {
     if(token.IsType(TokenTypes.MathIdentifier))
         return context.Library.LookupEntity(MathIdentifier.Parse(token.Text));
     else if(token.IsType(TokenTypes.Literal) || token.IsType(TokenTypes.SymbolIdentifier)) //symbol
         return context.Library.LookupEntity(token.Text, notation, inputs);
     else //textsymbol or label
     { 
         Entity entity;
         if(context.Library.TryLookupEntity(token.Text, notation, inputs, out entity))
             return entity;
         else
         {
             string domain = context.Library.Entities.FindDomainOfLabel(token.Text);
             return context.Library.LookupEntity(new MathIdentifier(token.Text, domain));
         }
     }
 }
Esempio n. 2
0
 private static bool IsBeginningEncapsulation(LexerToken token)
 {
     return token.IsType(TokenTypes.Left);
 }
Esempio n. 3
0
 private bool IsBinary(LexerToken token)
 {
     return (token.IsType(TokenTypes.SymbolIdentifier) || token.IsType(TokenTypes.TextIdentifier))
         && (context.Library.Entities.ContainsSymbol(token.Text,InfixNotation.LeftAssociativeInnerOperator)
         || context.Library.Entities.ContainsSymbol(token.Text, InfixNotation.RightAssociativeInnerOperator));
 }
Esempio n. 4
0
 private bool IsRightUnary(LexerToken token)
 {
     return (token.IsType(TokenTypes.SymbolIdentifier) || token.IsType(TokenTypes.TextIdentifier))
         && context.Library.Entities.ContainsSymbol(token.Text, InfixNotation.PostOperator);
 }
 /// <summary>Expand the token buffer by doubling its capacity</summary>
 private void Expand()
 {
     if(maxSize > 0 && buffer.Length * 2 > maxSize)
         throw new ParsingException("Parsing failed. Maximum parser buffer size exceeded.");
     LexerToken[] newBuffer = new LexerToken[buffer.Length * 2];
     for(int i = 0; i < buffer.Length; i++)
         newBuffer[i] = buffer[(offset + i) & sizeLessOne];
     buffer = newBuffer;
     sizeLessOne = buffer.Length - 1;
     offset = 0;
 }
 /// <summary>Add token to end of the queue</summary>
 /// <param name="token">The token to add</param>
 private void Append(LexerToken token)
 {
     if(count == buffer.Length)
         Expand();
     buffer[(offset + count) & sizeLessOne] = token;
     count++;
 }