Beispiel #1
0
        private static void ExecuteNumericAssignment()
        {
            // todo must check numeric assignment flavors
            // todo must handle numeric buffers as targets and values
            long?targetPos    = null;
            long?targetSize   = null;
            bool?isTargetByte = null;

            targetPos = MemPos.GetPosByte(_tokens[_tokenNum]);
            if (targetPos.HasValue)
            {
                targetSize   = 1;
                isTargetByte = true;
            }
            else
            {
                targetPos = MemPos.GetPosNumeric(_tokens[_tokenNum]);
                if (targetPos.HasValue)
                {
                    targetSize   = MemPos.GetSizeNumeric(_tokens[_tokenNum]);
                    isTargetByte = false;
                }
            }
            if (!targetPos.HasValue || !targetSize.HasValue || !isTargetByte.HasValue)
            {
                throw new SystemException("Cannot parse numeric assignment: Target not found");
            }
            _tokenNum++;
            if (_tokens[_tokenNum] == "[")
            {
                _tokenNum++; // "["
                long offset = GetNumericExpression();
                if (_tokens[_tokenNum++] != "]")
                {
                    throw new SystemException("GetNumericAssignment: No closing \"]\"");
                }
                targetPos += offset;
            }
            if (_tokens[_tokenNum] == "(")
            {
                throw new SystemException("TODO: Cannot handle buffer lengths yet");
            }
            if (_tokens[_tokenNum] != "=")
            {
                throw new SystemException("Cannot parse numeric expression: Equals sign expected");
            }
            _tokenNum++;
            long result = GetNumericExpression();

            if (isTargetByte.Value)
            {
                Mem.SetByte(targetPos.Value, result);
            }
            else
            {
                Mem.SetNum(targetPos.Value, targetSize.Value, result);
            }
        }
Beispiel #2
0
        private static long GetNumericValue()
        {
            string currToken = _tokens[_tokenNum++];

            if (Functions.IsNumber(currToken))
            {
                return(long.Parse(currToken));
            }
            if (currToken == "FALSE")
            {
                return(0);
            }
            if (currToken == "TRUE")
            {
                return(1);
            }
            long?targetPos    = null;
            long?targetSize   = null;
            bool?isTargetByte = null;
            bool?isBuffer     = null;

            targetPos = MemPos.GetPosByte(currToken);
            if (targetPos.HasValue)
            {
                targetSize   = 1;
                isTargetByte = true;
                isBuffer     = false;
            }
            else
            {
                targetPos = MemPos.GetPosNumeric(currToken);
                if (targetPos.HasValue)
                {
                    targetSize   = MemPos.GetSizeNumeric(currToken);
                    isTargetByte = false;
                    isBuffer     = false;
                }
                else
                {
                    targetPos = MemPos.GetPosBufferPtr(currToken);
                    if (targetPos.HasValue)
                    {
                        if (_tokens[_tokenNum] == "(")
                        {
                            _tokenNum++;
                            targetSize = GetNumericValue();
                            _tokenNum++;
                            isTargetByte = false;
                            isBuffer     = true;
                        }
                    }
                }
            }
            if (!targetPos.HasValue || !targetSize.HasValue || !isTargetByte.HasValue || !isBuffer.HasValue)
            {
                throw new SystemException("GetNumericValue error");
            }
            if (_tokenNum < _tokenCount && _tokens[_tokenNum] == "[")
            {
                _tokenNum++; // "["
                long offset = GetNumericExpression();
                if (_tokens[_tokenNum++] != "]")
                {
                    throw new SystemException("GetNumericValue: No closing \"]\"");
                }
                targetPos += offset;
            }
            if (isTargetByte.Value)
            {
                return(Mem.GetByte(targetPos.Value));
            }
            if (isBuffer.Value)
            {
                return(Mem.GetNumBuffer(targetPos.Value, targetSize.Value));
            }
            return(Mem.GetNum(targetPos.Value, targetSize.Value));
        }