Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9273983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T16:14:40+00:00 2026-06-18T16:14:40+00:00

I’m using antlr 4 to write my grammar. I would like to see the

  • 0

I’m using antlr 4 to write my grammar. I would like to see the gui three generated by my grammar.
When I try to run the example on the antlr site (http://www.antlr.org/wiki/display/ANTLR4/Getting+Started+with+ANTLR+v4) it works, but if I try with my grammar it doesn’t work.
In particular I’ve tried also to run the grammar on NetBeans and AntlrWorks 2 with the command “Run in TestRig..” , but the result is the same error message “”Can’t load Troubles as lexer or parser””.

This is my grammar:

    script 
    : include*
      systemDef
      labelsDef
      issueDef*
      observationDef*
      actionDef*
      procedure*
    ;

include
    : USE qualifiedName EOS;

systemDef
    : SYSTEM definition;

labelsDef
    : LABELS COLON '{' label* '}' EOS ;

label
    : IDENTIFIER COLON literal EOS
    ;

issueDef
    : ISSUES definition;

observationDef
    : OBSERVATIONS definition;

actionDef
    : ACTIONS definition;

definition
    : IDENTIFIER? parameters? ( COLON block )?  EOS
    ;

reference
    : IDENTIFIER? parameters? (COLON)? (atClause ( COMMA atClause )*)? EOS
    ;

parameters
    : '[' param (COMMA param)* ']'
    ;

param
    : literal
    | IDENTIFIER
    ;

literal
    : STRINGLITERAL
    | INTEGET_LITERAL
    | PERCENTAGELITERAL
    | FLOATLITERAL
    | TRUE
    | FALSE
    ;

block
    : '{' ( (marker)? (definition | reference) )+ '}'
    ;

marker
    : PLUS
    | MINUS
    | MULTIPLY
    | SHARP
    | QUESTION_MARK
    ;

atClause
    : '@' qualifiedName parameters?
    ;

qualifiedName
    : (DOT)? IDENTIFIER  (DOT IDENTIFIER)* 
    ;

procedure
    : PROCEDURE IDENTIFIER params? COLON body 
    ;

params
    : '[' IDENTIFIER (COMMA IDENTIFIER)* ']'
    ;

body
    : statement
    | '{' statement* '}'
    ;

statement
    : assignment 
    | expression // .str???
    | callExpression 
    | ifStatement
    | whileStatement
    | repeatStatement
    | forStatement
    ;

assignment
    : qualifiedName ASSIGN expression (EOS)?
    ;

expression
    : conditionalOrExpression (EOS)?;

conditionalOrExpression 
    : conditionalAndExpression ( OR conditionalAndExpression )*
    ;

conditionalAndExpression 
    : equalityExpression ( AND equalityExpression )*
    ;

equalityExpression 
    :  stringExpression (equalityOp stringExpression)?
    ;

equalityOp
    : EQUAL
    | NE
    ;

stringExpression
    : relationalExpression ('§' stringExpression)?
    ;

relationalExpression 
    : additiveExpression (relationalOp additiveExpression)*
    ;

relationalOp 
    : '<='
    | '>='
    | '<'
    | '>'
    ;

additiveExpression 
    : multiplicativeExpression (( PLUS | MINUS ) multiplicativeExpression )*
    ;

multiplicativeExpression 
    : unaryExpression (( MULTIPLY | DIVIDE ) unaryExpression )*
    ;

unaryExpression 
    : ( PLUS | MINUS | NOT )? basicExpression
    ;

basicExpression
    : rangeExpression 
    | callExpression
    | qualifiedName // .str > 
    | percentageExpression
    | '(' expression ')'
    | literal
    ;

percentageExpression
    : PERCENTAGELITERAL 'of' additiveExpression
    ;

rangeExpression
    : qualifiedName '(' ThreeDigits '..' ThreeDigits ')' (EOS)?
    ;

callExpression
    : qualifiedName arguments (EOS)?
    ;

arguments
    : '(' (expression (COMMA expression)*)? ')'
    ;

ifStatement // (ELSE body)?
    : IF '(' expression ')' body 
      (ELSE ifStatement | body )?
    ;

whileStatement
    : WHILE '(' expression ')' body
    ;

repeatStatement 
    : REPEAT body UNTIL '(' expression ')' EOS
    ;

forStatement 
    : FOR .qualifiedName ASSIGN value TO value STEP value body 
    ;

value
    : FLOATLITERAL
    ;

and this is my file build.xml:

 <target name="-pre-compile" depends="antlr">
    </target>

    <target name="init-antlr">
        <!-- Full path to Antlr jar -->
        <property name="antlr-4.0-complete.jar" location="C:/Users/Mary/Documents/TesiMagistrale/lib/antlr-4.0-complete.jar"/>
        <!-- Grammar path -->
        <property name="antlr.grammar" location="src/troubles/lang/Troubles.g4"/>
        <!--<property name="antlr.lexer" location="src/trouble/lang/TroublesL.g4"/>-->
    </target>

    <target name="antlr" depends="init-antlr" unless="up-to-date">
        <!-- Compiling grammar -->
        <java classname="org.antlr.v4.Tool"  fork="true">
            <arg value="${antlr.grammar}"/>
            <!--<arg value="${antlr.lexer}"/>-->
            <arg value="-visitor"/>
            <classpath path="${antlr-4.0-complete.jar}"/>
        </java> 
    </target>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T16:14:41+00:00Added an answer on June 18, 2026 at 4:14 pm

    I’m rewriting my answer so that it is more accurate.

    The most likely reason you can’t successfully run TestRig in NetBeans/antlrworks2 is because you set your grammar to be in a package other than the default package. If you have something like this in your grammar,

    @header {
        package org.whatever.troubles;
    }
    

    try commenting it out and running “Run in TestRig…”. It should work this way.

    Unfortunately, the “Run in TestRig…” feature does not allow you to specify a package. You’ll have to either keep your grammar in the default package, or use “grun” at the command prompt.

    I recommend running grun manually until this is fixed. A nice way to handle it is to create a batch file (run.bat) in your source folder (where your .g4 is). It will show up in NetBeans in the Projects pane where you can right-click on it and select “run”.

    And, still, your CLASSPATH must be accurate…

    Example run.bat contents:

    rem grun org.whatever.troubles.Troubles script -tokens -tree -gui test.txt
    
    java -cp .;C:\workdir\proj\dist\troubles.jar;C:\antlr-4.0-complete.jar;"C:\Program Files\Java\jre7\lib" org.whatever.troubles.Troubles script -tokens -tree -gui test.txt
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to run a str_replace or preg_replace which looks for certain words
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I would like to count the length of a string with PHP. The string
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am using JSon response to parse title,date content and thumbnail images and place
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.