这学期我们在操作系统课上学习状态机,我很挣扎。这是我们提供的一些代码的片段。谁能向我解释它在做什么或如何实现开关?我没有运气就读完了这本书,而且我的老师这周没有空。这不是一个作业,而是一个不计分的练习,可以帮助我们理解如何实现状态。请帮我!
/* Implements a state machine that parses the command line arguments, searching for switches and switch parameters.*/
int switches::getswitch()
{
while (true) // loop until a switch is identified and returned
{
int c = next(); // get next character to parse
switch (state) // process the current state
{
case START: //whats going on here?
{
sign = 0;
if (c == END_S && index >= args.size())
return END_S;
switch (c)
{
case '/':
state = S_SWITCH;
break;
default:
next_arg();
state = START;
break;
}
break;
}
// Add states here, what are the states that need to be implemented and how are they implemented?
}
}
}