Exemple #1
0
        private BaseToken AddToken(List <BaseToken> result, int lineNumber, string word, TokenTypeMiniJava tokenType, string scope = "", string type = "")
        {
            var foundedToken = new BaseToken()
            {
                Lexema = word, Linha = lineNumber, TokenType = tokenType, Scope = scope, Type = type
            };

            result.Add(foundedToken);

            return(foundedToken);
        }
Exemple #2
0
        public List <BaseToken> AnalizeV2(string filePath, Type tokenType)
        {
            int tokenMaxSize        = 8;
            List <BaseToken> result = new List <BaseToken>();

            for (int tokenSize = tokenMaxSize; tokenSize >= 1; tokenSize--)
            {
                int           lineNumber      = 1;
                string        line            = string.Empty;
                List <string> allTokensOfSize = GetTokensOfSize(tokenSize, tokenType);

                FileStream file = new FileStream(filePath, FileMode.Open);
                using (var stream = new StreamReader(file))
                {
                    while ((line = stream.ReadLine()) != null)
                    {
                        char[] lineCharArray = line.ToArray();
                        string word          = string.Empty;
                        for (int j = 0; j <= lineCharArray.Length; j++)
                        {
                            string currentChar = string.Empty;
                            if (j <= lineCharArray.Length - tokenSize)
                            {
                                for (int k = 0; k < tokenSize; k++)
                                {
                                    currentChar = string.Concat(currentChar, lineCharArray[j + k]);
                                }
                            }

                            if (allTokensOfSize.Contains(currentChar))
                            {
                                var foundedToken = new BaseToken()
                                {
                                    Lexema = currentChar, Linha = lineNumber
                                };
                                word = string.Empty;
                                result.Add(foundedToken);
                            }
                        }

                        lineNumber++;
                    }
                }
            }
            return(result);
        }
Exemple #3
0
        private void VerifySysOutIdentifier(string line, List <string> identifierList, BaseToken addedToken)
        {
            string identiFierConsoleOut = "System.out.println";

            if (identifierList.Contains(identiFierConsoleOut))
            {
                string printParameter = line.Replace(identiFierConsoleOut + "(", "").Replace(");", "").Trim();

                addedToken.PrintParameter = printParameter;
            }
        }