Here is my simple grammar
`grammar ilp;
program
: statements+ EOF
;
statements
: var_declaration*
| 'tampilkan' Lparen identifier Rparen Semicolon
;
var_declaration
: primitive_type identifier Semicolon
| primitive_type identifier '=' expression Semicolon
| primitive_type identifier '[' expression ']' Semicolon
;
expression
: Num
| string
| Decimal
;
primitive_type
: 'angka32'
| 'bita'
| 'angka64'
| 'desimal'
| 'karakter'
| 'kalimat'
| 'logika'
| 'komposisi'
;
identifier
: Id
;
string
: '"' (~'"'|'"')* '"'
;
Semicolon
: ';'
;
Lparen
: '('
;
Rparen
: ')'
;
Comma
: ','
;
Id
: Letter(Letter|Digit)*
;
Num
: Digit
;
Decimal
: '-'?[0-9]+('.'[0-9]+)?
;
fragment
Digit
: [0-9]+
;
Letter
: [a-zA-Z]
;
WS
: [ trnu000C]+ -> skip ;
LINE_COMMENT
: '//' ~[rn]* -> skip
;`
but its give me error. why?
what should i do?
You should not use empty alternatives such as var_declaration*
in rule
statements
: var_declaration*
| 'tampilkan' Lparen identifier Rparen Semicolon
;
Replace it with var_declaration+
or rewrite rules.
Please, use stackoverflow.com for questinons.
KVANTTT thankyou so much you save my life :')
if i have quetion i will email you. its work now :)
i generate for c#
You have specified your 'string' rule as a parser rule, but it should be a
lexer rule. Fix that, then see if you still get the error
On Sun, Apr 10, 2016 at 5:11 PM, Techno Camp [email protected]
wrote:
Here is my simple grammar
`grammar ilp;
program
: statements+ EOF
;statements
: var_declaration*
| 'tampilkan' Lparen identifier Rparen Semicolon
;var_declaration
: primitive_type identifier Semicolon
| primitive_type identifier '=' expression Semicolon| primitive_type identifier '[' expression ']' Semicolon
;
expression
: Num
| string
| Decimal
;primitive_type
: 'angka32'
| 'bita'
| 'angka64'
| 'desimal'
| 'karakter'
| 'kalimat'| 'logika'
| 'komposisi'
;identifier
: Id
;string
: '"' (~'"'|'"')* '"'
;Semicolon
: ';'
;Lparen
: '('
;Rparen
: ')'
;Comma
: ','
;Id
: Letter(Letter|Digit)*
;Num
: Digit
;Decimal
: '-'?[0-9]+('.'[0-9]+)?
;fragment
Digit
: [0-9]+
;Letter
: [a-zA-Z]
;WS
: [ trnu000C]+ -> skip ;LINE_COMMENT
: '//' ~[rn]* -> skip
;`but its give me error. why?
what should i do?—
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub
https://github.com/antlr/antlr4/issues/1167