[antlr-interest] I: Compile errors with CSharp2 Target

Massimiliano Donini maxgbr at hotmail.it
Tue Feb 15 06:02:50 PST 2011


Hi simon
don'you miss Language=CSharp2 in grammar's option section?
And why in grammar there is package definition? (line 98 and line 104) But
the erroneous code is defined above (line  107)

private boolean allowShortOpenTag = false;

    // Handle the first token, which will always be a BodyString.
    public Token nextToken(){
        //The following code was pulled out from super.nextToken()
        if (input.index() == 0) {
            try {
                state.token = null;
                state.channel = Token.DEFAULT_CHANNEL;
                state.tokenStartCharIndex = input.index();
                state.tokenStartCharPositionInLine =
input.getCharPositionInLine();
                state.tokenStartLine = input.getLine();
                state.text = null;
                state.backtracking = 0;
                mBodyStringRest();
                state.type = BodyString;
                emit();
                return state.token;
            } catch (NoViableAltException nva) {
                reportError(nva);
                recover(nva); // throw out current char and try again
            } catch (RecognitionException re) {
                reportError(re);
                // match() routine has already called recover()
            }    
        }
        return super.nextToken();
    }

    /**
     * Property to enable short open tags
     * 
     * Returns true if short open tags are enabled
     * false if short open tags are disabled.
     * 
     */
    public boolean isAllowShortOpenTag(){
        return allowShortOpenTag;
    }

    /**
     * Property to enable short open tags.
     *
     * Set to true to enable short open tags and false 
     * to disable.
     */
    public void setAllowShortOpenTag(boolean val){
        allowShortOpenTag = val;
    }

All these methods are written in target language (default Java) So you have
to change it for compile with C# For example Boolean should be bool and
Token should be IToken, input.index() should be input.Index and so on.

Hope it helps
Best regards
Max

-----Messaggio originale-----
Da: Simon [mailto:simonzmail at gmail.com]
Inviato: martedì 15 febbraio 2011 12:05
A: Massimiliano Donini
Oggetto: Re: [antlr-interest] Compile errors with CSharp2 Target

Hi Max,

Thanks for the thoughts - I've attached the generated code.   You can
see the grammar here:

http://code.google.com/p/phpparser/source/browse/#hg%2Fgrammar

Cheers,

Simon

On Tue, Feb 15, 2011 at 7:04 PM, Massimiliano Donini <maxgbr at hotmail.it>
wrote:
> Can you attach source (generated) code?
> In C# target there are some differeneces from java Antrl runtime (e.g. 
> Token interface is called IToken you can find others differences here:
> http://www.antlr.org/wiki/display/ANTLR3/Antlr+3+CSharp+Target?focused
> Commen
> tId=25559049#comment-25559049)
> If you send generated code and maybe test grammar I can give you more
info.
>
> Best regards
> Max
>
> -----Messaggio originale-----
> Da: antlr-interest-bounces at antlr.org
> [mailto:antlr-interest-bounces at antlr.org] Per conto di Simon
> Inviato: martedì 15 febbraio 2011 06:22
> A: antlr-interest at antlr.org
> Oggetto: [antlr-interest] Compile errors with CSharp2 Target
>
> Hello all,
>
> I'm trying to get the CSharp2 target to work.   I followed the 
> instructions here:
>
> http://www.antlr.org/wiki/pages/viewpage.action?pageId=557075
>
> except that I generated using the command line rather than using
Antlrworks:
>
> java -classpath antlr-3.1.3.jar org.antlr.Tool -o . Test.g
>
> The test example worked just fine and produced valid CSharp code, but 
> when I tried a PHP grammar (which works fine when generating to Java
> code) it produced a build error:
>
> C:\Temp\PHPParser\PhpLexer.cs(132,22): error CS0722:
> 'Antlr.Runtime.Token': static types cannot be used as return types
>
> I tried using various different .NET targets (2.0, 3.0, 3.5), but it 
> didn't help.
>
> Can anyone give me some hints about what might be wrong here?
>
> Cheers & Thanks!
>
> Simon
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe:
> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>
>



More information about the antlr-interest mailing list