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

Index: ChangeLog

from  Benoît Perrot  <benoit@lrde.epita.fr>
2005-01-08  Benoît Perrot  <benoit@lrde.epita.fr>

	Migrate to bison2.0a.
	
	* dev/parse-asm-parse-gen.py: Call the parser with a filename and
	a program builder instead of using global variables. Use bison's
	builtin system to print token values. Remove global program builder.
	* dev/parse-asm-scan-gen.py: Remove global string for file name. 
	Use yy::location instead of yy::Location.
	* src/parse/asm-scan.hh: Call the scanner with a trace flag.
	* src/parse/libparse.hh, src/parse/libparse.cc:
	Declare trace flags as booleans. 
	* src/vm/cp0.hh: Include common.hh to get exit_set.
parent e0719624
2004-01-04 Benot Perrot <benoit@lrde.epita.fr>
2005-01-08 Benot Perrot <benoit@lrde.epita.fr>
Migrate to bison2.0a.
* dev/parse-asm-parse-gen.py: Call the parser with a filename and
a program builder instead of using global variables. Use bison's
builtin system to print token values. Remove global program builder.
* dev/parse-asm-scan-gen.py: Remove global string for file name.
Use yy::location instead of yy::Location.
* src/parse/asm-scan.hh: Call the scanner with a trace flag.
* src/parse/libparse.hh, src/parse/libparse.cc:
Declare trace flags as booleans.
* src/vm/cp0.hh: Include common.hh to get exit_set.
2005-01-04 Benot Perrot <benoit@lrde.epita.fr>
Strengthen lexical analysis.
......
......@@ -54,19 +54,23 @@ print """
#include \"parse/libparse.hh\"
namespace yy
{
extern inst::ProgramBuilder program_builder;
}
using namespace inst;
using vm::Cpu;
%}
%error-verbose
%locations
%debug
%locations
%parse-param { std::string &filename }
%parse-param { inst::ProgramBuilder &program_builder }
%initial-action
{
@$.begin.filename = @$.end.filename = &filename;
}
%union
{
int i;
......@@ -84,6 +88,12 @@ using vm::Cpu;
%token <i> INTEGER \"integer\"
%token <s> STRING \"string\"
%token <reg> REGISTER \"register\"
%destructor { delete $$; } \"string\"
%printer { debug_stream () << *$$; } \"string\" \"register\"
%printer { debug_stream () << $$; } \"integer\"
%type <exp> exp
%token YYEOF 0 \"end of file\"
......@@ -271,34 +281,11 @@ exp:
%%
void
yy::Parser::error_ ()
yy::parser::error(const location &l, const std::string &msg)
{
std::cerr << location << \": \" << message << std::endl;
std::cerr << l << \": \" << msg << std::endl;
exit_set (exit_parse);
}
void
yy::Parser::print_ ()
{
std::cerr << ' ' << location;
switch (looka_)
{
case STRING:
std::cerr << \": \" << *value.s;
break;
case INTEGER:
std::cerr << \": \" << value.i;
break;
case REGISTER:
std::cerr << \": \" << *value.reg;
break;
}
}
namespace yy
{
inst::ProgramBuilder program_builder;
}
"""
sys.stdout.close()
......
......@@ -53,17 +53,9 @@ print """
#define YY_NEVER_INTERACTIVE 1
#define YY_USER_INIT \\
do { \\
yylloc->begin.filename = current_file; \\
yylloc->end.filename = current_file; \\
} while (0)
#define YY_USER_ACTION \\
yylloc->columns (yyleng);
static std::string current_file;
using inst::Register;
using vm::Cpu;
......@@ -246,7 +238,7 @@ print """
{eol} {
yylloc->lines (1);
yylval->s->append (yytext, yyleng);
yylval->s->append (\"\\n\", 1);
}
<<EOF>> {
......@@ -272,24 +264,20 @@ namespace parse
{
void
scan_open (const std::string &name)
scan_open(const std::string &filename, bool trace_p)
{
yy_flex_debug = trace_scan_p;
yy_flex_debug = trace_p;
if (name == \"-\")
{
yyin = stdin;
current_file = \"standard input\";
}
if (filename == \"-\")
yyin = stdin;
else
{
yyin = fopen (name.c_str (), \"r\");
current_file = name;
yyin = fopen (filename.c_str (), \"r\");
if (!yyin)
{
std::cerr
<< program_name
<< \": cannot open `\" << name << \"': \"
<< \": cannot open `\" << filename << \"': \"
<< strerror (errno) << std::endl;
exit (1);
}
......
......@@ -22,16 +22,16 @@
# include "parse/asm-parse.hh"
# define YY_DECL \
int yylex (yystype *yylval, yy::Location *yylloc)
int yylex (yystype *yylval, yy::location *yylloc)
YY_DECL;
namespace parse
{
/** \brief Open the scanner step. */
void scan_open (const std::string &name);
void scan_open(const std::string &filename, bool trace_p);
/** \brief Close the scanner step. */
void scan_close (void);
void scan_close(void);
}
#endif // !PARSE_ASM_SCAN_HH
......@@ -16,6 +16,7 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
#include "inst/program_builder.hh"
#include "parse/asm-parse.hh"
// Export parsed file name.
......@@ -26,8 +27,8 @@ namespace parse
{
// Display the results of intermediate steps.
int trace_scan_p = 0;
int trace_parse_p = 0;
bool trace_scan_p = 0;
bool trace_parse_p = false;
// Authorize unlimited registers.
bool unlimited_regs_p = false;
......@@ -37,17 +38,20 @@ namespace parse
// Parse a MIPS asm file, return the corresponding abstract syntax.
::inst::Program*
parse (const std::string &fname)
parse (const std::string &filename)
{
yy::Parser parser = yy::Parser (trace_parse_p);
inst::ProgramBuilder program_builder;
program_builder.reset(nop_after_branch_p);
yy::program_builder.reset(nop_after_branch_p);
std::string dummy(filename);
yy::parser parser = yy::parser(dummy, program_builder);
parser.set_debug_level(trace_parse_p);
scan_open (fname);
parser.parse ();
scan_close ();
scan_open(filename, trace_scan_p);
parser.parse();
scan_close();
return ::yy::program_builder.get();
return program_builder.get();
}
} // namespace parse
......@@ -28,10 +28,10 @@ namespace inst { class Program; }
namespace parse
{
::inst::Program* parse (const std::string &fname);
::inst::Program* parse(const std::string &fname);
extern int trace_scan_p;
extern int trace_parse_p;
extern bool trace_scan_p;
extern bool trace_parse_p;
extern bool unlimited_regs_p;
......
......@@ -21,6 +21,8 @@
#ifndef VM_CP0_HH
# define VM_CP0_HH
# include "common.hh"
# include "inst/register.hh"
namespace vm
......
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