简体   繁体   中英

antlr panic on pascal grammar

I want to generate Pascal java parser and then use it in my gradle application.

For Pascal I used this grammar https://github.com/antlr/grammars-v4/tree/master/pascal

My build.gradle looks like this. I used antlr plugin.

apply plugin: 'groovy'
apply plugin: 'antlr'

repositories {
    jcenter()
}

dependencies {
    compile 'org.codehaus.groovy:groovy-all:2.4.6'
    compile 'org.antlr:antlr4:4.5.3'

    testCompile 'org.spockframework:spock-core:1.0-groovy-2.4'
    testCompile 'junit:junit:4.12'
}

But when I try to run task generateGrammarSource I get this error

:generateGrammarSource
L:\app\src\main\antlr\pascal.g4:36:1: unexpected token: grammar
error: Token stream error reading grammar(s):
L:\app\src\main\antlr\pascal.g4:804:8: expecting ''', found '='
L:\app\src\main\antlr\pascal.g4:36:1: unexpected token: grammar
error: Token stream error reading grammar(s):
L:\app\src\main\antlr\pascal.g4:804:8: expecting ''', found '='
L:\app\src\main\antlr\pascal.g4:36:1: rule grammar trapped:
L:\app\src\main\antlr\pascal.g4:36:1: unexpected token: grammar
TokenStreamException: expecting ''', found '='
:generateGrammarSource FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':generateGrammarSource'.
> There was 1 error during grammar generation
   > ANTLR Panic: TokenStreamException: expecting ''', found '='

What it is the problem?

from the plug in docs at https://docs.gradle.org/current/userguide/antlr_plugin.html#sec:antlr_dependency_management

"antlr:antlr:2.7.7 will be used as the default."

to change this simply say which version to use as below

dependencies {
    //antlr "org.antlr:antlr:3.5.2" // use ANTLR version 3
    antlr "org.antlr:antlr4:4.5" // use ANTLR version 4
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM