Esempio n. 1
0
 //Expression que l'on a le droit de mettre devant une etoile
 public static NodeAST MatchStarable(StringCursor stringCursor)
 {
     if (stringCursor.Match('('))
     {
         return(MatchParenthesis(stringCursor));
     }
     return(MatchConstant(stringCursor));
 }
Esempio n. 2
0
        // Algo réalisé à l'aide de la grammaire formelle
        public static NodeAST MatchRegex(StringCursor stringCursor)
        {
            NodeAST node = MatchAlternative(stringCursor);

            if (node.Type == NodeASTType.Error)
            {
                return(node);
            }
            return(stringCursor.Match('\0') ? node : NodeAST.CreateError());
        }
Esempio n. 3
0
        public static NodeAST MatchConstant(StringCursor stringCursor)
        {
            if (!char.IsLetterOrDigit(stringCursor.Current))
            {
                return(NodeAST.CreateError());
            }
            NodeAST node = new NodeAST(NodeASTType.Constant, stringCursor.Current);

            stringCursor.Next();
            return(node);
        }
Esempio n. 4
0
        //Expression starable qui contient, ou pas, une étoile
        public static NodeAST MatchStar(StringCursor stringCursor)
        {
            NodeAST node = MatchStarable(stringCursor);

            if (node.Type == NodeASTType.Error)
            {
                return(node);
            }
            if (stringCursor.Match('*'))
            {
                stringCursor.Next();
                return(new NodeAST(NodeASTType.Star, new NodeAST[] { node }));
            }
            return(node);
        }
Esempio n. 5
0
        public static NodeAST MatchConcatenation(StringCursor stringCursor)
        {
            List <NodeAST> children = new List <NodeAST>();

            do
            {
                NodeAST node = MatchStar(stringCursor);
                if (node.Type == NodeASTType.Error)
                {
                    return(node);
                }
                children.Add(node);
            } while (stringCursor.Match('(') || char.IsLetterOrDigit(stringCursor.Current));
            return((children.Count == 1) ? children[0] : new NodeAST(NodeASTType.Concatenation, children.ToArray()));
        }
Esempio n. 6
0
        public static NodeAST MatchParenthesis(StringCursor stringCursor)
        {
            if (!stringCursor.Match('('))
            {
                return(NodeAST.CreateError());
            }
            stringCursor.Next();
            NodeAST node = MatchAlternative(stringCursor);

            if (node.Type == NodeASTType.Error)
            {
                return(node);
            }
            if (!stringCursor.Match(')'))
            {
                return(NodeAST.CreateError());
            }
            stringCursor.Next();
            return(node);
        }
Esempio n. 7
0
        public static NodeAST MatchAlternative(StringCursor stringCursor)
        {
            NodeAST node = MatchConcatenation(stringCursor);

            if (node.Type == NodeASTType.Error)
            {
                return(node);
            }
            List <NodeAST> children = new List <NodeAST>();

            children.Add(node);
            while (stringCursor.Match('|'))
            {
                stringCursor.Next();
                node = MatchConcatenation(stringCursor);
                if (node.Type == NodeASTType.Error)
                {
                    return(node);
                }
                children.Add(node);
            }

            return((children.Count == 1) ? children[0] : new NodeAST(NodeASTType.Alternative, children.ToArray()));
        }