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

Eiffel Grammar shift / reduce errors



Hi Etienne and others:

I am still having some issues with my grammar. Now, I have a shift / shift / reduce conflict.

I read through Etienne's tricks to resolve conflicts and I am at a loss for this error.

Please advise.

- Dave Makalsky

Error:


shift/reduce conflict in state [stack: PClassHeader TInvariant TPrecursor *] on
TLParen in {
[ PActuals = * TLParen PActualList TRParen ] (shift),
[ PActuals = * TLParen TRParen ] (shift),
[ PPrecursor = TPrecursor * ] followed by TLParen (reduce)
}
java.lang.RuntimeException:


shift/reduce conflict in state [stack: PClassHeader TInvariant TPrecursor *] on
TLParen in {
[ PActuals = * TLParen PActualList TRParen ] (shift),
[ PActuals = * TLParen TRParen ] (shift),
[ PPrecursor = TPrecursor * ] followed by TLParen (reduce)
}
at org.sablecc.sablecc.Grammar.computeLALR(Unknown Source)
at org.sablecc.sablecc.GenParser.caseStart(Unknown Source)
at org.sablecc.sablecc.node.Start.apply(Unknown Source)
at org.sablecc.sablecc.SableCC.processGrammar(Unknown Source)
at org.sablecc.sablecc.SableCC.processGrammar(Unknown Source)
at org.sablecc.sablecc.SableCC.main(Unknown Source)
Package eiffel;

Helpers
	all = [0..127];
	letter = [['A' .. 'Z'] + ['a' .. 'z']];
	digit = ['0' .. '9'];
	underscore = '_';
	
	cr=13;
	lf = 10;
	
	// case insensitive
	
	a = 'a' | 'A';
	b = 'b' | 'B';
	c = 'c' | 'C';
	d = 'd' | 'D';
	e = 'e' | 'E';
	f = 'f' | 'F';
	g = 'g' | 'G';
	h = 'h' | 'H';
	i = 'i' | 'I';
	j = 'j' | 'J';
	k = 'k' | 'K';
	l = 'l' | 'L';
	m = 'm' | 'M';
	n = 'n' | 'N';
	o = 'o' | 'O';
	p = 'p' | 'P';
	q = 'q' | 'Q';
	r = 'r' | 'R';
	s = 's' | 'S';
	t = 't' | 'T';
	u = 'u' | 'U';
	v = 'v' | 'V';
	w = 'w' | 'W';
	x = 'x' | 'X';
	y = 'y' | 'Y';
	z = 'z' | 'Z';
	
	newline_character = [[[[cr + lf] +  0x85 ]+ 0x2028 ] +0x2029];
	input = [all - newline_character];
	printable_input = [[input - ' '] - 9];
	free_operator_start =
		[[['@' + '#']+ '|']+ '&'];
	true_w = t r u e;
	false_w = f a l s e;
	separate_w = s e p a r a t e;
	deferred_w = d e f e r r e d;
	expanded_w = e x p a n d e d;
	
	sign = '+' | '-' ;
	
	integer = digit*;
	real = integer? '.' integer;
	semicolon = ';';
	
	regular_string_literal_character = [all - '"'];

	regular_string_literal = '"' regular_string_literal_character* '"';
	
	
Tokens

	free_operator =
		free_operator_start
		printable_input
		;
	
	unary =
		n o t | '+' |'-';
		
	binary =
		'+' | '-' | '*' | '/' | '<' | '>' |
		'<=' | '>=' | '//' | '\\' | '^' | a n d | o r | x o r |
		i m p l i e s
		;
	
	
	and = a n d;
	or = o r;
	agent = a g e n t;
	invariant = i n v a r i a n t;
	rescue = r e s c u e;
	require = r e q u i r e;
	ensure = e n s u r e;
	else = e l s e;
	inspect = i n s p e c t;
	when = w h e n;
	then = t h e n;
	from = f r o m;
	until = u n t i l;
	loop = l o o p;
	debug = d e b u g;
	variant = v a r i a n t;
	check = c h e c k;
	result = r e s u l t;
	current = c u r r e n t;
	precursor = p r e c u r s o r;
	old = o l d;
	strip = s t r i p;
	local = l o c a l;
	alias = a l i a s;
	external = e x t e r n a l;
	do = d o ;
	once = o n c e;
	deferred = d e f e r r e d;
	frozen = f r o z e n;
	unique = u n i q u e;
	is = i s;
	feature = f e a t u r e;
	rename = r e n a m e;
	as = a s;
	inherit = i n h e r i t;
	class_word = c l a s s;
	indexing = i n d e x i n g;
	end = e n d;
	separate = s e p a r a t e;
	expanded = e x p a n d e d;
	bit = b i t;
	like = l i k e;
	obsolete = o b s o l e t e;
	export = e x p o r t;
	all = a l l;
	redefine = r e d e f i n e;
	undefine = u n d e f i n e;
	select = s e l e c t;
	creation = c r e a t i o n;
	create = c r e a t e;
	prefix = p r e f i x;
	infix = i n f i x;
	retry = r e t r y;
	if = i f;
	elseif = e l s e i f;
	
	header_mark = separate_w | expanded_w | deferred_w;
	l_double_angle_bracket = '<<';
	r_double_angle_bracket = '>>';
	l_bracket = '[';
	r_bracket = ']';
	l_paren = '(';
	r_paren = ')';
	l_brace = '{';
	r_brace = '}';
	l_double_brace='{{';
	r_double_brace='}}';
	exclamation_mark = '!';
	dot = '.';
	dotdot ='..';
	equals = '=';
	nequals = '/=';
	question_mark = '?';
	dollar_sign = '$';
	constraint_arrow = '->';
	colon = ':';
	comma = ',';
	identifier =
		letter (letter | digit | underscore)*;
		
	separator = semicolon | cr | lf | cr lf | 0x85 | 0x2028 | 0x2029;
	
	blank = ' '*;
	tab = 9;
	
	boolean_constant = true_w | false_w;
	character_constant = ''' [ all - ''' ] ''';
	
	integer_constant = sign? integer;
	real_constant = sign? real;
	comment = '--' input*;
	header_comment = '--' input*;
	bit_constant = ('0' | '1') b ;
	
	manifest_string = regular_string_literal;
	
Ignored Tokens
	blank, tab, comment, separator;
	
Productions

/////////////////////////////////////////////////////////
	class_declaration =
		P.indexing?
		class_header
		formal_generics?
		P.obsolete?
		inheritance?
		creators?
		features?
		P.invariant?
		second_indexing?
		end
		;
		
//////////////////////////////////////////////////////////

	indexing =
		T.indexing
		index_list
		;
		
	second_indexing = P.indexing;
		
	index_list =
		index_clause*
		;
		
	index_clause =
		index?
		index_terms
		;
		
	index =
		identifier
		colon
		;
	
	index_terms =
		{single} index_value 
		| {multi} index_value comma index_terms 
		;
		
	index_value =
		{identifier}identifier
		|{constant} manifest_constant
		;
	
//////////////////////////////////////////////////////////
	manifest_constant =
		{boolean}boolean_constant  
		| {character}character_constant  
		| {integer}integer_constant 
		| {real}real_constant 
		| {string}manifest_string 
    	| {bit} bit_constant 
		;
		
	class_header =
		header_mark? class_word this_class_name
		;
		
	this_class_name = identifier;
	
	class_name = identifier;
	
	formal_generics =
		l_bracket formal_generic_list? r_bracket
		;
	
	formal_generic_list =
		{single} formal_generic
		| {multiple} formal_generic comma formal_generic_list
		;
		
	formal_generic =
		formal_generic_name constraint?
		;
		
	formal_generic_name =
		identifier
		;
		
	constraint =
		constraint_arrow class_type
		;
		
	class_type =
		class_name
		actual_generics?
		;

	actual_generics =
		l_bracket
		type_list?
		r_bracket
		;
		
	type_list =
		{single}entity_type
		| {multi} entity_type comma type_list
		;
		
	entity_type =
		{class} class_type |
   		{expanded} class_type_expanded |
    	{separate} class_type_separate |
    	{anchored} anchored | 
    	{bit} bit_type
	;
	
	
	class_type_expanded =
		expanded class_type
		;
		
	class_type_separate =
		separate class_type
		;
		
	bit_type =
		bit integer_constant
		;
		
	anchored =
		like identifier
		;
		
	obsolete =
		T.obsolete manifest_string ;
		
		
	inheritance =
		inherit parent_list;
		
	parent_list =
		parent*
		;
		
	parent =
		class_type feature_adaptation?;
	
	
	
	feature_adaptation =
		{rename}P.rename new_exports? P.undefine? P.redefine? P.select? end |
		{export} new_exports P.undefine? P.redefine? P.select? end |
		{undefine} P.undefine P.redefine? P.select? end |
		{redefine} P.redefine P.select? end |
		{select} P.select end
		;
		
	rename =
		T.rename rename_list;
		
	rename_list =
		{single} rename_pair |
		{multi} rename_pair comma? rename_list
		;
		
	rename_pair =
		feature_name as feature_name_target
		;
		
	feature_name_target = feature_name;
	
		
	new_exports =
		export
		new_export_list
		;
		
	new_export_list =
		{empty} |
		{non_empty} new_export_item
		new_export_list
		;
		
	new_export_item =
		clients feature_set
		;
		
	clients =
		l_brace class_list r_brace
		;
		
	class_list =
		{empty} |
		{one} class_name |
		{multi} class_name comma class_list
		;
		
	feature_set =
		{list} feature_list |
		{all} all
		;
		
	feature_list =
		{empty} |
		{one} feature_name |
		{multi} feature_name comma feature_list
		;
	
	redefine =
		T.redefine feature_list
		;
		
	undefine =
		T.undefine feature_list
		;
		
	select =
		T.select feature_list
		;
		
	creators =
		{single} creation_words creation_clause |
		{multi} creation_words creation_clause creators
		;
		
	creation_words =
		{creation} T.creation |
		{create} T.create
		;
		
	creation_clause =
		clients?
		feature_list
		;
		
	features =
		{single} feature feature_clause |
		{multi} feature feature_clause features
		;
		
	feature_clause =
		clients? feature_declaration_list
		;
		
	feature_declaration_list =
		feature_declaration*
		;
		
	feature_declaration =
		new_feature_list
		declaration_body
		;
		
	declaration_body =
		formal_arguments?
		type_mark?
		constant_or_routine?
		;
		
	constant_or_routine =
		is feature_value
		;
		
	feature_value =
		{const} manifest_constant |
		{unique} unique |
		{routine} routine
		;
		
	new_feature_list =
		{single} new_feature |
		{multi} new_feature comma new_feature_list
		;
		
	new_feature =
		frozen? feature_name
		;
		
	feature_name =
		{ident} identifier |
		{prefix} prefix |
		{infix} infix
		;
		
	formal_arguments =
		l_paren entity_declaration_list r_paren
		;
		
	entity_declaration_list =
		entity_declaration_group*
		;
	
	entity_declaration_group =
		identifier_list type_mark
		;
	
	identifier_list =
		{single} identifier |
		{multi} identifier comma identifier_list
		;
		
	type_mark =
		colon entity_type
		;

	
	routine =
		P.obsolete?
		precondition?
		local_declarations?
		routine_body
		postcondition?
		T.rescue?
		end
		;
		
	routine_body =
		{effective} effective |
		{deferred} deferred
		;
		
	effective =
		{internal} internal |
		{external} P.external
		;
		
	internal =
		routine_mark
		compound
		;
	
	routine_mark =
		{do} do |
		{once} once
		;
		
	external =
		T.external
		language_name
		external_name?
		;
		
	language_name =
		manifest_string
		;
		
	external_name =
		alias manifest_string
		;
	
	local_declarations =
		local
		entity_declaration_list
		;
	
	precondition =
		require
		else?
		assertion
		;
		
	postcondition =
		ensure
		then?
		assertion
		;
		
	invariant =
		T.invariant
		assertion
		;
		
	assertion =
		assertion_clause*
		;
	
	assertion_clause =
		tag_mark?
		unlabelled_assertion_clause
		;
		
	unlabelled_assertion_clause =
		{bool} boolean_expression |
		{comment} header_comment
		;
		
	tag_mark =
		tag colon
		;
		
	tag =
		identifier
		;
		
	rescue =
		T.rescue
		compound
		;
		
	compound =
		instruction*
		;
		
	instruction =
		{creation} P.creation |
		{call} call |
		{assignment} assignment |
		{assignment_attempt} assignment_attempt |
		{conditional} conditional |
		{multi_branch} multi_branch |
		{loop} P.loop |
		{debug} P.debug |
		{check} P.check |
		{retry} retry |
		{null} epsilon
		;
		
	creation =
		{old_style} T.exclamation_mark
			entity_type?
			r_exclamation_mark
			writable
			creation_call |
		{modern} create
			creation_type_mark?
			writable
			creation_call
		;
		
	r_exclamation_mark = T.exclamation_mark
		;
		
	
	creation_call =
		dot
		feature_name
		actuals?
		;
		
	creation_type_mark =
		l_brace
		entity_type
		r_brace
		;
		
	assignment =
		writable
		colon
		equals
		expression
		;
		
	assignment_attempt =
		writable
		question_mark
		equals
		expression
		;
		
	conditional =
		if
		then_part_list
		else_part?
		end
		;
		
	then_part_list =
		{single} then_part |
		{multi} then_part 
		elseif 
		then_part_list
		;
		
	then_part =
		boolean_expression
		then
		compound
		;
		
	else_part =
		else
		compound
		;
		
	multi_branch =
		inspect 
		expression
		when_part_list?
		else_part?
		end
		;
		
	when_part_list =
		{single} when when_part | 
		{multi} when when_part when_part_list
		;
		
	when_part =
		choices
		then
		compound
		;
		
	choices =
		{empty} |
		{single} choice |
		{multi} choice comma choices
		;
		
	choice =
		{const} choice_constant |
		{interval} interval
		;
		
	interval =
		choice_constant dotdot choice_constant1
		;
	
	choice_constant1 =
		choice_constant
		;	
	
	choice_constant =
		{int} integer_constant |
		{char} character_constant |
		{attrib} attribute
		;
	
	loop =
		initialization
		P.invariant?
		P.variant?
		loop_body
		end
		;
		
	initialization =
		from
		compound
		;
		
	variant =
		T.variant
		tag_mark?
		expression
		;
		
	loop_body =
		exit
		T.loop
		compound
		;
		
	exit =
		until
		boolean_expression
		;
		
	debug =
		T.debug
		debug_keys?
		compound
		end
		;
		
	debug_keys =
		l_paren
		debug_key_list?
		r_paren
		;
		
	debug_key_list =
		{single} debug_key |
		{multi} debug_key comma debug_key_list
		;
		
	debug_key =
		manifest_string
		;
		
	check =
		T.check
		assertion
		end
		;
		
	epsilon =
		; //epsilon
		
	call =
		{qualified} qualified_call1 |
		{precursor} P.precursor
		;
		
	qualified_call1 =
		call_qualifier?
		call_chain
		;
		
	call_qualifier =
		call_target
		dot
		;
		
	call_target =
		{paren} parenthesized |
		{result} result |
		{current} current |
		{precursor} P.precursor
		;
		
	call_chain =
		{single} unqualified_call |
		{multi} unqualified_call dot call_chain
		;
		
	unqualified_call =
		identifier
		actuals?
		;
		
	precursor =
		parent_qualification?
		T.precursor
		actuals?
		;
		
	//for ISE	
	parent_qualification =
		{single}l_brace  class_name  r_brace |
		{multi} l_double_brace class_name r_double_brace
		;
		
	l_brace_inner =
		l_brace
		;
	
	r_brace_inner =
		r_brace
		;
		
		
	attribute =
		identifier
		;
	
	writable =
		{id} identifier |
		{result} result
		;
		
	actuals =
		l_paren
		actual_list?
		r_paren
		;
		
	actual_list =
		{single} actual | 
		{multi} actual comma actual_list 
		;
		
	actual =
		{expression} expression |
		{address} address |
		{question_mark} question_mark //for agents
		;
		
	address = 
		{dollar_sign} dollar_sign address_mark |
		{agent} agent call //for agents
		;
		
	address_mark =
		{feature_name} feature_name |
		{current} current |
		{result} result
		;
		
	expression =
		{curr} current |
		{result} result |
		{call} call |
		{oper} operator_expression |
		{eq} equality |
		{arr} manifest_array |
		{old} P.old |
		{strip} P.strip |
		{bool} boolean_constant |
		{bit} bit_constant |
		{int} integer_constant |
		{real} real_constant |
		{str} manifest_string |
		{char} character_constant
		;
		
	boolean_expression =
		expression
		;
	
	operator_expression =
		{paren} parenthesized |
		{unary} unary_expression |
		{binary} binary_expression
		;
		
	parenthesized =
		l_paren
		expression
		r_paren
		;
	
	unary_expression =
		prefix_operator
		expression
		;
		
	binary_expression =
		expression
		infix_operator
		right_expression
		;
		
	right_expression =
		expression
		;
		
	equality =
		expression
		comparison
		right_expression
		;
		
	comparison =
		{equals} equals |
		{nequals} nequals
		;
	
	manifest_array =
		l_double_angle_bracket
		expression_list?
		r_double_angle_bracket
		;
		
	expression_list =
		{single} expression |
		{multi} expression comma expression_list
		;
		
	old =
		T.old expression
		;
		
	strip =
		T.strip
		l_paren
		attribute_list?
		r_paren
		;
		
	attribute_list =
		{single} attribute |
		{multi} attribute comma attribute_list
		;
		
	binary =
		T.binary |
		{and_then} and then |
		{or_else} or else
		;
		
	prefix_operator =
		{unary} unary |
		{free} free_operator
		;
	
	infix_operator =
		{binary} P.binary |
		{free} free_operator
		;