Trouble parsing structs with cdt.core.IParser [message #87176] |
Mon, 24 November 2003 09:09 |
Eclipse User |
|
|
|
Originally posted by: volanaki.informatik.uni-tuebingen.de
This is a multi-part message in MIME format.
--------------050009030704060803030700
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
Hi,
I'm experimenting with the cdt.core.Parser component and have trouble
parsing following (legal) code:
struct s { /* ... */ };
void f(int s) { struct s a; s++; }
I've attached a small java program demonstrating this problem.
Since I wasn't able to find an parser-bug in bugzilla for this case,
I would like to know if I'm doing something wrong?
Thanks for your time,
Elias.
--------------050009030704060803030700
Content-Type: text/plain;
name="CppStructParser.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="CppStructParser.java"
import java.io.StringReader;
import org.eclipse.cdt.core.parser.*;
public class CppStructParser {
public static void main(String[] args) throws Exception {
// code from page 27
// Ellis, Stroustrup, "Annotated C++ Reference Manual", Addisson-Wesley, 1990
// compiles with g++ 3.2
String code = "struct s { /* ... */ }; void f(int s) { struct s a; s++; }\n";
ParserMode mode = ParserMode.COMPLETE_PARSE;
ParserLanguage lang = ParserLanguage.CPP;
IScanner scanner =
ParserFactory.createScanner(new StringReader(code), "", new ScannerInfo(), mode, lang, null, null);
IParser parser = ParserFactory.createParser(scanner, new NullSourceElementRequestor(), mode, lang, null);
if (!parser.parse()) { // failure
System.err.println("failure at: "+parser.getLastErrorOffset()+": "
+ code.substring(parser.getLastErrorOffset()));
}
}
}
--------------050009030704060803030700--
|
|
|
Powered by
FUDForum. Page generated in 0.03984 seconds