I'm interested in making compiler, parser, and parser generator, but I don't know much about them.
After reading an answer of this question, I tried to make a 'very' simple LaTeX parser.
This is the code:
grammar Latex;
latex : ITEM*;
ITEM : CMD|LAWTEXT;
CMD : CHEAD ARGS;
CHEAD : '\\' LETTER(LETTER|DIGIT)*;
LETTER : 'A'..'Z'|'a'..'z';
DIGIT : '0'|'1'|'2'|'3'|'4'|'5'|'6'|'7'|'8'|'9';
ARGS : '{' ITEM* '}';
LAWTEXT : (LETTER|DIGIT|WHITESPACE|PUNC)*;
WHITESPACE
: ' '|'\t'|'\n'|'\r';
PUNC : '!'|'^';
(There's only two char in PUNC, for test purpose)
And this is the error message:
[18:39:09] warning(200): C:\Users\***\Documents\Latex.g:9:12: Decision can match input such as "{'\t'..'\n', '\r', ' '..'!', '0'..'9', 'A'..'Z', '\\', '^', 'a'..'z', '}'}" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
[18:39:09] error(201): C:\Users\***\Documents\Latex.g:9:12: The following alternatives can never be matched: 2
[18:39:09] error(211): C:\Users\***\Documents\Latex.g:1:8: [fatal] rule Tokens has non-LL(*) decision due to recursive rule invocations reachable from alts 1,2. Resolve by left-factoring or using syntactic predicates or using backtrack=true option.
I found that this error happens because there's an ambiguity, a code can be interpreted in more than two ways, but I have no idea how this ambiguity is generated.
And this is the diagram and two ways something can be interpreted (maybe).
... but how \
and }
can be confused?