[antlr-interest] urgent help required ...

Bart Kiers bkiers at gmail.com
Mon Jan 2 14:02:43 PST 2012


Hi James,

On Tue, Dec 27, 2011 at 9:03 AM, James Ladd <james_ladd at hotmail.com> wrote:

>  Hi Bart and all ....
>
> The main no viable alternative errors occur around line 25 of Smalltalk.g
> in the rule:
>
> method returns [Method n]
>     :    o = NAME c= '_class_'? '>>'  messagePattern '[' primitive?
> temporaries? statements  ']' {$n = MethodFactory.create($o.text, $c.text,
> $messagePattern.n, $primitive.n, $temporaries.n, $statements.n);}
>     ;
>
> To get started with building and parsing you can either use Antrl works or
> the getting started here:
> http://www.redline.st/discover/getting-started.html
> The project sources are here:
> https://github.com/redline-smalltalk/redline-smalltalk
>
> In  a nutshell there are a few binarySymbol methods that cause this rule
> to break with a "no viable" alternative.
>
> If you goto the file Magnitude.st and change line 14 from
>
> - \> aMagnitude
>
> to
>
> - > aMagnitude
>
> You will then start to get the error.
>
> If you were to make the line
>
> - , aMagnitude
>
> That will cause the error as well and it should not.
>
> The second error I get is on the same rule. Essentially I changed the file
> PreProcessor.g to spit out a
> '_class_' rather than 'class' to overcome a no viable alternative error I
> was getting. Id like to make sure
> the preprocessor did NOT put out _class_ and that the method pattern rule
> on line 25 of Smalltalk.g
> was ok with 'o = NAME c= 'class'? '>>'  messagePattern'
>
> Not it is ok for a method to look like the following:
>
> - class
>   ^ nil
>
> You could modify Magnitude.st to have a method like this for testing.
>
> Rgs, James.
>
>
If I strip your `Smalltalk.g` file from all custom code, copy the
`Magnitude.st`, and generate a small main class to let the parser only
parse the `Magnitude.st`  file:

    import org.antlr.runtime.*;

    public class Main {
      public static void main(String[] args) throws Exception {
        SmalltalkLexer lexer = new SmalltalkLexer(new
ANTLRFileStream("Magnitude.st"));
        SmalltalkParser parser = new SmalltalkParser(new
CommonTokenStream(lexer));
        parser.program();
      }
    }

    java -cp antlr-3.3.jar org.antlr.Tool Smalltalk.g
    javac -cp antlr-3.3.jar *.java
    java -cp .:antlr-3.3.jar Main

I get the following error (without changing anything to the input file!):

    Magnitude.st line 5:2 no viable alternative at input '<'

I'm probably doing something wrong, but I don't feel much like cloning a
Gith-repo, building it all with maven etc.

If you could post a self-containable grammar file (including a main method
and without any custom code, or accompanying Main class as I posted) and
could clearly indicate what goes wrong, and how you think it should be
parsed, your chances in getting an answer would increase greatly, I think.

Regards,

Bart.


More information about the antlr-interest mailing list