[antlr-interest] C# Antlr Problem (HANGED UP ANTLRInputStream)
Mohammed Ibrahim
snouto at gmail.com
Wed Aug 15 10:21:53 PDT 2007
----- Original Message -----
From: Mohammed Ibrahim
To: antlr-interest at antlr.org
Sent: Wednesday, August 15, 2007 8:20 PM
Subject: C# Antlr Problem (HANGED UP ANTLRInputStream)
Hello Everybody in this great Mailing list of antlr.
Im have been working with antlr from short time , i used it effectively in Java but i would like to use it in C# in Vs.Net 2005 , i wrote this piece of Too simple Grammar for antlr Tool
Here is the Grammar
======================================
Hello.g
======
grammar hello;
options
{
language = CSharp;
}
prog : stat+;
stat returns [string value] : GREETING{$value = $GREETING.text;} (LETTER{$value +=" "+$LETTER.text; })+;
GREETING: 'welcome'|'greeting'|'hello';
LETTER : ('a'..'z')+;
WS : ('"'|' '|'\r'|'\n'|'\t')+ {skip();};
===============================================
It Generated helloLexer and HelloParser code Pages , But when i use it in C# it hangs at ANTLRInputStream Code line.
Here is the code.
===============================================================================
using System;
using System.Collections.Generic;
using System.Text;
using Antlr.StringTemplate;
using antlr;
using Antlr.Runtime;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
helloLexer Currentlexer = new helloLexer((ICharStream)new CharBuffer (Console.In));
/* here is the error professor it
gives me an exception telling me that Charbuffer cant be converted
into ICharStream , and i found that logically correct but i don't
know how to get things work in C# in java i used ANLTRInputStream but when i use it in C# it hangs at that line and
the application becomes no longer responsive. i would like to know what is the problem , i need to have a good
working code in v3.0 in C# like getting inputted data and then
parsing it .
*/
helloParser Currentparser = new helloParser(new CommonTokenStream
(Currentlexer));
string result = Currentparser.stat();
Console.WriteLine(result);
Console.ReadLine();
}
}
}
You see Console.In Line when i expects Data from the user , The program Crashes There and gives me Exceptions Finally it stops.
How can i Pass this exception , I don't know what did i do to raise this exception ???????????????????????????
Second , i really want to know how to pass Data to the ANTLRInputStream Class in C# because in C# there is no StringBufferInputStream as in java ??????????????????????? To accept Data from the user as i did in Java here is the code in java
===============================================================
input = args[0];
ANTLRInputStream AntlrStream = new ANTLRInputStream(new StringBufferInputStream(input));
helloLexer CurrentLexer = new helloLexer(AntlrStream);
helloParser CurrentParser = new helloParser(new CommonTokenStream(CurrentLexer));
String result = CurrentParser.stat();
System.out.println(result);
Please Help me in this problem :(( i would like to effectively use Antlr in C# as i did in java ????????????????????????????/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20070815/c811938d/attachment.html
More information about the antlr-interest
mailing list