コード例 #1
0
 public void Action(Expansion e)
 {
     if (e is Choice)
     {
         if (Options.getLookahead() == 1 || Options.getForceLaCheck())
         {
             LookaheadCalc.choiceCalc((Choice)e);
         }
     }
     else if (e is OneOrMore)
     {
         OneOrMore exp = (OneOrMore)e;
         if (Options.getForceLaCheck() || (implicitLA(exp.Expansion) && Options.getLookahead() == 1))
         {
             LookaheadCalc.ebnfCalc(exp, exp.Expansion);
         }
     }
     else if (e is ZeroOrMore)
     {
         ZeroOrMore exp = (ZeroOrMore)e;
         if (Options.getForceLaCheck() || (implicitLA(exp.Expansion) && Options.getLookahead() == 1))
         {
             LookaheadCalc.ebnfCalc(exp, exp.Expansion);
         }
     }
     else if (e is ZeroOrOne)
     {
         ZeroOrOne exp = (ZeroOrOne)e;
         if (Options.getForceLaCheck() || (implicitLA(exp.Expansion) && Options.getLookahead() == 1))
         {
             LookaheadCalc.ebnfCalc(exp, exp.Expansion);
         }
     }
 }
コード例 #2
0
ファイル: LookaheadWalk.cs プロジェクト: meikeric/csharpcc
        public static IList <MatchInfo> genFirstSet(IList <MatchInfo> partialMatches, Expansion exp)
        {
            if (exp is RegularExpression)
            {
                IList <MatchInfo> retval = new List <MatchInfo>();
                for (int i = 0; i < partialMatches.Count; i++)
                {
                    MatchInfo m    = (MatchInfo)partialMatches[i];
                    MatchInfo mnew = new MatchInfo();
                    for (int j = 0; j < m.firstFreeLoc; j++)
                    {
                        mnew.match[j] = m.match[j];
                    }
                    mnew.firstFreeLoc = m.firstFreeLoc;
                    mnew.match[mnew.firstFreeLoc++] = ((RegularExpression)exp).Ordinal;
                    if (mnew.firstFreeLoc == MatchInfo.laLimit)
                    {
                        sizeLimitedMatches.Add(mnew);
                    }
                    else
                    {
                        retval.Add(mnew);
                    }
                }
                return(retval);
            }
            else if (exp is NonTerminal)
            {
                NormalProduction prod = ((NonTerminal)exp).Production;
                if (prod is CodeProduction)
                {
                    return(new List <MatchInfo>());
                }
                else
                {
                    return(genFirstSet(partialMatches, prod.Expansion));
                }
            }
            else if (exp is Choice)
            {
                IList <MatchInfo> retval = new List <MatchInfo>();
                Choice            ch     = (Choice)exp;
                foreach (Expansion e in ch.Choices)
                {
                    IList <MatchInfo> v = genFirstSet(partialMatches, e);
                    listAppend(retval, v);
                }
                return(retval);
            }
            else if (exp is Sequence)
            {
                IList <MatchInfo> v   = partialMatches;
                Sequence          seq = (Sequence)exp;
                foreach (Expansion unit in seq.Units)
                {
                    v = genFirstSet(v, unit);
                    if (v.Count == 0)
                    {
                        break;
                    }
                }
                return(v);
            }
            else if (exp is OneOrMore)
            {
                IList <MatchInfo> retval = new List <MatchInfo>();
                IList <MatchInfo> v      = partialMatches;
                OneOrMore         om     = (OneOrMore)exp;
                while (true)
                {
                    v = genFirstSet(v, om.Expansion);
                    if (v.Count == 0)
                    {
                        break;
                    }

                    listAppend(retval, v);
                }
                return(retval);
            }
            else if (exp is ZeroOrMore)
            {
                IList <MatchInfo> retval = new List <MatchInfo>();
                listAppend(retval, partialMatches);
                IList <MatchInfo> v  = partialMatches;
                ZeroOrMore        zm = (ZeroOrMore)exp;
                while (true)
                {
                    v = genFirstSet(v, zm.Expansion);
                    if (v.Count == 0)
                    {
                        break;
                    }

                    listAppend(retval, v);
                }
                return(retval);
            }
            else if (exp is ZeroOrOne)
            {
                IList <MatchInfo> retval = new List <MatchInfo>();
                listAppend(retval, partialMatches);
                listAppend(retval, genFirstSet(partialMatches, ((ZeroOrOne)exp).Expansion));
                return(retval);
            }
            else if (exp is TryBlock)
            {
                return(genFirstSet(partialMatches, ((TryBlock)exp).Expansion));
            }
            else if (considerSemanticLA &&
                     exp is Lookahead &&
                     ((Lookahead)exp).ActionTokens.Count != 0
                     )
            {
                return(new List <MatchInfo>());
            }
            else
            {
                IList <MatchInfo> retval = new List <MatchInfo>();
                listAppend(retval, partialMatches);
                return(retval);
            }
        }