我是ANTLR的新手并尝试解析ASP文件。我在走树时遇到了跟踪错误。
线程中的异常" main" java.lang.StackOverflowError的 在org.antlr.v4.runtime.atn.LexerATNSimulator.getEpsilonTarget(LexerATNSimulator.java:495) 在org.antlr.v4.runtime.atn.LexerATNSimulator.closure(LexerATNSimulator.java:476) 在org.antlr.v4.runtime.atn.LexerATNSimulator.closure(LexerATNSimulator.java:478) 在org.antlr.v4.runtime.atn.LexerATNSimulator.closure(LexerATNSimulator.java:478) 在org.antlr.v4.runtime.atn.LexerATNSimulator.closure(LexerATNSimulator.java:478) 在org.antlr.v4.runtime.atn.LexerATNSimulator.closure(LexerATNSimulator.java:458) 在org.antlr.v4.runtime.atn.LexerATNSimulator.closure(LexerATNSimulator.java:478) 在org.antlr.v4.runtime.atn.LexerATNSimulator.closure(LexerATNSimulator.java:478)
请建议可能的根本原因。
**Lexer Grammar**
lexer grammar ASPLexer;
HTML_COMMENT
: '<!--' .*? '-->'
;
HTML_CONDITIONAL_COMMENT
: '<![' .*? ']>'
;
XML_DECLARATION
: '<?xml' .*? '>'
;
CDATA
: '<![CDATA[' .*? ']]>'
;
DTD
: '<!' .*? '>'
;
SCRIPTLET
: '<?' .*? '?>'
| '<%' .*? '%>'
;
SEA_WS
: (' '|'\t'|'\r'? '\n')+
;
SCRIPT_OPEN
: '<script' .*? '>' ->pushMode(SCRIPT)
;
STYLE_OPEN
: '<style' .*? '>' ->pushMode(STYLE)
;
TAG_OPEN
: '<' -> pushMode(TAG)
;
HTML_TEXT
: ~'<'+
;
//
// tag declarations
//
mode TAG;
TAG_CLOSE
: '>' -> popMode
;
TAG_SLASH_CLOSE
: '/>' -> popMode
;
TAG_SLASH
: '/'
;
SCRIPT_TAG_OPEN
: '<%' -> pushMode(SCRIPTVALUE)
;
//
// lexing mode for attribute values
//
TAG_EQUALS
: '=' -> pushMode(ATTVALUE)
;
TAG_NAME
: TAG_NameStartChar TAG_NameChar*
;
TAG_WHITESPACE
: [ \t\r\n] -> skip
;
fragment
HEXDIGIT
: [a-fA-F0-9]
;
fragment
DIGIT
: [0-9]
;
fragment
TAG_NameChar
: TAG_NameStartChar
| '-'
| '_'
| '.'
| DIGIT
| '\u00B7'
| '\u0300'..'\u036F'
| '\u203F'..'\u2040'
;
fragment
TAG_NameStartChar
: [:a-zA-Z]
| '\u2070'..'\u218F'
| '\u2C00'..'\u2FEF'
| '\u3001'..'\uD7FF'
| '\uF900'..'\uFDCF'
| '\uFDF0'..'\uFFFD'
;
//
// <scripts>
//
mode SCRIPT;
SCRIPT_BODY
: .*? '</script>' -> popMode
;
SCRIPT_SHORT_BODY
: .*? '</>' -> popMode
;
//
// <styles>
//
mode STYLE;
STYLE_BODY
: .*? '</style>' -> popMode
;
STYLE_SHORT_BODY
: .*? '</>' -> popMode
;
//
// attribute values
//
mode ATTVALUE;
// an attribute value may have spaces b/t the '=' and the value
ATTVALUE_VALUE
: [ ]* ATTRIBUTE -> popMode
;
ATTRIBUTE
: DOUBLE_QUOTE_STRING
| SINGLE_QUOTE_STRING
| ATTCHARS
| HEXCHARS
| DECCHARS
;
fragment ATTCHAR
: '-'
| '_'
| '.'
| '/'
| '+'
| ','
| '?'
| '='
| ':'
| ';'
| '#'
| [0-9a-zA-Z]
;
fragment ATTCHARS
: ATTCHAR+ ' '?
;
fragment HEXCHARS
: '#' [0-9a-fA-F]+
;
fragment DECCHARS
: [0-9]+ '%'?
;
fragment DOUBLE_QUOTE_STRING
: '"' ~[<"]* '"'
;
fragment SINGLE_QUOTE_STRING
: '\'' ~[<']* '\''
;
mode SCRIPTVALUE;
SCRIPT_TAG_VALUE
: ATTCHARSCRIPTS*
;
SCRIPT_TAG_CLOSE
: '%>' -> popMode
;
fragment ATTCHARSCRIPT
: '-'
| '_'
| '.'
| '/'
| '+'
| ','
| '?'
| '='
| ':'
| ';'
| '#'
| ')'
| '('
| '"'
| '\r'
| '\n'
| ' '
| [0-9a-zA-Z]
;
fragment ATTCHARSCRIPTS
: ATTCHARSCRIPT* ' '?
;
**Parser Grammar**
parser grammar ASPParser;
options { tokenVocab=ASPLexer; }
htmlDocument
: (scriptlet | SEA_WS)* xml? (scriptlet | SEA_WS)* dtd? (scriptlet | SEA_WS)* htmlElements*
;
htmlElements
: htmlMisc* htmlElement htmlMisc*
;
htmlElement
: TAG_OPEN htmlTagName htmlAttribute* scriptlettag* htmlAttribute* TAG_CLOSE htmlContent TAG_OPEN TAG_SLASH htmlTagName TAG_CLOSE
| TAG_OPEN htmlTagName htmlAttribute* TAG_SLASH_CLOSE
| TAG_OPEN htmlTagName htmlAttribute* TAG_CLOSE
| scriptlet
| script
| style
;
htmlContent
: htmlChardata? ((htmlElement | xhtmlCDATA | htmlComment) htmlChardata?)*
;
htmlAttribute
: htmlAttributeName TAG_EQUALS htmlAttributeValue
| htmlAttributeName
| scriptlet
;
htmlAttributeName
: TAG_NAME
;
htmlAttributeValue
: ATTVALUE_VALUE
;
htmlTagName
: TAG_NAME
;
htmlChardata
: HTML_TEXT
| SEA_WS
;
htmlMisc
: htmlComment
| SEA_WS
;
htmlComment
: HTML_COMMENT
| HTML_CONDITIONAL_COMMENT
;
xhtmlCDATA
: CDATA
;
dtd
: DTD
;
xml
: XML_DECLARATION
;
scriptlet
: SCRIPTLET
;
scriptlettag
: SCRIPT_TAG_OPEN SCRIPT_TAG_VALUE SCRIPT_TAG_CLOSE
;
script
: SCRIPT_OPEN ( SCRIPT_BODY | SCRIPT_SHORT_BODY)
;
style
: STYLE_OPEN ( STYLE_BODY | STYLE_SHORT_BODY)
;
**Input File**
<!DOCTYPE html>
<html>
<%
dim cars
cars=Request.Form("cars")
%>
<body>
<form action="demo_radiob.asp" method="post">
<p>Please select your favorite car:</p>
<input type="radio" name="cars"
<%
if cars="Volvo" then Response.Write("checked")
%>
value="Volvo">Volvo</input>
<br>
<input type="radio" name="cars"
<% if cars="Saab" then Response.Write("checked") %>
value="Saab">Saab</input>
<br>
<input type="radio" name="cars"
<% if cars="BMW" then Response.Write("checked") %>
value="BMW">BMW</input>
<br><br>
<input type="submit" value="Submit" />
</form>
<%
if cars<>"" then
Response.Write("<p>Your favorite car is: " & cars & "</p>")
end if
%>
</body>
</html>