I am trying to make a compiler like a C .I entered my grammar into antlrWorks IDE and it show no error and but when I want to see the syntax diagram of my rules it complained that " cannot display rule 'xxxxx' because start state not found". I didn't find any special way for defining start symbol on the examples.I put my grammar here may be somebody can help me:
grammar MiniC;
tokens {
GET='get';
PUT='put';
CHANGE='change';
DATA='data';
METADATA='metadata';
DEPENDENCIES='dependencies';
DEPENDENTS='dependents';
STATISTICS='statistics';
FROM='from';
IN='in';
ABOUT='about';
OF='of';
MAIN='main()';
ID = 'ID';
SEMI = ';';
INT ='int';
VOID = 'void';
BOOL ='BOOL';
FLOAT = 'FLOAT';
IF = 'if';
ELSE = 'else';
RETURN = 'return';
BREAK ='break';
WHILE ='while';
};
program
: MAIN compound_stmt
;
compound_stmt
:
'{' local_declarations stmt_list'}'
;
local_declarations
:
() (var_declarations)*
;
var_declarations
:
type_specifier ID SEMI
|
type_specifier ID [('0'..'9')*]
;
type_specifier
:
'int'
|
'void'
|
'bool'
|
'float'
;
stmt_list
:
(stmt)*
;
stmt :
expression_stmt
|
compound_stmt
|
selection_stmt
|
iteration_stmt
|
return_stmt
|
break_stmt
;
selection_stmt
: IF('('expression')') compound_stmt
|
IF('('expression')') compound_stmt ELSE compound_stmt
;
iteration_stmt
:
WHILE ('('expression')') compound_stmt;
return_stmt
:
RETURN SEMI|RETURN expression;
break_stmt
: BREAK;
expression_stmt
:
expression;
expression
: var '=' simple_expression|simple_expression;
simple_expression
:
operand operator operand;
operand :
('1'..'9')
|
;
var :
ID|ID[('1'..'9')*];
operator
:
RelOp|LogicOp|ArithOp;
RelOp :
'<='|'<'|'>='|'>'|'!='|'==' ;
LogicOp :
'&&'|'||'
;
ArithOp :
'+'|'-'|'*'|'/'|'%';
WS
:) (' '|'\t'|'\n'|'\r')+ {skip();}
;