Exemple #1
0
        public string GetTokenDescription(int tokenIndex)
        {
            CodeContract.RequiresArgumentInRange(tokenIndex >= 0 && tokenIndex < m_tokenDescriptions.Length, "tokenIndex",
                                                 "tokenIndex must be greater than or equal to 0 and less than the token count");

            return(m_tokenDescriptions[tokenIndex]);
        }
Exemple #2
0
        public int Peek(int lookAhead)
        {
            CodeContract.RequiresArgumentInRange(lookAhead > 0, "lookAhead", "The lookAhead must be greater than zero");

            Lexeme lookAheadLexeme = PeekLexeme(lookAhead);

            return(lookAheadLexeme.TokenIndex);
        }
        public void DefineError(int id, int level, CompilationStage stage, string messageTemplate)
        {
            CodeContract.RequiresArgumentInRange(!m_errorInfoStore.Contains(id), "id", "Error id is duplicated");

            var errorInfo = new CompilationErrorInfo(id, level, stage, messageTemplate);

            m_errorInfoStore.Add(errorInfo);
        }
Exemple #4
0
        public int PeekInLexerState(int lexerStateIndex, int lookAhead)
        {
            CodeContract.RequiresArgumentInRange(lookAhead > 0, "lookAhead", "The lookAhead must be greater than zero");
            CodeContract.RequiresArgumentInRange(lexerStateIndex >= 0 && lexerStateIndex < ScannerInfo.LexerStateCount, "lexerStateIndex", "Invalid lexer state index");

            Lexeme lookAheadLexeme = PeekLexeme(lookAhead);

            return(lookAheadLexeme.GetTokenIndex(lexerStateIndex));
        }
Exemple #5
0
 public Lexeme this[int index]
 {
     get
     {
         CodeContract.RequiresArgumentInRange(index >= 0 && index < m_length,
                                              "index", "index must be greater than or equal to 0 and less than the length of the range");
         return(m_lexemeList[index + m_startIndex]);
     }
 }
Exemple #6
0
        public LexemeRange(IReadOnlyList <Lexeme> lexemeList, int startIndex, int length)
        {
            CodeContract.RequiresArgumentNotNull(lexemeList, "lexemeList");
            CodeContract.RequiresArgumentInRange(startIndex >= 0 && startIndex <= lexemeList.Count,
                                                 "startIndex", "startIndex must be greater or equal to 0 and less than the count of lexemeList");
            CodeContract.RequiresArgumentInRange(length >= 0 && startIndex + length <= lexemeList.Count,
                                                 "length", "lengh is invalid");

            m_lexemeList = lexemeList;
            m_startIndex = startIndex;
            m_length     = length;
        }
Exemple #7
0
        public static ProductionBase <Lexeme> Union(params Token[] tokens)
        {
            CodeContract.RequiresArgumentInRange(tokens.Length > 0, "tokens", "There must be at least on token to be unioned");

            ProductionBase <Lexeme> result = tokens[0].AsTerminal();

            for (int i = 1; i < tokens.Length; i++)
            {
                result = new AlternationProduction <Lexeme>(result, tokens[i].AsTerminal());
            }

            return(result);
        }
Exemple #8
0
        public static ProductionBase <T> Union <T>(params ProductionBase <T>[] productions)
        {
            CodeContract.RequiresArgumentInRange(productions.Length > 0, "productions", "There must be at least one production to be unioned");

            ProductionBase <T> result = productions[0];

            for (int i = 1; i < productions.Length; i++)
            {
                result = new AlternationProduction <T>(result, productions[i]);
            }

            return(result);
        }
Exemple #9
0
        public object GetResult(int index, CompilationErrorList errorList)
        {
            CodeContract.RequiresArgumentInRange(index >= 0 && index < m_acceptedHeads.Count, "index", "index is out of range");

            var head = m_acceptedHeads[index];

            if (head.Errors != null && errorList != null)
            {
                //aggregate errors
                foreach (var error in head.Errors)
                {
                    int errorId = error.ErrorId ?? m_errorDef.OtherErrorId;

                    errorList.AddError(errorId, error.ErrorPosition, error.ErrorArgument, error.ErrorArgument2);
                }
            }

            return(head.TopStackValue);
        }
Exemple #10
0
        public void Seek(int index)
        {
            CodeContract.RequiresArgumentInRange(index >= 0, "index", "Seek index must be greater than or equal to 0");

            if (index <= m_valuableHistory.Count)
            {
                m_valuableCursor = index;
            }
            else
            {
                //index > m_history.Count
                int restCount = index - m_valuableHistory.Count;

                m_valuableCursor = m_valuableHistory.Count;
                for (int i = 0; i < restCount; i++)
                {
                    Read();
                }
            }
        }