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>