public Token(int id, int line, int collumn, RecognitionToken recToken, string word)
 {
     this.Id = id;
     this.Line = line;
     this.Collumn = collumn;
     this.RecToken = recToken;
     this.Word = word;
 }
示例#2
0
        private CompilerFuzzy Compiler4()
        {
            //LR(1)
            //0. S
            //0 → S$
            //1. S → V = E
            //2. S → E
            //3. E → V
            //4. V → x
            //5. V → ∗E
            List <RecognitionToken> recs = new List <RecognitionToken>();
            var requal = new RecognitionToken(1, "equal", "=", "#7bf6b6", norm, conorm);
            var rast   = new RecognitionToken(2, "ast", "*", "#f28686", norm, conorm);
            var rx     = new RecognitionToken(3, "x", "x", "#fbdb65", norm, conorm);

            recs.Add(requal);
            recs.Add(rast);
            recs.Add(rx);

            Grammar grammar = new Grammar();
            var     x       = new Symbol(1, "x", true, 'x');

            x.SetCustomValue("RecToken", rx);

            var ast = new Symbol(2, "*", true, '*');

            ast.SetCustomValue("RecToken", rast);

            var equal = new Symbol(3, "=", true, '=');

            equal.SetCustomValue("RecToken", requal);


            var S  = new Symbol(4, "S", false);
            var V  = new Symbol(5, "V", false);
            var V1 = new Symbol(7, "V1", false);
            var E  = new Symbol(6, "E", false);

            grammar.Terminals.AddRange(new SymbolList(x, ast, equal));

            grammar.Variables.AddRange(new SymbolList(S, V, E, V1));
            grammar.VariableStart = S;
            grammar.AddRule(S, V, equal, E);
            grammar.AddRule(S, E);
            grammar.AddRule(E, V);
            grammar.AddRule(E, V1).Pertinence = 0.8;
            var ruleV = grammar.AddRule(V, x);

            grammar.AddRule(V1, equal).Parent = ruleV;
            grammar.AddRule(V, ast, E);

            return(new CompilerFuzzy(recs, grammar, null, null, norm, conorm));
        }
        // AbstractLexicalAnalysis lex;
        public FrmCompilerWithFuzzy()
        {
            InitializeComponent();

            var r1 = new RecognitionToken(1, "space", " ", "#7bf6b6", norm, conorm);
            var r2 = new RecognitionToken(2, "type", "int", "#f28686", norm, conorm);
            var r3 = new RecognitionToken(2, "var", "a", "#fbdb65", norm, conorm);
            var r4 = new RecognitionToken(2, "final", ";", "#dcc6ad", norm, conorm);

            List<RecognitionToken> rules = new List<RecognitionToken>();
            rules.Add(r1);
            rules.Add(r2);
            rules.Add(r3);
            rules.Add(r4);
            //    lex = new AbstractLexicalAnalysis(rules);

            btnSyn_Click(null, null);
            //btnLexicalAnalysis_Click(null, null);
        }
        private Container CreateContainer(Node <Symbol, double> node)
        {
            RuleProduction rule      = node.GetCustomOject <RuleProduction>("Rule");
            Container      container = new Container();

            container.Value = string.Empty;
            if (DestinyIsTerminal(node))
            {
                var token = node.Info.GetCustomValue <Token>("Token");
                RecognitionToken recToken = null;
                if (token != null)
                {
                    recToken         = token.RecToken;
                    container.Value  = token.Word;
                    container.Column = token.Collumn;
                    container.Line   = token.Line;
                }
                if (recToken == null)
                {
                    recToken = node.Info.GetCustomValue <RecognitionToken>("RecToken");
                }


                if ((recToken != null) &&
                    (token == null || recToken.RegexFuzzy.Match(token.Word) < 1)
                    )
                {
                    container.Value = recToken.RegexFuzzy.RegexFuzzy;
                }

                container.TypeName = node.Info.Name;
            }
            else
            {
                if (rule != null)
                {
                    container.TypeName = rule.TypeName;
                }
            }

            return(container);
        }
示例#5
0
        // AbstractLexicalAnalysis lex;
        public FrmCompilerWithFuzzy()
        {
            InitializeComponent();



            var r1 = new RecognitionToken(1, "space", " ", "#7bf6b6", norm, conorm);
            var r2 = new RecognitionToken(2, "type", "int", "#f28686", norm, conorm);
            var r3 = new RecognitionToken(2, "var", "a", "#fbdb65", norm, conorm);
            var r4 = new RecognitionToken(2, "final", ";", "#dcc6ad", norm, conorm);

            List <RecognitionToken> rules = new List <RecognitionToken>();

            rules.Add(r1);
            rules.Add(r2);
            rules.Add(r3);
            rules.Add(r4);
            //    lex = new AbstractLexicalAnalysis(rules);



            btnSyn_Click(null, null);
            //btnLexicalAnalysis_Click(null, null);
        }
 public Token(int id, int line, int collumn, RecognitionToken recToken, char word)
     : this(id, line, collumn, recToken, "" + word)
 {
 }
        private CompilerFuzzy Compiler4()
        {
            //LR(1)
            //0. S
            //0 → S$
            //1. S → V = E
            //2. S → E
            //3. E → V
            //4. V → x
            //5. V → ∗E
            List<RecognitionToken> recs = new List<RecognitionToken>();
            var requal = new RecognitionToken(1, "equal", "=", "#7bf6b6", norm, conorm);
            var rast = new RecognitionToken(2, "ast", "*", "#f28686", norm, conorm);
            var rx = new RecognitionToken(3, "x", "x", "#fbdb65", norm, conorm);
            recs.Add(requal);
            recs.Add(rast);
            recs.Add(rx);

            Grammar grammar = new Grammar();
            var x = new Symbol(1, "x", true, 'x');
            x.SetCustomValue("RecToken", rx);

            var ast = new Symbol(2, "*", true, '*');
            ast.SetCustomValue("RecToken", rast);

            var equal = new Symbol(3, "=", true, '=');
            equal.SetCustomValue("RecToken", requal);

            var S = new Symbol(4, "S", false);
            var V = new Symbol(5, "V", false);
            var V1 = new Symbol(7, "V1", false);
            var E = new Symbol(6, "E", false);

            grammar.Terminals.AddRange(new SymbolList(x, ast, equal));

            grammar.Variables.AddRange(new SymbolList(S, V, E, V1));
            grammar.VariableStart = S;
            grammar.AddRule(S, V, equal, E);
            grammar.AddRule(S, E);
            grammar.AddRule(E, V);
            grammar.AddRule(E, V1).Pertinence = 0.8;
            var ruleV = grammar.AddRule(V, x);
            grammar.AddRule(V1, equal).Parent = ruleV;
            grammar.AddRule(V, ast, E);

            return new CompilerFuzzy(recs, grammar, null, null, norm, conorm);
        }