Loading ...
Sorry, an error occurred while loading the content.
 

FW: floundering with an ambiguities problem

Expand Messages
  • Ernest Pasour
    Message 1 of 1 , May 1, 2000
      > I have the following lexer snippet (at bottom) that I wanted to see if someone could give me some pointers on. I am writing a grammar for Java Server Page files, and I am running across some ambiguities when I try to recognize strings in that language.
      >
      > Strings in JSPs can be bounded by double quotes or single quotes, and the following character sequences must be escaped.
      > \' => '
      > \" => "
      > \\ => \
      > %\> => %>
      > <\% => <%
      >
      > So the problem I run into is with the last two escape sequences. Based on the JSP spec, "<\%" and "%\>" can occur anywhere in the string (which distinguishes them from the syntactic predicate for ("<%="). The current formulation gives the following errors:
      >
      > warning: line 925: lexical nondeterminism upon
      > k==1:'%'
      > k==2:'\\'
      > k==3:'>'
      > k==4:'\3'..'\377'
      > between alts 1 and 3 of block
      > warning: line 925: lexical nondeterminism upon
      > k==1:'<'
      > k==2:'\\'
      > k==3:'%'
      > k==4:'\3'..'\377'
      > between alts 2 and 3 of block
      > warning: line 932: lexical nondeterminism upon
      > k==1:'%'
      > k==2:'\\'
      > k==3:'>'
      > k==4:'\3'..'\377'
      > between alts 1 and 3 of block
      > warning: line 932: lexical nondeterminism upon
      > k==1:'<'
      > k==2:'\\'
      > k==3:'%'
      > k==4:'\3'..'\377'
      > between alts 2 and 3 of block
      >
      > This seems to work because I've listed the alternatives that take precedence first--that is, I want "%\>" and "<\%" to be consumed before the next alternative handles individual characters. Can someone suggest a better way to handle this or to turn off the warnings?
      >
      > Thanks,
      > Ernest
      >
      >
      > protected
      > JSP_STRING
      > :
      > ('"'
      > (
      > ("<%=")=>JSP_EXPRESSION_TAG
      > 925: | ("%\\>" | "<\\%" | ~('"' | '\\') | "\\\\" | "\\\"" | "\\\'" )*
      > )
      > '"'
      > )
      > | '\''
      > (
      > ("<%=")=>JSP_EXPRESSION_TAG
      > 932: | ("%\\>" | "<\\%" | ~('\'' | '\\') | "\\\\" | "\\\"" | "\\\'" )*
      > )
      > '\''
      > ;
    Your message has been successfully submitted and would be delivered to recipients shortly.