コード例 #1
0
        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 MathNet.Symbolics.Exceptions.ParsingException("Parsing failed. Parser Scanner detected unexpected operand part token '" + ahead.Text + "'");
        }
コード例 #2
0
        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();
            }
        }
コード例 #3
0
        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());
        }
コード例 #4
0
        public LexerToken MatchGet(TokenTypes expected)
        {
            LexerToken t = buffer.ElementAt(consumeOffset);

            if (!t.IsType(expected))
            {
                throw new Exceptions.ParsingException(string.Format(
                                                          Config.UserCulture, Properties.Resources.ex_Parsing_Failed_TokenMismatch, expected.ToString(), t.Text, CurrentTokenNeighbourhood()));
            }
            Consume();
            return(t);
        }
コード例 #5
0
 private IEntity ScanEntity(LexerToken token, InfixNotation notation, int inputs)
 {
     if (token.IsType(TokenTypes.MathIdentifier))
     {
         return(library.LookupEntity(MathIdentifier.Parse(token.Text)));
     }
     else if (token.IsType(TokenTypes.Literal) || token.IsType(TokenTypes.SymbolIdentifier)) //symbol
     {
         return(library.LookupEntity(token.Text, notation, inputs));
     }
     else //textsymbol or label
     {
         IEntity entity;
         if (library.TryLookupEntity(token.Text, notation, inputs, out entity))
         {
             return(entity);
         }
         else
         {
             MathIdentifier id = library.FindEntityByLabel(token.Text);
             return(library.LookupEntity(id));
         }
     }
 }
コード例 #6
0
 private static bool IsBeginningEncapsulation(LexerToken token)
 {
     return(token.IsType(TokenTypes.Left));
 }
コード例 #7
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());
            IEntity lastEntity, topEntity;

            while (true)
            {
                LexerToken ahead = tokenizer.LookaheadFistToken;
                if (!(ahead.IsType(TokenTypes.SymbolIdentifier) || ahead.IsType(TokenTypes.TextIdentifier)))
                {
                    break;
                }
                // TODO: Optimize using TryMethods...
                if (library.ContainsEntity(ahead.Text, InfixNotation.LeftAssociativeInnerOperator))
                {
                    lastEntity = library.LookupEntity(ahead.Text, InfixNotation.LeftAssociativeInnerOperator, 2, 1, 0);
                }
                else if (library.ContainsEntity(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    = 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    = builder.Function(topEntity, expressionStack.Pop(), swap);
                expressionStack.Push(s);
            }

            Signal ret = expressionStack.Pop();

            system.AddSignalTree(ret, false, false);
            return(ret);
        }
コード例 #8
0
 private bool IsBinary(LexerToken token)
 {
     return((token.IsType(TokenTypes.SymbolIdentifier) || token.IsType(TokenTypes.TextIdentifier)) &&
            (library.ContainsEntity(token.Text, InfixNotation.LeftAssociativeInnerOperator) ||
             library.ContainsEntity(token.Text, InfixNotation.RightAssociativeInnerOperator)));
 }
コード例 #9
0
 private bool IsRightUnary(LexerToken token)
 {
     return((token.IsType(TokenTypes.SymbolIdentifier) || token.IsType(TokenTypes.TextIdentifier)) &&
            library.ContainsEntity(token.Text, InfixNotation.PostOperator));
 }