The objective of this exercise is to detect the repetition of a certain token, I am trying to do it with the symbol * coming from Regex, but it does not work.
I am doing a basic transpiler, it consists in translating certain syntax with already defined grammar. I still have some drawbacks when defining the detection of multiple tokens. That is, using * to specify the repetition of a regex token (I think the *
is used to define the repetition of a token), for example (see SENTENCE*
):
FUNCTION
: DEF ID PAR_OPEN PAR_CLOSE
SENTENCE*
END
{ $$ = 'function ' + $2 + '(){' + $5 + '}' };
SENTENCE
: PRINT
| VAR_ASSIGN
|;
Grammar works with the input:
def hello()
println "dsasd"
end
but it does not work with the entry:
def hello()
a = 3
println "dsasd"
end
The error thrown is:
bash
Error: Parse error on line 3:
...llo() a = 3 println "dsasd"end
---------------------^
Expecting 'EOF', '+', 'OR', 'AND', '=', '<>', '-', '*', '/', '>', '<', '>=', '<=','^', 'PAR_CLOSE', '%', 'END', got 'PRINTLN'
Could you tell me what I'm doing wrong?
Solved by adding %ebnf
to the grammar. See here