Exemple #1
0
        public SourceObject IndentifyOperators(string token, SourceObject srcObj)
        {
            if (string.IsNullOrWhiteSpace(token))
            {
                throw new InvalidOperationException("Could not identify symbol!\nSee inner exception.",
                                                    new ArgumentException("Parameter cannot be null, Empty or Whitespace!", nameof(token)));
            }

            int p   = 0;
            int len = token.Length;

            do
            {
                if (m_symbolTable.TryFind(token.Substring(p, len), out TRecord record))
                {
                    srcObj.LinkNext(CreateSourceObject(record));
                    srcObj = srcObj.Sequence;
                    p     += len;
                    len    = token.Length - p;
                }
                else
                {
                    len--;
                }
            } while (len > 0);

            if (p < token.Length)                                                         // this indicates that a (portion) of the token was not identified
            {
                srcObj.LinkNext(new ErrorObj($"@:{token.Substring(p, token.Length-p)}")); // HACK: create an error/warn/info system with sensible codes
                srcObj = srcObj.Sequence;
            }

            return(srcObj);
        }
Exemple #2
0
        private SourceObject ProcessToken(string type, string token, SourceObject sequence, ref Regex curRE)
        {
            TRecord record;

            switch (type)
            {
            case "identifier":
                record = m_symbolTable.FindOrAdd(token, m_typeList[3]);
                sequence.LinkNext(CreateSourceObject(record));
                sequence = sequence.Sequence;
                break;

            case "ws":
                // ignored for now
                break;

            case "symbol":
                sequence = IndentifyOperators(token, sequence);
                break;

            case "comment":
                break;

            case "string":
                break;

            case "blank":
                break;

            case "preprocessor":
                break;
            }

            return(sequence);
        }