From 82ea552985b3bad2f07c0fb13360ad73540ca4a2 Mon Sep 17 00:00:00 2001 From: Timothy Washington Date: Thu, 27 Nov 2008 18:43:47 -0500 Subject: [PATCH] got past the shift/reduce conflict in the multiplicativeexpr --- build.xml | 19 +++++++- cc/xpath.sablecc | 138 +++++++++++++++++++++++++++++++++++++------------------ 2 files changed, 112 insertions(+), 45 deletions(-) diff --git a/build.xml b/build.xml index b5af08d..42ae9d9 100755 --- a/build.xml +++ b/build.xml @@ -170,6 +170,23 @@ + + + + + + + + + + + + + + + + + - diff --git a/cc/xpath.sablecc b/cc/xpath.sablecc index 994a2b0..81e6370 100755 --- a/cc/xpath.sablecc +++ b/cc/xpath.sablecc @@ -29,7 +29,32 @@ Package com.interrupt.cc.xpath; ./child::node()[1]/child::service/child::port/child::soap:address/attribute::location *) Find the first child node of the XMl document, then find a service child element within the first child, then find a port element inside the service element, then look inside the port element for an address element that belongs to the sOAP namespace and return the value of its location attribute. - */ + +----------- + +//system/bookkeeping +/system/bookkeeping +system/bookkeeping +./child::node() + +-- forward axis +descendant::node() +attribute::attribute() +self::element() +descendant-or-self::element() +following-sibling::node() +following::element() +namespace::node() + +-- reverse axis +parent::node() +ancestor::node() +preceding-sibling::node() +preceding::node() +ancestor-or-self::node() + + +*/ /** * KNOWN ISSUES @@ -40,7 +65,6 @@ Package com.interrupt.cc.xpath; Helpers - //basechar = ['a' .. 'z'] | ['A' .. 'Z']; basechar = [0x0041..0x005A] | [0x0061..0x007A] | [0x00C0..0x00D6] | [0x00D8..0x00F6] | [0x00F8..0x00FF] | [0x0100..0x0131] | [0x0134..0x013E] | [0x0141..0x0148] | [0x014A..0x017E] | @@ -216,8 +240,11 @@ Tokens lbracket = '['; rbracket = ']'; plus = '+'; + plus2 = '+'; minus = '-'; - star = '*'; + minus2 = '-'; + star = '*'; + star2 = '*'; union = '|'; equals = '='; @@ -248,21 +275,25 @@ Tokens /** * Axes */ + + //forward axis axis_child = 'child'; axis_descendant = 'descendant'; + axis_attribute = 'attribute'; + axis_self = 'self'; + axis_descendant_or_self = 'descendant-or-self'; + axis_following_sibling = 'following-sibling'; + axis_following = 'following'; + axis_namespace = 'namespace'; + + // reverse axis axis_parent = 'parent'; axis_ancestor = 'ancestor'; - axis_following_sibling = 'following-sibling'; axis_preceding_sibling = 'preceding-sibling'; - axis_following = 'following'; axis_preceding = 'preceding'; - axis_attribute = 'attribute'; - axis_namespace = 'namespace'; - axis_self = 'self'; - axis_descendant_or_self = 'descendant-or-self'; axis_ancestor_or_self = 'ancestor-or-self'; - - + + /** * Node Set Functions * @@ -309,11 +340,11 @@ Tokens * function: number ceiling(number) * function: number round(number) */ - + /** * Reserved Function Names */ - fn_attribute = 'attribute'; + //fn_attribute = 'attribute'; fn_comment = 'comment'; fn_document_node = 'document-node'; fn_element = 'element'; @@ -347,18 +378,20 @@ Tokens Productions - xpath = expr; + xpath = expr; - expr = pathexpr; - /* expr = exprsingle? expr_part*; + expr = forexpr; + //expr = exprsingle? expr_part*; expr_part = T.comma exprsingle; - /*exprsingle = {for} forexpr | - {quantif} quantifiedexpr | - {if} ifexpr | - {or} orexpr; - * / + // Causes too much inlining + //exprsingle = {for} forexpr | + // {quantif} quantifiedexpr | + // {if} ifexpr | + // {or} orexpr; + + // cannot input expression - Error: [1,1] expecting: EOF exprsingle = {for} forexpr | {quantif} quantifiedexpr | {if} ifexpr; @@ -374,8 +407,8 @@ Productions quantifiedexpr_part = T.comma T.dollar varname T.keyword_in exprsingle; ifexpr = T.keyword_if T.lparenth expr T.rparenth T.keyword_then [exprsingle1]:exprsingle T.keyword_else [exprsingle2]:exprsingle; - - /// + + orexpr = andexpr orexpr_part*; orexpr_part = T.keyword_or andexpr; @@ -393,16 +426,41 @@ Productions additiveexpr = multiplicativeexpr additiveexpr_part*; additiveexpr_part = additiveexpr_part_part multiplicativeexpr; - additiveexpr_part_part = {plus} T.plus | - {minus} T.minus; + additiveexpr_part_part = {plus} T.plus2 | + {minus} T.minus2; + multiplicativeexpr = unionexpr multiplicativeexpr_part*; multiplicativeexpr_part = multiplicativeexpr_part_part unionexpr; - multiplicativeexpr_part_part = {star} T.star | + multiplicativeexpr_part_part = {star} T.star2 | {div} T.keyword_div | {idiv} T.keyword_idiv | {mod} T.keyword_mod; - /// + + //multiplicativeexpr = unionexpr mone; + // mone = T.star2 unionexpr; + + /* + shift/reduce conflict in state [stack: PCastableexpr PMultiplicativeexprPartPart PCastableexpr TKeywordInstance TKeywordOf PItemtype *] on TStar in { + [ PMultiplicativeexprPart = PMultiplicativeexprPartPart PCastableexpr TKeywordInstance TKeywordOf PItemtype * ] followed by TStar (reduce), + [ POccurrenceindicator = * TStar ] (shift) + + + + shift/reduce conflict in state [stack: PCastableexpr PMultiplicativeexprPartPart PCastableexpr TKeywordInstance TKeywordOf PItemtype *] on TStar in { + 36 * -16 instance of xs:double * + + [ PMultiplicativeexprPart = PMultiplicativeexprPartPart PCastableexpr TKeywordInstance TKeywordOf PItemtype * ] followed by TStar (reduce), + * -16 instance of xs:double * + + [ POccurrenceindicator = * TStar ] (shift) + * + + If I want to use the expression 'A', how can I remove any ambiguity that the last star is an occurence indicator (versus another multiplier) + A) 36 * -16 instance of xs:double* + + */ + unionexpr = intersectexceptexpr unionexpr_part*; unionexpr_part = unionexpr_part_part intersectexceptexpr; unionexpr_part_part = {unionkey} T.keyword_union | @@ -430,14 +488,14 @@ Productions {plus} T.plus; valueexpr = pathexpr; - + generalcomp = {eq} T.equals | {ne} T.ne_abbrev | {lt} T.lt_abbrev | {le} T.le_abbrev | {gt} T.gt_abbrev | {ge} T.ge_abbrev; - + valuecomp = {eq} T.eq | {ne} T.ne | {lt} T.lt | @@ -448,14 +506,6 @@ Productions nodecomp = {is} T.keyword_is | {ncomppre} T.ncomp_precedes | {ncompfol} T.ncomp_follows; - */ - - - //pathexpr = {path1} pathexpr_part_one | - // {path2} pathexpr_part_two; - // pathexpr_part_one = T.abbrev_root T.letter; - // pathexpr_part_two = T.abbrev_root_desc T.letter; - pathexpr = {path1} pathexpr_part_one | @@ -503,8 +553,8 @@ Productions forwardaxis_part_six = T.axis_following_sibling T.axis_delim; forwardaxis_part_seven = T.axis_following T.axis_delim; forwardaxis_part_eight = T.axis_namespace T.axis_delim; - - + + abbrevforwardstep = T.abbrev_attrib? nodetest; reversestep = {reverse} reversestep_part | @@ -588,9 +638,9 @@ Productions singletype = atomictype T.question?; sequencetype = {sequencetype1} sequencetype_part_one | - {sequencetype2} sequencetype_part_two; + {sequencetype2} itemtype occurrenceindicator?; sequencetype_part_one = T.fn_empty_sequence T.lparenth T.rparenth; - sequencetype_part_two = itemtype occurrenceindicator?; + //sequencetype_part_two = itemtype occurrenceindicator?; occurrenceindicator = {question} T.question | {star} T.star | @@ -631,11 +681,11 @@ Productions pitest_part = {ncname} ncname | {stringlit} stringliteral; - attributetest = T.fn_attribute T.lparenth attributetest_part? T.rparenth; + attributetest = T.axis_attribute T.lparenth attributetest_part? T.rparenth; //fn_attribute doesn't work attributetest_part = attribnameorwildcard attributetest_part_part?; attributetest_part_part = T.comma typename; - - + + attribnameorwildcard = {attrib} attributename | {star} T.star; -- 2.11.4.GIT