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

Re: States in grammar file

Jenny Lam writes:
> States
> 	normal,
> 	tag,
> 	element,
> 	attribute;
> Token
> 	{normal->tag, attribute->tag, tag}
> 	abc	= 'abc';
> 	blank	= ' ';
> 	...
> 	{tag->attribute, normal->attribute, attribute}
> 	alink 	= 'alink';
> 	....
> 	{element->normal, normal}
> 	valid_input 	= [[32..127] - [less_than + greater_than]]*;
> Productions
> 	...
> When I feed the gerenated parser a file where it contains a string "abc
> alink" and the parser is in States tag, shouldn't it match 'abc' as token
> abc, '  ' as blank, and 'alink' as token alink?  
> Instead, what it interprets string "abc alink" as valid_input. 
> valid_input is only suppose to be recognized in State normal. This would
> be perfectly understandable if States are not defined(it will goes for the
> longest possible match).  Am I not understanding how States work here? 
> Any light on this subject would be appreciated.

Looks like you can match token valid_input in states element or normal,
and you can match token abc in states normal, attribute, or tag.

Now if you're in state normal, input 'abc' will match both tokens
valid_input and abc.

The state before the arrow means 'match when in this state', and
the (optional) state after the arrow means 'then transition to this
other state'.


Archie Cobbs   *   Whistle Communications, Inc.  *   http://www.whistle.com