//! Always executed before all other actions when a token is matched.
//! This action just assign the first and last lines of the token to
//! the current line. In most cases this is correct.
#define YY_USER_ACTION do { \
m_location.m_firstLine = m_line; \
m_location.m_lastLine = m_line; \
} while (0);
[whb]/[^a-zA-Z_0-9] { // must be followed by any non-ident char
int_size_t theSize;
switch (yytext[0])
{
case 'w':
theSize = kWordSize;
break;
case 'h':
theSize = kHalfWordSize;
break;
case 'b':
theSize = kByteSize;
break;
}
m_symbolValue.m_int = new elftosb::SizedIntegerValue(0, theSize);
return TOK_INT_SIZE;
}
true|yes {
m_symbolValue.m_int = new elftosb::SizedIntegerValue(1, kWordSize);
return TOK_INT_LITERAL;
}
false|no {
m_symbolValue.m_int = new elftosb::SizedIntegerValue(0, kWordSize);
return TOK_INT_LITERAL;
}
{IDENT} {
m_symbolValue.m_str = new std::string(yytext);
if (isSourceName(m_symbolValue.m_str))
{
return TOK_SOURCE_NAME;
}
else
{
return TOK_IDENT;
}
}
({DIGIT}+|0x{HEXDIGIT}+|0b{BINDIGIT}+)([ \t]*[GMK])? {
int base = 0;
uint32_t value;
int mult;
// check for binary number
if (yytext[0] == '0' && yytext[1] == 'b')
{
base = 2; // this is a binary number
yytext += 2; // skip over the "0b"
}
// convert value
value = (uint32_t)strtoul(yytext, NULL, base);
// find multiplier
switch (yytext[strlen(yytext) - 1])
{
case 'G':
mult = 1024 * 1024 * 1024;
break;
case 'M':
mult = 1024 * 1024;
break;
case 'K':
mult = 1024;
break;
default:
mult = 1;
break;
}
// set resulting symbol value
m_symbolValue.m_int = new elftosb::SizedIntegerValue(value * mult, kWordSize);
return TOK_INT_LITERAL;
}
\'(.|ESC)\'|\'(.|ESC){2}\'|\'(.|ESC){4}\' {
uint32_t value = 0;
int_size_t theSize;
int len = strlen(yytext);
if (len >= 3)
{
value = yytext[1];
theSize = kByteSize;
}
if (len >= 4)
{
value = (value << 8) | yytext[2];
theSize = kHalfWordSize;
}
if (len >= 6)
{
value = (value << 8) | yytext[3];
value = (value << 8) | yytext[4];
theSize = kWordSize;
}
m_symbolValue.m_int = new elftosb::SizedIntegerValue(value, theSize);
return TOK_INT_LITERAL;
}
\$[\.\*a-zA-Z0-9_\[\]\^\?\-]+ {
// remove $ from string
m_symbolValue.m_str = new std::string(&yytext[1]);
return TOK_SECTION_NAME;
}