public override object VisitDirByteHex([NotNull] StdAssemblerParser.DirByteHexContext context)
        {
            string   value;
            StdToken token;

            if (context.children.Count != 5)
            {
                throw new Exception("Error de sintáxis: Instrucción no válida");
            }
            else
            {
                value = context.VAL().GetText();
                if (!Regex.IsMatch(value, @"^[0-9A-F]+$"))
                {
                    throw new Exception("Error de sintáxis: ingrese un valor hexadecimal");
                }
                token = new StdToken()
                {
                    Address       = count,
                    IsDirective   = true,
                    IsHex         = true,
                    Mode          = false,
                    OperationCode = "BYTE",
                    Value         = value
                };
                count += int.Parse(Math.Ceiling((double)value.Length / 2).ToString());
                return(token);
            }
        }
        public override object VisitDirWord([NotNull] StdAssemblerParser.DirWordContext context)
        {
            string   value;
            StdToken token;

            if (context.children.Count != 2)
            {
                throw new Exception("Error de sintáxis: Instrucción no válida");
            }
            else
            {
                value = context.VAL().GetText();
                if (Regex.IsMatch(value, @"(H|h)"))
                {
                    if (!Regex.IsMatch(value, @"^[0-9A-F]+(H|h)$"))
                    {
                        throw new Exception("Error de sintáxis: ingrese una dirección hexadecimal");
                    }

                    token = new StdToken()
                    {
                        Address       = count,
                        IsDirective   = true,
                        IsHex         = true,
                        Mode          = false,
                        OperationCode = "WORD",
                        Value         = value
                    };
                    count += 3;
                    return(token);
                }
                else
                {
                    if (Regex.IsMatch(value, "^[0-9]+$"))
                    {
                        value = int.Parse(value).ToString("X");
                        token = new StdToken()
                        {
                            Address       = count,
                            IsDirective   = true,
                            IsHex         = false,
                            Mode          = false,
                            OperationCode = "WORD",
                            Value         = value
                        };
                        count += 3;
                        return(token);
                    }
                    else
                    {
                        throw new Exception("Error de sintáxis: Instrucción no válida");
                    }
                }
            }
        }
        public override object VisitDirResw([NotNull] StdAssemblerParser.DirReswContext context)
        {
            string   value;
            StdToken token;

            if (context.children.Count != 2)
            {
                throw new Exception("Error de sintáxis: Instrucción no válida");
            }
            else
            {
                value = context.VAL().GetText();
                if (Regex.IsMatch(value, @"(H|h)"))
                {
                    if (!Regex.IsMatch(value, @"^[0-9A-F]+(H|h)$"))
                    {
                        throw new Exception("Error de sintáxis: ingrese una dirección hexadecimal");
                    }

                    token = new StdToken()
                    {
                        Address       = count,
                        IsDirective   = true,
                        IsHex         = true,
                        Mode          = false,
                        OperationCode = "RESW",
                        Value         = value
                    };
                    count += int.Parse(Regex.Replace(value, @"(H|h)", ""), System.Globalization.NumberStyles.HexNumber) * 3;
                    return(token);
                }
                else
                {
                    if (Regex.IsMatch(value, "^[0-9]+$"))
                    {
                        token = new StdToken()
                        {
                            Address       = count,
                            IsDirective   = true,
                            IsHex         = false,
                            Mode          = false,
                            OperationCode = "RESW",
                            Value         = value
                        };
                        count += int.Parse(value) * 3;
                        return(token);
                    }
                    else
                    {
                        throw new Exception("Error de sintáxis: Instrucción no válida");
                    }
                }
            }
        }
        public override object VisitRSub([NotNull] StdAssemblerParser.RSubContext context)
        {
            StdToken token;
            string   codOp;

            codOp = context.RSUB().GetText();
            token = new StdToken()
            {
                Address       = count,
                IsHex         = false,
                IsDirective   = false,
                Mode          = false,
                OperationCode = "RSUB"
            };
            return(token);
        }
        public override object VisitDirByteChar([NotNull] StdAssemblerParser.DirByteCharContext context)
        {
            string   ascii;
            StdToken token;


            {
                ascii = Regex.Match(context.start.InputStream.ToString(), @"\'([\x00-\xFF])+\'").Value.Replace("'", "");
                token = new StdToken()
                {
                    Address       = count,
                    IsDirective   = true,
                    IsHex         = false,
                    Mode          = false,
                    OperationCode = "BYTE",
                    Value         = ascii
                };
                count += ascii.Length;
                return(token);
            }
        }
        public override object VisitFin([NotNull] StdAssemblerParser.FinContext context)
        {
            string   end, inicio;
            StdToken token;

            if (context.children.Count > 3)
            {
                throw new Exception("Error de sintáxis: Instrucción no válida");
            }
            else
            {
                end = context.END().GetText();
                if (context.etiquetaFin() != null)
                {
                    inicio = Visit(context.etiquetaFin()) as String;
                }
                else
                {
                    inicio = string.Empty;
                }
                if (end.Contains("missing"))
                {
                    throw new Exception("Error de sintáxis: Instrucción no válida");
                }
            }
            token = new StdToken()
            {
                Address       = count,
                IsDirective   = true,
                IsHex         = false,
                Mode          = false,
                OperationCode = "END",
                Value         = inicio
            };
            TokenList.Add(token);
            return(token);
        }
        public override object VisitCodOp([NotNull] StdAssemblerParser.CodOpContext context)
        {
            string   codOp, etiqueta;
            StdToken token;
            Boolean  index = false;

            codOp    = context.CODOP().GetText();
            etiqueta = Visit(context.etiqueta()) as String;
            if (context.COMA() != null && context.HEX() != null)
            {
                index = true;
            }

            token = new StdToken()
            {
                Address       = count,
                IsDirective   = false,
                IsHex         = false,
                Mode          = index,
                OperationCode = codOp,
                Symbol        = etiqueta
            };
            return(token);
        }
        public override object VisitInicio([NotNull] StdAssemblerParser.InicioContext context)
        {
            string   etiqueta, start, dir;
            StdToken token;

            etiqueta = string.Empty;
            if (context.etiqueta() != null)
            {
                if (context.children.Count > 4)
                {
                    throw new Exception("Error de sintáxis: Instrucción no válida");
                }
                else
                {
                    etiqueta = Visit(context.etiqueta()) as String;
                    start    = context.START().GetText();
                    dir      = context.VAL().GetText();
                    if (!Regex.IsMatch(dir, @"^[0-9A-F]{4}(H|h)$"))
                    {
                        throw new Exception("Error de sintáxis: ingrese una dirección hexadecimal");
                    }
                    if (start.Contains("missing") || dir.Contains("missing"))
                    {
                        throw new Exception("Error de sintáxis: Instrucción no válida");
                    }
                    count = int.Parse(Regex.Replace(dir, "(H|h)", ""), System.Globalization.NumberStyles.HexNumber);
                }
            }
            else
            {
                if (context.children.Count > 3)
                {
                    throw new Exception("Error de sintáxis: Instrucción no válida");
                }
                else
                {
                    start = context.START().GetText();
                    dir   = context.VAL().GetText();
                    if (!Regex.IsMatch(dir, @"^[0-9A-F]{4}(H|h)$"))
                    {
                        throw new Exception("Error de sintáxis: ingrese una dirección hexadecimal");
                    }
                    if (start.Contains("missing") || dir.Contains("missing"))
                    {
                        throw new Exception("Error de sintáxis: Instrucción no válida");
                    }
                    count = int.Parse(Regex.Replace(dir, @"(H|h)", ""), System.Globalization.NumberStyles.HexNumber);
                }
            }
            token = new StdToken()
            {
                Address       = count,
                IsDirective   = true,
                IsHex         = true,
                Label         = etiqueta,
                Mode          = false,
                OperationCode = "START",
                Value         = dir
            };
            TokenList.Add(token);
            return(token);
        }
        public override object VisitLinea(StdAssemblerParser.LineaContext context)
        {
            StdToken token;

            try
            {
                if (context.exception != null)
                {
                    throw new Exception("Error de sintáxis: Instrucción no válida");
                }
                if (context.inicio() != null)
                {
                    return(Visit(context.inicio()));
                }
                else if (context.proposiciones() != null)
                {
                    return(Visit(context.proposiciones()));
                }
                else if (context.fin() != null)
                {
                    return(Visit(context.fin()));
                }
                else if (context.NL() != null)
                {
                    token = new StdToken()
                    {
                        IsEmpty = true
                    };
                    TokenList.Add(token);
                    return(token);
                }
                else
                {
                    token = new StdToken()
                    {
                        Address      = count,
                        StepOneError = "Error de sintáxis: Instrucción no válida"
                    };
                    TokenList.Add(token);
                    return(token);
                }
            }
            catch (NullReferenceException)
            {
                token = new StdToken()
                {
                    Address      = count,
                    StepOneError = "Error de sintáxis: Instrucción no válida",
                };
                TokenList.Add(token);
                return(token);
            }
            catch (Exception ex)
            {
                token = new StdToken()
                {
                    Address      = count,
                    StepOneError = ex.Message
                };
                TokenList.Add(token);
                return(token);
            }
        }