예제 #1
0
        public static Definition Create(ILineInfo line)
        {
            var def = new Definition()
            {
                LineNumber = line.LineNumber
            };

            def.Name = line.GetName();
            switch (line.Definition)
            {
            case "db":
                def.Type = DefinitionType.Byte;
                break;

            case "dw":
                def.Type = DefinitionType.Word;
                break;
            }
            switch (line.TypeOfValue())
            {
            case Lexer.ValueType.Number:
                var arg = new Arguments.Number((Int16)line.ValueAsNumber());
                if (arg.IsWord && def.Type == DefinitionType.Byte)
                {
                    throw new Exceptions.ArgumentSizeException(line.Definition);
                }
                def.Value = arg.GetValue(def.Type == DefinitionType.Word);
                break;

            case Lexer.ValueType.String:
                var val = line.ValueAsString();
                while (val.Length < (int)def.Type + 1)
                {
                    val += '\0';
                }
                def.Value = line.ValueAsString().Select(c => (byte)c).ToArray();
                break;

            case Lexer.ValueType.None:
                switch (def.Type)
                {
                case DefinitionType.Byte:
                    def.Value = new byte[] { 0x00 };
                    break;

                case DefinitionType.Word:
                    def.Value = new byte[] { 0x00, 0x00 };
                    break;
                }
                break;
            }
            line.GetName();             // can be RedefinedException later, point to variable name
            return(def);
        }
예제 #2
0
        public static Procedure Create(ILineInfo line)
        {
            var procedure = new Procedure()
            {
                LineNumber = line.LineNumber,
                Name       = line.GetName(),
                Inline     = line.GetAttribute() == "inline"
            };

            switch (line.Type)
            {
            case Lexer.LineType.Procedure:
                procedure.End = false;
                break;

            case Lexer.LineType.EndP:
                procedure.End = true;
                break;

            default:
                return(null);
            }
            return(procedure);
        }