Commit fcb768de authored by Benoit Perrot's avatar Benoit Perrot
Browse files

Index: ChangeLog

from  Benoît Perrot  <benoit@lrde.epita.fr>

	* src/shell.hh (is_register, is_label, get_next_word): 
	Rename and move into...
	* src/shell.cc (eat_register, eat_label, eat_word):
	This.
parent d36d3f31
2005-01-17 Benot Perrot <benoit@lrde.epita.fr>
* src/shell.hh (is_register, is_label, get_next_word):
Rename and move into...
* src/shell.cc (eat_register, eat_label, eat_word):
This.
2005-01-15 Benot Perrot <benoit@lrde.epita.fr>
Introduce utilities for lexical analysis.
......
......@@ -109,10 +109,53 @@ namespace shell
delete command;
}
std::string
Shell::eat_word(std::istringstream &iss)
{
misc::skip_blank(iss);
std::string res;
while (!isblank(iss.peek()))
{
char c = static_cast<char>(iss.get());
if (iss.eof())
break;
res += c;
}
return res;
}
bool
Shell::eat_register(std::istringstream &iss, std::string &reg)
{
reg = eat_word(iss);
if (reg == "pc")
return true;
map_register_type::const_iterator it = map_register_.find(reg);
if (it != map_register_.end())
return true;
// TODO: check unlimited register here
return false;
}
bool
Shell::eat_label(std::istringstream &iss, std::string &label)
{
label = eat_word(iss);
if (label.empty())
return false;
char c = label.c_str()[0];
if (isdigit(c))
return false;
return true;
}
Cmd::identifier_type
Shell::eat_command_id(std::istringstream &iss)
{
std::string id = get_next_word(iss);
std::string id = eat_word(iss);
if (id.empty())
return Cmd::id_null;
......@@ -142,11 +185,11 @@ namespace shell
case Cmd::id_run:
{
command = new Cmd(Cmd::id_run);
std::string tmp = get_next_word(iss);
std::string tmp = eat_word(iss);
while (0 < tmp.length())
{
command->push_arg(tmp);
tmp = get_next_word(iss);
tmp = eat_word(iss);
}
return command;
}
......@@ -154,14 +197,8 @@ namespace shell
case Cmd::id_break:
{
command = new Cmd(Cmd::id_break);
std::string tmp = get_next_word(iss);
if (tmp.empty())
{
delete command;
break;
}
// check tmp is a label
if (is_label(tmp))
std::string tmp;
if (eat_label(iss, tmp))
{
command->push_arg(tmp);
return command;
......@@ -172,14 +209,14 @@ namespace shell
case Cmd::id_load:
{
command = new Cmd(Cmd::id_load);
std::string tmp = get_next_word(iss);
if (tmp.empty())
std::string tmp = eat_word(iss);
if (!tmp.empty())
{
delete command;
break;
command->push_arg(tmp);
return command;
}
command->push_arg(tmp);
return command;
delete command;
break;
}
case Cmd::id_print:
......@@ -187,14 +224,8 @@ namespace shell
case Cmd::id_undisplay:
{
command = new Cmd(id);
std::string tmp = get_next_word(iss);
if (tmp.empty())
{
delete command;
break;
}
// check tmp is a register
if (is_register(tmp))
std::string tmp;
if (eat_register(iss, tmp))
{
command->push_arg(tmp);
return command;
......@@ -206,15 +237,16 @@ namespace shell
case Cmd::id_mem:
{
command = new Cmd(Cmd::id_mem);
std::string tmp = get_next_word(iss);
if (tmp.empty())
// FIXME: check tmp is a memory address: eat_memory_address()
std::string tmp = eat_word(iss);
if (!tmp.empty())
{
delete command;
break;
command->push_arg(tmp);
return command;
}
// check tmp is a memory addr
command->push_arg(tmp);
return command;
delete command;
break;
}
case Cmd::id_quit:
......
......@@ -111,47 +111,17 @@ namespace shell
// Internal scanner/parser
private:
/// Check if str is a valid register.
bool is_register(const std::string &str)
{
if (str == "pc")
return true;
map_register_type::const_iterator it = map_register_.find(str);
if (it != map_register_.end())
return true;
// TODO: check unlimited register here
return false;
}
/// Check if str is a valid label.
bool is_label(const std::string& str)
{
char c = str.c_str()[0];
/// Eat the next word from input stringstream.
std::string eat_word(std::istringstream &iss);
if (isdigit(c))
return false;
return true;
}
/// Get the next word in the command line.
std::string get_next_word(std::istringstream &iss)
{
misc::skip_blank(iss);
/// Eat a valid register identifier from input stringstream.
bool eat_register(std::istringstream &iss, std::string &reg);
std::string res;
while (!isblank(iss.peek()))
{
char c = static_cast<char>(iss.get());
if (iss.eof())
break;
res += c;
}
return res;
}
/// Eat a valid label from input stringstream.
bool eat_label(std::istringstream &iss, std::string &label);
/// Eat a word in the command line and return the corresponding keyword.
/// Eat a word from input stringstream and return the
/// corresponding keyword.
Cmd::identifier_type eat_command_id(std::istringstream &iss);
/** \name Execution engine
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment