[antlr-interest] i have a problem with multiplexing.Can anyone help
me?
=?gb2312?B?us6zrA==?=
hc7750 at 163.com
Mon Jan 31 18:19:41 PST 2005
i've realized two separate grammars, one for java code analyse, the other for javadoc embedded in the java file. Then i try to link them together using the
technology multiplexing. The critical parts are as follows:
---------- in java.g ------------------
...
JAVADOC_OPEN: "/**"
{
selector.select("javadocLexer");
// create a parser to handle the javadoc comment
JavadocParser jdocparser = new JavadocParser(selector);
jdocparser.comment();
};
...
---------- in javadoc.g ------------------
...
javadoc_comment
: (options{greedy=true;}:STAR)*
( (AT)=>AT javadoc_tag | description )
javadoc_tags
JAVADOC_CLOSE //here without EOF, and i believe no need
;
...
...
JAVADOC_CLOSE: "*/" {selector.select("javaLexer");};
...
----------------------- Test.java---------------------------------
import java.io.*;
import antlr.CommonAST;
import antlr.collections.AST;
import antlr.debug.misc.ASTFrame;
import java.util.*;
import antlr.TokenStreamSelector;
class Test{
public static void main(String[] args)
{
try {
TokenStreamSelector selector = new TokenStreamSelector();
JavaLexer mainLexer = new JavaLexer(
new FileInputStream(args[0]));
mainLexer.selector = selector;
JavadocLexer docLexer =
new JavadocLexer (mainLexer.getInputState());
docLexer.selector = selector;
selector.addInputStream(mainLexer, "javaLexer");
selector.addInputStream(docLexer, "javadocLexer");
selector.select("javaLexer");
JavaParser parser = new JavaParser(selector);
parser.compilationUnit();
}catch(Exception e) {
System.err.println("exception: "+e);
}
}
}
---------- java file for testing-------------------------------------------
package com;
import java.io.*;
//single-line comment
/*multi-line comment*/
public class A
{
public A()
{
}
/**
* javadoc comment
*
* @author hc
* @version 1.0
* @param i the first number
* @param j the second number
* @return the sum of two numbers
* @cml my own defined javadoc tag for some special purpose
*/
public int add(int i,int j)
{
return i+j;
}
}
-----------------------------------------------------------------------------
Then i got the error message:
exception: line 24:5: expecting EOF, found 'public'
i've been bewildered by this problem for quite a few days and look forward to help.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20050201/e565f2da/attachment.html
More information about the antlr-interest
mailing list