/// <summary>
        /// Expression = somme | somme '=' somme
        /// </summary>
        /// <returns></returns>
        private IElementCalcul LitAffectationFonction()
        {
            IElementCalcul retour;
            IElementCalcul premiereSomme = LitSomme();

            if (mTokenCourant == "=") //Définition d'une fonction
            {
                LitToken();
                if (!(premiereSomme is Fonction))
                {
                    throw new Exception("Erreur de syntaxe");
                }
                //Tous les paramètres de la fonction doivent être des variables avec des nom différents
                int i = 0;
                foreach (ElementCalculVariable elt in (premiereSomme as Fonction).ListeParametres)
                {
                    mParamsFonctionCourante.Add(elt.NomVariable, i.ToString());
                    i++;
                }
                retour = new ElementCalculAffFonc(premiereSomme as Fonction, LitSomme());
            }
            else
            {
                retour = premiereSomme;
            }
            return(retour);
        }
Beispiel #2
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);
        }
 /// <summary>
 /// Visit d'un ElementCalculAffFonc
 /// </summary>
 /// <param name="elt"></param>
 void IVisiteurIElement.Visit(ElementCalculAffFonc elt)
 {
     elt.Fonction.ElementRacine = elt.ElementRacine;
     _listeFonc.Ajouter(elt.Fonction);
     _valeurCourante = 0;
 }