[antlr-interest] Illegal escape sequence in C#

rkevinburton at charter.net rkevinburton at charter.net
Wed Jul 30 13:16:14 PDT 2008


I am getting closer. This last problem is probably something wrong with the grammar. I changed start to Start and the code now compiles (yea!!) But I get a runtime error:

A first chance exception of type 'System.InvalidCastException' occurred in JScriptParser.dll

It seems to occur with the following input:

function GetSiteConfiguration(catalogContext:CatalogContext, profileManagementContext:ProfileManagementContext)
{
 return ProfileManagementConverter.SiteConfiguration(catalogContext, profileManagementContext);
}

Is what is strange is that when I put just this input into ANTLRWorks interpretor I don't get any errors.

If I put two function declarations in ANTLRWorks with the start token as functionDeclaration I also don't get any errors but I only see the tree for one declaration. I don't think it reset properly. Unlike the rror exception thrown there is no cast being attempted. Anyway it seems to be a problem with the grammar. Unless you have some suggestions on how best to debug this kind of problem I will consider this issue closed. Thank you.

Kevin


--- rkevinburton at charter.net wrote: 
> I downloaded 3.1b2 of ANTLR and replaced the references that I had with the references to the runtime->CSharp->net2.0 assemblies. Now I am down to one error:
> 
> 'Antlr.Runtime.ParserRuleReturnScope' does not contain a definition for 'start' and no extension method 'start' accepting a first argument of type 'Antlr.Runtime.ParserRuleReturnScope' could be found (are you missing a using directive or an assembly reference?)
> 
> This seems to be generated as part of the actions in the grammar. Do you know what replaced .start?
> 
> 			else if (lt.Type == EOL || (lt.Type == MultiLineComment && Regex.IsMatch(lt.Text, "/.*\r\n|\r|\n")))
> 			{
> 				// We found our EOL: promote the token to on channel, position the input on it and reset the rule start.
> 				lt.Channel = Token.DEFAULT_CHANNEL;
> 				input.Seek(lt.TokenIndex);
> 				if (rule != null)
> 				{
> 					rule.start = lt;
> 				}
> 				break;
> 			}
> 
> I am relatively new to ANTLR and this from a grammar that is for ECMAScript that is on the ANTLR grammar site. I think is what is being done here is an attempt at "auto semicolon inserstion". I think is what is supposed to happen here is that if there is no semicolon but there is an EOL then reset the parser. How that is done as apparently changed between 3.0 and 3.1. Thanks again.
> 
> Kevin
> 
> ---- Johannes Luber <jaluber at gmx.de> wrote: 
> > rkevinburton at charter.net schrieb:
> > > I changed the "language" to be CSharp2 and that fixed the illegal escape equence (thank youl) but now the following will not compile:
> > > 
> > >         public ECMAScriptParser(ITokenStream input)
> > >     		: this(input, new RecognizerSharedState()) {
> > >         }
> > > 
> > >         public ECMAScriptParser(ITokenStream input, RecognizerSharedState state)
> > >     		: base(input, state) {
> > >     		InitializeCyclicDFAs();
> > >         }
> > > 
> > > It seems that RecognizerSharedState is no longer recognized. Any substitutes?
> > > 
> > > Thanks again.
> > > 
> > > Kevin
> > 
> > Did you use the correct assemblies? Each beta has it own version.
> > 
> > Johannes
> > > ---- rkevinburton at charter.net wrote: 
> > >> I did a quick check and it seems that 1.2b5 is the latest version of ANTLRWorks that is offered on the web site. Should I go back to 1.1.7? What about the version of ANTLR itselft (but I thought ANTLRWorks included ANTLR).
> > >>
> > >> Now I am confused.
> > >>
> > >> Thank you for the tips.
> > >>
> > >> Kevin
> > >>
> > >> ---- Johannes Luber <jaluber at gmx.de> wrote: 
> > >>> rkevinburton at charter.net schrieb:
> > >>>> I am not sure what I have done but now when I generate code from ANTLRWorks it generates lines containing escape sequences that C# doesn't understand. Like:
> > >>>>
> > >>>>     const string DFA18_eotS =
> > >>>>         "\1\uffff\2\4\3\uffff\1\4";
> > >>>>     const string DFA18_eofS =
> > >>>>         "\7\uffff";
> > >>>>     const string DFA18_minS =
> > >>>>         "\3\56\3\uffff\1\56";
> > >>>>     const string DFA18_maxS =
> > >>>>         "\1\71\1\56\1\71\3\uffff\1\71";
> > >>>>     const string DFA18_acceptS =
> > >>>>         "\3\uffff\1\2\1\3\1\1\1\uffff";
> > >>>>     const string DFA18_specialS =
> > >>>>         "\7\uffff}>";
> > >>>>     static readonly string[] DFA18_transitionS = {
> > >>>>             "\1\3\1\uffff\1\1\11\2",
> > >>>>             "\1\5",
> > >>>>             "\1\5\1\uffff\12\6",
> > >>>>             "",
> > >>>>             "",
> > >>>>             "",
> > >>>>             "\1\5\1\uffff\12\6"
> > >>>>     };
> > >>>>
> > >>>> This is just a sample. There are over 400 such errors when C# tries to compile the generated code from the lexer. How do I get ANTLRWorks to generate the "right" code again?
> > >>>>
> > >>>> Thank you.
> > >>>>
> > >>>> Kevin
> > >>>>
> > >>> Could it be that you are using AW 1.2 beta with the CSharp target? That 
> > >>> was broken in an earlier version of ANTLR. I don't know if the newest 
> > >>> beta includes ANTLR 3.1b2 but you can also switch to CSharp2 as target.
> > >>>
> > >>> Johannes
> > > 
> > 
> 



More information about the antlr-interest mailing list