private Signal ScanOperandPart()
        {
            LexerToken ahead = tokenizer.LookaheadFistToken;

            if (IsBeginningEncapsulation(ahead))
            {
                return(ScanEncapsulation());
            }
            if (IsLeftUnary(ahead))
            {
                return(ScanLeftUnary());
            }
            if (ahead.IsType(TokenTypes.TextIdentifier) || ahead.IsType(TokenTypes.SymbolIdentifier))
            {
                return(ScanIdentifierInExpression());
            }
            if (ahead.IsType(TokenTypes.Integer))
            {
                return(ScanIntegerSignal());
            }
            if (ahead.IsType(TokenTypes.Real))
            {
                return(ScanRealSignal());
            }
            if (ahead.IsType(TokenTypes.Literal))
            {
                return(ScanLiteralSignal());
            }
            throw new ParsingException("Parsing failed. Parser Scanner detected unexpected operand part token '" + ahead.Text + "'");
        }
        private void ScanCommand()
        {
            LexerToken t = tokenizer.LookaheadFistToken;

            if (t.IsType(TokenTypes.DefineKeyword))
            {
                ScanDefine();
            }
            else if (t.IsType(TokenTypes.InstantiateKeyword))
            {
                ScanInstantiate();
            }
            else if (t.IsType(TokenTypes.SignalKeyword))
            {
                ScanSignalDeclaration();
            }
            else if (t.IsType(TokenTypes.BusKeyword))
            {
                ScanBusDeclaration();
            }
            else if (t.IsType(TokenTypes.TextIdentifier) && tokenizer.LookaheadToken(1).IsType(TokenTypes.Assignment))
            {
                ScanSignalAssignment();
            }
            else
            {
                ScanSignalExpression();
            }
        }
        private Signal ScanEncapsulation()
        {
            LexerToken ahead = tokenizer.LookaheadFistToken;

            if (ahead.IsType(TokenTypes.LeftList))
            {
                return(ScanParenthesisSignal());
            }
            if (ahead.IsType(TokenTypes.LeftVector))
            {
                return(ScanVectorSignal());
            }
            if (ahead.IsType(TokenTypes.LeftSet))
            {
                return(ScanSetSignal());
            }
            return(ScanScalarSignal());
        }
        public LexerToken MatchGet(TokenTypes expected)
        {
            LexerToken t = buffer.ElementAt(consumeOffset);

            if (!t.IsType(expected))
            {
                throw new ParsingException(string.Format(MathNet.Symbolics.Properties.Resources.ex_Parsing_Failed_TokenMismatch, expected.ToString(), t.Text, CurrentTokenNeighbourhood()));
            }
            Consume();
            return(t);
        }
 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. 6
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. 7
0
 private static bool IsBeginningEncapsulation(LexerToken token)
 {
     return token.IsType(TokenTypes.Left);
 }
Esempio n. 8
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. 9
0
 private bool IsRightUnary(LexerToken token)
 {
     return (token.IsType(TokenTypes.SymbolIdentifier) || token.IsType(TokenTypes.TextIdentifier))
         && context.Library.Entities.ContainsSymbol(token.Text, InfixNotation.PostOperator);
 }
Esempio n. 10
0
 private static bool IsBeginningEncapsulation(LexerToken token)
 {
     return(token.IsType(TokenTypes.Left));
 }
Esempio n. 11
0
        private Signal ScanSignalExpression()
        {
            /*
             *  This method is kind of a postfix machine, parsing
             *  infix expressions to postfix expressions (having
             *  regard to precedence) using the operator stack and
             *  evaluates the postfix term to an expression tree
             *  using the expression stack.
             */

            SignalStack expressionStack = new SignalStack(4, 4096);
            EntityStack operatorStack   = new EntityStack(4, 4096);

            expressionStack.Push(ScanOperand());
            Entity lastEntity, topEntity;

            MathNet.Symbolics.Backend.Containers.EntityTable entityTable = context.Library.Entities;
            Library library = context.Library;

            while (true)
            {
                LexerToken ahead = tokenizer.LookaheadFistToken;
                if (!(ahead.IsType(TokenTypes.SymbolIdentifier) || ahead.IsType(TokenTypes.TextIdentifier)))
                {
                    break;
                }
                if (entityTable.ContainsSymbol(ahead.Text, InfixNotation.LeftAssociativeInnerOperator))
                {
                    lastEntity = library.LookupEntity(ahead.Text, InfixNotation.LeftAssociativeInnerOperator, 2, 1, 0);
                }
                else if (entityTable.ContainsSymbol(ahead.Text, InfixNotation.RightAssociativeInnerOperator))
                {
                    lastEntity = library.LookupEntity(ahead.Text, InfixNotation.RightAssociativeInnerOperator, 2, 1, 0);
                }
                else
                {
                    break;
                }
                tokenizer.Consume();

                while (operatorStack.Count > 0 && IsPrecedenceLeftFirst(operatorStack.Peek(), lastEntity))
                {
                    topEntity = operatorStack.Pop();
                    Signal swap = expressionStack.Pop();
                    Signal s    = context.Builder.Function(topEntity, expressionStack.Pop(), swap);
                    expressionStack.Push(s);
                }

                operatorStack.Push(lastEntity);
                expressionStack.Push(ScanOperand());
            }

            while (operatorStack.Count > 0)
            {
                topEntity = operatorStack.Pop();
                Signal swap = expressionStack.Pop();
                Signal s    = context.Builder.Function(topEntity, expressionStack.Pop(), swap);
                expressionStack.Push(s);
            }

            Signal ret = expressionStack.Pop();

            system.AddSignalTree(ret, false, false);
            return(ret);
        }
Esempio n. 12
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. 13
0
 private bool IsRightUnary(LexerToken token)
 {
     return((token.IsType(TokenTypes.SymbolIdentifier) || token.IsType(TokenTypes.TextIdentifier)) &&
            context.Library.Entities.ContainsSymbol(token.Text, InfixNotation.PostOperator));
 }