Beispiel #1
0
        /// <summary>
        /// Parses Acc to array or seq ([], .)
        /// and ListTrans call e.g. Param.Count()
        /// </summary>
        /// <param Name="lBaseAcc"></param>
        /// <returns>true - access found, continue chain of accs, false - stop parsing</returns>
        private bool Acc(ref IExpr lBaseAcc)
        {
            //arr
            if (null != lex)
            {
                if (lex.Text == "[")
                {
                    lex = lex.Next();
                    IExpr lIndExpr = Expr();
                    ExpectSign("]");
                    lBaseAcc = new AccessArray(mGrammar, (Access)lBaseAcc, lIndExpr);
                    return(true);
                }

                //struct
                if (lex.Text == ".")
                {
                    lex = lex.Next();
                    string lFieldName = lex.Text;
                    lex = lex.Next();
                    if (lex != null && lex.Type == LexemType.LeftBr)
                    {
// call of ListTrans
                        lex      = lex.Next();
                        lBaseAcc = (IExpr)TransCall1((Access)lBaseAcc, lFieldName);
                    }
                    else
                    {
                        lBaseAcc = new AccessSeq(mGrammar, lBaseAcc, lFieldName);
                        return(true);
                    }
                }
            }
            return(false);
        }
Beispiel #2
0
        public static UIElement CreateControl(IPhrase element, List <string> aOuterSymbols)
        {
            if (element is Seqence)
            {
                MainWindow.AllSequenses++;
                return(new SeqenceControl(element as Seqence, aOuterSymbols));
            }
            else if (element is AlternativeSet)
            {
                MainWindow.AllAlternativeSets++;
                return(new AlternativeControl(element as AlternativeSet, aOuterSymbols));
            }
            else if (element is QuantifiedPhrase)
            {
                return(new QuantifierControl(element as QuantifiedPhrase, aOuterSymbols));
            }
            else if (element is NonTerminal)
            {
                NonTerminal s = element as NonTerminal;

                MainWindow.AllNonTerminals++;
                return(new NonTerminalControl(s, aOuterSymbols));
            }
            else if (element is Terminal)
            {
                Terminal s = element as Terminal;

                Label l = new Label();
                l.Content = s.Text;
                //Run r = new Run(s.Text);
                l.Foreground = Brushes.Red;
                return(l);
            }


            Label unk = new Label();

            if (element is AccessSeq)
            {
                AccessSeq acc = element as AccessSeq;
                unk.Content = "#" + acc.ObjectName + "." + acc.mFieldName;
            }
            else if (element is TransCallPhrase)
            {
                TransCallPhrase trans = element as TransCallPhrase;
                unk.Content = "call " + trans.BindedMethod.Name;
            }
            else if (element is AccessArray)
            {
                AccessArray ar = element as AccessArray;
                unk.Content = ar.ObjectName + "[" + ar.IndexExpr.ToString() + "]";
            }
            else
            {
                unk.Content = "unknown:" + element.ToString();
            }
            return(unk);
        }
        public override IDerivation Visit(AccessArray aAccessArray, DerivationContext aContext)
        {
            CyclesDetectContext context = aContext as CyclesDetectContext;

            aAccessArray.Parent = context.Parent;
            CyclesDetectContext newContext = new CyclesDetectContext(aContext as CyclesDetectContext);

            newContext.Parent = aAccessArray;
            return(base.Visit(aAccessArray, newContext));
        }
Beispiel #4
0
        public virtual IDerivation Visit(AccessArray aAccessArray, DerivationContext aContext)
        {
            //TODO через строку некрасиво, надо чтобы были разные типы выражений (числовые и строковые)
            //и чтобы операция раскрытия для каждого типа была своей (возвращала int а не string)
            //А здесь надо проверить тип выражения и если не числовой, ругнуться осмысленно, причем :)
            int            lInd  = int.Parse(aAccessArray.IndexExpr.Accept(aContext).ToString());
            ListDerivation lList = aAccessArray.mParentAccess.Accept(aContext) as ListDerivation;

            if (lList != null)
            {
                return(lList[lInd]);
            }
            else
            {
                throw new GrammarDeductException("Incorrect [] access! There is no ListDerivation!");
            }
        }
Beispiel #5
0
 public virtual IDerivation Visit(AccessArray aAccessArray, DerivationContext aContext)
 {
     return(null);
 }