C# AntlrInputStream error ?

307 views
Skip to first unread message

Ghislain Benrais

unread,
Nov 25, 2013, 1:23:27 PM11/25/13
to antlr-di...@googlegroups.com
Hello,
I have an issue when running this :
StreamReader sr = new StreamReader(filePath);
AntlrInputStream input = new AntlrInputStream(sr);
The program hangs forever on line 2.
For your information, if I use the string constructor, it works :
StreamReader sr = new StreamReader(source);
AntlrInputStream input = new AntlrInputStream(sr.ReadToEnd());

Thanks for your help,
Ghislain

Greg D

unread,
Nov 25, 2013, 2:25:07 PM11/25/13
to antlr-di...@googlegroups.com
Until you get a more authoritative response, you might try:

ANTLRFileStream input = new ANTLRFileStream(filePath);

Ghislain Benrais

unread,
Nov 26, 2013, 7:05:48 AM11/26/13
to antlr-di...@googlegroups.com
Thanks Greg but my goal is to parse the content of the file

Sam Harwell

unread,
Nov 26, 2013, 7:25:33 AM11/26/13
to antlr-di...@googlegroups.com

Hi Ghislain,

 

The second constructor you used is implemented with the following assignment:

 

this.data = input.ToCharArray();

 

The first constructor you used is implemented with the following assignment:

 

data = r.ReadToEnd().ToCharArray();

 

Since they are clearly the same, the difference in your program must have to do with the “filePath” vs. the “source” variables in your code.

 

Thanks,

Sam

--
You received this message because you are subscribed to the Google Groups "antlr-discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to antlr-discussi...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Ghislain Benrais

unread,
Nov 26, 2013, 9:20:01 AM11/26/13
to antlr-di...@googlegroups.com
Hello Sam (by the way I'm glad to meet you and tell you thanks a LOT for your useful answers about ANTLR),
As I have to read large files (100MB), I tried the following program :
           StreamReader sr = new StreamReader(source);

           
UnbufferedCharStream input = new UnbufferedCharStream(sr);
            qbridgeLexer lexer
= new qbridgeLexer(input);
           
CommonTokenStream tokens = new CommonTokenStream(lexer);
            qbridgeParser parser
= new qbridgeParser(tokens);
           
IParseTree tree = parser.qbridge();
           
ParseTreeWalker walker = new ParseTreeWalker();
           
QbridgeLoader loader = new QbridgeLoader(_document);
            walker
.Walk(loader, tree);

It failed with exception 'Unbuffered stream cannot know its size'.

I also tried without success this program :

            StreamReader sr = new StreamReader(source);

           
UnbufferedCharStream input = new UnbufferedCharStream(sr);
            qbridgeLexer lexer
= new qbridgeLexer(input);
           
UnbufferedTokenStream tokens = new UnbufferedTokenStream(lexer);
            qbridgeParser parser
= new qbridgeParser(tokens);
            parser
.BuildParseTree = false;
           
IParseTree tree = parser.qbridge();
           
ParseTreeWalker walker = new ParseTreeWalker();
           
QbridgeLoader loader = new QbridgeLoader(_document);
            walker
.Walk(loader, tree);


I am actually parsing tables of figures which are independent, so I am about to parse them separately, unless there is something more straightforward.
Thanks,
Ghislain
Reply all
Reply to author
Forward
0 new messages