예제 #1
0
        private void ResaltarSintaxis()
        {
            StringReader     input = new StringReader(codigoFuente.Text);
            TinyMachineLexer lexer = new TinyMachineLexer(input);
            Symbol           sym;

            int textOffset = 0, lineaActual = 0;

            codigoFuente.Enabled = false;
            while ((sym = lexer.next_token()).sym != TokenDef.EOF)
            {
                if (sym.sym == TokenDef.FIN_LINEA)
                {
                    textOffset += codigoFuente.Lines[lineaActual++].Length + 1;
                    continue;
                }

                PropiedadesTexto p = ObtenerPropiedadesToken(sym);

                codigoFuente.Select(textOffset + sym.right - 1, p.longitud);
                codigoFuente.SelectionColor = p.colorTexto;

                if (sym.sym == TokenDef.FIN_LINEA || sym.sym == TokenDef.COMENTARIO_LINEA || sym.sym == TokenDef.COMENTARIO_FIN)
                {
                    textOffset += codigoFuente.Lines[lineaActual++].Length + 1;
                }
            }
            codigoFuente.SelectionStart  = 0;
            codigoFuente.SelectionLength = 0;
            codigoFuente.Enabled         = true;
        }
예제 #2
0
        private PropiedadesTexto ObtenerPropiedadesToken(Symbol sym)
        {
            PropiedadesTexto p = new PropiedadesTexto();

            switch (sym.sym)
            {
            case TinyMachine.parser.TokenDef.COMENTARIO_FIN:
            case TinyMachine.parser.TokenDef.COMENTARIO_LINEA:
                p.colorTexto = Color.Green;
                p.longitud   = sym.value.ToString().Length;
                break;

            case TinyMachine.parser.TokenDef.COLON:
                p.colorTexto = Color.Brown;
                break;

            case TinyMachine.parser.TokenDef.ENTERO:
                p.colorTexto = Color.Brown;
                p.longitud   = ((Symbol)sym.value).value.ToString().Length;
                break;

            case TinyMachine.parser.TokenDef.LD:
            case TinyMachine.parser.TokenDef.ST:
            case TinyMachine.parser.TokenDef.IN:
                p.colorTexto = Color.Blue;
                p.longitud   = 2;
                break;

            case TinyMachine.parser.TokenDef.HALT:
                p.colorTexto = Color.Blue;
                p.longitud   = 4;
                break;

            case TinyMachine.parser.TokenDef.ADD:
            case TinyMachine.parser.TokenDef.DIV:
            case TinyMachine.parser.TokenDef.JEQ:
            case TinyMachine.parser.TokenDef.JGE:
            case TinyMachine.parser.TokenDef.JGT:
            case TinyMachine.parser.TokenDef.JLE:
            case TinyMachine.parser.TokenDef.JLT:
            case TinyMachine.parser.TokenDef.JNE:
            case TinyMachine.parser.TokenDef.LDA:
            case TinyMachine.parser.TokenDef.LDC:
            case TinyMachine.parser.TokenDef.MUL:
            case TinyMachine.parser.TokenDef.OUT:
            case TinyMachine.parser.TokenDef.SUB:
                p.colorTexto = Color.Blue;
                p.longitud   = 3;
                break;
            }

            return(p);
        }