[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Tokens priority



I understand SableCC Lexer relies on the order of tokens declaration for their
recognition. This is a problem for me in the following example:

Tokens
	litteral = 'litteral';
	name = (letter | digit)+;

Productions
	sentence = litteral name litteral;

If the sentence is "litteral foo litteral", the parser will recognize it. However,
if the sentence is "litteral litteral litteral", it won't (the series of tokens
"litteral litteral litteral" is not a sentence production).

If I rearange the tokens declaration in the inverse order, then the parser will not
recognise any of the sentences (it will always be recognized as a production of "name
name name", which is not declared).

I know it is possible to use states in order to solve this problem. Is there any
other way (except from the obvious:
	sentence =
		{case1} litteral name litteral |
		{case2} litteral litteral litteral;)

Sorry if it's a really simple matter, my background in parsing is very scarce,
I'm just trying to use SableCC in a real world application.

--
Benjamin Ryzman	  "Deliver yesterday, code today, think tomorrow."
Software Engineer, NetPartitioner(TM) design team.
SOLsoft SA, 4bis rue de la Gare, 92300 Levallois-Perret, France.