Exemple #1
0
        private Token ByteArrayToken()
        {
            StringBuilder strBuilder = new StringBuilder();

            for (; ; Read())
            {
                if (char.IsDigit(Lookahead))
                {
                    strBuilder.Append(Lookahead);
                }
                else
                {
                    break;
                }
            }

            int length = Convert.ToInt32(strBuilder.ToString());

            strBuilder.Remove(0, strBuilder.Length);
            length *= 2;

            if (Lookahead == ':')
            {
                Read();
                for (int count = 0; count < length; Read())
                {
                    if (ByteArrayValue.IsHex(Lookahead))
                    {
                        strBuilder.Append(Lookahead);
                        count++;
                    }
                    else if (Lookahead == '\u000A')     // '\n' LF
                    {
                        Line++;
                    }
                    else if (Lookahead == '\u0009' ||   // '\t' HT
                             Lookahead == '\u000D' ||   // '\r' CR
                             Lookahead == '\u0020')     // ' '  SP
                    {
                        continue;
                    }
                    else if (Lookahead == ';')
                    {
                        while (true)
                        {
                            Read();
                            if (Lookahead == '\u000A')  // '\n' LF
                            {
                                Line++;
                                break;
                            }
                            else if (Lookahead == '\0')
                            {
                                break;
                            }
                        }
                    }
                    else
                    {
                        throw new Exception("Lexical analyzer line " + Line.ToString() + ": Found a non-hexadecimal value.");
                    }
                }
            }
            else
            {
                throw new Exception("Lexical analyzer line " + Line.ToString() + ": The ':' character of starting an byte array was expected.");
            }

            return(new ByteArrayValue(strBuilder.ToString(), KeyLabel.ByteArray));
        }
Exemple #2
0
        private Token IntToken()
        {
            StringBuilder strBuilder = new StringBuilder();

            if (Lookahead == '0')
            {
                Read();
                if (Lookahead == 'x')
                {
                    Read();
                    if (ByteArrayValue.IsHex(Lookahead))
                    {
                        strBuilder.Append(Lookahead);
                        Read();
                        for (int count = 1; ; Read())
                        {
                            if (ByteArrayValue.IsHex(Lookahead))
                            {
                                strBuilder.Append(Lookahead);
                            }
                            else
                            {
                                break;
                            }

                            if (count > 7)
                            {
                                throw new Exception("Lexical analyzer line " + Line.ToString() + ": Detected a hexadecimal number of more than 32 bits.");
                            }

                            count++;
                        }
                        return(new IntValue(Convert.ToInt32(strBuilder.ToString(), 16), KeyLabel.IntHEX));
                    }
                    else
                    {
                        throw new Exception("Lexical analyzer line " + Line.ToString() + ": A hexadecimal number was expected.");
                    }
                }
                else if (char.IsDigit(Lookahead))
                {
                    throw new Exception("Lexical analyzer line " + Line.ToString() + ": A number that starts with zero is invalid.");
                }
                else
                {
                    return(new IntValue(0, KeyLabel.IntDEC));
                }
            }
            else
            {
                strBuilder.Append(Lookahead);
                Read();
                for (; ; Read())
                {
                    if (char.IsDigit(Lookahead))
                    {
                        strBuilder.Append(Lookahead);
                    }
                    else
                    {
                        break;
                    }
                }
                return(new IntValue(Convert.ToInt32(strBuilder.ToString()), KeyLabel.IntDEC));
            }
        }