Exemplo n.º 1
0
 public FSAFloat() {
     this._state = State.START;
     this._intPart = 0;
     this._fracPart = 0;
     this._fracCount = 0;
     this._expPart = 0;
     this._suffix = TokenFloat.FloatSuffix.NONE;
     this._expPos = true;
     this._raw = "";
 }
Exemplo n.º 2
0
 public override void Reset()
 {
     this._state     = State.START;
     this._intPart   = 0;
     this._fracPart  = 0;
     this._fracCount = 0;
     this._expPart   = 0;
     this._suffix    = TokenFloat.FloatSuffix.NONE;
     this._expPos    = true;
     this._raw       = "";
 }
Exemplo n.º 3
0
        public override void ReadChar(Char ch)
        {
            this._raw += ch;
            switch (this._state)
            {
            case State.ERROR:
            case State.END:
                this._state = State.ERROR;
                break;

            case State.START:
                if (Char.IsDigit(ch))
                {
                    this._intPart = ch - '0';
                    this._state   = State.D;
                }
                else if (ch == '.')
                {
                    this._state = State.P;
                }
                else
                {
                    this._state = State.ERROR;
                }
                break;

            case State.D:
                if (Char.IsDigit(ch))
                {
                    this._intPart *= 10;
                    this._intPart += ch - '0';
                    this._state    = State.D;
                }
                else if (ch == 'e' || ch == 'E')
                {
                    this._state = State.DE;
                }
                else if (ch == '.')
                {
                    this._state = State.DP;
                }
                else
                {
                    this._state = State.ERROR;
                }
                break;

            case State.P:
                if (Char.IsDigit(ch))
                {
                    this._fracPart  = ch - '0';
                    this._fracCount = 1;
                    this._state     = State.PD;
                }
                else
                {
                    this._state = State.ERROR;
                }
                break;

            case State.DP:
                if (Char.IsDigit(ch))
                {
                    this._fracPart  = ch - '0';
                    this._fracCount = 1;
                    this._state     = State.PD;
                }
                else if (ch == 'e' || ch == 'E')
                {
                    this._state = State.DE;
                }
                else if (ch == 'f' || ch == 'F')
                {
                    this._suffix = TokenFloat.FloatSuffix.F;
                    this._state  = State.PDF;
                }
                else if (ch == 'l' || ch == 'L')
                {
                    this._suffix = TokenFloat.FloatSuffix.L;
                    this._state  = State.DPL;
                }
                else
                {
                    this._state = State.END;
                }
                break;

            case State.PD:
                if (Char.IsDigit(ch))
                {
                    this._fracPart *= 10;
                    this._fracPart += ch - '0';
                    this._fracCount++;
                    this._state = State.PD;
                }
                else if (ch == 'e' || ch == 'E')
                {
                    this._state = State.DE;
                }
                else if (ch == 'f' || ch == 'F')
                {
                    this._suffix = TokenFloat.FloatSuffix.F;
                    this._state  = State.PDF;
                }
                else if (ch == 'l' || ch == 'L')
                {
                    this._suffix = TokenFloat.FloatSuffix.L;
                    this._state  = State.DPL;
                }
                else
                {
                    this._state = State.END;
                }
                break;

            case State.DE:
                if (Char.IsDigit(ch))
                {
                    this._expPart = ch - '0';
                    this._state   = State.DED;
                }
                else if (ch == '+' || ch == '-')
                {
                    if (ch == '-')
                    {
                        this._expPos = false;
                    }
                    this._state = State.DES;
                }
                else
                {
                    this._state = State.ERROR;
                }
                break;

            case State.DES:
                if (Char.IsDigit(ch))
                {
                    this._expPart = ch - '0';
                    this._state   = State.DED;
                }
                else
                {
                    this._state = State.ERROR;
                }
                break;

            case State.DPL:
                this._suffix = TokenFloat.FloatSuffix.L;
                this._state  = State.END;
                break;

            case State.DED:
                if (Char.IsDigit(ch))
                {
                    this._expPart *= 10;
                    this._expPart += ch - '0';
                    this._state    = State.DED;
                }
                else if (ch == 'f' || ch == 'F')
                {
                    this._suffix = TokenFloat.FloatSuffix.F;
                    this._state  = State.PDF;
                }
                else if (ch == 'l' || ch == 'L')
                {
                    this._suffix = TokenFloat.FloatSuffix.L;
                    this._state  = State.DPL;
                }
                else
                {
                    this._state = State.END;
                }
                break;

            case State.PDF:
                this._state = State.END;
                break;

            default:
                this._state = State.ERROR;
                break;
            }
        }
Exemplo n.º 4
0
        public override void ReadChar(Char ch) {
            this._raw += ch;
            switch (this._state) {
                case State.ERROR:
                case State.END:
                    this._state = State.ERROR;
                    break;

                case State.START:
                    if (Char.IsDigit(ch)) {
                        this._intPart = ch - '0';
                        this._state = State.D;
                    } else if (ch == '.') {
                        this._state = State.P;
                    } else {
                        this._state = State.ERROR;
                    }
                    break;

                case State.D:
                    if (Char.IsDigit(ch)) {
                        this._intPart *= 10;
                        this._intPart += ch - '0';
                        this._state = State.D;
                    } else if (ch == 'e' || ch == 'E') {
                        this._state = State.DE;
                    } else if (ch == '.') {
                        this._state = State.DP;
                    } else {
                        this._state = State.ERROR;
                    }
                    break;

                case State.P:
                    if (Char.IsDigit(ch)) {
                        this._fracPart = ch - '0';
                        this._fracCount = 1;
                        this._state = State.PD;
                    } else {
                        this._state = State.ERROR;
                    }
                    break;

                case State.DP:
                    if (Char.IsDigit(ch)) {
                        this._fracPart = ch - '0';
                        this._fracCount = 1;
                        this._state = State.PD;
                    } else if (ch == 'e' || ch == 'E') {
                        this._state = State.DE;
                    } else if (ch == 'f' || ch == 'F') {
                        this._suffix = TokenFloat.FloatSuffix.F;
                        this._state = State.PDF;
                    } else if (ch == 'l' || ch == 'L') {
                        this._suffix = TokenFloat.FloatSuffix.L;
                        this._state = State.DPL;
                    } else {
                        this._state = State.END;
                    }
                    break;

                case State.PD:
                    if (Char.IsDigit(ch)) {
                        this._fracPart *= 10;
                        this._fracPart += ch - '0';
                        this._fracCount++;
                        this._state = State.PD;
                    } else if (ch == 'e' || ch == 'E') {
                        this._state = State.DE;
                    } else if (ch == 'f' || ch == 'F') {
                        this._suffix = TokenFloat.FloatSuffix.F;
                        this._state = State.PDF;
                    } else if (ch == 'l' || ch == 'L') {
                        this._suffix = TokenFloat.FloatSuffix.L;
                        this._state = State.DPL;
                    } else {
                        this._state = State.END;
                    }
                    break;

                case State.DE:
                    if (Char.IsDigit(ch)) {
                        this._expPart = ch - '0';
                        this._state = State.DED;
                    } else if (ch == '+' || ch == '-') {
                        if (ch == '-') {
                            this._expPos = false;
                        }
                        this._state = State.DES;
                    } else {
                        this._state = State.ERROR;
                    }
                    break;

                case State.DES:
                    if (Char.IsDigit(ch)) {
                        this._expPart = ch - '0';
                        this._state = State.DED;
                    } else {
                        this._state = State.ERROR;
                    }
                    break;

                case State.DPL:
                    this._suffix = TokenFloat.FloatSuffix.L;
                    this._state = State.END;
                    break;

                case State.DED:
                    if (Char.IsDigit(ch)) {
                        this._expPart *= 10;
                        this._expPart += ch - '0';
                        this._state = State.DED;
                    } else if (ch == 'f' || ch == 'F') {
                        this._suffix = TokenFloat.FloatSuffix.F;
                        this._state = State.PDF;
                    } else if (ch == 'l' || ch == 'L') {
                        this._suffix = TokenFloat.FloatSuffix.L;
                        this._state = State.DPL;
                    } else {
                        this._state = State.END;
                    }
                    break;

                case State.PDF:
                    this._state = State.END;
                    break;

                default:
                    this._state = State.ERROR;
                    break;
            }

        }
Exemplo n.º 5
0
 public FloatLiteral(Double value, TokenFloat.FloatSuffix floatSuffix)
 {
     this.Value       = value;
     this.FloatSuffix = floatSuffix;
 }