/// <summary>
        /// Visit d'un ElementCalculFUnaire
        /// </summary>
        /// <param name="elt"></param>
        void IVisiteurIElement.Visit(ElementCalculFUnaire elt)
        {
            double valeurElement;

            elt.Element.Accept(this);
            valeurElement   = _valeurCourante;
            _valeurCourante = elt.Fonction(valeurElement);
        }
Example #2
0
        /// <summary>
        /// -------------------------------------------------------
        /// | Elem  ::= variable | constante | '(' Somme ')' | Fonction '(' Parametres ')'
        /// | Analyse des variable, contantes et parenthèses
        /// -------------------------------------------------------
        /// </summary>
        /// <returns></returns>
        private IElementCalcul LitElem()
        {
            IElementCalcul retour;

            if (_tokenCourant.TypeToken == ENTypeToken.ENOuvertureParenthese)
            {
                LitTokenSuivant();
                retour = LitSomme();
                if (_tokenCourant.TypeToken != ENTypeToken.ENFermetureParenthese)
                {
                    // Erreur de synthaxe
                    throw (new FormatException(string.Format(System.Globalization.CultureInfo.CurrentUICulture,
                                                             Calculateur.ResourceManager.GetString("EltAttPos"),
                                                             (_tokenCourant.PositionDebutToken), ")")));
                }
                LitTokenSuivant();
            }
            else if (_tokenCourant.TypeToken == ENTypeToken.ENPlus) // oprérateur unaire
            {
                LitTokenSuivant();
                retour = LitElem();
            }
            else if (_tokenCourant.TypeToken == ENTypeToken.ENMoins) // oprérateur unaire
            {
                LitTokenSuivant();
                retour = new ElementCalculFUnaire(new FonctionUnaire((double a) => - a), LitElem());
            }
            else
            {
                Token tokenSuivant = LitTokenSuivant(false);
                if (tokenSuivant.TypeToken == ENTypeToken.ENOuvertureParenthese) //C'est une fonction
                {
                    retour = LitFonction();
                }
                else //Variable ou définition d'une nouvelle fonction
                {
                    retour = LitValeur();
                }
            }
            return(retour);
        }
Example #3
0
        // -------------------------------------------------------
        // | Elem  ::= variable | constante | '(' Somme ')' | Fonction '(' Parametres ')'
        // | Analyse des variable, contantes et parenthèses
        // -------------------------------------------------------
        private IElementCalcul LitElem()
        {
            IElementCalcul retour;

            if (mTokenCourant == "(")
            {
                LitToken();
                retour = LitSomme();
                if (mTokenCourant != ")")
                {
                    // Erreure de synthaxe
                    throw (new Exception("Elément attendu à la position " + (mPosCourant - mTokenCourant.Length) + " : )"));
                }
                LitToken();
            }
            else if (mTokenCourant == "+")            // oprérateur unaire
            {
                LitToken();
                retour = LitElem();
            }
            else if (mTokenCourant == "-") // oprérateur unaire
            {
                LitToken();
                retour = new ElementCalculFUnaire(new fonctionUnaire(Negatif), LitElem());
            }
            else
            {
                string tokenSuivant = LitTokenSuivant();
                if (tokenSuivant == "(") //C'est une fonction
                {
                    retour = LitFonction();
                }
                else //Variable ou définition d'une nouvelle fonction
                {
                    retour = LitValeur();
                }
            }
            return(retour);
        }