Ejemplo n.º 1
0
            public void Action(Expansion e)
            {
                if (e is Sequence)
                {
                    if (e.Parent is Choice || e.Parent is ZeroOrMore ||
                        e.Parent is OneOrMore || e.Parent is ZeroOrOne)
                    {
                        return;
                    }
                    Sequence  seq = (Sequence)e;
                    Lookahead la  = (Lookahead)(seq.Units[0]);
                    if (!la.IsExplicit)
                    {
                        return;
                    }

                    // Create a singleton choice with an empty action.
                    Choice ch = new Choice();
                    ch.Line   = la.Line;
                    ch.Column = la.Column;
                    ch.Parent = seq;
                    Sequence seq1 = new Sequence();
                    seq1.Line   = la.Line;
                    seq1.Column = la.Column;
                    seq1.Parent = ch;
                    seq1.Units.Add(la);
                    la.Parent = seq1;
                    Action act = new Action();
                    act.Line   = la.Line;
                    act.Column = la.Column;
                    act.Parent = seq1;
                    seq1.Units.Add(act);
                    ch.Choices.Add(seq1);
                    if (la.Amount != 0)
                    {
                        if (la.ActionTokens.Count != 0)
                        {
                            CSharpCCErrors.Warning(la,
                                                   "Encountered LOOKAHEAD(...) at a non-choice location.  " +
                                                   "Only semantic lookahead will be considered here.");
                        }
                        else
                        {
                            CSharpCCErrors.Warning(la, "Encountered LOOKAHEAD(...) at a non-choice location.  This will be ignored.");
                        }
                    }
                    // Now we have moved the lookahead into the singleton choice.  Now create
                    // a new dummy lookahead node to replace this one at its original location.
                    Lookahead la1 = new Lookahead();
                    la1.IsExplicit = false;
                    la1.Line       = la.Line;
                    la1.Column     = la.Column;
                    la1.Parent     = seq;
                    // Now set the la_expansion field of la and la1 with a dummy expansion (we use EOF).
                    la.Expansion  = new REndOfFile();
                    la1.Expansion = new REndOfFile();
                    seq.Units[0]  = la1;
                    seq.Units[1]  = ch;
                }
            }
Ejemplo n.º 2
0
        private static bool explicitLA(Expansion exp)
        {
            if (!(exp is Sequence))
            {
                return(false);
            }
            Sequence seq = (Sequence)exp;
            Object   obj = seq.Units[0];

            if (!(obj is Lookahead))
            {
                return(false);
            }
            Lookahead la = (Lookahead)obj;

            return(la.IsExplicit);
        }
Ejemplo n.º 3
0
 public Sequence(Token token, Lookahead la)
 {
     Line   = token.beginLine;
     Column = token.beginColumn;
     Units.Add(la);
 }