Exemple #1
0
 internal bool AddNfaNode(NfaNode nfa)
 {
     if (!m_nfa.Add(nfa))
     {
         return(false);
     }
     if (nfa.m_sTerminal != "")
     {
         int    qi, n = 0;
         string tokClass = "";
         string p        = nfa.m_sTerminal;
         if (p[0] == '%')
         {                                                 // check for %Tokname special action
             for (n = 0, qi = 1; qi < p.Length; qi++, n++) // extract the class name
             {
                 if (p[qi] == ' ' || p[qi] == '\t' || p[qi] == '\n' || p[qi] == '{' || p[qi] == ':')
                 {
                     break;
                 }
             }
             tokClass = nfa.m_sTerminal.Substring(1, n);
         }
         // check for ResWds machinery // 4.7
         if (n > 0 && n + 1 < p.Length)
         {
             string st = nfa.m_sTerminal.Substring(n + 1).Trim();
             if (st.Length > 0)
             {
                 if (st.StartsWith("%except"))
                 {
                     m_reswds = nfa.m_state;
                     m_tks.m_tokens.reswds[nfa.m_state] = ResWds.New(m_tks, st.Substring(7));
                 }
             }
         }
         // special action is always last in the list
         if (tokClass == "")
         {                                        //nfa has an old action
             if (m_tokClass == ""                 // if both are old-style
                 ||                               // or we have a special action that is later
                 (m_actions.a_act) > nfa.m_state) // m_actions has at least one entry
             {
                 AddAction(nfa.m_state);
             }
             // else we have a higher-precedence special action so we do nothing
         }
         else if (m_actions == null || m_actions.a_act > nfa.m_state)
         {
             MakeLastAction(nfa.m_state);
             m_tokClass = tokClass;
         }                 // else we have a higher-precedence special action so we do nothing
     }
     return(true);
 }
Exemple #2
0
 void ClosureAdd(NfaNode nfa)
 {
     for (int pos = 0; pos < nfa.m_eps.Count; pos++)
     {
         NfaNode p = (NfaNode)nfa.m_eps[pos];
         if (AddNfaNode(p))
         {
             ClosureAdd(p);
         }
     }
 }
Exemple #3
0
 private void ClosureAdd(NfaNode nfa)
 {
     for (int index = 0; index < nfa.m_eps.Count; ++index)
     {
         NfaNode ep = (NfaNode)nfa.m_eps[index];
         if (this.AddNfaNode(ep))
         {
             this.ClosureAdd(ep);
         }
     }
 }
Exemple #4
0
        public override void Build(Nfa nfa)
        {
            int     j, n = m_str.Length;
            NfaNode p, pp = nfa;

            for (j = 0; j < n; pp = p, j++)
            {
                p = new NfaNode(nfa.m_tks);
                pp.AddArc(m_str[j], p);
            }
            pp.AddEps(nfa.m_end);
        }
Exemple #5
0
        public override void Build(Nfa nfa)
        {
            int     length  = this.m_str.Length;
            NfaNode nfaNode = (NfaNode)nfa;

            for (int index = 0; index < length; ++index)
            {
                NfaNode next = new NfaNode(nfa.m_tks);
                nfaNode.AddUArc(this.m_str[index], next);
                nfaNode = next;
            }
            nfaNode.AddEps(nfa.m_end);
        }
Exemple #6
0
 internal bool AddNfaNode(NfaNode nfa)
 {
     if (!this.m_nfa.Add(nfa))
     {
         return(false);
     }
     if (nfa.m_sTerminal != "")
     {
         int    length    = 0;
         string str1      = "";
         string sTerminal = nfa.m_sTerminal;
         if (sTerminal[0] == '%')
         {
             length = 0;
             int index = 1;
             while (index < sTerminal.Length && (sTerminal[index] != ' ' && sTerminal[index] != '\t') && (sTerminal[index] != '\n' && sTerminal[index] != '{' && sTerminal[index] != ':'))
             {
                 ++index;
                 ++length;
             }
             str1 = nfa.m_sTerminal.Substring(1, length);
         }
         if (length > 0 && length + 1 < sTerminal.Length)
         {
             string str2 = nfa.m_sTerminal.Substring(length + 1).Trim();
             if (str2.Length > 0 && str2.StartsWith("%except"))
             {
                 this.m_reswds = nfa.m_state;
                 this.m_tks.m_tokens.reswds[(object)nfa.m_state] = (object)ResWds.New(this.m_tks, str2.Substring(7));
             }
         }
         if (str1 == "")
         {
             if (this.m_tokClass == "" || this.m_actions.a_act > nfa.m_state)
             {
                 this.AddAction(nfa.m_state);
             }
         }
         else if (this.m_actions == null || this.m_actions.a_act > nfa.m_state)
         {
             this.MakeLastAction(nfa.m_state);
             this.m_tokClass = str1;
         }
     }
     return(true);
 }
Exemple #7
0
 internal bool AddNfaNode(NfaNode nfa)
 {
     if (!m_nfa.Add(nfa))
     {
         return(false);
     }
     if (nfa.m_sTerminal != "")
     {
         int    qi, n;
         string tokClass = "";
         string p        = nfa.m_sTerminal;
         if (p[0] == '%')
         {                                                 // check for %Tokname special action
             for (n = 0, qi = 1; qi < p.Length; qi++, n++) // extract the class name
             {
                 if (p[qi] == ' ' || p[qi] == '\t' || p[qi] == '\n' || p[qi] == '{' || p[qi] == ':')
                 {
                     break;
                 }
             }
             tokClass = nfa.m_sTerminal.Substring(1, n);
         }
         // special action is always last in the list
         if (tokClass == "")
         {                                        //nfa has an old action
             if (m_tokClass == ""                 // if both are old-style
                 ||                               // or we have a special action that is later
                 (m_actions.a_act) > nfa.m_state) // m_actions has at least one entry
             {
                 AddAction(nfa.m_state);
             }
             // else we have a higher-precedence special action so we do nothing
         }
         else if (m_actions == null || m_actions.a_act > nfa.m_state)
         {
             MakeLastAction(nfa.m_state);
             m_tokClass = tokClass;
         }                 // else we have a higher-precedence special action so we do nothing
     }
     return(true);
 }
Exemple #8
0
 public bool Add(NfaNode n)
 {
     if (m_node == null)
     {              // m_node==null iff m_next==null
         m_next = new NList();
         m_node = n;
     }
     else if (m_node.m_state < n.m_state)
     {
         m_next = new NList(m_node, m_next);
         m_node = n;
     }
     else if (m_node.m_state == n.m_state)
     {
         return(false);                 // Add fails, there already
     }
     else
     {
         return(m_next.Add(n));
     }
     return(true);            // was added
 }
Exemple #9
0
        public NfaNode m_node; // null for the sentinel

        #endregion Fields

        #region Constructors

        public NList()
        {
            m_node=null; m_next=null;
        }
Exemple #10
0
		internal bool AddNfaNode(NfaNode nfa)
		{
			if (!m_nfa.Add(nfa))
				return false;
			if (nfa.m_sTerminal!="")
			{
				int qi,n;
				string tokClass = "";
				string p=nfa.m_sTerminal;
				if (p[0]=='%')
				{ // check for %Tokname special action
					for (n=0,qi=1;qi<p.Length;qi++,n++) // extract the class name
						if (p[qi]==' '||p[qi]=='\t'||p[qi]=='\n'||p[qi]=='{'||p[qi]==':')
							break;
					tokClass = nfa.m_sTerminal.Substring(1,n);
				}
				// special action is always last in the list
				if (tokClass=="")
				{ //nfa has an old action
					if (m_tokClass=="" // if both are old-style
						|| // or we have a special action that is later
						(m_actions.a_act)>nfa.m_state)   // m_actions has at least one entry
						AddAction(nfa.m_state);
					// else we have a higher-precedence special action so we do nothing
				}
				else if (m_actions==null || m_actions.a_act>nfa.m_state)
				{
					MakeLastAction(nfa.m_state);
					m_tokClass = tokClass;
				} // else we have a higher-precedence special action so we do nothing
			}
			return true;
		}
Exemple #11
0
 public ArcEx(Regex re,NfaNode next)
 {
     m_ref=re; m_next=next;
 }
Exemple #12
0
 public void AddUArc(char ch, NfaNode next)
 {
     m_arcs.Add(new UArc(ch, next));
 }
Exemple #13
0
		public NList() { m_node=null; m_next=null; } // sentinel only
Exemple #14
0
        public override void Build(Nfa nfa)
        {
            int j,n = m_str.Length;
            NfaNode p, pp = nfa;

            for (j=0;j<n;pp = p,j++)
            {
                p = new NfaNode(nfa.m_tks);
                pp.AddUArc(m_str[j],p);
            }
            pp.AddEps(nfa.m_end);
        }
Exemple #15
0
 /// <exclude/>
 internal bool AddNfaNode(NfaNode nfa)
 {
     if (!m_nfa.Add(nfa))
         return false;
     if (nfa.m_sTerminal!="")
     {
         int qi,n=0;
         string tokClass = "";
         string p=nfa.m_sTerminal;
         if (p[0]=='%')
         { // check for %Tokname special action
             for (n=0,qi=1;qi<p.Length;qi++,n++) // extract the class name
                 if (p[qi]==' '||p[qi]=='\t'||p[qi]=='\n'||p[qi]=='{'||p[qi]==':')
                     break;
             tokClass = nfa.m_sTerminal.Substring(1,n);
         }
         // check for ResWds machinery // 4.7
         if (n>0 && n+1<p.Length)
         {
             string st = nfa.m_sTerminal.Substring(n+1).Trim();
             if (st.Length>0) {
                 if (st.StartsWith("%except"))
                 {
                     m_reswds = nfa.m_state;
                     m_tks.m_tokens.reswds[nfa.m_state] = ResWds.New(m_tks,st.Substring(7));
                 }
             }
         }
         // special action is always last in the list
         if (tokClass=="")
         { //nfa has an old action
             if (m_tokClass=="" // if both are old-style
                 || // or we have a special action that is later
                 (m_actions.a_act)>nfa.m_state)   // m_actions has at least one entry
                 AddAction(nfa.m_state);
             // else we have a higher-precedence special action so we do nothing
         }
         else if (m_actions==null || m_actions.a_act>nfa.m_state)
         {
             MakeLastAction(nfa.m_state);
             m_tokClass = tokClass;
         } // else we have a higher-precedence special action so we do nothing
     }
     return true;
 }
Exemple #16
0
        }                                                    // sentinel only

        NList(NfaNode nd, NList nx)
        {
            m_node = nd; m_next = nx;
        }
Exemple #17
0
 /// <exclude/>
 public Nfa(TokensGen tks)
     : base(tks)
 {
     m_end = new NfaNode(m_tks);
 }
Exemple #18
0
 // build an NFA for a given regular expression
 public Nfa(TokensGen tks, Regex re) : base(tks)
 {
     m_end = new NfaNode(tks);
     re.Build(this);
 }
Exemple #19
0
 public NList()
 {
     m_node = null; m_next = null;
 }                                                    // sentinel only
Exemple #20
0
 public Nfa(TokensGen tks) : base(tks)
 {
     m_end = new NfaNode(m_tks);
 }
Exemple #21
0
 public void AddEps(NfaNode next)
 {
     m_eps.Add(next);
 }
Exemple #22
0
 public void AddArcEx(Regex re, NfaNode next)
 {
     m_arcs.Add(new ArcEx(re, next));
 }
Exemple #23
0
 NList(NfaNode nd,NList nx)
 {
     m_node=nd; m_next=nx;
 }
Exemple #24
0
 /// <exclude/>
 public void AddArcEx(Regex re,NfaNode next)
 {
     m_arcs.Add(new ArcEx(re,next));
 }
Exemple #25
0
 public bool Add(NfaNode n)
 {
     if (m_node==null)
     {  // m_node==null iff m_next==null
         m_next = new NList();
         m_node = n;
     }
     else if (m_node.m_state < n.m_state)
     {
         m_next = new NList(m_node,m_next);
         m_node = n;
     }
     else if (m_node.m_state == n.m_state)
         return false;  // Add fails, there already
     else
         return m_next.Add(n);
     return true; // was added
 }
Exemple #26
0
 public ArcEx(Regex re, NfaNode next)
 {
     m_ref = re; m_next = next;
 }
Exemple #27
0
 public UArc(char ch,NfaNode next)
     : base(ch,next)
 {
 }
Exemple #28
0
 public Arc(char ch, NfaNode next)
 {
     m_ch = ch; m_next = next;
 }
Exemple #29
0
 /// <exclude/>
 void ClosureAdd(NfaNode nfa)
 {
     for (int pos=0;pos<nfa.m_eps.Count;pos++)
     {
         NfaNode p = (NfaNode)nfa.m_eps[pos];
         if (AddNfaNode(p))
             ClosureAdd(p);
     }
 }
Exemple #30
0
 public UArc(char ch, NfaNode next) : base(ch, next)
 {
 }
Exemple #31
0
 // build an NFA for a given regular expression
 /// <exclude/>
 public Nfa(TokensGen tks,Regex re)
     : base(tks)
 {
     m_end = new NfaNode(tks);
     re.Build(this);
 }
Exemple #32
0
 /// <exclude/>
 public void AddUArc(char ch,NfaNode next)
 {
     m_arcs.Add(new UArc(ch,next));
 }
Exemple #33
0
 /// <exclude/>
 public void AddEps(NfaNode next)
 {
     m_eps.Add(next);
 }
Exemple #34
0
 public ArcEx(Regex re, NfaNode next)
 {
     this.m_ref  = re;
     this.m_next = next;
 }
Exemple #35
0
 public Arc(char ch, NfaNode next)
 {
     m_ch=ch; m_next=next;
 }
Exemple #36
0
 public Arc(char ch, NfaNode next)
 {
     this.m_ch   = ch;
     this.m_next = next;
 }