Ejemplo n.º 1
0
        private void lex()
        {
            Token tok = fTokenizer.CurrentToken;

            switch (tok.Kind)
            {
            case TokenKind.Number:
                fToken = ExpToken.tkNUMBER;
                fValue = SysUtils.ParseFloat(tok.Value, double.NaN);
                break;

            case TokenKind.Symbol:
            {
                switch (tok.Value[0])
                {
                case '!':
                    fToken = ExpToken.tkNOT;
                    tok    = fTokenizer.Next();
                    if (tok.Value[0] == '=')
                    {
                        fToken = ExpToken.tkNE;
                    }
                    else
                    {
                        return;
                    }
                    break;

                case '%':
                    fToken = ExpToken.tkMOD;
                    tok    = fTokenizer.Next();
                    if (tok.Value[0] == '%')
                    {
                        fToken = ExpToken.tkPER;
                    }
                    else
                    {
                        return;
                    }
                    break;

                case '&':
                    fToken = ExpToken.tkAND;
                    break;

                case '(':
                    fToken = ExpToken.tkLBRACE;
                    break;

                case ')':
                    fToken = ExpToken.tkRBRACE;
                    break;

                case '*':
                    fToken = ExpToken.tkMUL;
                    tok    = fTokenizer.Next();
                    if (tok.Value[0] == '*')
                    {
                        fToken = ExpToken.tkPOW;
                    }
                    else
                    {
                        return;
                    }
                    break;

                case '+':
                    fToken = ExpToken.tkADD;
                    break;

                case '-':
                    fToken = ExpToken.tkSUB;
                    break;

                case '/':
                    fToken = ExpToken.tkDIV;
                    break;

                case ';':
                    fToken = ExpToken.tkSEMICOLON;
                    break;

                case '<':
                    fToken = ExpToken.tkLT;
                    tok    = fTokenizer.Next();
                    if (tok.Value[0] == '=')
                    {
                        fToken = ExpToken.tkLE;
                    }
                    else
                    {
                        return;
                    }
                    break;

                case '=':
                    fToken = ExpToken.tkASSIGN;
                    tok    = fTokenizer.Next();
                    if (tok.Value[0] == '=')
                    {
                        fToken = ExpToken.tkEQ;
                    }
                    else
                    {
                        return;
                    }
                    break;

                case '>':
                    fToken = ExpToken.tkGT;
                    tok    = fTokenizer.Next();
                    if (tok.Value[0] == '=')
                    {
                        fToken = ExpToken.tkGE;
                    }
                    else
                    {
                        return;
                    }
                    break;

                case '^':
                    fToken = ExpToken.tkXOR;
                    break;

                case '|':
                    fToken = ExpToken.tkOR;
                    break;

                case '~':
                    fToken = ExpToken.tkINV;
                    break;

                default:
                    fToken = ExpToken.tkERROR;
                    break;
                }
            }
            break;

            case TokenKind.Word:
            case TokenKind.Ident:
                fIdent = tok.Value;
                fToken = ExpToken.tkIDENT;
                break;

            case TokenKind.HexNumber:
                try {
                    fToken = ExpToken.tkNUMBER;
                    fValue = Convert.ToInt32(tok.Value, 16);
                } catch {
                    fToken = ExpToken.tkERROR;
                }
                break;

            case TokenKind.BinNumber:
                try {
                    fToken = ExpToken.tkNUMBER;
                    fValue = Convert.ToInt32(tok.Value.Substring(2), 2);
                } catch {
                    fToken = ExpToken.tkERROR;
                }
                break;

            case TokenKind.EOF:
                fToken = ExpToken.tkEOF;
                break;

            default:
                fToken = ExpToken.tkERROR;
                break;
            }

            fTokenizer.Next();
        }
Ejemplo n.º 2
0
 public void MergeSort(Comparison <T> comparer)
 {
     SysUtils.MergeSort(fList, comparer);
 }
Ejemplo n.º 3
0
        public void ParseText(List <BBTextChunk> chunksList, string text)
        {
            fChunks = chunksList;
            fChunks.Clear();

            float              lastFontSize = fDefaultFontSize;
            BBTextChunk        lastChunk    = null;
            Stack <SizeChange> stackSizes   = new Stack <SizeChange>();

            //lastChunk = SetChunkFontSize(0, lastChunk, fDefaultFontSize);

            if (string.IsNullOrEmpty(text))
            {
                text      = EMPTY_CHUNK;
                lastChunk = SetChunkText(0, lastChunk, text);
                return;
            }

            StringTokenizer strTok = new StringTokenizer(text);

            strTok.IgnoreWhiteSpace  = false;
            strTok.RecognizeDecimals = false;

            Token tok = strTok.Next();

            while (tok.Kind != TokenKind.EOF)
            {
                if (tok.Kind == TokenKind.Symbol && tok.Value == "[")
                {
                    string temp = tok.Value;
                    tok = strTok.Next();

                    bool closedTag;
                    if (tok.Kind == TokenKind.Symbol && tok.Value == "/")
                    {
                        closedTag = true;
                        temp     += tok.Value;
                        tok       = strTok.Next();
                    }
                    else
                    {
                        closedTag = false;
                    }

                    if (tok.Kind != TokenKind.Word)
                    {
                        // not tag
                        lastChunk = SetChunkText(tok.Line, lastChunk, temp + tok.Value);
                    }
                    else
                    {
                        string tag = tok.Value;
                        //bool skipTag = false;

                        if (tag == "color")
                        {
                            // [color="{red|#ff0000}"][/color]
                            IColor color = fTextColor;
                            if (!closedTag)
                            {
                                tok = strTok.Next();
                                if (tok.Kind == TokenKind.Symbol && tok.Value == "=")
                                {
                                    tok = strTok.Next();
                                    if (tok.Kind == TokenKind.Word)
                                    {
                                        color     = fGfxProvider.CreateColor(tok.Value);
                                        lastChunk = SetChunkColor(tok.Line, lastChunk, color);
                                    }
                                }
                            }
                            else
                            {
                                // TODO: colorStack
                                color     = fTextColor;
                                lastChunk = SetChunkColor(tok.Line, lastChunk, color);
                            }
                        }
                        else if (tag == "size")
                        {
                            // [size={+/-x}][/size]
                            if (!closedTag)
                            {
                                tok = strTok.Next();
                                if (tok.Kind == TokenKind.Symbol && tok.Value == "=")
                                {
                                    tok = strTok.Next();
                                    int factor = 0;
                                    if (tok.Kind == TokenKind.Symbol)
                                    {
                                        if (tok.Value == "+")
                                        {
                                            factor = +1;
                                        }
                                        else if (tok.Value == "-")
                                        {
                                            factor = -1;
                                        }
                                        tok = strTok.Next();
                                    }
                                    if (tok.Kind == TokenKind.Number)
                                    {
                                        float newSize = lastFontSize + factor * SysUtils.ParseInt(tok.Value, 0);
                                        stackSizes.Push(new SizeChange(lastFontSize, newSize));
                                        lastChunk    = SetChunkFontSize(tok.Line, lastChunk, newSize);
                                        lastFontSize = newSize;
                                    }
                                }
                            }
                            else
                            {
                                if (stackSizes.Count > 0)
                                {
                                    SizeChange sizeChange = stackSizes.Pop();
                                    lastChunk    = SetChunkFontSize(tok.Line, lastChunk, sizeChange.PrevSize);
                                    lastFontSize = sizeChange.PrevSize;
                                }
                            }
                        }
                        else if (tag == "b")
                        {
                            // [b][/b]
                            lastChunk = SetChunkFontStyle(tok.Line, lastChunk, ExtFontStyle.Bold, !closedTag);
                        }
                        else if (tag == "i")
                        {
                            // [i][/i]
                            lastChunk = SetChunkFontStyle(tok.Line, lastChunk, ExtFontStyle.Italic, !closedTag);
                        }
                        else if (tag == "s")
                        {
                            // [s][/s]
                            lastChunk = SetChunkFontStyle(tok.Line, lastChunk, ExtFontStyle.Strikeout, !closedTag);
                        }
                        else if (tag == "u")
                        {
                            // [u][/u]
                            lastChunk = SetChunkFontStyle(tok.Line, lastChunk, ExtFontStyle.Underline, !closedTag);
                        }
                        else if (tag == "url")
                        {
                            // bad impementation
                            // [url][/url] and [url=...][/url], but now only [url=...][/url]
                            string url = "";

                            tok = strTok.Next();
                            if (tok.Kind == TokenKind.Symbol && tok.Value == "=")
                            {
                                tok = strTok.Next();
                                do
                                {
                                    url += tok.Value;
                                    tok  = strTok.Next();
                                } while (tok.Kind != TokenKind.Symbol || tok.Value != "]");
                            }
                            else
                            {
                                //
                            }

                            lastChunk = SetChunkFontStyle(tok.Line, lastChunk, ExtFontStyle.Underline, !closedTag);
                            IColor color = (closedTag) ? fTextColor : fLinkColor;
                            lastChunk = SetChunkColor(tok.Line, lastChunk, color);
                            if (!closedTag)
                            {
                                lastChunk.URL = url;
                            }
                        }
                        else
                        {
                            // not tag
                            lastChunk = SetChunkText(tok.Line, lastChunk, temp + tok.Value);
                        }

                        if (tok.Kind != TokenKind.Symbol || tok.Value != "]")
                        {
                            // Possible syntax error?
                            strTok.Next();
                        }
                    }
                }
                else if (tok.Kind == TokenKind.EOL)
                {
                    lastChunk = SetChunkText(tok.Line, null, EMPTY_CHUNK);
                    lastChunk = null;
                }
                else
                {
                    lastChunk = SetChunkText(tok.Line, lastChunk, tok.Value);
                }

                tok = strTok.Next();
            }

            // eof
            lastChunk = SetChunkText(tok.Line, null, EMPTY_CHUNK);
        }
Ejemplo n.º 4
0
 public void QuickSort(Comparison <T> comparer)
 {
     SysUtils.QuickSort(fList, comparer);
 }