beebasm
changeset 45:89a6ac2de2e9 v1.07
Fixed mixed-case bug for keywords (so now oddities such as INy are parsed correctly).
Now function keywords require an open bracket immediately afterwards (which now means that symbol names such as HIGHSCORE, which start with the keyword HI, are valid).
| author | RichTW <richtw1@gmail.com> |
|---|---|
| date | Thu Oct 06 18:15:30 2011 +0200 |
| parents | 1602b5d50bb2 |
| children | 0824f1c0ceaa |
| files | beebasm.exe demo.ssd src/assemble.cpp src/commands.cpp src/expression.cpp src/main.cpp |
| diffstat | 6 files changed, 71 insertions(+), 40 deletions(-) [+] |
line diff
1.1 Binary file beebasm.exe has changed
2.1 Binary file demo.ssd has changed
3.1 --- a/src/assemble.cpp Thu Jun 23 11:33:32 2011 +0200 3.2 +++ b/src/assemble.cpp Thu Oct 06 18:15:30 2011 +0200 3.3 @@ -143,19 +143,19 @@ 3.4 if ( cpu > ObjectCode::Instance().GetCPU() ) 3.5 continue; 3.6 3.7 - // create lower-case version of token 3.8 + // see if token matches 3.9 3.10 - char tokenLC[ 16 ]; 3.11 - 3.12 - for ( size_t j = 0; j <= len; j++ ) 3.13 + bool bMatch = true; 3.14 + for ( unsigned int j = 0; j < len; j++ ) 3.15 { 3.16 - tokenLC[ j ] = tolower( token[ j ] ); 3.17 + if ( token[ j ] != toupper( m_line[ m_column + j ] ) ) 3.18 + { 3.19 + bMatch = false; 3.20 + break; 3.21 + } 3.22 } 3.23 3.24 - // see if token matches 3.25 - 3.26 - if ( m_line.compare( m_column, len, token ) == 0 || 3.27 - m_line.compare( m_column, len, tokenLC ) == 0 ) 3.28 + if ( bMatch ) 3.29 { 3.30 m_column += len; 3.31 return i;
4.1 --- a/src/commands.cpp Thu Jun 23 11:33:32 2011 +0200 4.2 +++ b/src/commands.cpp Thu Oct 06 18:15:30 2011 +0200 4.3 @@ -100,19 +100,19 @@ 4.4 const char* token = m_gaTokenTable[ i ].m_pName; 4.5 size_t len = strlen( token ); 4.6 4.7 - // create lower-case version of token 4.8 + // see if token matches 4.9 4.10 - char tokenLC[ 16 ]; 4.11 - 4.12 - for ( size_t j = 0; j <= len; j++ ) 4.13 + bool bMatch = true; 4.14 + for ( unsigned int j = 0; j < len; j++ ) 4.15 { 4.16 - tokenLC[ j ] = tolower( token[ j ] ); 4.17 + if ( token[ j ] != toupper( m_line[ m_column + j ] ) ) 4.18 + { 4.19 + bMatch = false; 4.20 + break; 4.21 + } 4.22 } 4.23 4.24 - // see if token matches 4.25 - 4.26 - if ( m_line.compare( m_column, len, token ) == 0 || 4.27 - m_line.compare( m_column, len, tokenLC ) == 0 ) 4.28 + if ( bMatch ) 4.29 { 4.30 m_column += len; 4.31 return i;
5.1 --- a/src/expression.cpp Thu Jun 23 11:33:32 2011 +0200 5.2 +++ b/src/expression.cpp Thu Oct 06 18:15:30 2011 +0200 5.3 @@ -78,27 +78,27 @@ 5.4 5.5 { "-", 8, &LineParser::EvalNegate }, 5.6 { "+", 8, &LineParser::EvalPosate }, 5.7 - { "HI", 10, &LineParser::EvalHi }, 5.8 - { "LO", 10, &LineParser::EvalLo }, 5.9 + { "HI(", 10, &LineParser::EvalHi }, 5.10 + { "LO(", 10, &LineParser::EvalLo }, 5.11 { ">", 10, &LineParser::EvalHi }, 5.12 { "<", 10, &LineParser::EvalLo }, 5.13 - { "SIN", 10, &LineParser::EvalSin }, 5.14 - { "COS", 10, &LineParser::EvalCos }, 5.15 - { "TAN", 10, &LineParser::EvalTan }, 5.16 - { "ASN", 10, &LineParser::EvalArcSin }, 5.17 - { "ACS", 10, &LineParser::EvalArcCos }, 5.18 - { "ATN", 10, &LineParser::EvalArcTan }, 5.19 - { "SQR", 10, &LineParser::EvalSqrt }, 5.20 - { "RAD", 10, &LineParser::EvalDegToRad }, 5.21 - { "DEG", 10, &LineParser::EvalRadToDeg }, 5.22 - { "INT", 10, &LineParser::EvalInt }, 5.23 - { "ABS", 10, &LineParser::EvalAbs }, 5.24 - { "SGN", 10, &LineParser::EvalSgn }, 5.25 - { "RND", 10, &LineParser::EvalRnd }, 5.26 - { "NOT", 10, &LineParser::EvalNot }, 5.27 - { "LOG", 10, &LineParser::EvalLog }, 5.28 - { "LN", 10, &LineParser::EvalLn }, 5.29 - { "EXP", 10, &LineParser::EvalExp } 5.30 + { "SIN(", 10, &LineParser::EvalSin }, 5.31 + { "COS(", 10, &LineParser::EvalCos }, 5.32 + { "TAN(", 10, &LineParser::EvalTan }, 5.33 + { "ASN(", 10, &LineParser::EvalArcSin }, 5.34 + { "ACS(", 10, &LineParser::EvalArcCos }, 5.35 + { "ATN(", 10, &LineParser::EvalArcTan }, 5.36 + { "SQR(", 10, &LineParser::EvalSqrt }, 5.37 + { "RAD(", 10, &LineParser::EvalDegToRad }, 5.38 + { "DEG(", 10, &LineParser::EvalRadToDeg }, 5.39 + { "INT(", 10, &LineParser::EvalInt }, 5.40 + { "ABS(", 10, &LineParser::EvalAbs }, 5.41 + { "SGN(", 10, &LineParser::EvalSgn }, 5.42 + { "RND(", 10, &LineParser::EvalRnd }, 5.43 + { "NOT(", 10, &LineParser::EvalNot }, 5.44 + { "LOG(", 10, &LineParser::EvalLog }, 5.45 + { "LN(", 10, &LineParser::EvalLn }, 5.46 + { "EXP(", 10, &LineParser::EvalExp } 5.47 }; 5.48 5.49 5.50 @@ -277,10 +277,31 @@ 5.51 5.52 // see if token matches 5.53 5.54 - if ( m_line.compare( m_column, len, token ) == 0 ) 5.55 + bool bMatch = true; 5.56 + for ( unsigned int j = 0; j < len; j++ ) 5.57 + { 5.58 + if ( token[ j ] != toupper( m_line[ m_column + j ] ) ) 5.59 + { 5.60 + bMatch = false; 5.61 + break; 5.62 + } 5.63 + } 5.64 + 5.65 + // it matches; advance line pointer and remember token 5.66 + 5.67 + if ( bMatch ) 5.68 { 5.69 matchedToken = i; 5.70 m_column += len; 5.71 + 5.72 + // if token ends with (but is not) an open bracket, step backwards one place so that we parse it next time 5.73 + 5.74 + if ( len > 1 && token[ len - 1 ] == '(' ) 5.75 + { 5.76 + m_column--; 5.77 + assert( m_line[ m_column ] == '(' ); 5.78 + } 5.79 + 5.80 break; 5.81 } 5.82 } 5.83 @@ -367,7 +388,17 @@ 5.84 5.85 // see if token matches 5.86 5.87 - if ( m_line.compare( m_column, len, token ) == 0 ) 5.88 + bool bMatch = true; 5.89 + for ( unsigned int j = 0; j < len; j++ ) 5.90 + { 5.91 + if ( token[ j ] != toupper( m_line[ m_column + j ] ) ) 5.92 + { 5.93 + bMatch = false; 5.94 + break; 5.95 + } 5.96 + } 5.97 + 5.98 + if ( bMatch ) 5.99 { 5.100 matchedToken = i; 5.101 m_column += len;
6.1 --- a/src/main.cpp Thu Jun 23 11:33:32 2011 +0200 6.2 +++ b/src/main.cpp Thu Oct 06 18:15:30 2011 +0200 6.3 @@ -41,7 +41,7 @@ 6.4 using namespace std; 6.5 6.6 6.7 -#define VERSION "1.06" 6.8 +#define VERSION "1.07" 6.9 6.10 6.11 /*************************************************************************************************/
