dcsimg
NO VIABLE ALTERNATIVE TO G NO VIABLE ALTERNATIVE TO E is the error i Get when i type GET on the Console
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Amandeep_Singh
Posted On:   Wednesday, October 14, 2009 04:39 AM

GentleMen, NO VIABLE ALTERNATIVE TO G NO VIABLE ALTERNATIVE TO E I have been wanting to write DSL when i encounterd ANTLR althou i have to do my things in C#. one aspect of this DLR would be like this GET CHART OF COMPANYNAME FROM STARTINGDATE TO ENDINGDATE WHERE EXCHANGE = EXCAHNGENAME SCRIPTYPE = EQ etc etc... (Example...) GET CHART OF GeneralMotors FROM 1/1/1990 to 1/1/2001 WHERE EXCHANGE = NewYorkStockExchange SCRIPTYPE = Eq i wrote the grammar as listed below but cannot get it to work my questions are as follows according to the errors i get. Q1) if i have to define a literal which will become a K   More>>
			
GentleMen,

NO VIABLE ALTERNATIVE TO G
NO VIABLE ALTERNATIVE TO E

I have been wanting to write DSL when i encounterd ANTLR
althou i have to do my things in C#.
one aspect of this DLR would be like this

GET CHART OF COMPANYNAME FROM STARTINGDATE TO ENDINGDATE
WHERE EXCHANGE = EXCAHNGENAME
SCRIPTYPE = EQ
etc etc...
(Example...)
GET CHART OF GeneralMotors FROM 1/1/1990 to 1/1/2001
WHERE EXCHANGE = NewYorkStockExchange
SCRIPTYPE = Eq

i wrote the grammar as listed below but cannot get it to work
my questions are as follows according to the
errors i get.

Q1) if i have to define a literal which will become a Keyword
should it not be defined as say

GET: 'GET'

Q2) when i Define My Keywords Then is it necessary to use
them all in my grammar because in testing and building
phase i cannot use all of them i will implement them gradually
as testing one logic to another. i ask this
because i commeted everything in my grammer Except for GET
and it worked. because GET was the only lexer rule i was using in Parser rule
at that time rest of them i had merely created to implement later.

Q3) When ANTLR V3 produces Lexer and parser code for C#
in DFA Class the const strings that it produces are all giving error because
it produces like this

const string DFA1_eotS =
"1uffff7121uffff11221uffff1374uffff";

which becomes an invalid escape sequence assuming that it wanted to produce Hex
i prefix them like this

const string DFA1_eotS =
"x01uffffx07x012x01uffffx01x012x021uffffx01x037x04uffff";

or should i let them be as they are and merely put @ in front of them like this
const string DFA1_eotS =
@"1uffff7121uffff11221uffff1374uffff";

then also error goes away thou..


//The Code

grammar Chart;

options
{
language = CSharp3 ;
}

tokens
{

GET;
SET;
WHERE;
EXCHANGE;
FROM;
TO;
COMPARE;
SHOW;
CHART;
COMPANY;
CHARTSERIES;
EMPTYSPACE;
COMPANYNAME;
SCRIPID;
SCRIPCODE;
}

@parser::header {
// turn of unreachable code warnings
// turn off obsolete code warnings
// turn off unused variable
# pragma warning disable 0162,0618,0219
using System.Text;
}

@lexer::header {
// turn of unreachable code warnings
// turn off obsolete code warnings
// turn off unused variable
# pragma warning disable 0162,0618,0219
using System.Text;
}



/*PARSERS*/
// i cannot make even GET to Work....
// NO VIABLE ALTERNATIVE TO G
// NO VIABLE ALTERNATIVE TO E
// is the erroe and then programm is
// lost somwhere looping
// i gues untill it say OutOfMemory .

public request : GET ;
//|SET|COMPARE|SHOW)? EMPTYSPACE+ CHART EMPTYSPACE OF EMPTYSPACE ;//(COMPANYNAME)* ;

// i commented the above all to see if i even have the calibre of mking the GET work it did not..

/* lEXERS */

GET: 'GET' ;

SET: 'SET' ;

WHERE: 'WHERE' ;

EXCHANGE: ('EXCHANGE') ;

FROM:'FROM' ;

TO: 'TO' ;

COMPARE: 'COMPARE' ;

SHOW: 'SHOW' ;

CHART: 'CHART' ;

COMPANY: 'COMPANY' ;

CHARTSERIES: 'CHARTSERIES' ;

EMPTYSPACE
: ' ' ;

OF : 'OF' ;

COMPANYNAME
: ('A'..'Z' | 'a'..'z' | '0'..'9' | '.' | '!' | '@' | '#' | '$' | '%' | '^' | '&' | '*' | '(' | ')' | '+' | '|' | '}' | '{' | ':' | '"' | '?' | '>' | ' <' ) ;


WF : ( '
' ) { Skip(); } ;


//Code End

Lastly could somebody please write a book on ANTLR from the prespective of a c# programmers.

just realized this is ajava forum

Hey Sirs Java Rules...


Thanking You
RIGHT_THEN

i dont know the abc of java

   <<Less

Re: NO VIABLE ALTERNATIVE TO G NO VIABLE ALTERNATIVE TO E is the error i Get when i type GET on the Console

Posted By:   Amandeep_Singh  
Posted On:   Friday, December 18, 2009 10:57 AM


ThankYou Mr. Harry Baker



after wating too long for my question to get answered
i just gave up and went for other alternatives.Today
i thought of checking if hopefully there is some answer
and found your reply.Althou i havent tested what you said because i have moved on to doing something else.



but i just want to thankyou for considering it to reply

Many Thanks again

Re: NO VIABLE ALTERNATIVE TO G NO VIABLE ALTERNATIVE TO E is the error i Get when i type GET on the Console

Posted By:   Harry_Bakker  
Posted On:   Wednesday, October 28, 2009 10:15 AM

Hi Amandeep,



i can probably answer the first two questions, but not the third.

Q1: I don't think you can use the apostrophs to bracket a string. In other words, when you want to specify the token for GET, you probably do it like GET: 'G' 'E' 'T'. (though if this is the case, i would surely want a simpler way to formulate a string).

Q2: I don't think it is necessary to use every token or rule you define. It would boil down to generating a method that is never called. Such methods mean no harm, though some IDE's will give you a warning when this occurs.


Hope this helps somewhat (or turns into a educational moment for me),



-Harry

About | Sitemap | Contact