Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jdt-core-dev] Re: Infinite loop in scanner

Entered:   https://bugs.eclipse.org/bugs/show_bug.cgi?id=88849



                                                                           
             Philippe P                                                    
             Mulet/France/IBM                                              
                                                                        To 
             03/23/2005 02:20          jdt-core-dev@xxxxxxxxxxx            
             PM                                                         cc 
                                                                           
                                                                   Subject 
                                       Infinite loop in scanner            
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           



(since bugzilla is down)

The following snippet does not complete. Problem is located in Scanner,
looping for ever since never getting beyond EOF_POSITION
(Integer.MAX_VALUE).


import java.io.*;
import org.eclipse.jdt.core.compiler.InvalidInputException;
import org.eclipse.jdt.internal.compiler.parser.Scanner;
import org.eclipse.jdt.internal.compiler.parser.TerminalTokens;
import org.eclipse.jdt.internal.compiler.util.Util;

public class Scan {

    public static void main(String[] args) {

        try{
            char[] content = Util.getFileCharContent(new File(
"d:/eclipse/workspaces/dev3.1/plugins/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java"
), null);
            Scanner scanner = new Scanner();
            scanner.setSource(content);

            long start = System.currentTimeMillis();
            int tokenCount = 0;
            for (int i = 0; i < 800; i++ ) {
//                scanner.resetTo(0, content.length);
                scanner.resetTo(0, Integer.MAX_VALUE);
                tokenize: while (true) {
                    int token = scanner.getNextToken();
                    switch (token) {
                        case TerminalTokens.TokenNameEOF :
                            break tokenize;
                    }
                    tokenCount++;
                }
            }
            long duration = System.currentTimeMillis() - start;
            System.out.print(tokenCount + " tokens read in " + duration + "
ms");
            System.out.println(", " + ((tokenCount / duration) / 1000.00) +
" Mtokens/s");

        } catch(InvalidInputException e) {
            e.printStackTrace();
        } catch(IOException e) {
            e.printStackTrace();
        }
    }
}



Back to the top