예제 #1
0
        public override (Symbol, SymbolList) Call(Symbol inputs, SymbolList states)
        {
            this._counter += 1;
            var seq_idx      = this._counter;
            var name         = $"{this._prefix}t{this._counter}_";
            var prev_state_h = states[0];
            var i2h          = sym.FullyConnected(data: inputs, weight: this._iW, bias: this._iB, num_hidden: this._num_hidden * 3, symbol_name: String.Format("%s_i2h", name));
            var h2h          = sym.FullyConnected(data: prev_state_h, weight: this._hW, bias: this._hB, num_hidden: this._num_hidden * 3, symbol_name: String.Format("%s_h2h", name));
            // pylint: disable=unbalanced-tuple-unpacking
            var _tup_1 = sym.SliceChannel(i2h, num_outputs: 3, symbol_name: $"{name}_i2h_slice");
            var i2h_r  = _tup_1[0];
            var i2h_z  = _tup_1[1];

            i2h = _tup_1[2];
            var _tup_2 = sym.SliceChannel(h2h, num_outputs: 3, symbol_name: $"{name}_h2h_slice");
            var h2h_r  = _tup_2[0];
            var h2h_z  = _tup_2[1];

            h2h = _tup_2[2];
            var reset_gate  = sym.Activation(i2h_r + h2h_r, act_type: ActivationType.Sigmoid, symbol_name: $"{name}_r_act");
            var update_gate = sym.Activation(i2h_z + h2h_z, act_type: ActivationType.Sigmoid, symbol_name: $"{name}_z_act");
            var next_h_tmp  = sym.Activation(i2h + reset_gate * h2h, act_type: ActivationType.Tanh, symbol_name: $"{name}_h_act");
            var next_h      = sym.ElemwiseAdd((1 - update_gate) * next_h_tmp, update_gate * prev_state_h, symbol_name: $"{name}out");

            return(next_h, next_h);
        }
예제 #2
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);
        }
예제 #3
0
        private void btnGerar_Click(object sender, EventArgs e)
        {
            g = new Grammar();

            g.Variables.Clear();
            g.Variables.AddRange(txtVariaveis.Text.Select(c => new Symbol(-1, c, false)));
            g.Terminals.Clear();
            g.Terminals.AddRange(txtVariaveis.Text.Select(c => new Symbol(-1, c, true, c)));



            string[] regras = txtRegras.Text.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);

            for (int i = 0; i < regras.Length; i++)
            {
                char variavel = regras[i].ToUpper()[0];

                string prod = regras[i].Substring(2).Trim();

                string[] prods = prod.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);

                for (int j = 0; j < prods.Length; j++)
                {
                    var symbols = new SymbolList();
                    symbols = symbols.AddRange(prods[j].Select(prd => new Symbol(-1, prd, prd.IsTerminal(), prd)));
                    g.AddRule(g.Variables.Find(variavel), symbols);
                }
            }
        }
예제 #4
0
        public static SymbolBlock Imports(string symbol_file, string[] input_names, string param_file = null,
                                          Context[] ctx = null)
        {
            Symbol     sym    = Symbol.Load(symbol_file);
            SymbolList inputs = null;

            if (string.IsNullOrWhiteSpace(param_file))
            {
                inputs = input_names.Select(x => (Symbol.Var(x, dtype: DType.Float32))).ToArray();
            }
            else
            {
                inputs = input_names.Select(x => (Symbol.Var(x))).ToArray();
            }

            var ret = new SymbolBlock(new SymbolList {
                sym
            }, inputs);

            if (!string.IsNullOrWhiteSpace(param_file))
            {
                var p = ret.CollectParams();
                p.Load(param_file, ctx: ctx, cast_dtype: true, dtype_source: "saved");
            }

            return(ret);
        }
        public override object ReadJson(JsonReader reader, Type objectType, object?existingValue, JsonSerializer serializer)
        {
            var value = (string)reader.Value !;

            // ReSharper disable once HeapView.BoxingAllocation
            return(SymbolList.Parse(value));
        }
예제 #6
0
        static private ISentenceItem CreateSentenseItem(SymbolList symbols, ParserState state)
        {
            if (symbols == null || symbols.Count == 0)
            {
                throw new ArgumentNullException(nameof(symbols));
            }

            switch (state)
            {
            case ParserState.Letter:
                return(new Word(symbols));

            case ParserState.Separator:
                return(SpaceSeparator.GetSeparator());

            case ParserState.Punctuation:
            case ParserState.Other:
                return(new Punctuation(symbols.ToString()));

            case ParserState.EndSentense:
            case ParserState.None:
            default:
                throw new AggregateException($"State can't be \"{state}\"");
            }
        }
예제 #7
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);
                        }
                    }
                }
            }
        }
예제 #8
0
 protected override void Start()
 {
     base.Start();
     machine    = GetComponentInParent <Machine>();
     symbolList = machine.GetComponent <SymbolList>();
     cam        = machine.getCamera();
 }
예제 #9
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);
        }
예제 #10
0
파일: EntityBase.cs 프로젝트: plocklsh/lwip
        public EntityBase(IModule module, SymbolList preAssignSymbols, ISymbolEnumerator symbols)
        {
            _module = module;
            _name   = preAssignSymbols[0].ToString();

            Lexer.ParseOidValue(symbols, out _parent, out _value);
        }
예제 #11
0
 public override Empty SetDistributingSymbolList(SymbolList input)
 {
     AssertPerformedByVoteWeightInterestController();
     Assert(input.Value.Contains(Context.Variables.NativeSymbol), "Need to contain native symbol.");
     State.SymbolList.Value = input;
     return(new Empty());
 }
예제 #12
0
        public static string SymbolArrayToString(object[,] symbolData)
        {
            int row = symbolData.GetLength(0);
            int col = symbolData.GetLength(1);

            SymbolParamList param = new SymbolParamList
            {
                Symbols = new List <SymbolList>()
            };

            for (int i = 0; i < row; i++)
            {
                var test = new SymbolList
                {
                    Symbol   = symbolData[i, 0].ToString(),
                    Exchange = int.Parse(symbolData[i, 1].ToString()),
                };

                param.Symbols.Add(test);
            }

            var json = "";

            using (var stream = new MemoryStream())
            {
                var serializer = new DataContractJsonSerializer(typeof(SymbolParamList));
                serializer.WriteObject(stream, param);
                json = Encoding.UTF8.GetString(stream.ToArray());
            }

            return(json);
        }
예제 #13
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);
        }
예제 #14
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);
        }
예제 #15
0
        public override (Symbol, SymbolList) Call(Symbol inputs, SymbolList states)
        {
            var cell        = this.base_cell;
            var p_outputs   = this.zoneout_outputs;
            var p_states    = this.zoneout_states;
            var _tup_1      = cell.Call(inputs, states);
            var next_output = _tup_1.Item1;
            var next_states = _tup_1.Item2;
            Func <float, Symbol, Symbol> mask = (p, like) => sym.Dropout(sym.OnesLike(like), p: p);
            var prev_output = this.prev_output != null ? this.prev_output : sym.Zeros(new Shape(0, 0));
            var output      = p_outputs != 0.0 ? sym.Where(mask(p_outputs, next_output), next_output, prev_output) : next_output;

            if (p_states != 0)
            {
                states = Enumerable.Zip(next_states, states, (new_s, old_s) =>
                {
                    return(sym.Where(mask(p_states, new_s), new_s, old_s));
                }).ToList();
            }
            else
            {
                states = next_states;
            }

            this.prev_output = output;
            return(output, states);
        }
        public EntityBase(IModule module, SymbolList preAssignSymbols, ISymbolEnumerator symbols)
        {
            _module = module;
            _name   = preAssignSymbols[0].ToString();

            Lexer.ParseOidValue(symbols, out _parent, out _value);
        }
예제 #17
0
        private NDArrayOrSymbol F(Symbol x, Symbol anchors)
        {
            SymbolList a = null;

            if (this.corner_to_center != null)
            {
                a = this.corner_to_center.Call(anchors).SymXList;
            }
            else
            {
                a = sym.Split(anchors, axis: -1, num_outputs: 4);
            }

            var p  = sym.Split(x, axis: -1, num_outputs: 4);
            var ox = sym.BroadcastAdd(sym.BroadcastMul(p[0] * this._stds[0], a[2]), a[0]);
            var oy = sym.BroadcastAdd(sym.BroadcastMul(p[1] * this._stds[1], a[3]), a[1]);
            var dw = p[2] * this._stds[2];
            var dh = p[3] * this._stds[3];

            if (this._clip.HasValue)
            {
                dw = sym.MinimumScalar(dw, this._clip.Value);
                dh = sym.MinimumScalar(dh, this._clip.Value);
            }

            dw = sym.Exp(dw);
            dh = sym.Exp(dh);

            var ow = sym.BroadcastMul(dw, a[2]) * 0.5f;
            var oh = sym.BroadcastMul(dh, a[3]) * 0.5f;

            return(sym.Concat(new SymbolList(ox - ow, oy - oh, ox + ow, oy + oh), dim: -1));
        }
예제 #18
0
        public override (Symbol, SymbolList) Unroll(int length, SymbolList inputs, SymbolList begin_state = null, string layout = null, bool?merge_outputs = null)
        {
            this.Reset();
            this.base_cell._modified = false;
            var(outputs, states)     = this.base_cell.Unroll(length, inputs: inputs, begin_state: begin_state, layout: layout, merge_outputs: merge_outputs);
            this.base_cell._modified = true;
            merge_outputs            = merge_outputs == null ? outputs is Symbol : merge_outputs;
            var _tup_2 = __internals__.NormalizeSequence(length, inputs, layout, merge_outputs.Value);

            inputs = _tup_2.Item1;
            if (merge_outputs.Value)
            {
                outputs = sym.ElemwiseAdd(outputs, inputs, symbol_name: $"{outputs.Name}_plus_residual");
            }
            else
            {
                var outputsList = Enumerable.Zip(outputs.ToList(), inputs.ToList(), (output_sym, input_sym) =>
                {
                    return(sym.ElemwiseAdd(output_sym, input_sym, symbol_name: $"{output_sym.Name}_plus_residual"));
                }).ToList();

                outputs = Symbol.Group(outputs);
            }

            return(outputs, states);
        }
예제 #19
0
        public async Task Treasury_SetSymbolList_Success_Test()
        {
            var tokenSymbol       = "CWJ";
            var nativeTokenSymbol = EconomicContractsTestConstants.NativeTokenSymbol;
            var methodName        = nameof(TreasuryContractStub.SetSymbolList);
            var tokenCreateInput  = new CreateInput
            {
                Symbol       = tokenSymbol,
                TokenName    = "CWJ name",
                TotalSupply  = 1_0000_0000,
                Issuer       = BootMinerAddress,
                IsProfitable = true
            };
            await TokenContractStub.Create.SendAsync(tokenCreateInput);

            var newSymbolList = new SymbolList
            {
                Value =
                {
                    nativeTokenSymbol, tokenSymbol
                }
            };

            await ExecuteProposalForParliamentTransaction(Tester, TreasuryContractAddress, methodName,
                                                          newSymbolList);

            var getSymbolList = await TreasuryContractStub.GetSymbolList.CallAsync(new Empty());

            getSymbolList.Value.Count.ShouldBe(2);
            getSymbolList.Value.Contains(tokenSymbol).ShouldBeTrue();
        }
예제 #20
0
        public static void Init(SymbolList listControl, string userName)
        {
            _userName    = userName;
            _listControl = listControl;

            listControl.ItemStopCollectingClick += listControl_ItemStopCollectingClick;
        }
예제 #21
0
 public Grammar()
 {
     Variables = new SymbolList();
     Terminals = new SymbolList();
     VariablesEmpty = new SymbolList();
     Rules = new List<RuleProduction>();
     VariableStart = new Symbol(1, "S", false);
 }
예제 #22
0
        public override (Symbol, SymbolList) Call(Symbol inputs, SymbolList states)
        {
            Symbol output = null;

            (output, states) = this.base_cell.Call(inputs, states);
            output           = sym.ElemwiseAdd(output, inputs, symbol_name: $"{output.Name}_plus_residual");
            return(output, states);
        }
예제 #23
0
 override public void using_directive(using_directive ast, SymbolTable bindings, SymbolList usingdirectives)
 {
     if (ast.parent is namespace_body)
     {
         msg.Error(ast.begin, "using directives are not permitted inside namespaces in csi files");
     }
     base.using_directive(ast, bindings, usingdirectives);
 }
예제 #24
0
        public override (Symbol, SymbolList) Call(Symbol inputs, SymbolList states)
        {
            if (this.dropout > 0)
            {
                inputs = sym.Dropout(data: inputs, p: this.dropout);
            }

            return(inputs, states);
        }
예제 #25
0
파일: Operator.cs 프로젝트: horker/py2cs
        public Operator SetInput(SymbolList symbols)
        {
            foreach (var item in symbols)
            {
                _inputSymbols.Add(item.Handle);
            }

            return(this);
        }
예제 #26
0
        public void CombinedTest(string value, string[] segments, string?expectedValue = null)
        {
            var l = SymbolList.Parse(value);

            l.SegmentCount.Should().Be(segments.Length);
            l.GetSegments().Should().BeEquivalentTo(segments.Select(s => (Symbol)s));
            l.FormattedValue.Should().Be(expectedValue ?? value);
            l.AssertPassesThroughAllSerializers();
        }
 public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
 {
     if (value is string s)
     {
         // ReSharper disable once HeapView.BoxingAllocation
         return(SymbolList.Parse(s));
     }
     return(base.ConvertFrom(context, culture, value) !);
 }
예제 #28
0
 void HideMenu()
 {
     if (_SymbolList != null)
     {
         _SymbolListContainer.Clear();
         _SymbolList.SelectedItem = null;
         _SymbolList = null;
     }
 }
예제 #29
0
 public Word(SymbolList letters)
 {
     if (letters == null && letters.Count > 0)
     {
         throw new ArgumentNullException(nameof(letters));
     }
     Letters  = letters;
     hashCode = Letters.ToString().GetHashCode();
 }
예제 #30
0
 void SetupSymbolListMenu(SymbolList list)
 {
     list.ReferenceCrispImageBackground(EnvironmentColors.MainWindowActiveCaptionColorKey);
     list.MouseLeftButtonUp += MenuItemSelect;
     if (list.Symbols.Count > 100)
     {
         ScrollViewer.SetCanContentScroll(list, true);
     }
 }
예제 #31
0
    public SymbolList Lookup(string name, stringList namespaces)
    {
        SymbolList list = reader.Lookup(name, namespaces);

        if (list != null)
        {
            return(list);
        }
        return(null);
    }
 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);
 }
예제 #33
0
파일: TrapType.cs 프로젝트: plocklsh/lwip
        public TrapType(IModule module, SymbolList preAssignSymbols, ISymbolEnumerator symbols)
        {
            _module = module;
            _name = preAssignSymbols[0].ToString();

            Symbol valueSymbol = symbols.NextNonEOLSymbol();

            bool succeeded = int.TryParse(valueSymbol.ToString(), out _value);
            valueSymbol.Assert(succeeded, "not a decimal");
        }
예제 #34
0
 public string ToString(SymbolList source)
 {
     using var f = ListFormat.CreateFormatter();
     foreach (var segment in source.GetSegments())
     {
         f.Append(segment.Value);
     }
     f.AppendEnd();
     return(f.Output);
 }
예제 #35
0
파일: Macro.cs 프로젝트: plocklsh/lwip
        public Macro(IModule module, SymbolList preAssignSymbols, ISymbolEnumerator symbols)
        {
            _module = module;
            _name = preAssignSymbols[0].ToString();
            
            while (symbols.NextNonEOLSymbol() != Symbol.Begin)
            {                
            }

            while (symbols.NextNonEOLSymbol() != Symbol.End)
            {
            }
        }
 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);
     }
 }
예제 #37
0
파일: ObjectType.cs 프로젝트: plocklsh/lwip
        private void ParseProperties(SymbolList header)
        {
            ISymbolEnumerator headerSymbols = header.GetSymbolEnumerator();
            Symbol temp = headerSymbols.NextNonEOLSymbol();

            // Skip name
            temp = headerSymbols.NextNonEOLSymbol();
            temp.Expect(Symbol.ObjectType);

            _syntax         = ParseSyntax       (Module, headerSymbols);
            _units          = ParseUnits        (headerSymbols);
            _access         = ParseAccess       (headerSymbols);
            _status         = ParseStatus       (headerSymbols);
            _description    = ParseDescription  (headerSymbols);
            _reference      = ParseReference    (headerSymbols);
            _indices        = ParseIndices      (headerSymbols);
            _augments        = ParseAugments     (headerSymbols);
            _defVal         = ParseDefVal       (headerSymbols);
        }
        internal CodeGenerationUnit(CodeGenerationUnitSyntax syntax,
                                    IReadOnlyList<string> codeUsings,
                                    IReadOnlySymbolCollection<ITaskDeclarationSymbol> taskDeclarations,
                                    IReadOnlySymbolCollection<ITaskDefinitionSymbol> taskDefinitions,
                                    IReadOnlySymbolCollection<IIncludeSymbol> includes,
                                    IEnumerable<ISymbol> symbols,
                                    IReadOnlyList<Diagnostic> diagnostics) {

            if(syntax == null) {
                throw new ArgumentNullException(nameof(syntax));
            }

            Syntax           = syntax;
            CodeUsings       = codeUsings       ?? new List<string>();
            TaskDeclarations = taskDeclarations ?? new SymbolCollection<ITaskDeclarationSymbol>();
            TaskDefinitions  = taskDefinitions  ?? new SymbolCollection<ITaskDefinitionSymbol>();
            Diagnostics      = diagnostics      ?? new List<Diagnostic>();
            Includes         = includes         ?? new SymbolCollection<IIncludeSymbol>();
            Symbols          = new SymbolList(symbols ?? Enumerable.Empty<IIncludeSymbol>());            
        }
예제 #39
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");
        }
        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);
                        }

                    }
                }
            }
        }
예제 #41
0
파일: ObjectType.cs 프로젝트: plocklsh/lwip
 public ObjectType(IModule module, SymbolList preAssignSymbols, ISymbolEnumerator symbols)
     : base(module, preAssignSymbols, symbols)
 {
     ParseProperties(preAssignSymbols);
 }
예제 #42
0
파일: EGT.cs 프로젝트: cwellsx/GOLDEngine
        internal EGT(BinaryReader Reader)
        {
            EGTReader EGT = new EGTReader(Reader);
            EGTRecord RecType = default(EGTRecord);

            try
            {
                while (!EGT.EndOfFile())
                {
                    EGT.GetNextRecord();

                    RecType = (EGTRecord)EGT.RetrieveByte();

                    switch (RecType)
                    {
                        case EGTRecord.Property:
                            {
                                //Index, Name, Value
                                int Index = 0;
                                string Name = null;

                                Index = EGT.RetrieveInt16();
                                Name = EGT.RetrieveString();
                                //Just discard
                                m_Grammar.SetValue(Index, EGT.RetrieveString());
                            }
                            break;
                        case EGTRecord.TableCounts:
                            //Symbol, CharacterSet, Rule, DFA, LALR
                            m_SymbolTable = new SymbolList(EGT.RetrieveInt16());
                            m_CharSetTable = new CharacterSetList(EGT.RetrieveInt16());
                            m_ProductionTable = new ProductionList(EGT.RetrieveInt16());
                            m_DFA = new FAStateList(EGT.RetrieveInt16());
                            m_LRStates = new LRStateList(EGT.RetrieveInt16());
                            m_GroupTable = new GroupList(EGT.RetrieveInt16());

                            break;
                        case EGTRecord.InitialStates:
                            //DFA, LALR
                            m_DFA.InitialState = EGT.RetrieveInt16();
                            m_LRStates.InitialState = EGT.RetrieveInt16();

                            break;
                        case EGTRecord.Symbol:
                            {
                                //#, Name, Kind
                                short Index = 0;
                                string Name = null;
                                SymbolType Type = default(SymbolType);

                                Index = EGT.RetrieveInt16();
                                Name = EGT.RetrieveString();
                                Type = (SymbolType)EGT.RetrieveInt16();

                                m_SymbolTable[Index] = new Symbol(Name, Type, Index);
                            }
                            break;
                        case EGTRecord.Group:
                            //#, Name, Container#, Start#, End#, Tokenized, Open Ended, Reserved, Count, (Nested Group #...)
                            {
                                Group G = new Group();

                                G.TableIndex = EGT.RetrieveInt16();
                                //#

                                G.Name = EGT.RetrieveString();
                                G.Container = m_SymbolTable[EGT.RetrieveInt16()];
                                G.Start = m_SymbolTable[EGT.RetrieveInt16()];
                                G.End = m_SymbolTable[EGT.RetrieveInt16()];

                                G.Advance = (Group.AdvanceMode)EGT.RetrieveInt16();
                                G.Ending = (Group.EndingMode)EGT.RetrieveInt16();
                                EGT.RetrieveEntry();
                                //Reserved

                                int Count = EGT.RetrieveInt16();
                                for (int n = 1; n <= Count; n++)
                                {
                                    G.Nesting.Add(EGT.RetrieveInt16());
                                }

                                //=== Link back
                                m_GroupStart.Add(G.Start, G);
                                m_GroupTable[G.TableIndex] = G;
                            }
                            break;
                        case EGTRecord.CharRanges:
                            //#, Total Sets, RESERVED, (Start#, End#  ...)
                            {
                                int Index = 0;
                                int Total = 0;

                                Index = EGT.RetrieveInt16();
                                EGT.RetrieveInt16();
                                //Codepage
                                Total = EGT.RetrieveInt16();
                                EGT.RetrieveEntry();
                                //Reserved

                                m_CharSetTable[Index] = new CharacterSet();
                                while (!(EGT.RecordComplete()))
                                {
                                    m_CharSetTable[Index].Add(new CharacterRange(EGT.RetrieveUInt16(), EGT.RetrieveUInt16()));
                                }
                            }
                            break;
                        case EGTRecord.Production:
                            //#, ID#, Reserved, (Symbol#,  ...)
                            {
                                short Index = 0;
                                int HeadIndex = 0;
                                int SymIndex = 0;

                                Index = EGT.RetrieveInt16();
                                HeadIndex = EGT.RetrieveInt16();
                                EGT.RetrieveEntry();
                                //Reserved

                                List<Symbol> symbols = new List<Symbol>();
                                while (!(EGT.RecordComplete()))
                                {
                                    SymIndex = EGT.RetrieveInt16();
                                    //m_ProductionTable[Index].Handle().Add(m_SymbolTable[SymIndex]);
                                    symbols.Add(m_SymbolTable[SymIndex]);
                                }
                                SymbolList symbolList = new SymbolList(symbols);
                                m_ProductionTable[Index] = new Production(m_SymbolTable[HeadIndex], Index, symbolList);
                            }
                            break;
                        case EGTRecord.DFAState:
                            //#, Accept?, Accept#, Reserved (CharSet#, Target#, Reserved)...
                            {
                                int Index = 0;
                                bool Accept = false;
                                int AcceptIndex = 0;
                                int SetIndex = 0;
                                short Target = 0;

                                Index = EGT.RetrieveInt16();
                                Accept = EGT.RetrieveBoolean();
                                AcceptIndex = EGT.RetrieveInt16();
                                EGT.RetrieveEntry();
                                //Reserved

                                if (Accept)
                                {
                                    m_DFA[Index] = new FAState(m_SymbolTable[AcceptIndex]);
                                }
                                else
                                {
                                    m_DFA[Index] = new FAState();
                                }

                                //(Edge chars, Target#, Reserved)...
                                while (!(EGT.RecordComplete()))
                                {
                                    SetIndex = EGT.RetrieveInt16();
                                    //Char table index
                                    Target = EGT.RetrieveInt16();
                                    //Target
                                    EGT.RetrieveEntry();
                                    //Reserved

                                    m_DFA[Index].Edges.Add(new FAEdge(m_CharSetTable[SetIndex], Target));
                                }
                            }
                            break;
                        case EGTRecord.LRState:
                            //#, Reserved (Symbol#, Action, Target#, Reserved)...
                            {
                                int Index = 0;
                                int SymIndex = 0;
                                LRActionType Action = 0;
                                short Target = 0;

                                Index = EGT.RetrieveInt16();
                                EGT.RetrieveEntry();
                                //Reserved

                                m_LRStates[Index] = new LRState();

                                //(Symbol#, Action, Target#, Reserved)...
                                while (!EGT.RecordComplete())
                                {
                                    SymIndex = EGT.RetrieveInt16();
                                    Action = (LRActionType)EGT.RetrieveInt16();
                                    Target = EGT.RetrieveInt16();
                                    EGT.RetrieveEntry();
                                    //Reserved

                                    m_LRStates[Index].Add(new LRAction(m_SymbolTable[SymIndex], Action, Target));
                                }
                            }
                            break;
                        default:
                            //RecordIDComment
                            throw new ParserException("File Error. A record of type '" + (char)RecType + "' was read. This is not a valid code.");
                    }
                }
            }
            catch (Exception ex)
            {
                throw new ParserException(ex.Message, ex, "LoadTables");
            }
        }
        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);
                    }
                }
            }
        }
        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);

                            }
                        }
                    }
                }
            }
        }
예제 #45
0
 public RuleProduction AddRule(int idSource, params Symbol[] destiny)
 {
     SymbolList sl = new SymbolList();
     sl.AddRange(destiny);
     return AddRule(idSource, sl);
 }
        private void btnGerar_Click(object sender, EventArgs e)
        {
            g = new Grammar();

            g.Variables.Clear();
            g.Variables.AddRange(txtVariaveis.Text.Select(c => new Symbol(-1, c, false)));
            g.Terminals.Clear();
            g.Terminals.AddRange(txtVariaveis.Text.Select(c => new Symbol(-1, c, true, c)));

            string[] regras = txtRegras.Text.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);

            for (int i = 0; i < regras.Length; i++)
            {
                char variavel = regras[i].ToUpper()[0];

                string prod = regras[i].Substring(2).Trim();

                string[] prods = prod.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);

                for (int j = 0; j < prods.Length; j++)
                {
                    var symbols = new SymbolList();
                    symbols = symbols.AddRange(prods[j].Select(prd => new Symbol(-1, prd, prd.IsTerminal(), prd)));
                    g.AddRule(g.Variables.Find(variavel), symbols);
                }
            }
        }
예제 #47
0
 public RuleProduction AddRule(Symbol source, SymbolList destiny)
 {
     if (Rules.Count == 0)
     {
         VariableStart = source;
     }
     RuleProduction rule = Rules.FirstOrDefault(r => r.Destiny == destiny && r.Source == source && r.Pertinence == 1);
     if (rule == null)
     {
         rule = new RuleProduction();
         rule.Source = source;
         rule.Destiny.AddRange(destiny.ToList());
         rule.Pertinence = 1;
         Rules.Add(rule);
     }
     return rule;
 }
예제 #48
0
 /// <summary>
 /// Creates an <see cref="AgentCapabilities"/> instance.
 /// </summary>
 /// <param name="module"></param>
 /// <param name="header"></param>
 /// <param name="lexer"></param>
 public AgentCapabilities(IModule module, SymbolList preAssignSymbols, ISymbolEnumerator symbols)
     : base(module, preAssignSymbols, symbols)
 {
 }
예제 #49
0
 public RuleProduction AddRule(int idSource, SymbolList destiny)
 {
     return AddRule(Variables.Find(idSource), destiny);
 }
예제 #50
0
 public override void PopulateSymbols(DataSource ds, List<string> symbols)
 {
     SymbolList symbolList = new SymbolList();
     symbolList.AddText(ds.DSString);
     symbols.AddRange(symbolList.Items);
 }
예제 #51
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();
                }
            }
        }
예제 #52
0
 /// <summary>
 /// Creates a <see cref="ObjectIdentity"/>.
 /// </summary>
 /// <param name="module">Module name</param>
 /// <param name="header">Header</param>
 /// <param name="lexer">Lexer</param>
 public ObjectIdentity(IModule module, SymbolList preAssignSymbols, ISymbolEnumerator symbols)
     : base(module, preAssignSymbols, symbols)
 {
 }
예제 #53
0
 public ModuleCompliance(IModule module, SymbolList preAssignSymbols, ISymbolEnumerator symbols)
     : base(module, preAssignSymbols, symbols)
 {
 }
예제 #54
0
 /// <summary>
 /// Creates a <see cref="OidValueAssignment"/>.
 /// </summary>
 /// <param name="module">Module</param>
 /// <param name="name">Name</param>
 /// <param name="lexer">Lexer</param>
 public OidValueAssignment(IModule module, SymbolList preAssignSymbols, ISymbolEnumerator symbols)
     : base(module, preAssignSymbols, symbols)
 {
 }
        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 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());
            }
        }
예제 #57
0
 public Symbol GetExclusiveVars(SymbolList destiny)
 {
     var origens = Rules.Where(c => c.Destiny == destiny).Select(r => r.Source);
     foreach (var origem in origens)
     {
         if (GetRules(origem.Name).Count == 1)
         {
             return origem;
         }
     }
     return Symbol.EmptyVariable;
 }
예제 #58
0
파일: MibModule.cs 프로젝트: plocklsh/lwip
        private void ParseEntity(SymbolList preAssignSymbols, ISymbolEnumerator symbols)
        {
            if ((preAssignSymbols == null) || (preAssignSymbols.Count == 0))
            {
                Symbol s = symbols.NextSymbol();
                if (s != null)
                {
                    s.Assert(false, "Invalid Entitiy declaration");
                }
                else
                {
                    throw new MibException("Invalid Entitiy declaration");
                }
            }

            // check for a valid identifier
            preAssignSymbols[0].AssertIsValidIdentifier();
            
            if (preAssignSymbols.Count == 1)
            {
                // its a typedef
                _tokens.Add(Lexer.ParseBasicTypeDef(this, preAssignSymbols[0].ToString(), symbols, isMacroSyntax: false));
                return;
            }

            ISymbolEnumerator preAssignSymbolsEnumerator = preAssignSymbols.GetSymbolEnumerator();
            preAssignSymbolsEnumerator.NextNonEOLSymbol(); // returns identifier
            Symbol type = preAssignSymbolsEnumerator.NextNonEOLSymbol();

            // parse declarations
            if (type == Symbol.Object)
            {
                Symbol next = preAssignSymbolsEnumerator.NextNonEOLSymbol();

                if (next == Symbol.Identifier)
                {
                    _tokens.Add(new OidValueAssignment(this, preAssignSymbols, symbols));
                    return;
                }
                else if (next != null)
                {
                    preAssignSymbolsEnumerator.PutBack(next);
                }
            }
            if (type == Symbol.ModuleIdentity)
            {
                _tokens.Add(new ModuleIdentity(this, preAssignSymbols, symbols));
                return;
            }
            if (type == Symbol.ObjectType)
            {
                _tokens.Add(new ObjectType(this, preAssignSymbols, symbols));
                return;
            }
            if (type == Symbol.ObjectGroup)
            {
                _tokens.Add(new ObjectGroup(this, preAssignSymbols, symbols));
                return;
            }
            if (type == Symbol.NotificationGroup)
            {
                _tokens.Add(new NotificationGroup(this, preAssignSymbols, symbols));
                return;
            }
            if (type == Symbol.ModuleCompliance)
            {
                _tokens.Add(new ModuleCompliance(this, preAssignSymbols, symbols));
                return;
            }
            if (type == Symbol.NotificationType)
            {
                _tokens.Add(new NotificationType(this, preAssignSymbols, symbols));
                return;
            }
            if (type == Symbol.ObjectIdentity)
            {
                _tokens.Add(new ObjectIdentity(this, preAssignSymbols, symbols));
                return;
            }
            if (type == Symbol.Macro)
            {
                _tokens.Add(new Macro(this, preAssignSymbols, symbols));
                return;
            }
            if (type == Symbol.TrapType)
            {
                _tokens.Add(new TrapType(this, preAssignSymbols, symbols));
                return;
            }
            if (type == Symbol.AgentCapabilities)
            {
                _tokens.Add(new AgentCapabilities(this, preAssignSymbols, symbols));
                return;
            }

            preAssignSymbols[1].Assert(false, "Unknown/Invalid declaration");
        }
예제 #59
0
 public NotificationType(IModule module, SymbolList preAssignSymbols, ISymbolEnumerator symbols)
     : base(module, preAssignSymbols, symbols)
 {
 }
        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]);
                            }

                        }
                    }
                }
            }
        }