예제 #1
0
파일: Parser.cs 프로젝트: fabianhick/viana
        /// <summary>
        ///   Method of the Scanfkt: reads a constant_identifier.
        /// </summary>
        public void ScanFkt_ConstantIdentifier()
        {
            string buf  = string.Empty;
            string buf1 = string.Empty;
            ushort i;

            do
            {
                buf  = buf + this.ch;
                buf1 = buf1 + this.ch_;
                this.ScanFkt_GetCh();
            }while (((this.ch >= 'A') && (this.ch <= 'Z')) || (Constants.spezialChars.IndexOf(this.ch) >= 0));

            i = 0;
            while (i < Constants.konstante.Length)
            {
                if ((Constants.konstante[i].bez.ToLower().CompareTo(buf.ToLower()) == 0) &&
                    (!this.noUpCase || (Constants.konstante[i].bez.CompareTo(buf1) == 0)))
                {
                    this.sym        = symTyp.istKonst;
                    this.kVar       = this.ScanFkt_MakeNode(null, symTyp.istKonst, null);
                    this.kVar.Name  = Constants.konstante[i].bez;
                    this.kVar.Nr    = i;
                    this.kVar.Zwert = Constants.konstante[i].wert;
                    return;
                }
                i++;
            }
            // keine Konstantenbezeichnung gefunden
            ScanFkt_Err(7);
        }
예제 #2
0
파일: Parser.cs 프로젝트: fabianhick/viana
        /// <summary>
        ///   Method of the Scanfkt: reads an identifier.
        /// </summary>
        public void ScanFkt_Identifier()
        {
            string buf  = string.Empty;
            string buf1 = string.Empty;

            do
            {
                buf  = buf + this.ch;
                buf1 = buf1 + this.ch_;
                this.ScanFkt_GetCh();
            }while ((this.ch >= 'A') && (this.ch <= 'Z'));

            if (buf == "PI")
            {
                this.sym  = symTyp.istZahl;
                this.wert = Math.PI;
                return;
            }

            if (buf == "E")
            {
                if (this.ch == '^')
                {
                    this.sym = symTyp.expf;
                    this.ScanFkt_GetCh();
                    return;
                }
                else
                {
                    this.sym  = symTyp.istZahl;
                    this.wert = Constants.eulerZahl;
                    return;
                }
            }
            // teste auf Funktionsbezeichner
            this.sym = symTyp.sinf;
            while ((this.sym < symTyp.ffmax) && (buf != Constants.fnam[(int)this.sym - 5]))
            {
                this.sym++;
            }

            if (this.sym == symTyp.ffmax)
            {
                if (buf.ToLower().CompareTo(Constants.varName.ToLower()) == 0)
                {
                    this.sym = symTyp.ident;
                    if (this.xVar == null)
                    {
                        this.xVar       = this.ScanFkt_MakeNode(null, symTyp.ident, null);
                        this.xVar.Zwert = 0;
                        this.xVar.Name  = buf1;
                    }
                }
                else
                {
                    ScanFkt_Err(7);
                }
            }
        }
예제 #3
0
파일: Parser.cs 프로젝트: fabianhick/viana
        /// <summary>
        /// Makes a node in the function tree.
        /// </summary>
        /// <param name="op1">
        ///  op1 - left tree/operand
        /// </param>
        /// <param name="code">
        ///  code - operator
        /// </param>
        /// <param name="op2">
        /// op2 right tree/operand
        /// </param>
        /// <returns>
        /// The <see cref="CalculatorFunctionTerm"/> .
        /// </returns>
        public FunctionCalcTree ScanFkt_MakeNode(FunctionCalcTree op1, symTyp code, FunctionCalcTree op2)
        {
            FunctionCalcTree result;

            result       = new FunctionCalcTree();
            result.Cwert = code;
            result.Li    = op1;
            result.Re    = op2;
            return(result);
        }
예제 #4
0
파일: Parser.cs 프로젝트: fabianhick/viana
        /// <summary>
        /// Method of the Scanfkt: get expression.
        /// expression is a sum of terms or a term
        /// </summary>
        /// <param name="expr">
        /// The expression
        /// </param>
        public void ScanFkt_Expression(ref FunctionCalcTree expr)
        {
            symTyp           addop;
            FunctionCalcTree temp = null;

            if ((this.sym == symTyp.plus) || (this.sym == symTyp.minus))
            {
                addop = this.sym;
                this.ScanFkt_GetSym();
            }
            else
            {
                addop = symTyp.plus;
            }

            this.ScanFkt_Expression_Term(ref expr);
            if (addop == symTyp.minus)
            {
                if ((expr != null) && (expr.Cwert == symTyp.istZahl))
                {
                    expr = this.ScanFkt_Zahl(-expr.Zwert);
                }
                else
                {
                    expr = this.ScanFkt_MakeNode(this.ScanFkt_Zahl(-1), symTyp.mal, expr);
                }
            }

            while ((this.sym == symTyp.plus) || (this.sym == symTyp.minus))
            {
                do
                {
                    addop = this.sym;
                    this.ScanFkt_GetSym();
                    if (this.sym == symTyp.plus)
                    {
                        this.sym = addop;
                    }
                    else if ((this.sym == symTyp.minus) && (addop == symTyp.minus))
                    {
                        this.sym = symTyp.plus;
                    }
                }while (!((this.sym != symTyp.plus) && (this.sym != symTyp.minus)));
                this.ScanFkt_Expression_Term(ref temp);
                if (!this.fehler)
                {
                    expr = this.ScanFkt_MakeNode(expr, addop, temp);
                }
            }
        }
예제 #5
0
파일: Parser.cs 프로젝트: fabianhick/viana
        /// <summary>
        /// Method of the Scanfkt: set error number and its position in the string.
        /// </summary>
        /// <param name="nr">
        /// error number
        /// </param>
        public void ScanFkt_Err(byte nr)
        {
            if (this.fehler)
            {
                return;
            }

            this.errPos = this.oldChPos;
            this.errNr  = nr;
            this.fehler = true;
            this.chPos  = 255;
            this.ch     = '\0';
            this.sym    = symTyp.fstrEnd;
            this.Loesch(ref this.fx);
        }
예제 #6
0
파일: Parser.cs 프로젝트: fabianhick/viana
        // Number
        /// <summary>
        ///   Method of the Scanfkt: reads a number.
        /// </summary>
        public void ScanFkt_Number()
        {
            this.hStr = string.Empty;
            this.sym  = symTyp.istZahl;
            this.ScanFkt_ReadInt();
            if ((this.ch == '.') || (this.ch == ','))
            {
                this.hStr = this.hStr + this.ch;
                this.ScanFkt_GetCh();
                this.ScanFkt_ReadInt();
            }

            if (this.ch == 'E')
            {
                this.hStr = this.hStr + this.ch;
                this.ScanFkt_GetCh();
                if ((this.ch == '+') || (this.ch == '-'))
                {
                    this.hStr = this.hStr + this.ch;
                    this.ScanFkt_GetCh();
                }

                this.ScanFkt_ReadInt();
            }

            try
            {
                this.wert = Convert.ToDouble(this.hStr);
            }
            catch
            {
                this.ScanFkt_Err(4);
            }
            finally
            {
            }
        }
예제 #7
0
파일: Parser.cs 프로젝트: fabianhick/viana
 /// <summary>
 /// Method of the Scanfkt: set sym and reads next char
 /// </summary>
 /// <param name="s">
 /// s - symbol
 /// </param>
 public void ScanFkt_MakeSym(symTyp s)
 {
     this.sym = s;
     this.ScanFkt_GetCh();
 }
예제 #8
0
파일: Parser.cs 프로젝트: fabianhick/viana
        /// <summary>
        ///   Method of the Scanfkt: get next symbol.
        /// </summary>
        public void ScanFkt_GetSym()
        {
            if (this.fehler)
            {
                return;
            }

            while (this.ch == ' ')
            {
                this.ScanFkt_GetCh();
            }

            this.oldChPos = this.chPos;
            if (('A' <= this.ch) && (this.ch <= 'Z'))
            {
                this.ScanFkt_Identifier();
            }
            else if (('0' <= this.ch) && (this.ch <= '9'))
            {
                this.ScanFkt_Number();
            }
            else
            {
                switch (this.ch)
                {
                case '(':
                    this.ScanFkt_MakeSym(symTyp.lklammer);
                    break;

                case ')':
                    this.ScanFkt_MakeSym(symTyp.rklammer);
                    break;

                case '*':
                    this.ScanFkt_MakeSym(symTyp.mal);
                    break;

                case '+':
                    this.ScanFkt_MakeSym(symTyp.plus);
                    break;

                case '-':
                    this.ScanFkt_MakeSym(symTyp.minus);
                    break;

                case '/':
                    this.ScanFkt_MakeSym(symTyp.durch);
                    break;

                case '^':
                    this.ScanFkt_MakeSym(symTyp.pot);
                    break;

                case '§':
                    this.ScanFkt_ConstantIdentifier();
                    break;

                case '\0':
                    this.sym = symTyp.fstrEnd;
                    break;

                default:
                    this.ScanFkt_Err(5);
                    break;
                }
            }
        }