ANTLR3 throws internal error with java.lang.NullPointerException





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I tried to use ANTLR3 to build a simple Regexpression parser, but it throws the internal error



Here is the Sample.g



grammar Sample;

options {
memoize=true;
output=AST;
}

tokens {
RegExp;
}

RegExpression:
'/' (a=~('/' | NL))+ '/'
-> ^(RegExp[$RegExpression.start, $RegExpression.text] $a+ )
;

fragment NL: 'n' | 'r';
ANY : . ;


I run the command:
java -jar antlr-3.5.2-complete.jar -print Sample.g



and it gives this:



error(10):  internal error: Sample.g : java.lang.NullPointerException
org.antlr.grammar.v3.DefineGrammarItemsWalker.rewrite_atom(DefineGrammarItemsWalker.java:3896)


...
...



Updated according to comments



grammar Sample{
memoize=true;
output=AST;
}

tokens {
RegExp;
}

regExpression:
'/' (a=~('/' | NL))+ '/'
-> ^(RegExp[$regExpression.start, $regExpression.text] $a+ )
;

NL: 'n' | 'r';


And here are the errors after running the java -jar antlr-3.5.2-complete.jar Sample.g



error(10):  internal error: Sample.g : java.lang.NullPointerException
org.antlr.grammar.v3.CodeGenTreeWalker.getTokenElementST(CodeGenTreeWalker.java:311)
org.antlr.grammar.v3.CodeGenTreeWalker.notElement(CodeGenTreeWalker.java:2886)
org.antlr.grammar.v3.CodeGenTreeWalker.element(CodeGenTreeWalker.java:2431)
org.antlr.grammar.v3.CodeGenTreeWalker.element(CodeGenTreeWalker.java:2446)
org.antlr.grammar.v3.CodeGenTreeWalker.alternative(CodeGenTreeWalker.java:2250)
org.antlr.grammar.v3.CodeGenTreeWalker.block(CodeGenTreeWalker.java:1798)
org.antlr.grammar.v3.CodeGenTreeWalker.ebnf(CodeGenTreeWalker.java:3014)
org.antlr.grammar.v3.CodeGenTreeWalker.element(CodeGenTreeWalker.java:2495)
org.antlr.grammar.v3.CodeGenTreeWalker.alternative(CodeGenTreeWalker.java:2250)
org.antlr.grammar.v3.CodeGenTreeWalker.block(CodeGenTreeWalker.java:1798)
org.antlr.grammar.v3.CodeGenTreeWalker.rule(CodeGenTreeWalker.java:1321)
org.antlr.grammar.v3.CodeGenTreeWalker.rules(CodeGenTreeWalker.java:955)
org.antlr.grammar.v3.CodeGenTreeWalker.grammarSpec(CodeGenTreeWalker.java:877)
org.antlr.grammar.v3.CodeGenTreeWalker.grammar_(CodeGenTreeWalker.java:518)
org.antlr.codegen.CodeGenerator.genRecognizer(CodeGenerator.java:415)
org.antlr.Tool.generateRecognizer(Tool.java:674)
org.antlr.Tool.process(Tool.java:487)
org.antlr.Tool.main(Tool.java:98)









share|improve this question

























  • Why are you using such an old version of ANTLR? It's almost 5 years since 3.5.2 was last updated. I recommend you use ANTLR4 instead.

    – Bart Kiers
    Jan 4 at 11:01











  • It is a legacy code (being used) so it is not easy to move a big .g file to ANLTR 4

    – user10791468
    Jan 4 at 11:04











  • Someone else is also working on the same legacy code: stackoverflow.com/questions/54029954/… Homework, by any chance? Perhaps team up with that user? Not many people answering v3 questions anymore... Good luck anyway!

    – Bart Kiers
    Jan 4 at 11:32













  • @BartKiers v3 is far from dead yet, I see quite some projects around Hadoop still use it, e.g. Hive, Apache Pig.

    – Jiri Tousek
    Jan 7 at 9:03











  • Didn't say it was dead (at least, that isn't what I meant), I'm merely pointing out that many people answering questions here do so for v4. I for one used to answer quite a few v3 questions, but don't use v3 anymore and therefor don't have a quick test setup available on my machine.

    – Bart Kiers
    Jan 7 at 9:27


















0















I tried to use ANTLR3 to build a simple Regexpression parser, but it throws the internal error



Here is the Sample.g



grammar Sample;

options {
memoize=true;
output=AST;
}

tokens {
RegExp;
}

RegExpression:
'/' (a=~('/' | NL))+ '/'
-> ^(RegExp[$RegExpression.start, $RegExpression.text] $a+ )
;

fragment NL: 'n' | 'r';
ANY : . ;


I run the command:
java -jar antlr-3.5.2-complete.jar -print Sample.g



and it gives this:



error(10):  internal error: Sample.g : java.lang.NullPointerException
org.antlr.grammar.v3.DefineGrammarItemsWalker.rewrite_atom(DefineGrammarItemsWalker.java:3896)


...
...



Updated according to comments



grammar Sample{
memoize=true;
output=AST;
}

tokens {
RegExp;
}

regExpression:
'/' (a=~('/' | NL))+ '/'
-> ^(RegExp[$regExpression.start, $regExpression.text] $a+ )
;

NL: 'n' | 'r';


And here are the errors after running the java -jar antlr-3.5.2-complete.jar Sample.g



error(10):  internal error: Sample.g : java.lang.NullPointerException
org.antlr.grammar.v3.CodeGenTreeWalker.getTokenElementST(CodeGenTreeWalker.java:311)
org.antlr.grammar.v3.CodeGenTreeWalker.notElement(CodeGenTreeWalker.java:2886)
org.antlr.grammar.v3.CodeGenTreeWalker.element(CodeGenTreeWalker.java:2431)
org.antlr.grammar.v3.CodeGenTreeWalker.element(CodeGenTreeWalker.java:2446)
org.antlr.grammar.v3.CodeGenTreeWalker.alternative(CodeGenTreeWalker.java:2250)
org.antlr.grammar.v3.CodeGenTreeWalker.block(CodeGenTreeWalker.java:1798)
org.antlr.grammar.v3.CodeGenTreeWalker.ebnf(CodeGenTreeWalker.java:3014)
org.antlr.grammar.v3.CodeGenTreeWalker.element(CodeGenTreeWalker.java:2495)
org.antlr.grammar.v3.CodeGenTreeWalker.alternative(CodeGenTreeWalker.java:2250)
org.antlr.grammar.v3.CodeGenTreeWalker.block(CodeGenTreeWalker.java:1798)
org.antlr.grammar.v3.CodeGenTreeWalker.rule(CodeGenTreeWalker.java:1321)
org.antlr.grammar.v3.CodeGenTreeWalker.rules(CodeGenTreeWalker.java:955)
org.antlr.grammar.v3.CodeGenTreeWalker.grammarSpec(CodeGenTreeWalker.java:877)
org.antlr.grammar.v3.CodeGenTreeWalker.grammar_(CodeGenTreeWalker.java:518)
org.antlr.codegen.CodeGenerator.genRecognizer(CodeGenerator.java:415)
org.antlr.Tool.generateRecognizer(Tool.java:674)
org.antlr.Tool.process(Tool.java:487)
org.antlr.Tool.main(Tool.java:98)









share|improve this question

























  • Why are you using such an old version of ANTLR? It's almost 5 years since 3.5.2 was last updated. I recommend you use ANTLR4 instead.

    – Bart Kiers
    Jan 4 at 11:01











  • It is a legacy code (being used) so it is not easy to move a big .g file to ANLTR 4

    – user10791468
    Jan 4 at 11:04











  • Someone else is also working on the same legacy code: stackoverflow.com/questions/54029954/… Homework, by any chance? Perhaps team up with that user? Not many people answering v3 questions anymore... Good luck anyway!

    – Bart Kiers
    Jan 4 at 11:32













  • @BartKiers v3 is far from dead yet, I see quite some projects around Hadoop still use it, e.g. Hive, Apache Pig.

    – Jiri Tousek
    Jan 7 at 9:03











  • Didn't say it was dead (at least, that isn't what I meant), I'm merely pointing out that many people answering questions here do so for v4. I for one used to answer quite a few v3 questions, but don't use v3 anymore and therefor don't have a quick test setup available on my machine.

    – Bart Kiers
    Jan 7 at 9:27














0












0








0


1






I tried to use ANTLR3 to build a simple Regexpression parser, but it throws the internal error



Here is the Sample.g



grammar Sample;

options {
memoize=true;
output=AST;
}

tokens {
RegExp;
}

RegExpression:
'/' (a=~('/' | NL))+ '/'
-> ^(RegExp[$RegExpression.start, $RegExpression.text] $a+ )
;

fragment NL: 'n' | 'r';
ANY : . ;


I run the command:
java -jar antlr-3.5.2-complete.jar -print Sample.g



and it gives this:



error(10):  internal error: Sample.g : java.lang.NullPointerException
org.antlr.grammar.v3.DefineGrammarItemsWalker.rewrite_atom(DefineGrammarItemsWalker.java:3896)


...
...



Updated according to comments



grammar Sample{
memoize=true;
output=AST;
}

tokens {
RegExp;
}

regExpression:
'/' (a=~('/' | NL))+ '/'
-> ^(RegExp[$regExpression.start, $regExpression.text] $a+ )
;

NL: 'n' | 'r';


And here are the errors after running the java -jar antlr-3.5.2-complete.jar Sample.g



error(10):  internal error: Sample.g : java.lang.NullPointerException
org.antlr.grammar.v3.CodeGenTreeWalker.getTokenElementST(CodeGenTreeWalker.java:311)
org.antlr.grammar.v3.CodeGenTreeWalker.notElement(CodeGenTreeWalker.java:2886)
org.antlr.grammar.v3.CodeGenTreeWalker.element(CodeGenTreeWalker.java:2431)
org.antlr.grammar.v3.CodeGenTreeWalker.element(CodeGenTreeWalker.java:2446)
org.antlr.grammar.v3.CodeGenTreeWalker.alternative(CodeGenTreeWalker.java:2250)
org.antlr.grammar.v3.CodeGenTreeWalker.block(CodeGenTreeWalker.java:1798)
org.antlr.grammar.v3.CodeGenTreeWalker.ebnf(CodeGenTreeWalker.java:3014)
org.antlr.grammar.v3.CodeGenTreeWalker.element(CodeGenTreeWalker.java:2495)
org.antlr.grammar.v3.CodeGenTreeWalker.alternative(CodeGenTreeWalker.java:2250)
org.antlr.grammar.v3.CodeGenTreeWalker.block(CodeGenTreeWalker.java:1798)
org.antlr.grammar.v3.CodeGenTreeWalker.rule(CodeGenTreeWalker.java:1321)
org.antlr.grammar.v3.CodeGenTreeWalker.rules(CodeGenTreeWalker.java:955)
org.antlr.grammar.v3.CodeGenTreeWalker.grammarSpec(CodeGenTreeWalker.java:877)
org.antlr.grammar.v3.CodeGenTreeWalker.grammar_(CodeGenTreeWalker.java:518)
org.antlr.codegen.CodeGenerator.genRecognizer(CodeGenerator.java:415)
org.antlr.Tool.generateRecognizer(Tool.java:674)
org.antlr.Tool.process(Tool.java:487)
org.antlr.Tool.main(Tool.java:98)









share|improve this question
















I tried to use ANTLR3 to build a simple Regexpression parser, but it throws the internal error



Here is the Sample.g



grammar Sample;

options {
memoize=true;
output=AST;
}

tokens {
RegExp;
}

RegExpression:
'/' (a=~('/' | NL))+ '/'
-> ^(RegExp[$RegExpression.start, $RegExpression.text] $a+ )
;

fragment NL: 'n' | 'r';
ANY : . ;


I run the command:
java -jar antlr-3.5.2-complete.jar -print Sample.g



and it gives this:



error(10):  internal error: Sample.g : java.lang.NullPointerException
org.antlr.grammar.v3.DefineGrammarItemsWalker.rewrite_atom(DefineGrammarItemsWalker.java:3896)


...
...



Updated according to comments



grammar Sample{
memoize=true;
output=AST;
}

tokens {
RegExp;
}

regExpression:
'/' (a=~('/' | NL))+ '/'
-> ^(RegExp[$regExpression.start, $regExpression.text] $a+ )
;

NL: 'n' | 'r';


And here are the errors after running the java -jar antlr-3.5.2-complete.jar Sample.g



error(10):  internal error: Sample.g : java.lang.NullPointerException
org.antlr.grammar.v3.CodeGenTreeWalker.getTokenElementST(CodeGenTreeWalker.java:311)
org.antlr.grammar.v3.CodeGenTreeWalker.notElement(CodeGenTreeWalker.java:2886)
org.antlr.grammar.v3.CodeGenTreeWalker.element(CodeGenTreeWalker.java:2431)
org.antlr.grammar.v3.CodeGenTreeWalker.element(CodeGenTreeWalker.java:2446)
org.antlr.grammar.v3.CodeGenTreeWalker.alternative(CodeGenTreeWalker.java:2250)
org.antlr.grammar.v3.CodeGenTreeWalker.block(CodeGenTreeWalker.java:1798)
org.antlr.grammar.v3.CodeGenTreeWalker.ebnf(CodeGenTreeWalker.java:3014)
org.antlr.grammar.v3.CodeGenTreeWalker.element(CodeGenTreeWalker.java:2495)
org.antlr.grammar.v3.CodeGenTreeWalker.alternative(CodeGenTreeWalker.java:2250)
org.antlr.grammar.v3.CodeGenTreeWalker.block(CodeGenTreeWalker.java:1798)
org.antlr.grammar.v3.CodeGenTreeWalker.rule(CodeGenTreeWalker.java:1321)
org.antlr.grammar.v3.CodeGenTreeWalker.rules(CodeGenTreeWalker.java:955)
org.antlr.grammar.v3.CodeGenTreeWalker.grammarSpec(CodeGenTreeWalker.java:877)
org.antlr.grammar.v3.CodeGenTreeWalker.grammar_(CodeGenTreeWalker.java:518)
org.antlr.codegen.CodeGenerator.genRecognizer(CodeGenerator.java:415)
org.antlr.Tool.generateRecognizer(Tool.java:674)
org.antlr.Tool.process(Tool.java:487)
org.antlr.Tool.main(Tool.java:98)






antlr3






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 8 at 10:36







user10791468

















asked Jan 4 at 10:45









user10791468user10791468

11




11













  • Why are you using such an old version of ANTLR? It's almost 5 years since 3.5.2 was last updated. I recommend you use ANTLR4 instead.

    – Bart Kiers
    Jan 4 at 11:01











  • It is a legacy code (being used) so it is not easy to move a big .g file to ANLTR 4

    – user10791468
    Jan 4 at 11:04











  • Someone else is also working on the same legacy code: stackoverflow.com/questions/54029954/… Homework, by any chance? Perhaps team up with that user? Not many people answering v3 questions anymore... Good luck anyway!

    – Bart Kiers
    Jan 4 at 11:32













  • @BartKiers v3 is far from dead yet, I see quite some projects around Hadoop still use it, e.g. Hive, Apache Pig.

    – Jiri Tousek
    Jan 7 at 9:03











  • Didn't say it was dead (at least, that isn't what I meant), I'm merely pointing out that many people answering questions here do so for v4. I for one used to answer quite a few v3 questions, but don't use v3 anymore and therefor don't have a quick test setup available on my machine.

    – Bart Kiers
    Jan 7 at 9:27



















  • Why are you using such an old version of ANTLR? It's almost 5 years since 3.5.2 was last updated. I recommend you use ANTLR4 instead.

    – Bart Kiers
    Jan 4 at 11:01











  • It is a legacy code (being used) so it is not easy to move a big .g file to ANLTR 4

    – user10791468
    Jan 4 at 11:04











  • Someone else is also working on the same legacy code: stackoverflow.com/questions/54029954/… Homework, by any chance? Perhaps team up with that user? Not many people answering v3 questions anymore... Good luck anyway!

    – Bart Kiers
    Jan 4 at 11:32













  • @BartKiers v3 is far from dead yet, I see quite some projects around Hadoop still use it, e.g. Hive, Apache Pig.

    – Jiri Tousek
    Jan 7 at 9:03











  • Didn't say it was dead (at least, that isn't what I meant), I'm merely pointing out that many people answering questions here do so for v4. I for one used to answer quite a few v3 questions, but don't use v3 anymore and therefor don't have a quick test setup available on my machine.

    – Bart Kiers
    Jan 7 at 9:27

















Why are you using such an old version of ANTLR? It's almost 5 years since 3.5.2 was last updated. I recommend you use ANTLR4 instead.

– Bart Kiers
Jan 4 at 11:01





Why are you using such an old version of ANTLR? It's almost 5 years since 3.5.2 was last updated. I recommend you use ANTLR4 instead.

– Bart Kiers
Jan 4 at 11:01













It is a legacy code (being used) so it is not easy to move a big .g file to ANLTR 4

– user10791468
Jan 4 at 11:04





It is a legacy code (being used) so it is not easy to move a big .g file to ANLTR 4

– user10791468
Jan 4 at 11:04













Someone else is also working on the same legacy code: stackoverflow.com/questions/54029954/… Homework, by any chance? Perhaps team up with that user? Not many people answering v3 questions anymore... Good luck anyway!

– Bart Kiers
Jan 4 at 11:32







Someone else is also working on the same legacy code: stackoverflow.com/questions/54029954/… Homework, by any chance? Perhaps team up with that user? Not many people answering v3 questions anymore... Good luck anyway!

– Bart Kiers
Jan 4 at 11:32















@BartKiers v3 is far from dead yet, I see quite some projects around Hadoop still use it, e.g. Hive, Apache Pig.

– Jiri Tousek
Jan 7 at 9:03





@BartKiers v3 is far from dead yet, I see quite some projects around Hadoop still use it, e.g. Hive, Apache Pig.

– Jiri Tousek
Jan 7 at 9:03













Didn't say it was dead (at least, that isn't what I meant), I'm merely pointing out that many people answering questions here do so for v4. I for one used to answer quite a few v3 questions, but don't use v3 anymore and therefor don't have a quick test setup available on my machine.

– Bart Kiers
Jan 7 at 9:27





Didn't say it was dead (at least, that isn't what I meant), I'm merely pointing out that many people answering questions here do so for v4. I for one used to answer quite a few v3 questions, but don't use v3 anymore and therefor don't have a quick test setup available on my machine.

– Bart Kiers
Jan 7 at 9:27












1 Answer
1






active

oldest

votes


















1














You're trying to use a rewrite rule (tree construction) on a lexer rule. That doesn't make sense.



In ANTLR, all rules with name starting with an uppercase letter are lexer rules. The tree construction is used on AST nodes, not on tokens themselves, so you have to use it on parser rules (starting with lowercase letter).



When you do that, keep in mind that your NL is a fragment now (you cannot use fragments in parser rules) and make sure your ANY token doesn't collide with anything else, i.e. define all needed tokens (/, NL etc.) and put them above the ANY token definition.






share|improve this answer
























  • Haha, the tree rewrite rule was something even I without a test setup could have answered/spotted! Good call.

    – Bart Kiers
    Jan 7 at 9:28











  • I have updated the code, but it seems still producing the NullPointerException.

    – user10791468
    Jan 8 at 10:37













  • I can't see how a=~('/' | NL) could ever match anything, provided that NL and / are the only tokens defined in your grammar as posted.

    – Jiri Tousek
    Jan 8 at 12:01











  • Could you give me more hints? Basically I am trying to match a regular expression in lexer and would like to transform it to AST

    – user10791468
    Jan 14 at 10:48












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54037397%2fantlr3-throws-internal-error-with-java-lang-nullpointerexception%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














You're trying to use a rewrite rule (tree construction) on a lexer rule. That doesn't make sense.



In ANTLR, all rules with name starting with an uppercase letter are lexer rules. The tree construction is used on AST nodes, not on tokens themselves, so you have to use it on parser rules (starting with lowercase letter).



When you do that, keep in mind that your NL is a fragment now (you cannot use fragments in parser rules) and make sure your ANY token doesn't collide with anything else, i.e. define all needed tokens (/, NL etc.) and put them above the ANY token definition.






share|improve this answer
























  • Haha, the tree rewrite rule was something even I without a test setup could have answered/spotted! Good call.

    – Bart Kiers
    Jan 7 at 9:28











  • I have updated the code, but it seems still producing the NullPointerException.

    – user10791468
    Jan 8 at 10:37













  • I can't see how a=~('/' | NL) could ever match anything, provided that NL and / are the only tokens defined in your grammar as posted.

    – Jiri Tousek
    Jan 8 at 12:01











  • Could you give me more hints? Basically I am trying to match a regular expression in lexer and would like to transform it to AST

    – user10791468
    Jan 14 at 10:48
















1














You're trying to use a rewrite rule (tree construction) on a lexer rule. That doesn't make sense.



In ANTLR, all rules with name starting with an uppercase letter are lexer rules. The tree construction is used on AST nodes, not on tokens themselves, so you have to use it on parser rules (starting with lowercase letter).



When you do that, keep in mind that your NL is a fragment now (you cannot use fragments in parser rules) and make sure your ANY token doesn't collide with anything else, i.e. define all needed tokens (/, NL etc.) and put them above the ANY token definition.






share|improve this answer
























  • Haha, the tree rewrite rule was something even I without a test setup could have answered/spotted! Good call.

    – Bart Kiers
    Jan 7 at 9:28











  • I have updated the code, but it seems still producing the NullPointerException.

    – user10791468
    Jan 8 at 10:37













  • I can't see how a=~('/' | NL) could ever match anything, provided that NL and / are the only tokens defined in your grammar as posted.

    – Jiri Tousek
    Jan 8 at 12:01











  • Could you give me more hints? Basically I am trying to match a regular expression in lexer and would like to transform it to AST

    – user10791468
    Jan 14 at 10:48














1












1








1







You're trying to use a rewrite rule (tree construction) on a lexer rule. That doesn't make sense.



In ANTLR, all rules with name starting with an uppercase letter are lexer rules. The tree construction is used on AST nodes, not on tokens themselves, so you have to use it on parser rules (starting with lowercase letter).



When you do that, keep in mind that your NL is a fragment now (you cannot use fragments in parser rules) and make sure your ANY token doesn't collide with anything else, i.e. define all needed tokens (/, NL etc.) and put them above the ANY token definition.






share|improve this answer













You're trying to use a rewrite rule (tree construction) on a lexer rule. That doesn't make sense.



In ANTLR, all rules with name starting with an uppercase letter are lexer rules. The tree construction is used on AST nodes, not on tokens themselves, so you have to use it on parser rules (starting with lowercase letter).



When you do that, keep in mind that your NL is a fragment now (you cannot use fragments in parser rules) and make sure your ANY token doesn't collide with anything else, i.e. define all needed tokens (/, NL etc.) and put them above the ANY token definition.







share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 7 at 8:59









Jiri TousekJiri Tousek

10.5k52240




10.5k52240













  • Haha, the tree rewrite rule was something even I without a test setup could have answered/spotted! Good call.

    – Bart Kiers
    Jan 7 at 9:28











  • I have updated the code, but it seems still producing the NullPointerException.

    – user10791468
    Jan 8 at 10:37













  • I can't see how a=~('/' | NL) could ever match anything, provided that NL and / are the only tokens defined in your grammar as posted.

    – Jiri Tousek
    Jan 8 at 12:01











  • Could you give me more hints? Basically I am trying to match a regular expression in lexer and would like to transform it to AST

    – user10791468
    Jan 14 at 10:48



















  • Haha, the tree rewrite rule was something even I without a test setup could have answered/spotted! Good call.

    – Bart Kiers
    Jan 7 at 9:28











  • I have updated the code, but it seems still producing the NullPointerException.

    – user10791468
    Jan 8 at 10:37













  • I can't see how a=~('/' | NL) could ever match anything, provided that NL and / are the only tokens defined in your grammar as posted.

    – Jiri Tousek
    Jan 8 at 12:01











  • Could you give me more hints? Basically I am trying to match a regular expression in lexer and would like to transform it to AST

    – user10791468
    Jan 14 at 10:48

















Haha, the tree rewrite rule was something even I without a test setup could have answered/spotted! Good call.

– Bart Kiers
Jan 7 at 9:28





Haha, the tree rewrite rule was something even I without a test setup could have answered/spotted! Good call.

– Bart Kiers
Jan 7 at 9:28













I have updated the code, but it seems still producing the NullPointerException.

– user10791468
Jan 8 at 10:37







I have updated the code, but it seems still producing the NullPointerException.

– user10791468
Jan 8 at 10:37















I can't see how a=~('/' | NL) could ever match anything, provided that NL and / are the only tokens defined in your grammar as posted.

– Jiri Tousek
Jan 8 at 12:01





I can't see how a=~('/' | NL) could ever match anything, provided that NL and / are the only tokens defined in your grammar as posted.

– Jiri Tousek
Jan 8 at 12:01













Could you give me more hints? Basically I am trying to match a regular expression in lexer and would like to transform it to AST

– user10791468
Jan 14 at 10:48





Could you give me more hints? Basically I am trying to match a regular expression in lexer and would like to transform it to AST

– user10791468
Jan 14 at 10:48




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54037397%2fantlr3-throws-internal-error-with-java-lang-nullpointerexception%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas