antlr / grammars-v4

Grammars written for ANTLR v4; expectation that the grammars are free of actions.
MIT License
10.11k stars 3.69k forks source link

CPP14.g4 only compatible with Java ANTLR #415

Open shaahmad opened 8 years ago

shaahmad commented 8 years ago

@Camiloasc1 As you know, ANTLR has targets for languages other than Java. I am using it in a Python script. But line 1093 i.e. the pure-specifier bit has a line of embedded Java: {if($val.text.compareTo("0")!=0) throw new InputMismatchException(this, $val.text);}

This causes Python to not be able to interpret the ANTLR output, raising a Syntax Error.

It would be nice to either indicate this in the "Possible Issues" section or somehow work around this.

Camiloasc1 commented 8 years ago

Yes, it's a very tricky issue to solve without embedded code (considering the '0' as a token breaks the lexer), but I guess you can also verify this rule in your listeners or visitors. I'm not sure if $val works in python or has another name, but if does you could try with:

if not $val.text == "0":
    raise InputMismatchException(this);

Check #416.

Hyunsu-Lee commented 5 years ago

@Camiloasc1 I think that your code need to change to like this:

purespecifier : Assign val = Octalliteral {if not $val.text == '0': raise InputMismatchException(this)} ; `

Camiloasc1 commented 5 years ago

@Hyunsu-Lee Seems good to me. Can you go ahead and create a PR with that? I've been traveling for a few days and have no access to a proper workstation.

Marti2203 commented 4 years ago

Is this fixed? @Camiloasc1 @Hyunsu-Lee

Hyunsu-Lee commented 4 years ago

Is this fixed? @Camiloasc1 @Hyunsu-Lee

I was using changed code separately. Today, I applied this change to the fork and made a pull request, but all checks failed. There seems to be an error in the CI Maven build.

Marti2203 commented 4 years ago

I can check out the changes and help with the PR then