Commit b9336511 authored by Roland Levillain's avatar Roland Levillain
Browse files

2006-01-02 Roland Levillain <roland@lrde.epita.fr>

	Prepare for Bison 2.2.

	* src/parse/asm-parse.yy.gen.py: Require Bison 2.1a.
	Use the LALR(1) C++ skeleton.
	* asm-scan.ll.gen.py: Update the the scanner to use tokens from
	yy::parser::token.
	* src/parse/asm-scan.hh (yylex): Adjust the types of the
	arguments.
	* src/parse/libparse.cc: Include parse/asm-scan.hh.
	* build-aux/bison++.in: Remove Bison 2.0 support.
parent ab222035
2006-01-02 Roland Levillain <roland@lrde.epita.fr>
Prepare for Bison 2.2.
* src/parse/asm-parse.yy.gen.py: Require Bison 2.1a.
Use the LALR(1) C++ skeleton.
* asm-scan.ll.gen.py: Update the the scanner to use tokens from
yy::parser::token.
* src/parse/asm-scan.hh (yylex): Adjust the types of the
arguments.
* src/parse/libparse.cc: Include parse/asm-scan.hh.
* build-aux/bison++.in: Remove Bison 2.0 support.
2005-12-27 Benot Perrot <benoit@lrde.epita.fr> 2005-12-27 Benot Perrot <benoit@lrde.epita.fr>
print is still a python keyword print is still a python keyword
......
...@@ -18,7 +18,7 @@ input=$1 ...@@ -18,7 +18,7 @@ input=$1
shift shift
output=$1 output=$1
shift shift
options="-S lalr1.cc $@" options="-d -ra $@"
# Alexandre Duret-Lutz also notes that in VPATH-builds $(srcdir) can # Alexandre Duret-Lutz also notes that in VPATH-builds $(srcdir) can
# be an absolute path depending on how ./configure is called ... # be an absolute path depending on how ./configure is called ...
...@@ -38,14 +38,7 @@ mkdir $tmp ...@@ -38,14 +38,7 @@ mkdir $tmp
# Don't use `ln -s' as its semantics of paths sucks. # Don't use `ln -s' as its semantics of paths sucks.
cp $srcdir/$input $tmp cp $srcdir/$input $tmp
cd $tmp cd $tmp
$BISON $options -S lalr1.cc $input -o $output $BISON $options $input -o $output
# Bison 2.0 forgets to implement %lex-param for the C++ parsers.
lex_param=$(perl -ne 'print /^%lex-param\s*\{.*\b(\w+)\s*\}/' $input)
if test x"$lex_param" != x; then
# Replace the two-argument call to yylex to a three argument call.
perl -pi -e 's/(yylex \(&yylval, &yylloc)\)/$1, '"$lex_param)/" $output;
fi
for file in * for file in *
do do
......
...@@ -55,6 +55,8 @@ print """ ...@@ -55,6 +55,8 @@ print """
using namespace inst; using namespace inst;
%} %}
%require "2.1a"
%skeleton "lalr1.cc"
%error-verbose %error-verbose
%debug %debug
......
...@@ -22,7 +22,8 @@ ...@@ -22,7 +22,8 @@
# include "parse/asm-parse.hh" # include "parse/asm-parse.hh"
# define YY_DECL \ # define YY_DECL \
int yylex (yystype *yylval, yy::location *yylloc) int yylex (yy::parser::semantic_type *yylval, \
yy::parser::location_type *yylloc)
YY_DECL; YY_DECL;
namespace parse namespace parse
......
...@@ -59,6 +59,8 @@ print """ ...@@ -59,6 +59,8 @@ print """
using inst::Register; using inst::Register;
using vm::Cpu; using vm::Cpu;
typedef yy::parser::token token;
%} %}
%option noyywrap %option noyywrap
...@@ -82,40 +84,41 @@ id [a-zA-Z_][a-zA-Z_0-9]* ...@@ -82,40 +84,41 @@ id [a-zA-Z_][a-zA-Z_0-9]*
[#;][^\\n\\r]* yylloc->step (); [#;][^\\n\\r]* yylloc->step ();
{eol} yylloc->lines (1); yylloc->step (); {eol} yylloc->lines (1); yylloc->step ();
\"(\" return LPAREN; \"(\" return token::LPAREN;
\")\" return RPAREN; \")\" return token::RPAREN;
\",\" return COMMA; \",\" return token::COMMA;
\"+\" return EXP_ADD; \"+\" return token::EXP_ADD;
\"-\" return EXP_SUB; \"-\" return token::EXP_SUB;
\"*\" return EXP_MUL; \"*\" return token::EXP_MUL;
\"/\" return EXP_DIV; \"/\" return token::EXP_DIV;
\".text\" return DIR_TEXT; \".text\" return token::DIR_TEXT;
\".data\" return DIR_DATA; \".data\" return token::DIR_DATA;
\".space\" return DIR_SPACE; \".space\" return token::DIR_SPACE;
\".byte\" return DIR_BYTE; \".byte\" return token::DIR_BYTE;
\".half\" return DIR_HALF; \".half\" return token::DIR_HALF;
\".word\" return DIR_WORD; \".word\" return token::DIR_WORD;
\".ascii\" return DIR_ASCII; \".ascii\" return token::DIR_ASCII;
\".asciiz\" return DIR_ASCIIZ; \".asciiz\" return token::DIR_ASCIIZ;
""" """
## Body -------------------------------- ## Body --------------------------------
for inst in instructions: for inst in instructions:
print '"' + inst.opcode + '"\t\t\treturn ' + define_id(inst.opcode) + ";" print '"' + inst.opcode + \
'"\t\t\treturn token::' + define_id(inst.opcode) + ";"
## Epilogue ---------------------------- ## Epilogue ----------------------------
print """ print """
\"$\"([0-9]|[12][0-9]|3[01]) { \"$\"([0-9]|[12][0-9]|3[01]) {
yylval->reg = new Register(Register::generic, atoi(yytext +1)); yylval->reg = new Register(Register::generic, atoi(yytext +1));
return REGISTER; return token::REGISTER;
} }
\"$zero\" { \"$zero\" {
yylval->reg = new Register(Register::general, Cpu::zero); yylval->reg = new Register(Register::general, Cpu::zero);
return REGISTER; return token::REGISTER;
}""" }"""
for k, r in [("v", range(2)), ("a", range(4)), for k, r in [("v", range(2)), ("a", range(4)),
("t", range(10)), ("s", range(8))]: ("t", range(10)), ("s", range(8))]:
...@@ -123,35 +126,35 @@ for k, r in [("v", range(2)), ("a", range(4)), ...@@ -123,35 +126,35 @@ for k, r in [("v", range(2)), ("a", range(4)),
print "\"$" + k + str(i) + "\" {" print "\"$" + k + str(i) + "\" {"
print " yylval->reg = new Register(Register::general, " + \ print " yylval->reg = new Register(Register::general, " + \
"Cpu::" + k + str(i)+ ");" "Cpu::" + k + str(i)+ ");"
print " return REGISTER;\n}" print " return token::REGISTER;\n}"
print """ print """
\"$sp\" { \"$sp\" {
yylval->reg = new Register(Register::general, Cpu::sp); yylval->reg = new Register(Register::general, Cpu::sp);
return REGISTER; return token::REGISTER;
} }
\"$fp\" { \"$fp\" {
yylval->reg = new Register(Register::general, Cpu::fp); yylval->reg = new Register(Register::general, Cpu::fp);
return REGISTER; return token::REGISTER;
} }
\"$ra\" { \"$ra\" {
yylval->reg = new Register(Register::general, Cpu::ra); yylval->reg = new Register(Register::general, Cpu::ra);
return REGISTER; return token::REGISTER;
} }
\"$x\"{dec_int} { \"$x\"{dec_int} {
yylval->reg = new Register(Register::unlimited, atoi(yytext +2)); yylval->reg = new Register(Register::unlimited, atoi(yytext +2));
return REGISTER; return token::REGISTER;
} }
{id} { {id} {
yylval->id = new misc::unique_string(yytext); yylval->id = new misc::unique_string(yytext);
return LABEL; return token::LABEL;
} }
{id}\":\" { {id}\":\" {
yytext[yyleng - 1] = 0; // Remove last character (side-effects on yytext are allowed) yytext[yyleng - 1] = 0; // Remove last character (side-effects on yytext are allowed)
yylval->id = new misc::unique_string(yytext); yylval->id = new misc::unique_string(yytext);
return LABEL_DEF; return token::LABEL_DEF;
} }
...@@ -170,7 +173,7 @@ print """ ...@@ -170,7 +173,7 @@ print """
<< yytext << std::endl; << yytext << std::endl;
exit_set (exit_scan); exit_set (exit_scan);
} }
return INTEGER; return token::INTEGER;
} }
-?{hex_int} { -?{hex_int} {
std::istringstream iss(yytext); std::istringstream iss(yytext);
...@@ -187,30 +190,30 @@ print """ ...@@ -187,30 +190,30 @@ print """
<< yytext << std::endl; << yytext << std::endl;
exit_set (exit_scan); exit_set (exit_scan);
} }
return INTEGER; return token::INTEGER;
} }
'\\\\a' yylval->i = '\\a'; return INTEGER; '\\\\a' yylval->i = '\\a'; return token::INTEGER;
'\\\\b' yylval->i = '\\b'; return INTEGER; '\\\\b' yylval->i = '\\b'; return token::INTEGER;
'\\\\f' yylval->i = '\\f'; return INTEGER; '\\\\f' yylval->i = '\\f'; return token::INTEGER;
'\\\\n' yylval->i = '\\n'; return INTEGER; '\\\\n' yylval->i = '\\n'; return token::INTEGER;
'\\\\r' yylval->i = '\\r'; return INTEGER; '\\\\r' yylval->i = '\\r'; return token::INTEGER;
'\\\\t' yylval->i = '\\t'; return INTEGER; '\\\\t' yylval->i = '\\t'; return token::INTEGER;
'\\\\v' yylval->i = '\\v'; return INTEGER; '\\\\v' yylval->i = '\\v'; return token::INTEGER;
'\\\\[\\\\\\']' yylval->i = yytext[1]; return INTEGER; '\\\\[\\\\\\']' yylval->i = yytext[1]; return token::INTEGER;
'\\\\.' { '\\\\.' {
std::cerr << *yylloc std::cerr << *yylloc
<< \": unrecognized escape: \" << escape (yytext) << std::endl; << \": unrecognized escape: \" << escape (yytext) << std::endl;
exit_set (exit_scan); exit_set (exit_scan);
} }
'[^\\'\\n\\r\\\\]' yylval->i = yytext[1]; return INTEGER; '[^\\'\\n\\r\\\\]' yylval->i = yytext[1]; return token::INTEGER;
\\\" yylval->s = new std::string; BEGIN STATE_STRING; \\\" yylval->s = new std::string; BEGIN STATE_STRING;
<STATE_STRING>{ <STATE_STRING>{
\\\" { \\\" {
BEGIN INITIAL; BEGIN INITIAL;
return STRING; return token::STRING;
} }
\\\\[0-7]{3} { \\\\[0-7]{3} {
...@@ -256,7 +259,7 @@ print """ ...@@ -256,7 +259,7 @@ print """
exit_set (exit_scan); exit_set (exit_scan);
BEGIN INITIAL; BEGIN INITIAL;
return STRING; return token::STRING;
} }
} }
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
// //
#include "inst/program_builder.hh" #include "inst/program_builder.hh"
#include "parse/asm-scan.hh"
#include "parse/asm-parse.hh" #include "parse/asm-parse.hh"
// Export parsed file name. // Export parsed file name.
......
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