找到你要的答案

Q:parsing multiple files in javaCC

Q:在JavaCC多文件解析

I want to parse multiple files. I have JavaCC code which generates the parser. It works fine when I parse the first file (a.txt). But, I want to parse multiple files. because the first file (a.txt) call many files.

Thanks in advance.

I want to parse multiple files. I have JavaCC code which generates the parser. It works fine when I parse the first file (a.txt). But, I want to parse multiple files. because the first file (a.txt) call many files.

先谢谢了。

answer1: 回答1:

Just make sure you you use the STATIC=false option. Then you can do something along these lines

void Include() :
{    Token t ;
}
{
    <INCLUDE>  t=<STRING> 
    {
        try {
            File f = extractFile( t.image ) ;
            Parser p = new Parser( new FileReader(f) )
            p.Start() ; }
        catch( ParseException x ) { throw x ; }
        catch( TokenManagerError x ) { throw x ; }
        catch( Throwable x ) { throw new ParseException( x.getMessage() ) ; }
    }
}

Just make sure you you use the STATIC=false option. Then you can do something along these lines

void Include() :
{    Token t ;
}
{
    <INCLUDE>  t=<STRING> 
    {
        try {
            File f = extractFile( t.image ) ;
            Parser p = new Parser( new FileReader(f) )
            p.Start() ; }
        catch( ParseException x ) { throw x ; }
        catch( TokenManagerError x ) { throw x ; }
        catch( Throwable x ) { throw new ParseException( x.getMessage() ) ; }
    }
}
javacc