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

Shift/reduce conflict



Hi all,

I'm currently playing with SableCC and found it a very valuable tool. My knowledge about parser technology is quite limited (although I read the dragon book and others), so I thought I start learning by creating a real grammar. This went fine until now but unfortunately I've hit a point where I don't know how to proceed from. Maybe somebody of you can give me a hint or solution.

What I'm trying to do is to write a grammar for Windows rc resource files (e.g. for conversion of dialog resources to Eclipse (Jigloo) form resources) and found a shift/reduce conflict. There are, among others, these productions:

Productions
	resource_entry = 
		{preprocessor} number_sign preprocessor_entry | 
		{resource_statement} resource_statement
	;

	// This is the typical C like "#define name value" macro definition.
	preprocessor_entry = 
		define identifier preprocessor_symbol_value?
	;

	preprocessor_symbol_value =
		{number} integer_literal |
		{string} string_literal |
		{char} character_literal
	;

	// This could be:
	// 1 BITMAP "filename"
	resource_statement = 
		...
		{named} entry_identifier named_entry
	;

	entry_identifier =
		{number} integer_literal |
		{name} string_literal
	;

As you can see from the above the #define statement ends optionally with an integer literal but the resource statement can start with an integer literal. So there is a shift/reduce conflict.

How do experienced parser creators solve that conflict? I have no idea what I can do here, as the only differencing item I can see is the new line character (which is an ignored token in my grammar).

I would really much appreciate any help to solve this problem.

Mike
--
www.soft-gems.net