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>
print is still a python keyword
......
......@@ -18,7 +18,7 @@ input=$1
shift
output=$1
shift
options="-S lalr1.cc $@"
options="-d -ra $@"
# Alexandre Duret-Lutz also notes that in VPATH-builds $(srcdir) can
# be an absolute path depending on how ./configure is called ...
......@@ -38,14 +38,7 @@ mkdir $tmp
# Don't use `ln -s' as its semantics of paths sucks.
cp $srcdir/$input $tmp
cd $tmp
$BISON $options -S lalr1.cc $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
$BISON $options $input -o $output
for file in *
do
......
......@@ -55,6 +55,8 @@ print """
using namespace inst;
%}
%require "2.1a"
%skeleton "lalr1.cc"
%error-verbose
%debug
......
......@@ -22,7 +22,8 @@
# include "parse/asm-parse.hh"
# define YY_DECL \
int yylex (yystype *yylval, yy::location *yylloc)
int yylex (yy::parser::semantic_type *yylval, \
yy::parser::location_type *yylloc)
YY_DECL;
namespace parse
......
......@@ -59,6 +59,8 @@ print """
using inst::Register;
using vm::Cpu;
typedef yy::parser::token token;
%}
%option noyywrap
......@@ -82,40 +84,41 @@ id [a-zA-Z_][a-zA-Z_0-9]*
[#;][^\\n\\r]* yylloc->step ();
{eol} yylloc->lines (1); yylloc->step ();
\"(\" return LPAREN;
\")\" return RPAREN;
\",\" return COMMA;
\"(\" return token::LPAREN;
\")\" return token::RPAREN;
\",\" return token::COMMA;
\"+\" return EXP_ADD;
\"-\" return EXP_SUB;
\"*\" return EXP_MUL;
\"/\" return EXP_DIV;
\"+\" return token::EXP_ADD;
\"-\" return token::EXP_SUB;
\"*\" return token::EXP_MUL;
\"/\" return token::EXP_DIV;
\".text\" return DIR_TEXT;
\".data\" return DIR_DATA;
\".text\" return token::DIR_TEXT;
\".data\" return token::DIR_DATA;
\".space\" return DIR_SPACE;
\".byte\" return DIR_BYTE;
\".half\" return DIR_HALF;
\".word\" return DIR_WORD;
\".ascii\" return DIR_ASCII;
\".asciiz\" return DIR_ASCIIZ;
\".space\" return token::DIR_SPACE;
\".byte\" return token::DIR_BYTE;
\".half\" return token::DIR_HALF;
\".word\" return token::DIR_WORD;
\".ascii\" return token::DIR_ASCII;
\".asciiz\" return token::DIR_ASCIIZ;
"""
## Body --------------------------------
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 ----------------------------
print """
\"$\"([0-9]|[12][0-9]|3[01]) {
yylval->reg = new Register(Register::generic, atoi(yytext +1));
return REGISTER;
return token::REGISTER;
}
\"$zero\" {
yylval->reg = new Register(Register::general, Cpu::zero);
return REGISTER;
return token::REGISTER;
}"""
for k, r in [("v", range(2)), ("a", range(4)),
("t", range(10)), ("s", range(8))]:
......@@ -123,35 +126,35 @@ for k, r in [("v", range(2)), ("a", range(4)),
print "\"$" + k + str(i) + "\" {"
print " yylval->reg = new Register(Register::general, " + \
"Cpu::" + k + str(i)+ ");"
print " return REGISTER;\n}"
print " return token::REGISTER;\n}"
print """
\"$sp\" {
yylval->reg = new Register(Register::general, Cpu::sp);
return REGISTER;
return token::REGISTER;
}
\"$fp\" {
yylval->reg = new Register(Register::general, Cpu::fp);
return REGISTER;
return token::REGISTER;
}
\"$ra\" {
yylval->reg = new Register(Register::general, Cpu::ra);
return REGISTER;
return token::REGISTER;
}
\"$x\"{dec_int} {
yylval->reg = new Register(Register::unlimited, atoi(yytext +2));
return REGISTER;
return token::REGISTER;
}
{id} {
yylval->id = new misc::unique_string(yytext);
return LABEL;
return token::LABEL;
}
{id}\":\" {
yytext[yyleng - 1] = 0; // Remove last character (side-effects on yytext are allowed)
yylval->id = new misc::unique_string(yytext);
return LABEL_DEF;
return token::LABEL_DEF;
}
......@@ -170,7 +173,7 @@ print """
<< yytext << std::endl;
exit_set (exit_scan);
}
return INTEGER;
return token::INTEGER;
}
-?{hex_int} {
std::istringstream iss(yytext);
......@@ -187,30 +190,30 @@ print """
<< yytext << std::endl;
exit_set (exit_scan);
}
return INTEGER;
return token::INTEGER;
}
'\\\\a' yylval->i = '\\a'; return INTEGER;
'\\\\b' yylval->i = '\\b'; return INTEGER;
'\\\\f' yylval->i = '\\f'; return INTEGER;
'\\\\n' yylval->i = '\\n'; return INTEGER;
'\\\\r' yylval->i = '\\r'; return INTEGER;
'\\\\t' yylval->i = '\\t'; return INTEGER;
'\\\\v' yylval->i = '\\v'; return INTEGER;
'\\\\[\\\\\\']' yylval->i = yytext[1]; return INTEGER;
'\\\\a' yylval->i = '\\a'; return token::INTEGER;
'\\\\b' yylval->i = '\\b'; return token::INTEGER;
'\\\\f' yylval->i = '\\f'; return token::INTEGER;
'\\\\n' yylval->i = '\\n'; return token::INTEGER;
'\\\\r' yylval->i = '\\r'; return token::INTEGER;
'\\\\t' yylval->i = '\\t'; return token::INTEGER;
'\\\\v' yylval->i = '\\v'; return token::INTEGER;
'\\\\[\\\\\\']' yylval->i = yytext[1]; return token::INTEGER;
'\\\\.' {
std::cerr << *yylloc
<< \": unrecognized escape: \" << escape (yytext) << std::endl;
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;
<STATE_STRING>{
\\\" {
BEGIN INITIAL;
return STRING;
return token::STRING;
}
\\\\[0-7]{3} {
......@@ -256,7 +259,7 @@ print """
exit_set (exit_scan);
BEGIN INITIAL;
return STRING;
return token::STRING;
}
}
......
......@@ -17,6 +17,7 @@
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
#include "inst/program_builder.hh"
#include "parse/asm-scan.hh"
#include "parse/asm-parse.hh"
// 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