예제 #1
0
        public StackAutoma(Grammar grammar)
            : this("q0", grammar.VariablesEmpty.Contains(grammar.VariableStart))
        {
            this.gramma = grammar;
            AdicionarEstado("q1", false);
            AdicionarEstado("q2", true);
            AdicionarTransicao("q0", "q1", Symbol.EmptySymbol, Symbol.EmptySymbol, grammar.VariableStart);

            AdicionarTransicao("q1", "q2", Symbol.StackFinal, Symbol.TapeFinal, Symbol.EmptySymbol);

            SymbolList     visitados         = new SymbolList();
            Queue <Symbol> variaveisAVisitar = new Queue <Symbol>();

            variaveisAVisitar.Enqueue(grammar.VariableStart);
            visitados.Add(grammar.VariableStart);
            while (variaveisAVisitar.Count > 0)
            {
                Symbol variavelAtual = variaveisAVisitar.Dequeue();

                List <RuleProduction> regrasAtuais = grammar.GetRules(variavelAtual.Name);

                foreach (var item in regrasAtuais)
                {
                    AdicionarTransicao("q1", "q1", item.Source, item.FirstDestiny(), item.SkipFirstDestiny().ToArray());
                    foreach (var itemDestino in item.Destiny)
                    {
                        if (!itemDestino.Terminal && !visitados.Contains(itemDestino))
                        {
                            variaveisAVisitar.Enqueue(itemDestino);
                            visitados.Add(itemDestino);
                        }
                    }
                }
            }
        }
예제 #2
0
            async Task AddPartialTypeDeclarationsAsync(BaseTypeDeclarationSyntax node, CancellationToken cancellationToken)
            {
                await _Bar._SemanticContext.UpdateAsync(cancellationToken);

                var symbol = await _Bar._SemanticContext.GetSymbolAsync(node, cancellationToken);

                if (symbol == null)
                {
                    return;
                }
                var current = node.SyntaxTree;
                int c       = 1;

                foreach (var item in symbol.DeclaringSyntaxReferences)
                {
                    if (item.SyntaxTree == current || String.Equals(item.SyntaxTree.FilePath, current.FilePath, StringComparison.OrdinalIgnoreCase))
                    {
                        continue;
                    }
                    var partial = await item.GetSyntaxAsync(cancellationToken);

                    var i = _Menu.Add(partial, _Bar._SemanticContext);
                    i.Content.Text = System.IO.Path.GetFileName(item.SyntaxTree.FilePath);
                    i.Type         = SymbolItemType.Container;
                    AddMemberDeclarations(partial, true);
                    ++c;
                }
                _PartialCount = c;
            }
예제 #3
0
        public override (Symbol, SymbolList) Unroll(int length, SymbolList inputs, SymbolList begin_state = null, string layout = null, bool?merge_outputs = null)
        {
            this.Reset();
            var num_cells = this._cells.Count;

            if (begin_state == null)
            {
                begin_state = this.BeginState();
            }

            var p           = 0;
            var next_states = new SymbolList();

            foreach (var _tup_1 in this._cells.Select((_p_1, _p_2) => Tuple.Create(_p_2, _p_1)))
            {
                var i      = _tup_1.Item1;
                var cell   = _tup_1.Item2;
                var n      = cell.StateInfo.Length;
                var states = begin_state.Skip(p).Take(p + n).ToArray();
                p += n;
                var _tup_2 = cell.Unroll(length, inputs: inputs, begin_state: states, layout: layout, merge_outputs: i < num_cells - 1 ? null : merge_outputs);
                inputs = _tup_2.Item1;
                states = _tup_2.Item2;
                next_states.Add(states);
            }

            return(inputs, next_states);
        }
예제 #4
0
        public virtual (Symbol, SymbolList) Unroll(int length, SymbolList inputs, SymbolList begin_state = null, string layout = "NTC", bool?merge_outputs = null)
        {
            this.Reset();
            var _tup_1 = __internals__.NormalizeSequence(length, inputs, layout, false);

            inputs = _tup_1.Item1;
            if (begin_state == null)
            {
                begin_state = this.BeginState();
            }
            var states  = begin_state;
            var outputs = new SymbolList();

            foreach (var i in Enumerable.Range(0, length))
            {
                var _tup_2 = Call(inputs[i], states);
                var output = _tup_2.Item1;
                states = _tup_2.Item2;
                outputs.Add(output);
            }

            var _tup_3 = __internals__.NormalizeSequence(length, outputs, layout, merge_outputs.Value);

            outputs = _tup_3.Item1;
            return(outputs, states);
        }
예제 #5
0
        public virtual SymbolList BeginState(string func = "sym.Zeros", FuncArgs kwargs = null)
        {
            if (_modified)
            {
                throw new Exception("After applying modifier cells (e.g. DropoutCell) the base " +
                                    "cell cannot be called directly. Call the modifier cell instead.");
            }

            SymbolList states = new SymbolList();

            for (int i = 0; i < StateInfo.Length; i++)
            {
                var    info  = StateInfo[i];
                Symbol state = null;
                _init_counter++;
                kwargs.Add("name", $"{_prefix}begin_state_{_init_counter}");
                if (info == null)
                {
                    info = new StateInfo(kwargs);
                }
                else
                {
                    info.Update(kwargs);
                }

                var obj       = new sym();
                var m         = typeof(sym).GetMethod(func.Replace("sym.", ""), BindingFlags.Static);
                var keys      = m.GetParameters().Select(x => x.Name).ToArray();
                var paramArgs = info.GetArgs(keys);
                states.Add((Symbol)m.Invoke(obj, paramArgs));
            }

            return(states);
        }
예제 #6
0
        public static IEnumerable <ISentenceItem> Parse(string str)
        {
            var         items    = new List <ISentenceItem>();
            var         symbols  = new SymbolList();
            ParserState state    = ParserState.None;
            ParserState newState = ParserState.None;
            char        symbol;

            for (int i = 0; i < str.Length; i++)
            {
                symbol   = str[i];
                newState = GetState(symbol);
                if (state != newState && state != ParserState.None)
                {
                    items.Add(CreateSentenseItem(symbols.PopAll(), state));
                }

                state = newState;
                symbols.Add(new Symbol(symbol));
            }

            items.Add(CreateSentenseItem(symbols.PopAll(), newState));

            return(items);
        }
 public Transition(State source, Symbol symbol, State destiny, Symbol consumirPilha, SymbolList gravarPilha)
 {
     Source = source;
     Symbol = symbol;
     Destiny = destiny;
     ConsumingStack = new SymbolList();
     PushStack = new SymbolList();
     ConsumingStack.Add(consumirPilha);
     PushStack.AddRange(gravarPilha);
 }
 public Transition(State source, Symbol symbol, State destiny, Symbol consumirPilha, SymbolList gravarPilha)
 {
     Source         = source;
     Symbol         = symbol;
     Destiny        = destiny;
     ConsumingStack = new SymbolList();
     PushStack      = new SymbolList();
     ConsumingStack.Add(consumirPilha);
     PushStack.AddRange(gravarPilha);
 }
예제 #9
0
        protected override void InitialSymbol()
        {
            base.InitialSymbol();
            ISymbol         pSymbol      = m_pSimpleRender.Symbol;
            ptSymbolFactory pSymbolFac   = new ptSymbolFactory(pSymbol);
            ptSymbolClass   pSymbolClass = pSymbolFac.GetSymbolClass(m_pSimpleRender.Label, new List <string>()
                                                                     , 0, 0);

            SymbolList.Add(pSymbolClass);
        }
예제 #10
0
        public static SymbolList CellsBeginState(BaseRNNCell[] cells, string func, FuncArgs kwargs = null)
        {
            SymbolList ret = new SymbolList();

            foreach (var item in cells)
            {
                ret.Add(item.BeginState(func, kwargs));
            }

            return(ret.ToArray());
        }
예제 #11
0
        public override (Symbol, SymbolList) Call(Symbol inputs, SymbolList states)
        {
            this._counter += 1;
            var next_states = new SymbolList();
            var p           = 0;

            foreach (var cell in this._cells)
            {
                Debug.Assert(!(cell is BidirectionalCell));
                var n     = cell.StateInfo.Length;
                var state = states.Skip(p).Take(p + n).ToArray();
                p += n;
                var _tup_1 = cell.Call(inputs, state);
                inputs = _tup_1.Item1;
                state  = _tup_1.Item2;
                next_states.Add(state);
            }

            next_states.Add(null);
            return(inputs, next_states);
        }
 private void GenerateNewVars()
 {
     Normalized = new Grammar();
     NewVariables = new SymbolList();
     foreach (var item in simplified.Terminals)
     {
         int newId = GetNewId();
         Symbol s = new Symbol(newId, string.Empty, false);
         NewVariables.Add(s);
         NewRoles.Add(Normalized.AddRule(newId, item));
         DicVariablesTerminals.Add(item, s);
     }
 }
예제 #13
0
    public virtual SymbolList Flatten()
    {
        SymbolList all = new SymbolList();

        foreach (Symbol s in this)
        {
            all.Add(s);
        }
        for (ClassType c = this.baseClass; c != null; c = c.baseClass)
        {
            foreach (Symbol s in c)
            {
                if (s.Is("private"))
                {
                    continue;
                }
                if (s is Method || s is Property || s is Event)
                {
                    int i;
                    for (i = 0; i < all.Count; i++)
                    {
                        if (s.Equals(all[i]))
                        {
                            break;
                        }
                    }
                    if (i == all.Count || s.Is("abstract") && !all[i].Is("override"))
                    {
                        all.Add(s);
                    }
                }
                else
                {
                    all.Add(s);
                }
            }
        }
        return(all);
    }
예제 #14
0
파일: Parser.cs 프로젝트: Kotridiy/Task2
        public Text Parse(TextReader reader)
        {
            if (reader == null)
            {
                throw new ArgumentException(nameof(reader));
            }
            var         sentences = new List <Sentence>();
            var         items     = new List <ISentenceItem>();
            string      str;
            var         symbols  = new SymbolList();
            ParserState state    = ParserState.None;
            ParserState newState = ParserState.None;
            char        symbol;

            while (reader.Peek() != -1)
            {
                str = reader.ReadLine();
                for (int i = 0; i < str.Length; i++)
                {
                    symbol   = str[i];
                    newState = GetState(symbol);
                    if (state != newState && state != ParserState.None)
                    {
                        items.Add(CreateSentenseItem(symbols.PopAll(), state));

                        if (state == ParserState.EndSentense)
                        {
                            sentences.Add(CreateSectence(items));
                            items = new List <ISentenceItem>();
                        }
                    }


                    state = newState;
                    symbols.Add(new Symbol(symbol));
                }

                if (symbols.Count > 0)
                {
                    items.Add(CreateSentenseItem(symbols.PopAll(), newState));
                    if (newState == ParserState.EndSentense)
                    {
                        sentences.Add(CreateSectence(items));
                        items = new List <ISentenceItem>();
                        state = ParserState.None;
                    }
                }
            }

            return(new Text(sentences.ToArray()));
        }
예제 #15
0
    public SymbolList Lookup(string name, stringList namespaces)
    {
        SymbolList symbols = new SymbolList();

        foreach (Assembly a in assemblies)
        {
            foreach (System.Type t in a.GetTypes())
            {
                if (name == GetName(t) && (t.Namespace == "" || t.Namespace == null || namespaces.Contains(t.Namespace)))
                {
                    symbols.Add(GetSymbol(t));
                }
            }
        }
        return(symbols);
    }
예제 #16
0
    public SymbolList Lookup(string name, stringList namespaces)
    {
        SymbolList symbols = new SymbolList();

        foreach (MetaData m in metaData)
        {
            foreach (MetaDataTypeDefinition d in m.TypeDefs)
            {
                if (name == d.Name && (d.Namespace == "" || namespaces.Contains(d.Namespace)))
                {
                    symbols.Add(GetSymbol(d, m.Name));
                }
            }
        }
        return(symbols);
    }
예제 #17
0
        static int AddSymbolMembers(CSharpSmartBar bar, SymbolList list, ISymbol source, string typeCategory)
        {
            var nsOrType = source as INamespaceOrTypeSymbol;
            var members  = nsOrType.GetMembers().RemoveAll(m => m.CanBeReferencedByName == false);

            if (bar._IsVsProject)
            {
                switch (nsOrType.Name)
                {
                case nameof(KnownImageIds):
                    list.ContainerType = SymbolItemType.VsKnownImage;
                    list.IconProvider  = s => {
                        var f = s.Symbol as IFieldSymbol;
                        if (f == null || f.HasConstantValue == false || f.Type.SpecialType != SpecialType.System_Int32)
                        {
                            return(null);
                        }
                        return(ThemeHelper.GetImage((int)f.ConstantValue));
                    };
                    break;
                }
            }
            if (source.Kind == SymbolKind.NamedType && (source as INamedTypeSymbol).TypeKind == TypeKind.Enum)
            {
                // sort enum members by value
                members = members.Sort(CodeAnalysisHelper.CompareByFieldIntegerConst);
            }
            else
            {
                members = members.Sort(CodeAnalysisHelper.CompareByAccessibilityKindName);
            }
            foreach (var item in members)
            {
                var i = list.Add(item, bar._Context, false);
                if (typeCategory != null)
                {
                    i.Hint = typeCategory;
                }
            }
            return(members.Length);
        }
예제 #18
0
        /// <summary>
        /// Adiciona transição entre 2 estados.
        /// </summary>
        /// <param name="estadoOrigem">O estado origem do autômato.</param>
        /// <param name="consumirFita">O símbolo a ser avaliado.</param>
        /// <param name="estadoDestino">O estado destino.</param>

        public void AdicionarTransicao(string estadoOrigem, string estadoDestino, Symbol consumirPilha,
                                       Symbol consumirFita, params Symbol[] gravarPilha)
        {
            if (consumirPilha == null)
            {
                consumirPilha = Symbol.EmptySymbol;
            }
            SymbolList vars = new SymbolList();

            if (gravarPilha == null || gravarPilha.Length == 0)
            {
                vars.Add(Symbol.EmptySymbol);
            }
            else
            {
                vars.AddRange(gravarPilha);
            }


            foreach (var symbol in vars)
            {
                if (StackAlphabet.IndexOf(symbol) < 0 && symbol != Symbol.EmptySymbol && symbol != Symbol.StackFinal && symbol != Symbol.TapeFinal)
                {
                    StackAlphabet.Add(symbol);
                }
            }

            // Adiciona transições..
            if (States.ContainsKey(estadoOrigem) && States.ContainsKey(estadoDestino))
            {
                if (!Alphabet.Contains(consumirFita))
                {
                    Alphabet.Add(consumirFita);
                }

                States[estadoOrigem].AdicionarTransicao(States[estadoDestino], consumirFita, consumirPilha, vars);
            }
        }
예제 #19
0
        /// <summary>
        /// 初始化符号信息
        /// </summary>
        protected override void InitialSymbol()
        {
            base.InitialSymbol();
            IClassBreaksUIProperties objClassBreaksProp = m_pClassBreaksRender as IClassBreaksUIProperties;

            try
            {
                for (int i = 0; i < BreakCount; i++)
                {
                    double          cLowerLimit  = objClassBreaksProp.LowBreak[i];
                    double          cUpperLimit  = m_pClassBreaksRender.Break[i];
                    ISymbol         pSymbol      = m_pClassBreaksRender.get_Symbol(i);
                    ptSymbolFactory pSymbolFac   = new ptSymbolFactory(pSymbol);
                    ptSymbolClass   pSymbolClass = pSymbolFac.GetSymbolClass(m_pClassBreaksRender.Label[i], new List <string>()
                                                                             , cUpperLimit, cLowerLimit);
                    SymbolList.Add(pSymbolClass);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void FillAcessibles(Grammar gramatica)
        {
            AcessiblesVariables = new SymbolList();
            AcessiblesTerminals = new SymbolList();

            Visited = new SymbolList();

            Queue<Symbol> variaveisAVisitar = new Queue<Symbol>();

            variaveisAVisitar.Enqueue(gramatica.VariableStart);
            AcessiblesVariables.Add(gramatica.VariableStart);
            while (variaveisAVisitar.Count > 0)
            {
                var variavelAtual = variaveisAVisitar.Dequeue();
                Visited.Add(variavelAtual);

                List<RuleProduction> regrasAtuais = gramatica.Rules.Where(r => r.Source == variavelAtual).ToList();

                foreach (var item in regrasAtuais)
                {

                    foreach (var itemDestino in item.Destiny)
                    {
                        if (itemDestino.Terminal)
                        {
                            if (!AcessiblesTerminals.Contains(itemDestino))
                                AcessiblesTerminals.Add(itemDestino);

                        }
                        else if (!Visited.Contains(itemDestino) && !AcessiblesVariables.Contains(itemDestino))
                        {
                            variaveisAVisitar.Enqueue(itemDestino);
                            AcessiblesVariables.Add(itemDestino);
                        }

                    }
                }
            }
        }
        private void FillVariablesAcessibleTerminals()
        {
            VariablesCallTerminals = new SymbolList();

            for (int i = 0; i < GrammarNoUnitarianProductions.Variables.Count; i++)
            {
                Visited = new SymbolList();

                Queue<Symbol> varsToVisit = new Queue<Symbol>();

                varsToVisit.Enqueue(GrammarNoUnitarianProductions.Variables[i]);

                while (varsToVisit.Count > 0)
                {
                    Symbol variavelAtual = varsToVisit.Dequeue();
                    Visited.Add(variavelAtual);

                    List<RuleProduction> regrasAtuais = GrammarNoUnitarianProductions.Rules.Where(r => r.Source == variavelAtual).ToList();

                    foreach (var item in regrasAtuais)
                    {

                        if (item.DestinyContainsTerminal())
                        {
                            VariablesCallTerminals.Add(Source.Variables[i]);
                            varsToVisit.Clear();
                            break;
                        }
                        else
                        {
                            foreach (var itemDestino in item.Destiny)
                            {
                                if (!Visited.Contains(itemDestino))
                                    varsToVisit.Enqueue(itemDestino);

                            }
                        }
                    }
                }
            }
        }
        public CompilerXmlParser(string filename)
        {
            NamesVars = new Dictionary<int, List<string>>();
            RecsTokens = new List<RecognitionToken>();
            Grammar = new Grammar();

            using (FileStream file = File.OpenRead(filename))
            {
                XDocument xdoc = XDocument.Load(file, LoadOptions.None);

                var settings = xdoc.Element("Compiler").Element("Settings");
                NormAbstract norm;
                switch (settings.Element("Norm").Value)
                {
                    case "MIN":
                        norm = new MinNorm();
                        break;
                    default:
                        norm = new MultiplyNorm();
                        break;
                }
                ConormAbstract conorm;
                switch (settings.Element("Conorm").Value)
                {
                    case "SUM":
                        conorm = new SumMinusProductConorm();
                        break;
                    default:
                        conorm = new MaxConorm();
                        break;
                }

                var recTokens = xdoc.Element("Compiler").Element("RecTokens").Elements("RecToken");
                int idTokens = 1;
                foreach (var token in recTokens)
                {

                    int id = idTokens++;
                    if (token.Attributes("id").Any() && !string.IsNullOrWhiteSpace(token.Attribute("id").Value))
                    {
                        id = Convert.ToInt32(token.Attribute("id").Value);
                    }

                    string name = token.Attribute("name").Value;
                    string fregex = token.Attribute("fregex").Value;

                    string hexColor = string.Empty;
                    if (token.Attributes("color").Any())
                    {
                        hexColor = token.Attribute("color").Value;
                    }

                    RecsTokens.Add(new RecognitionToken(id, name, fregex, hexColor, norm, conorm));
                }

                int idSymbols = 100;
                var symbolsXml = xdoc.Element("Compiler").Element("Grammar").Element("Symbols").Elements("Symbol");
                foreach (var symbolXml in symbolsXml)
                {
                    int id = idSymbols++;
                    if (symbolXml.Attributes("id").Any() && !string.IsNullOrWhiteSpace(symbolXml.Attribute("id").Value))
                    {
                        id = Convert.ToInt32(symbolXml.Attribute("id").Value);
                    }

                    string name = symbolXml.Attribute("name").Value;
                    bool terminal = false;

                    if (symbolXml.Attributes("terminal").Any())
                    {
                        terminal = Convert.ToBoolean(symbolXml.Attribute("terminal").Value);
                    }

                    string tempTokenReference = string.Empty;
                    int recTokenId = 0;

                    if (symbolXml.Attributes("recTokenId").Any())
                    {
                        tempTokenReference = symbolXml.Attribute("recTokenId").Value;
                        if (!string.IsNullOrWhiteSpace(tempTokenReference))
                            recTokenId = Convert.ToInt32(tempTokenReference);
                    }

                    if (string.IsNullOrWhiteSpace(tempTokenReference) && symbolXml.Attributes("recTokenName").Any())
                    {
                        tempTokenReference = symbolXml.Attribute("recTokenName").Value;
                    }

                    string temp = symbolXml.Attribute("charValue").Value;
                    if (string.IsNullOrWhiteSpace(temp))
                    {
                        temp = "\0";
                    }
                    char value = temp[0];
                    Symbol symbol = new Symbol(id, name, terminal, value);

                    if (terminal)
                    {
                        if (recTokenId > 0)
                        {
                            symbol.SetCustomValue("RecToken", RecsTokens.First(rt => rt.Id == recTokenId));
                        }
                        else if (!string.IsNullOrWhiteSpace(tempTokenReference))
                        {
                            symbol.SetCustomValue("RecToken", RecsTokens.First(rt => rt.Name == tempTokenReference));
                        }

                        Grammar.Terminals.Add(symbol);
                    }
                    else
                    {
                        bool variableInitial = false;
                        if (symbolXml.Attribute("variableInitial") != null)
                            variableInitial = Convert.ToBoolean(symbolXml.Attribute("variableInitial").Value);

                        if (variableInitial)
                        {
                            Grammar.VariableStart = symbol;
                        }
                        Grammar.Variables.Add(symbol);
                    }
                }

                int idRules = 100;
                var rulesXml = xdoc.Element("Compiler").Element("Grammar").Element("Rules").Elements("Rule");

                foreach (var ruleXml in rulesXml)
                {

                    bool gotoEmpty = false;
                    string sourceName = ruleXml.Attribute("sourceName").Value;

                    if (sourceName.Contains("normalAnnotation"))
                    {

                    }

                    double pertinence = Convert.ToDouble(ruleXml.Attribute("pertinence").Value.Replace(",", "."), CultureInfo.InvariantCulture);

                    SymbolList destinys = new SymbolList();

                    var destinysXml = ruleXml.Element("Destinys").Elements("Destiny");

                    List<string> nameVars = new List<string>();
                    foreach (var destinyXml in destinysXml)
                    {
                        string name = destinyXml.Attribute("name").Value;

                        if (name != "Empty")
                        {

                            var symbol = Grammar.Symbols.FirstOrDefault(s => s.Name == name);

                            if (symbol == null)
                            {
                                symbol = new Symbol(idSymbols++, name, false, '\0');
                                Grammar.Variables.Add(symbol);
                            }

                            destinys.Add(symbol);
                        }
                        else
                        {
                            gotoEmpty = destinysXml.Count() == 1;

                            destinys.Add(Symbol.EmptySymbol);

                            if (!Grammar.Terminals.Contains(Symbol.EmptySymbol))
                            {
                                Grammar.Terminals.Add(Symbol.EmptySymbol);
                            }

                        }
                        string namevar = name;
                        if (destinyXml.Attribute("var") != null && !string.IsNullOrWhiteSpace(destinyXml.Attribute("var").Value))
                        {
                            namevar = destinyXml.Attribute("var").Value.Trim();
                        }
                        nameVars.Add(namevar);
                    }

                    var sourceSymbol = Grammar.Variables.FirstOrDefault(s => s.Name == sourceName);

                    if (sourceSymbol == null)
                    {
                        if (sourceSymbol == null)
                        {
                            sourceSymbol = new Symbol(idSymbols++, sourceName, false, '\0');
                        }
                        Grammar.Variables.Add(sourceSymbol);
                    }
                    sourceSymbol.GoToEmpty = gotoEmpty;
                    RuleProduction rule = new RuleProduction(sourceSymbol, destinys, pertinence);

                    rule.Description = ruleXml.Element("Description").Value;

                    foreach (var attr in ruleXml.Attributes())
                    {
                        if (attr.Name == "typeName")
                            rule.TypeName = attr.Value;
                        if (attr.Name == "id")
                        {
                            if (!string.IsNullOrWhiteSpace(attr.Value))
                            {
                                rule.Id = Convert.ToInt32(attr.Value);
                            }
                        }
                        if (attr.Name == "default")
                            rule.Default = Convert.ToBoolean(attr.Value);
                    }

                    if (rule.Id == 0)
                    {
                        rule.Id = idRules++;
                    }

                    string temp = ruleXml.Attribute("idRuleParent").Value;
                    int idRuleParent = 0;
                    if (!string.IsNullOrWhiteSpace(temp))
                        idRuleParent = Convert.ToInt32(temp);

                    if (idRuleParent > 0)
                    {
                        rule.Parent = Grammar.Rules.First(r => r.Id == idRuleParent);
                    }

                    //Adicionando Nome das variáveis
                    NamesVars.Add(rule.Id, nameVars);

                    Grammar.Rules.Add(rule);
                }

                this.Compiler = new CompilerFuzzy(RecsTokens, Grammar, NamesVars, null, norm, conorm);

                switch (settings.Element("Parser").Value)
                {
                    case "SyntacticAnalysisCYK":
                        this.Compiler.Syn = new SyntacticAnalysisCYK(Grammar);
                        break;
                    case "SyntacticAnalysisLR1":
                    default:
                        this.Compiler.Syn = new SyntacticAnalysisLR1(Grammar, norm, conorm);
                        break;
                }
                switch (settings.Element("Lexer").Value)
                {
                    case "FullLexicalAnalysis":
                        this.Compiler.Lex = new FullLexicalAnalysis(RecsTokens, norm, conorm);
                        break;
                    case "TokenizerLexicalAnalysis":
                    default:
                        this.Compiler.Lex = new TokenizerLexicalAnalysis(RecsTokens, norm, conorm);
                        break;
                }
            }
        }
        private void Normalize()
        {
            Normalized.VariableStart = simplified.VariableStart;
            Normalized.Terminals.AddRange(simplified.Terminals);
            Normalized.Variables.AddRange(simplified.Variables);

            for (int i = 0; i < simplified.Rules.Count; i++)
            {
                RuleProduction rgActual = simplified.Rules[i];

                var destiny = rgActual.Destiny;

                foreach (var item in DicVariablesTerminals)
                {
                    destiny = destiny.Replace(item.Key, item.Value);
                }

                if (destiny.Unitary)
                {
                    Normalized.AddRule(rgActual.Source, destiny);
                }
                else
                {
                    if (destiny.Count == 2 && !rgActual.DestinyContainsTerminal())
                    {
                        Normalized.AddRule(rgActual.Source, destiny);
                    }
                    else
                    {

                        List<SymbolList> destinys = new List<SymbolList>();

                        while (destiny.Count > 2)
                        {
                            destinys.Clear();
                            for (int k = 0; k < destiny.Count; k += 2)
                            {
                                if (k + 1 < destiny.Count)
                                {
                                    destinys.Add(new SymbolList(destiny[k], destiny[k + 1]));
                                }
                                else
                                {
                                    destinys.Add(new SymbolList(destiny[k]));
                                }
                            }

                            destiny = new SymbolList();
                            foreach (var des in destinys)
                            {
                                Symbol destinyVariable = des[0];
                                if (!des.Unitary)
                                {
                                    destinyVariable = Normalized.GetExclusiveVars(des);

                                    if (destinyVariable == Symbol.EmptyVariable)
                                    {
                                        destinyVariable = new Symbol(GetNewId(), string.Empty, false);
                                        Normalized.Variables.Add(destinyVariable);
                                        Normalized.AddRule(destinyVariable, des);
                                    }
                                }
                                destiny.Add(destinyVariable);
                            }

                        }
                        Normalized.AddRule(rgActual.Source, destiny);
                    }
                }
            }
        }
예제 #24
0
        private void Construct(SymbolList outputs, SymbolList inputs, ParameterDict @params, int[] num_filters, bool use_1x1 = true, bool use_upsample = true,
                               bool use_elewadd = true, bool use_p6        = false, bool p6_conv = true, bool no_bias       = true,
                               bool pretrained  = false, string norm_layer = null, FuncArgs norm_kwargs = null, Context ctx = null)
        {
            Symbol y_p6 = null;

            // e.g. For ResNet50, the feature is :
            // outputs = ['stage1_activation2', 'stage2_activation3',
            //            'stage3_activation5', 'stage4_activation2']
            // with regard to [conv2, conv3, conv4, conv5] -> [C2, C3, C4, C5]
            // append more layers with reversed order : [P5, P4, P3, P2]
            var y             = outputs.Last();
            var base_features = outputs.Take(outputs.Length - 1).ToArray();
            var num_stages    = num_filters.Length + 1;
            var weight_init   = new Xavier(rnd_type: "uniform", factor_type: "in", magnitude: 1);
            var tmp_outputs   = new List <Symbol>();

            // num_filter is 256 in ori paper
            for (int i = 0; i < base_features.Length; i++)
            {
                var bf = base_features[i];
                var f  = num_filters[i];
                if (i == 0)
                {
                    if (use_1x1)
                    {
                        y = sym.Convolution(y, weight_init.InitWeight("weight"), null, num_filter: f, kernel: new Shape(1, 1), pad: new Shape(0, 0), stride: new Shape(1, 1), no_bias: no_bias, symbol_name: $"P{num_stages - i}_conv_lat");

                        if (norm_layer != null)
                        {
                            if (norm_layer == "SyncBatchNorm")
                            {
                                norm_kwargs["key"]  = $"P{num_stages - i}_lat_bn";
                                norm_kwargs["name"] = $"P{num_stages - i}_lat_bn";
                            }

                            var bn = LayerUtils.NormLayer(norm_layer, norm_kwargs);

                            y = bn.Call(y);
                        }
                    }
                    if (use_p6 && p6_conv)
                    {
                        // method 2 : use conv (Deformable use this)
                        y_p6 = sym.Convolution(y, weight_init.InitWeight("weight"), null, num_filter: f, kernel: new Shape(3, 3), pad: new Shape(1, 1), stride: new Shape(2, 2), no_bias: no_bias, symbol_name: $"P{num_stages + 1}_conv1");
                        if (norm_layer != null)
                        {
                            if (norm_layer == "SyncBatchNorm")
                            {
                                norm_kwargs["key"]  = $"P{num_stages - i}_pre_bn";
                                norm_kwargs["name"] = $"P{num_stages - i}_pre_bn";
                            }

                            var bn = LayerUtils.NormLayer(norm_layer, norm_kwargs);
                            y_p6 = bn.Call(y_p6);
                        }
                    }
                }
                else
                {
                    if (use_1x1)
                    {
                        bf = sym.Convolution(bf, weight_init.InitWeight("weight"), null, num_filter: f, kernel: new Shape(1, 1), pad: new Shape(0, 0), stride: new Shape(1, 1), no_bias: no_bias, symbol_name: $"P{num_stages - i}_conv_lat");

                        if (norm_layer != null)
                        {
                            if (norm_layer == "SyncBatchNorm")
                            {
                                norm_kwargs["key"]  = $"P{num_stages - i}_conv1_bn";
                                norm_kwargs["name"] = $"P{num_stages - i}_conv1_bn";
                            }

                            var bn = LayerUtils.NormLayer(norm_layer, norm_kwargs);
                            bf = bn.Call(bf);
                        }
                    }
                    if (use_upsample)
                    {
                        y = sym.UpSampling(y, scale: 2, num_args: 1, sample_type: UpsamplingSampleType.Nearest, symbol_name: $"P{num_stages - i}_upsp");
                    }

                    if (use_elewadd)
                    {
                        // make two symbol alignment
                        // method 1 : mx.sym.Crop
                        // y = mx.sym.Crop(*[y, bf], name="P{}_clip".format(num_stages-i))
                        // method 2 : mx.sym.slice_like
                        y = sym.SliceLike(y, bf, axes: new Shape(2, 3), symbol_name: $"P{num_stages - i}_clip");
                        y = sym.ElemwiseAdd(bf, y, symbol_name: $"P{num_stages - i}_sum");
                    }
                }
                // Reduce the aliasing effect of upsampling described in ori paper
                var @out = sym.Convolution(y, weight_init.InitWeight("weight"), null, num_filter: f, kernel: new Shape(3, 3), pad: new Shape(1, 1), stride: new Shape(1, 1), no_bias: no_bias, symbol_name: $"P{num_stages - i}_conv1");
                if (i == 0 && use_p6 && !p6_conv)
                {
                    // method 2 : use max pool (Detectron use this)
                    y_p6 = sym.Pooling(@out, pool_type: PoolingType.Max, kernel: new Shape(1, 1), pad: new Shape(0, 0), stride: new Shape(2, 2), symbol_name: $"P{num_stages + 1}_pre");
                }
                if (norm_layer != null)
                {
                    if (norm_layer == "SyncBatchNorm")
                    {
                        norm_kwargs["key"]  = $"P{num_stages - i}_bn";
                        norm_kwargs["name"] = $"P{num_stages - i}_bn";
                    }

                    var bn = LayerUtils.NormLayer(norm_layer, norm_kwargs);
                    @out = bn.Call(@out);
                }

                tmp_outputs.Add(@out);
            }

            if (use_p6)
            {
                outputs = tmp_outputs.Take(tmp_outputs.Count - 1).ToList();
                outputs.Add(y_p6);
            }
            else
            {
                outputs = tmp_outputs.Take(tmp_outputs.Count - 1).ToList();
            }

            base.Construct(outputs, inputs, @params);
        }
예제 #25
0
파일: MibModule.cs 프로젝트: plocklsh/lwip
        private void ParseEntities(ISymbolEnumerator symbols)
        {
            Symbol     temp   = symbols.NextNonEOLSymbol();
            SymbolList buffer = new SymbolList();

            while (temp != Symbol.End)
            {
                if (temp == Symbol.Assign)
                {
                    ParseEntity(buffer, symbols);
                    buffer.Clear();
                    // skip linebreaks behind an entity
                    temp = symbols.NextNonEOLSymbol();
                }
                else
                {
                    buffer.Add(temp);
                    temp = symbols.NextSymbol();
                }
            }
        }
예제 #26
0
        public CompilerXmlParser(string filename)
        {
            NamesVars  = new Dictionary <int, List <string> >();
            RecsTokens = new List <RecognitionToken>();
            Grammar    = new Grammar();

            using (FileStream file = File.OpenRead(filename))
            {
                XDocument xdoc = XDocument.Load(file, LoadOptions.None);


                var          settings = xdoc.Element("Compiler").Element("Settings");
                NormAbstract norm;
                switch (settings.Element("Norm").Value)
                {
                case "MIN":
                    norm = new MinNorm();
                    break;

                default:
                    norm = new MultiplyNorm();
                    break;
                }
                ConormAbstract conorm;
                switch (settings.Element("Conorm").Value)
                {
                case "SUM":
                    conorm = new SumMinusProductConorm();
                    break;

                default:
                    conorm = new MaxConorm();
                    break;
                }

                var recTokens = xdoc.Element("Compiler").Element("RecTokens").Elements("RecToken");
                int idTokens  = 1;
                foreach (var token in recTokens)
                {
                    int id = idTokens++;
                    if (token.Attributes("id").Any() && !string.IsNullOrWhiteSpace(token.Attribute("id").Value))
                    {
                        id = Convert.ToInt32(token.Attribute("id").Value);
                    }

                    string name   = token.Attribute("name").Value;
                    string fregex = token.Attribute("fregex").Value;

                    string hexColor = string.Empty;
                    if (token.Attributes("color").Any())
                    {
                        hexColor = token.Attribute("color").Value;
                    }


                    RecsTokens.Add(new RecognitionToken(id, name, fregex, hexColor, norm, conorm));
                }

                int idSymbols  = 100;
                var symbolsXml = xdoc.Element("Compiler").Element("Grammar").Element("Symbols").Elements("Symbol");
                foreach (var symbolXml in symbolsXml)
                {
                    int id = idSymbols++;
                    if (symbolXml.Attributes("id").Any() && !string.IsNullOrWhiteSpace(symbolXml.Attribute("id").Value))
                    {
                        id = Convert.ToInt32(symbolXml.Attribute("id").Value);
                    }

                    string name     = symbolXml.Attribute("name").Value;
                    bool   terminal = false;

                    if (symbolXml.Attributes("terminal").Any())
                    {
                        terminal = Convert.ToBoolean(symbolXml.Attribute("terminal").Value);
                    }

                    string tempTokenReference = string.Empty;
                    int    recTokenId         = 0;

                    if (symbolXml.Attributes("recTokenId").Any())
                    {
                        tempTokenReference = symbolXml.Attribute("recTokenId").Value;
                        if (!string.IsNullOrWhiteSpace(tempTokenReference))
                        {
                            recTokenId = Convert.ToInt32(tempTokenReference);
                        }
                    }

                    if (string.IsNullOrWhiteSpace(tempTokenReference) && symbolXml.Attributes("recTokenName").Any())
                    {
                        tempTokenReference = symbolXml.Attribute("recTokenName").Value;
                    }


                    string temp = symbolXml.Attribute("charValue").Value;
                    if (string.IsNullOrWhiteSpace(temp))
                    {
                        temp = "\0";
                    }
                    char   value  = temp[0];
                    Symbol symbol = new Symbol(id, name, terminal, value);

                    if (terminal)
                    {
                        if (recTokenId > 0)
                        {
                            symbol.SetCustomValue("RecToken", RecsTokens.First(rt => rt.Id == recTokenId));
                        }
                        else if (!string.IsNullOrWhiteSpace(tempTokenReference))
                        {
                            symbol.SetCustomValue("RecToken", RecsTokens.First(rt => rt.Name == tempTokenReference));
                        }

                        Grammar.Terminals.Add(symbol);
                    }
                    else
                    {
                        bool variableInitial = false;
                        if (symbolXml.Attribute("variableInitial") != null)
                        {
                            variableInitial = Convert.ToBoolean(symbolXml.Attribute("variableInitial").Value);
                        }

                        if (variableInitial)
                        {
                            Grammar.VariableStart = symbol;
                        }
                        Grammar.Variables.Add(symbol);
                    }
                }

                int idRules  = 100;
                var rulesXml = xdoc.Element("Compiler").Element("Grammar").Element("Rules").Elements("Rule");

                foreach (var ruleXml in rulesXml)
                {
                    bool   gotoEmpty  = false;
                    string sourceName = ruleXml.Attribute("sourceName").Value;

                    if (sourceName.Contains("normalAnnotation"))
                    {
                    }

                    double pertinence = Convert.ToDouble(ruleXml.Attribute("pertinence").Value.Replace(",", "."), CultureInfo.InvariantCulture);

                    SymbolList destinys = new SymbolList();

                    var destinysXml = ruleXml.Element("Destinys").Elements("Destiny");

                    List <string> nameVars = new List <string>();
                    foreach (var destinyXml in destinysXml)
                    {
                        string name = destinyXml.Attribute("name").Value;


                        if (name != "Empty")
                        {
                            var symbol = Grammar.Symbols.FirstOrDefault(s => s.Name == name);

                            if (symbol == null)
                            {
                                symbol = new Symbol(idSymbols++, name, false, '\0');
                                Grammar.Variables.Add(symbol);
                            }

                            destinys.Add(symbol);
                        }
                        else
                        {
                            gotoEmpty = destinysXml.Count() == 1;

                            destinys.Add(Symbol.EmptySymbol);

                            if (!Grammar.Terminals.Contains(Symbol.EmptySymbol))
                            {
                                Grammar.Terminals.Add(Symbol.EmptySymbol);
                            }
                        }
                        string namevar = name;
                        if (destinyXml.Attribute("var") != null && !string.IsNullOrWhiteSpace(destinyXml.Attribute("var").Value))
                        {
                            namevar = destinyXml.Attribute("var").Value.Trim();
                        }
                        nameVars.Add(namevar);
                    }

                    var sourceSymbol = Grammar.Variables.FirstOrDefault(s => s.Name == sourceName);

                    if (sourceSymbol == null)
                    {
                        if (sourceSymbol == null)
                        {
                            sourceSymbol = new Symbol(idSymbols++, sourceName, false, '\0');
                        }
                        Grammar.Variables.Add(sourceSymbol);
                    }
                    sourceSymbol.GoToEmpty = gotoEmpty;
                    RuleProduction rule = new RuleProduction(sourceSymbol, destinys, pertinence);

                    rule.Description = ruleXml.Element("Description").Value;

                    foreach (var attr in ruleXml.Attributes())
                    {
                        if (attr.Name == "typeName")
                        {
                            rule.TypeName = attr.Value;
                        }
                        if (attr.Name == "id")
                        {
                            if (!string.IsNullOrWhiteSpace(attr.Value))
                            {
                                rule.Id = Convert.ToInt32(attr.Value);
                            }
                        }
                        if (attr.Name == "default")
                        {
                            rule.Default = Convert.ToBoolean(attr.Value);
                        }
                    }

                    if (rule.Id == 0)
                    {
                        rule.Id = idRules++;
                    }


                    string temp         = ruleXml.Attribute("idRuleParent").Value;
                    int    idRuleParent = 0;
                    if (!string.IsNullOrWhiteSpace(temp))
                    {
                        idRuleParent = Convert.ToInt32(temp);
                    }

                    if (idRuleParent > 0)
                    {
                        rule.Parent = Grammar.Rules.First(r => r.Id == idRuleParent);
                    }


                    //Adicionando Nome das variáveis
                    NamesVars.Add(rule.Id, nameVars);

                    Grammar.Rules.Add(rule);
                }



                this.Compiler = new CompilerFuzzy(RecsTokens, Grammar, NamesVars, null, norm, conorm);

                switch (settings.Element("Parser").Value)
                {
                case "SyntacticAnalysisCYK":
                    this.Compiler.Syn = new SyntacticAnalysisCYK(Grammar);
                    break;

                case "SyntacticAnalysisLR1":
                default:
                    this.Compiler.Syn = new SyntacticAnalysisLR1(Grammar, norm, conorm);
                    break;
                }
                switch (settings.Element("Lexer").Value)
                {
                case "FullLexicalAnalysis":
                    this.Compiler.Lex = new FullLexicalAnalysis(RecsTokens, norm, conorm);
                    break;

                case "TokenizerLexicalAnalysis":
                default:
                    this.Compiler.Lex = new TokenizerLexicalAnalysis(RecsTokens, norm, conorm);
                    break;
                }
            }
        }
예제 #27
0
        public override (Symbol, SymbolList) Unroll(int length, SymbolList inputs, SymbolList begin_state = null, string layout = null, bool?merge_outputs = null)
        {
            this.Reset();
            var _tup_1 = __internals__.NormalizeSequence(length, inputs, layout, false);

            inputs = _tup_1.Item1;
            var axis = _tup_1.Item2;

            if (begin_state == null)
            {
                begin_state = this.BeginState();
            }

            var        states    = begin_state;
            var        l_cell    = _cells[0];
            var        r_cell    = _cells[1];
            SymbolList l_outputs = null;
            SymbolList l_states  = null;
            SymbolList r_outputs = null;
            SymbolList r_states  = null;

            (l_outputs, l_states) = l_cell.Unroll(length, inputs: inputs, begin_state: states.Take(l_cell.StateInfo.Length).ToArray(), layout: layout, merge_outputs: merge_outputs);
            (r_outputs, r_states) = r_cell.Unroll(length, inputs: inputs.Reverse().ToList(), begin_state: states[l_cell.StateInfo.Length], layout: layout, merge_outputs: merge_outputs);
            if (merge_outputs == null)
            {
                merge_outputs = l_outputs.Length == 1 && r_outputs.Length == 1;
                if (!merge_outputs.Value)
                {
                    l_outputs = sym.SliceChannel(l_outputs, axis: axis, num_outputs: length, squeeze_axis: true).ToList();
                    r_outputs = sym.SliceChannel(r_outputs, axis: axis, num_outputs: length, squeeze_axis: true).ToList();
                }
            }

            if (merge_outputs.Value)
            {
                r_outputs = sym.Reverse(r_outputs, axis: axis);
            }
            else
            {
                r_outputs = r_outputs.Reverse().ToList();
            }

            SymbolList outputs = new SymbolList();

            for (int i = 0; i < l_outputs.Length; i++)
            {
                var l_o = l_outputs[i];
                var r_o = r_outputs[i];
                var lr  = sym.Concat(new SymbolList(l_o, r_o), dim: 1 + (merge_outputs.Value ? 1 : 0), symbol_name: merge_outputs.Value ? $"{_output_prefix}out" : $"{_output_prefix}t{i}");
                outputs.Add(lr);
            }

            states = new List <Symbol> {
                l_states,
                r_states
            };

            if (merge_outputs.Value)
            {
                outputs = outputs[0];
            }

            return(outputs, states);
        }
        private void FillNewsNames()
        {
            NewNames = new Dictionary<Symbol, Symbol>();

            SymbolList visitados = new SymbolList();

            Queue<Symbol> variaveisAVisitar = new Queue<Symbol>();

            variaveisAVisitar.Enqueue(simplified.VariableStart);

            int i = 1;
            NewNames.Add(simplified.VariableStart, new Symbol(GetNewId(), string.Format("A{0:000}", i), false));
            visitados.Add(simplified.VariableStart);
            while (variaveisAVisitar.Count > 0)
            {
                var variavelAtual = variaveisAVisitar.Dequeue();

                List<RuleProduction> regrasAtuais = simplified.GetRules(variavelAtual);

                foreach (var item in regrasAtuais)
                {
                    foreach (var itemDestino in item.Destiny)
                    {
                        if (!itemDestino.Terminal && !visitados.Contains(itemDestino))
                        {
                            variaveisAVisitar.Enqueue(itemDestino);
                            i++;
                            NewNames.Add(itemDestino, new Symbol(GetNewId(), string.Format("A{0:000}", i), false));
                            visitados.Add(itemDestino);
                        }
                    }
                }
            }

            Normalized = new Grammar();
            Normalized.VariableStart = simplified.VariableStart;
            Normalized.Variables.AddRange(simplified.Variables);
            Normalized.Terminals.AddRange(simplified.Terminals);
            Normalized.VariablesEmpty = simplified.VariablesEmpty;
            for (i = 0; i < simplified.Rules.Count; i++)
            {
                Normalized.AddRule(simplified.Rules[i].Source, simplified.Rules[i].Destiny.Copy());
            }
        }
예제 #29
0
        /// <summary>
        /// Creates an <see cref="TypeAssignment" />.
        /// </summary>
        /// <param name="module">The module.</param>
        /// <param name="name">The name.</param>
        /// <param name="type">The type.</param>
        /// <param name="symbols">The symbols.</param>
        /// <param name="isMacroSyntax">if set to <c>true</c> indicates that the syntax clause of a macro is parsed (e.g. OBJECT-TYPE, TEXTUAL-CONVENTION).</param>
        public TypeAssignment(IModule module, string name, Symbol type, ISymbolEnumerator symbols, bool isMacroSyntax)
        {
            _module = module;
            _name   = name;

            SymbolList typeSymbols = new SymbolList();
            typeSymbols.Add(type);

            Symbol current = symbols.NextSymbol();
            while (current != Symbol.EOL)
            {
                if (current == Symbol.OpenParentheses)
                {
                    // parse range of unknown type
                    symbols.PutBack(current);
                    _ranges = Lexer.DecodeRanges(symbols);
                    break;
                }
                else if (current == Symbol.OpenBracket)
                {
                    symbols.PutBack(current);
                    _map = Lexer.DecodeEnumerations(symbols);
                    break;
                }

                typeSymbols.Add(current);
                current = symbols.NextSymbol();
            }

            _type = typeSymbols.Join(" ");

            if ((_ranges == null) && (_map == null))
            {
                current = symbols.NextNonEOLSymbol();
                if (current == Symbol.OpenParentheses)
                {
                    // parse range of unknown type
                    symbols.PutBack(current);
                    _ranges = Lexer.DecodeRanges(symbols);
                }
                else if (current == Symbol.OpenBracket)
                {
                    symbols.PutBack(current);
                    _map = Lexer.DecodeEnumerations(symbols);
                }
                else if (current != null)
                {
                    symbols.PutBack(current);
                }
            }

            if (isMacroSyntax)
            {
                // inside a macro the syntax is limited to one line, except there are brackets used for ranges/enums
                return;
            }

            // outside macro Syntax clause we  wait for two consecutive linebreaks with a following valid identifier as end condition         
            Symbol previous = current;
            Symbol veryPrevious = null;

            while ((current = symbols.NextSymbol()) != null)
            {
                if ((veryPrevious == Symbol.EOL) && (previous == Symbol.EOL) && current.IsValidIdentifier())
                {
                    symbols.PutBack(current);
                    return;
                }

                veryPrevious = previous;
                previous = current;
            }
            
            previous.Assert(false, "end of file reached");
        }
        public void FillTableEmpty()
        {
            VariablesEmpty = new SymbolList();

            for (int i = 0; i < Source.Variables.Count; i++)
            {
                Visited = new SymbolList();

                Queue<Symbol> variaveisAVisitar = new Queue<Symbol>();

                variaveisAVisitar.Enqueue(Source.Variables[i]);

                while (variaveisAVisitar.Count > 0)
                {
                    Symbol variavelAtual = variaveisAVisitar.Dequeue();

                    Visited.Add(variavelAtual);
                    List<RuleProduction> regrasAtuais = Source.Rules.Where(r => r.Source == variavelAtual).ToList();

                    foreach (var item in regrasAtuais)
                    {

                        if (item.Destiny.Count == 1)
                        {
                            if (item.Destiny[0] == Symbol.EmptyTerminal)
                            {
                                VariablesEmpty.Add(Source.Variables[i]);
                                variaveisAVisitar.Clear();
                                break;
                            }

                            if (!item.Destiny[0].Terminal && !Visited.Contains(item.Destiny[0]))
                            {
                                variaveisAVisitar.Enqueue(item.Destiny[0]);
                            }

                        }
                    }
                }
            }
        }
예제 #31
0
        /// <summary>
        /// Creates an <see cref="TypeAssignment" />.
        /// </summary>
        /// <param name="module">The module.</param>
        /// <param name="name">The name.</param>
        /// <param name="type">The type.</param>
        /// <param name="symbols">The symbols.</param>
        /// <param name="isMacroSyntax">if set to <c>true</c> indicates that the syntax clause of a macro is parsed (e.g. OBJECT-TYPE, TEXTUAL-CONVENTION).</param>
        public TypeAssignment(IModule module, string name, Symbol type, ISymbolEnumerator symbols, bool isMacroSyntax)
        {
            _module = module;
            _name   = name;

            SymbolList typeSymbols = new SymbolList();

            typeSymbols.Add(type);

            Symbol current = symbols.NextSymbol();

            while (current != Symbol.EOL)
            {
                if (current == Symbol.OpenParentheses)
                {
                    // parse range of unknown type
                    symbols.PutBack(current);
                    _ranges = Lexer.DecodeRanges(symbols);
                    break;
                }
                else if (current == Symbol.OpenBracket)
                {
                    symbols.PutBack(current);
                    _map = Lexer.DecodeEnumerations(symbols);
                    break;
                }

                typeSymbols.Add(current);
                current = symbols.NextSymbol();
            }

            _type = typeSymbols.Join(" ");

            if ((_ranges == null) && (_map == null))
            {
                current = symbols.NextNonEOLSymbol();
                if (current == Symbol.OpenParentheses)
                {
                    // parse range of unknown type
                    symbols.PutBack(current);
                    _ranges = Lexer.DecodeRanges(symbols);
                }
                else if (current == Symbol.OpenBracket)
                {
                    symbols.PutBack(current);
                    _map = Lexer.DecodeEnumerations(symbols);
                }
                else if (current != null)
                {
                    symbols.PutBack(current);
                }
            }

            if (isMacroSyntax)
            {
                // inside a macro the syntax is limited to one line, except there are brackets used for ranges/enums
                return;
            }

            // outside macro Syntax clause we  wait for two consecutive linebreaks with a following valid identifier as end condition
            Symbol previous     = current;
            Symbol veryPrevious = null;

            while ((current = symbols.NextSymbol()) != null)
            {
                if ((veryPrevious == Symbol.EOL) && (previous == Symbol.EOL) && current.IsValidIdentifier())
                {
                    symbols.PutBack(current);
                    return;
                }

                veryPrevious = previous;
                previous     = current;
            }

            previous.Assert(false, "end of file reached");
        }
예제 #32
0
        /// <summary>
        /// 初始化符号信息
        /// </summary>
        protected override void InitialSymbol()
        {
            base.InitialSymbol();

            if (m_pUniqueRender == null || m_pFeatureLayer == null)
            {
                return;
            }
            //是否是多个字段
            bool bNoSepFieldVal = false;
            //是否是连接表
            bool bIsJoined = false;

            try
            {
                IDisplayTable pDisplayTable = m_pFeatureLayer as IDisplayTable;
                ITable        pTable        = pDisplayTable.DisplayTable;
                IDataset      objDataset    = m_FeatureClass as IDataset;
                //是否是关系表
                if (pTable is IRelQueryTable)
                {
                    bIsJoined = true;
                }

                if (FieldCount > 1)
                {
                    bNoSepFieldVal = true;
                }
                //唯一值字段有多个
                if (bNoSepFieldVal)
                {
                    //数据源为SHAPE文件
                    if (objDataset.Workspace.Type == esriWorkspaceType.esriFileSystemWorkspace)
                    {
                        for (int i = 1; i <= FieldCount; i++)
                        {
                            FieldNames.Add(m_pUniqueRender.Field[i - 1].ToLower());
                        }

                        CommStaticClass.GimmeUniqueValuesFromShape(m_FeatureClass as ITable, FieldNames);
                    }
                    //数据源为其他
                    else
                    {
                        for (int i = 1; i <= FieldCount; i++)
                        {
                            FieldNames.Add(m_pUniqueRender.Field[i - 1].ToLower());
                            //属性表有连接表
                            if (pTable is IRelQueryTable)
                            {
                                IRelQueryTable pRelQueryTable     = default(IRelQueryTable);
                                ITable         pDestTable         = default(ITable);
                                IDataset       pDataSet           = default(IDataset);
                                IList <string> alJoinedTableNames = new List <string>();
                                while (pTable is IRelQueryTable)
                                {
                                    pRelQueryTable = pTable as IRelQueryTable;
                                    pDestTable     = pRelQueryTable.DestinationTable;
                                    pDataSet       = pDestTable as IDataset;

                                    pTable = pRelQueryTable.SourceTable;
                                    alJoinedTableNames.Add(pDataSet.Name);
                                }
                                CommStaticClass.GimmeUniqeValuesForFieldname(m_FeatureClass as ITable, m_pUniqueRender.Field[i - 1], alJoinedTableNames);
                                pTable = pDisplayTable.DisplayTable;
                            }
                            //属性表没有连接表
                            else
                            {
                                CommStaticClass.GimmeUniqeValuesForFieldname(m_FeatureClass as ITable, m_pUniqueRender.Field[i - 1]);
                            }
                        }
                    }
                }
                //唯一值字段只有一个
                else
                {
                    FieldNames.Add(m_pUniqueRender.Field[FieldCount - 1].ToLower());
                }

                //开始解析符号
                for (int j = 0; j <= ValueCount - 1; j++)
                {
                    ISymbol         pSymbol      = m_pUniqueRender.get_Symbol(m_pUniqueRender.get_Value(j));
                    ptSymbolFactory pSymbolFac   = new ptSymbolFactory(pSymbol);
                    ptSymbolClass   pSymbolClass = pSymbolFac.GetSymbolClass(m_pUniqueRender.Label[m_pUniqueRender.get_Value(j)], CommStaticClass.getUVFieldValues(m_pUniqueRender, j)
                                                                             , 0, 0);
                    SymbolList.Add(pSymbolClass);
                }
            }
            catch (Exception ex)
            {
                ptLogManager.WriteMessage(string.Format("方法名称:{0}{1}{2}{3}{4}", "InitialSymbol", Environment.NewLine, ex.Message, Environment.NewLine, ex.StackTrace));
            }
        }