CAccept packAccept() throws IOException {
CAccept accept;
char action[];
int action_index;
int brackets;
boolean insinglequotes;
boolean indoublequotes;
boolean instarcomment;
boolean inslashcomment;
boolean escaped;
boolean slashed;
action = new char[BUFFER_SIZE];
action_index = 0;
if (CUtility.DEBUG)
{
CUtility.assert(null != this);
CUtility.assert(null != m_outstream);
CUtility.assert(null != m_input);
CUtility.assert(null != m_tokens);
CUtility.assert(null != m_spec);
}
/* Get a new line, if needed. */
while (m_input.m_line_index >= m_input.m_line_read)
{
if (m_input.getLine())
{
CError.parse_error(CError.E_EOF,m_input.m_line_number);
return null;
}
}
/* Look for beginning of action. */
while (CUtility.isspace(m_input.m_line[m_input.m_line_index]))
{
++m_input.m_line_index;
/* Get a new line, if needed. */
while (m_input.m_line_index >= m_input.m_line_read)
{
if (m_input.getLine())
{
CError.parse_error(CError.E_EOF,m_input.m_line_number);
return null;
}
}
}
/* Look for brackets. */
if ('{" != m_input.m_line[m_input.m_line_index])
{
CError.parse_error(CError.E_BRACE,m_input.m_line_number);
}
/* Copy new line into action buffer. */
brackets = 0;
insinglequotes = indoublequotes = inslashcomment = instarcomment =
escaped = slashed = false;
while (true)
{
action[action_index] = m_input.m_line[m_input.m_line_index];
/* Look for quotes. */
if ((insinglequotes || indoublequotes) && escaped)
escaped=false; // only protects one char, but this is enough.
else if ((insinglequotes || indoublequotes) &&
'\\" == m_input.m_line[m_input.m_line_index])
escaped=true;
else if (!(insinglequotes || inslashcomment || instarcomment) &&
'\"" == m_input.m_line[m_input.m_line_index])
indoublequotes=!indoublequotes; // unescaped double quote.
else if (!(indoublequotes || inslashcomment || instarcomment) &&
'\'" == m_input.m_line[m_input.m_line_index])
insinglequotes=!insinglequotes; // unescaped single quote.
/* Look for comments. */
if (instarcomment) { // inside "/*" comment; look for "*/"
if (slashed && '/" == m_input.m_line[m_input.m_line_index])
instarcomment = slashed = false;
else // note that inside a star comment, slashed means starred
slashed = ('*" == m_input.m_line[m_input.m_line_index]);
} else if (!inslashcomment && !insinglequotes && !indoublequotes) {
// not in comment, look for /* or //
inslashcomment =
(slashed && '/" == m_input.m_line[m_input.m_line_index]);
instarcomment =
(slashed && '*" == m_input.m_line[m_input.m_line_index]);
slashed = ('/" == m_input.m_line[m_input.m_line_index]);
}
/* Look for brackets. */
if (!insinglequotes && !indoublequotes &&
!instarcomment && !inslashcomment) {
if ('{" == m_input.m_line[m_input.m_line_index])
{
++brackets;
}
else if ('}" == m_input.m_line[m_input.m_line_index])
{
--brackets;
if (0 == brackets)
{
++action_index;
++m_input.m_line_index;
break;
}
}
}
++action_index;
/* Double the buffer size, if needed. */
if (action_index >= action.length)
{
action = CUtility.doubleSize(action);
}
++m_input.m_line_index;
/* Get a new line, if needed. */
while (m_input.m_line_index >= m_input.m_line_read)
{
inslashcomment = slashed = false;
if (insinglequotes || indoublequotes) { // non-fatal
CError.parse_error(CError.E_NEWLINE,m_input.m_line_number);
insinglequotes = indoublequotes = false;
}
if (m_input.getLine())
{
CError.parse_error(CError.E_SYNTAX,m_input.m_line_number);
return null;
}
}
}
accept = new CAccept(action,action_index,m_input.m_line_number);
if (CUtility.DEBUG)
{
CUtility.assert(null != accept);
}
if (CUtility.DESCENT_DEBUG)
{
System.out.print("Accepting action:");
System.out.println(new String(accept.m_action,0,accept.m_action_read));
}
return accept;
}
Function: packAccept
Description: Packages and returns CAccept
for action next in input stream. |