Exemple #1
0
        private void r_skip(List <LexerRule> rules, string name, RExpr ex)
        {
            LexerRule rule = new LexerRule(name, new List <string> (), new List <string> (), new List <string> (),
                                           "", true, ex);

            rules.Add(rule);
            tokenVocab [name] = tokVocabCount++;
        }
Exemple #2
0
        private void r_skip(ICollection <LexerRule> rules, string name, RExpr ex)
        {
            var rule = new LexerRule(name, new List <string> (), new List <string> (), new List <string> (),
                                     "", true, ex);

            rules.Add(rule);
            TokenVocab [name] = _tokenVocabularyCounter++;
        }
Exemple #3
0
 public LexerRule(string _Name,
                  List <string> _Within,
                  List <string> _Pushes,
                  List <string> _Pops,
                  string _Class,
                  bool _Skip,
                  RExpr _Expr)
 {
     Name   = _Name;
     Within = _Within;
     Pushes = _Pushes;
     Pops   = _Pops;
     Class  = _Class;
     Skip   = _Skip;
     Expr   = _Expr;
 }
        public static bool CheckForItems(Clause checkclause)
        {
            DateTime leftdate = DateTime.Now;
            LExpr    LE       = checkclause.LSide;
            string   retquest = "";

            if (LE.EType == Clause.ElementTypeLeft.Item || LE.EType == Clause.ElementTypeLeft.Item)
            {
                return(true);
            }


            RExpr RE = checkclause.RSide;

            if (RE.EType == Clause.ElementTypeRight.Item || RE.EType == Clause.ElementTypeRight.Item)
            {
                return(true);
            }


            return(false);
        }
        public static string CheckForQuestions(Clause checkclause)
        {
            DateTime leftdate = DateTime.Now;
            LExpr    LE       = checkclause.LSide;
            string   retquest = "";

            if (LE.EType == Clause.ElementTypeLeft.Question)
            {
                retquest += "," + LE.Qid.ToString();
            }


            RExpr RE = checkclause.RSide;

            if (RE.EType == Clause.ElementTypeRight.Question)
            {
                retquest += "," + RE.Qid.ToString();
            }


            return(retquest);
        }
Exemple #6
0
 private static Plus plus(RExpr expr)
 => new Plus(expr);
Exemple #7
0
 private static Star star(RExpr expr)
 => new Star(expr);
Exemple #8
0
        public FA nfaFromRegEx(RExpr _e)
        {
            if (_e is ByName)
            {
                //ByName e = (ByName) _e;
                throw new System.NotImplementedException("nfaFromRegEx/ByName not implemented");
            }
            else if (_e is CharClass)
            {
                CharClass e = _e as CharClass;
                e = canonicalized(e);
                int start = newState();
                int end   = newState();

                return(fa(start, end).trans(start, end, charRange(e)));
            }
            else if (_e is NotCharClass)
            {
                NotCharClass __e   = _e as NotCharClass;
                CharClass    e     = canonicalized(__e);
                int          start = newState();
                int          end   = newState();

                return(fa(start, end).trans(start, end, charRange(e)));
            }
            else if (_e is Oring)
            {
                Oring      e             = _e as Oring;
                List <FA>  opts          = Utils.list(e.Exprs.Select(a => { return(nfaFromRegEx(a)); }));
                List <int> startEpsilons = Utils.list(opts.Select(a => { return(a.startState); }));
                List <int> endEpsilons   = Utils.list(opts.Select(a => { return(onlyAcceptingState(a)); }));

                int start = newState();
                int end   = newState();

                FA _fa = fa(start, end).merge(opts);

                for (int i = 0; i < opts.Count; ++i)
                {
                    _fa.trans(start, startEpsilons[i], epsilon());
                    _fa.trans(endEpsilons[i], end, epsilon());
                }
                return(_fa);
            }
            else if (_e is Plus)
            {
                Plus e  = _e as Plus;
                FA   fa = nfaFromRegEx(e.Expr);
                fa.trans(onlyAcceptingState(fa), fa.startState, epsilon());
                return(fa);
            }
            else if (_e is RXSeq)
            {
                RXSeq e = _e as RXSeq;
                if (e.Exprs.Count == 1)
                {
                    return(nfaFromRegEx(e.Exprs[0]));
                }
                List <FA> opts = Utils.list(e.Exprs.Select(a => { return(nfaFromRegEx(a)); }));
                FA        _fa  = fa(opts[0].startState, onlyAcceptingState(Utils.last(opts))).merge(opts);
                for (int i = 0; i < opts.Count - 1; ++i)
                {
                    int prev = onlyAcceptingState(opts [i]);
                    int next = opts [i + 1].startState;
                    _fa.trans(prev, next, epsilon());
                }
                return(_fa);
            }
            else if (_e is Star)
            {
                Star e  = _e as Star;
                FA   fa = nfaFromRegEx(e.Expr);
                fa.trans(onlyAcceptingState(fa), fa.startState, epsilon());
                fa.trans(fa.startState, onlyAcceptingState(fa), epsilon());
                return(fa);
            }
            else if (_e is Question)
            {
                Question e  = _e as Question;
                FA       fa = nfaFromRegEx(e.Expr);
                fa.trans(fa.startState, onlyAcceptingState(fa), epsilon());
                return(fa);
            }
            else if (_e is Str)
            {
                Str          e   = _e as Str;
                List <RExpr> seq = new List <RExpr>();
                // todo: iterating over a string, this would
                // not work with surrogate pairs...etc
                for (int i = 0; i < e.Value.Length; ++i)
                {
                    char c = e.Value[i];
                    List <CharClassPart> v  = Utils.list1((CharClassPart) new CharPartRange(c, c));
                    CharClass            cc = new CharClass(v);
                    seq.Add(cc);
                }
                return(nfaFromRegEx(new RXSeq(seq)));
            }
            else
            {
                throw new Exception("OptionNotHandledException(_e)");
            }
        }
Exemple #9
0
 private static Plus plus(RExpr expr)
 {
     return(new Plus(expr));
 }
Exemple #10
0
 private static Star star(RExpr expr)
 {
     return(new Star(expr));
 }
Exemple #11
0
 LexerRule(string _Name, RExpr _Expr, bool _Skip)
 {
     Name = _Name;
     Expr = _Expr;
     Skip = _Skip;
 }
Exemple #12
0
 LexerRule(string _Name, RExpr _Expr)
 {
     Name = _Name;
     Expr = _Expr;
 }
Exemple #13
0
 public Star(RExpr _Expr)
 {
     Expr = _Expr;
 }
Exemple #14
0
 public Question(RExpr _Expr)
 {
     Expr = _Expr;
 }
Exemple #15
0
 public Plus(RExpr _Expr)
 {
     Expr = _Expr;
 }