Exemplo n.º 1
0
        /// <summary>
        /// Expression = somme | somme '=' somme
        /// </summary>
        /// <returns></returns>
        private IElementCalcul LitAffectationFonction()
        {
            IElementCalcul retour;
            int            positionDebutFonction = _tokenCourant.PositionDebutToken; // token courant = nom de la fonction
            IElementCalcul premiereSomme         = LitSomme();

            if (_tokenCourant.TypeToken == ENTypeToken.ENEgal) //Définition d'une fonction
            {
                Fonction premierFonction = premiereSomme as Fonction;
                LitTokenSuivant();
                if (premierFonction == null)
                {
                    throw new FormatException(Calculateur.ResourceManager.GetString("ErreurSyntaxe"));
                }
                //Tous les paramètres de la fonction doivent être des variables avec des noms différents
                int i = 0;
                foreach (ElementCalculVariable elt in premiereSomme.ListeParametres)
                {
                    _paramsFonctionCourante.Add(elt.NomVariable, i.ToString(System.Globalization.CultureInfo.InvariantCulture));
                    i++;
                }
                retour = new ElementCalculAffFonc(premierFonction, LitSomme(), _tokensiner.Expression.Substring(positionDebutFonction, _tokenCourant.PositionDebutToken - positionDebutFonction));
            }
            else
            {
                retour = premiereSomme;
            }
            return(retour);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Visit d'un Fonction
        /// </summary>
        /// <param name="elt"></param>
        void IVisiteurIElement.Visit(Fonction elt)
        {
            IVariables ancienContext;
            IVariables nouveauContext;
            int        i = 0;

            if (elt.ElementRacine == null)
            {
                nouveauContext = new Variables();
                foreach (IElementCalcul element in elt.ListeParametres)
                {
                    element.Accept(this);
                    nouveauContext.Ajouter(i.ToString(System.Globalization.CultureInfo.InvariantCulture), _valeurCourante);
                    i++;
                }
                //Recherche de la fonction dans le contexte de calcul
                Fonction fonction = _listeFonc.ObtenirFonction(elt.Nom);
                if (fonction == null)
                {
                    throw new ArgumentOutOfRangeException(string.Format(System.Globalization.CultureInfo.InvariantCulture, Calculateur.ResourceManager.GetString("FonctionIndefini"), elt.Nom));
                }
                if (elt.NombreParametres != fonction.NombreParametres)
                {
                    throw new ArgumentException(string.Format(System.Globalization.CultureInfo.InvariantCulture, Calculateur.ResourceManager.GetString("ParametreIndefini"), elt.Nom, fonction.NombreParametres));
                }
                ancienContext   = _contexFonction;
                _contexFonction = nouveauContext;
                fonction.ElementRacine.Accept(this);
                _contexFonction = ancienContext;
            }
            else
            {
                elt.ElementRacine.Accept(this);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Lecture de la fonction
        /// </summary>
        /// <param name="nomFonction">Nom de la fonction</param>
        private IElementCalcul LitFonction()
        {
            string nomFonction = _tokenCourant.Text;
            List <IElementCalcul> listParametres;

            LitTokenSuivant(); // "("
            //Lecture de la liste des paramètres
            listParametres = LitParametresFonction();
            return(Fonction.Factory(nomFonction, listParametres));
        }
Exemplo n.º 4
0
 /// <summary>
 /// Constructeur
 /// </summary>
 /// <param name="fonction">La fonction</param>
 public FonctionEventArgs(Fonction fonction)
 {
     _fonction = fonction;
 }
Exemplo n.º 5
0
 /// <summary>
 /// Constructeur
 /// </summary>
 /// <param name="fonction">La fonction a affecter</param>
 /// <param name="elementRacine">Détail de la fonction</param>
 /// <param name="expression">Expression qui décrit la fonction</param>
 public ElementCalculAffFonc(Fonction fonction, IElementCalcul elementRacine, string expression)
 {
     _fonction            = fonction;
     _fonction.Expression = expression;
     _elementRacine       = elementRacine;
 }