========== CSplit: Version 2.0 ==========
========== CSplit: Begin part 5/11 ==========
if (ReadCh == '\n')
{
print ('\r');
}
print (ReadCh);
}
}
//==================================================================
/**
* Print current line number.
*/
protected void printLineNumber()
{
String str = "\n" + lines + ":\n";
print (str);
}
//==================================================================
/**
* Write current state to output file.
*/
protected void logState()
{
if (itsPrevState == itsState)
return;
String str = "\t\t\t\t| ";
CPState st = new CPState (itsState);
str += st.toString();
str += "\n";
print (str);
}
//====================================================================
/**
* The heart of the comment parser. A finite state machine which
* does nothing else than determines the current state based on
* the events.
*/
private void processState (int theEvent)
{
if (itsState != CPState.InsideEscape)
itsPrevState = itsState;
// Escaped character.
if (theEvent == CPEvent.FOUND_BACKSLASH)
{
itsState = CPState.InsideEscape;
return;
}
switch (itsState)
{
case CPState.NormalInput:
switch (theEvent)
{
case CPEvent.FOUND_QUOTE:
itsState = CPState.InsideString;
break;
case CPEvent.FOUND_SINGLEQUOTE:
itsState = CPState.InsideChar;
break;
case CPEvent.FOUND_SLASH:
// to be investigated: begin of comment.
itsState = CPState.BeginComment;
break;
}
break;
case CPState.InsideString:
switch (theEvent)
{
case CPEvent.FOUND_QUOTE:
// End of the string.
itsState = CPState.NormalInput;
break;
}
break;
case CPState.InsideChar:
switch (theEvent)
{
case CPEvent.FOUND_SINGLEQUOTE:
// End of the character constant.
itsState = CPState.NormalInput;
break;
}
break;
// We have found a '/', maybe this is a comment...
case CPState.BeginComment:
switch (theEvent)
{
case CPEvent.FOUND_SLASH:
// Yes, it's a C++ comment.
itsState = CPState.InCppComment;
break;
case CPEvent.FOUND_STAR:
// Yes, it's a C comment.
itsState = CPState.InCComment;
break;
default:
// No, just a slash.
itsState = CPState.NormalInput;
break;
}
break;
case CPState.InsideEscape:
// Found backslash -- restore previous state.
itsState = itsPrevState;
break;
case CPState.InCppComment:
switch (theEvent)
{
case CPEvent.FOUND_CR:
case CPEvent.FOUND_NL:
// Newline is end of C++ comment.
itsState = CPState.NormalInput;
break;
case CPEvent.FOUND_STAR:
itsState = CPState.StarInCppComment;
break;
}
break;
case CPState.InCComment:
switch (theEvent)
{
case CPEvent.FOUND_STAR:
// to be investigated: end of comment.
itsState = CPState.StarInCComment;
break;
}
break;
// '*' in C++ comment: action processors can use this to check
// e.g. C comments inside C++ comment.
========== CSplit: End part 5/11 crc: 898b ==========
// Albert email: jla@to.icl.fi
--- GoldED/2 2.50+
---------------
* Origin: Albert's Point/2 in Finland, Europe (2:221/360.20)
|