Add := assignment op, define some currently unused keywords

git-svn-id: svn://svn.cc65.org/cc65/trunk@2542 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz
2003-10-17 00:38:21 +00:00
parent 3085e7583e
commit c12c231f14
6 changed files with 94 additions and 47 deletions

View File

@@ -183,7 +183,7 @@ static void DefineSymbol (const char* Def)
} }
/* Define the symbol */ /* Define the symbol */
SymDef (SymName, GenLiteralExpr (Val), 0, 0); SymDef (SymName, GenLiteralExpr (Val), SYM_DEFAULT);
} }
@@ -373,16 +373,20 @@ static void OneLine (void)
/* If a colon follows, this is a label definition. If there /* If a colon follows, this is a label definition. If there
* is no colon, it's an assignment. * is no colon, it's an assignment.
*/ */
if (Tok == TOK_EQ) { if (Tok == TOK_EQ || Tok == TOK_ASSIGN) {
/* If it's an assign token, we have a label */
unsigned Flags = (Tok == TOK_ASSIGN)? SYM_LABEL : SYM_DEFAULT;
/* Skip the '=' */ /* Skip the '=' */
NextTok (); NextTok ();
/* Define the symbol with the expression following the '=' */ /* Define the symbol with the expression following the '=' */
SymDef (Ident, Expression(), 0, 0); SymDef (Ident, Expression(), Flags);
/* Don't allow anything after a symbol definition */ /* Don't allow anything after a symbol definition */
Done = 1; Done = 1;
} else { } else {
/* Define the symbol flags */
unsigned Flags = IsZPSeg ()? SYM_ZP | SYM_LABEL : SYM_LABEL;
/* Define a label */ /* Define a label */
SymDef (Ident, GenCurrentPC(), IsZPSeg(), 1); SymDef (Ident, GenCurrentPC (), Flags);
/* Skip the colon. If NoColonLabels is enabled, allow labels /* Skip the colon. If NoColonLabels is enabled, allow labels
* without a colon if there is no whitespace before the * without a colon if there is no whitespace before the
* identifier. * identifier.

View File

@@ -1243,7 +1243,11 @@ static void DoProc (void)
{ {
if (Tok == TOK_IDENT) { if (Tok == TOK_IDENT) {
/* The new scope has a name */ /* The new scope has a name */
SymDef (SVal, GenCurrentPC (), IsZPSeg (), 1); unsigned Flags = SYM_LABEL;
if (IsZPSeg ()) {
Flags |= SYM_ZP;
}
SymDef (SVal, GenCurrentPC (), Flags);
NextTok (); NextTok ();
} }
SymEnterLevel (); SymEnterLevel ();
@@ -1418,6 +1422,14 @@ static void DoSmart (void)
static void DoStruct (void)
/* Struct definition */
{
Error (ERR_NOT_IMPLEMENTED);
}
static void DoSunPlus (void) static void DoSunPlus (void)
/* Switch to the SUNPLUS CPU */ /* Switch to the SUNPLUS CPU */
{ {
@@ -1426,6 +1438,14 @@ static void DoSunPlus (void)
static void DoUnion (void)
/* Union definition */
{
Error (ERR_NOT_IMPLEMENTED);
}
static void DoUnexpected (void) static void DoUnexpected (void)
/* Got an unexpected keyword */ /* Got an unexpected keyword */
{ {
@@ -1525,6 +1545,7 @@ static CtrlDesc CtrlCmdTab [] = {
{ ccNone, DoUnexpected }, /* .ENDMACRO */ { ccNone, DoUnexpected }, /* .ENDMACRO */
{ ccNone, DoEndProc }, { ccNone, DoEndProc },
{ ccNone, DoUnexpected }, /* .ENDREPEAT */ { ccNone, DoUnexpected }, /* .ENDREPEAT */
{ ccNone, DoUnexpected }, /* .ENDSTRUCT */
{ ccNone, DoError }, { ccNone, DoError },
{ ccNone, DoExitMacro }, { ccNone, DoExitMacro },
{ ccNone, DoExport }, { ccNone, DoExport },
@@ -1589,9 +1610,12 @@ static CtrlDesc CtrlCmdTab [] = {
{ ccNone, DoUnexpected }, /* .STRAT */ { ccNone, DoUnexpected }, /* .STRAT */
{ ccNone, DoUnexpected }, /* .STRING */ { ccNone, DoUnexpected }, /* .STRING */
{ ccNone, DoUnexpected }, /* .STRLEN */ { ccNone, DoUnexpected }, /* .STRLEN */
{ ccNone, DoStruct },
{ ccNone, DoSunPlus }, { ccNone, DoSunPlus },
{ ccNone, DoUnexpected }, /* .TAG */
{ ccNone, DoUnexpected }, /* .TCOUNT */ { ccNone, DoUnexpected }, /* .TCOUNT */
{ ccNone, DoUnexpected }, /* .TIME */ { ccNone, DoUnexpected }, /* .TIME */
{ ccNone, DoUnion },
{ ccNone, DoUnexpected }, /* .VERSION */ { ccNone, DoUnexpected }, /* .VERSION */
{ ccNone, DoWarning }, { ccNone, DoWarning },
{ ccNone, DoWord }, { ccNone, DoWord },

View File

@@ -159,6 +159,7 @@ struct DotKeyword {
{ ".ENDPROC", TOK_ENDPROC }, { ".ENDPROC", TOK_ENDPROC },
{ ".ENDREP", TOK_ENDREP }, { ".ENDREP", TOK_ENDREP },
{ ".ENDREPEAT", TOK_ENDREP }, { ".ENDREPEAT", TOK_ENDREP },
{ ".ENDSTRUCT", TOK_ENDSTRUCT },
{ ".ERROR", TOK_ERROR }, { ".ERROR", TOK_ERROR },
{ ".EXITMAC", TOK_EXITMACRO }, { ".EXITMAC", TOK_EXITMACRO },
{ ".EXITMACRO", TOK_EXITMACRO }, { ".EXITMACRO", TOK_EXITMACRO },
@@ -233,9 +234,12 @@ struct DotKeyword {
{ ".STRAT", TOK_STRAT }, { ".STRAT", TOK_STRAT },
{ ".STRING", TOK_STRING }, { ".STRING", TOK_STRING },
{ ".STRLEN", TOK_STRLEN }, { ".STRLEN", TOK_STRLEN },
{ ".STRUCT", TOK_STRUCT },
{ ".SUNPLUS", TOK_SUNPLUS }, { ".SUNPLUS", TOK_SUNPLUS },
{ ".TAG", TOK_TAG },
{ ".TCOUNT", TOK_TCOUNT }, { ".TCOUNT", TOK_TCOUNT },
{ ".TIME", TOK_TIME }, { ".TIME", TOK_TIME },
{ ".UNION", TOK_UNION },
{ ".VERSION", TOK_VERSION }, { ".VERSION", TOK_VERSION },
{ ".WARNING", TOK_WARNING }, { ".WARNING", TOK_WARNING },
{ ".WORD", TOK_WORD }, { ".WORD", TOK_WORD },
@@ -911,6 +915,11 @@ CharAgain:
Tok = TOK_ULABEL; Tok = TOK_ULABEL;
break; break;
case '=':
NextChar ();
Tok = TOK_ASSIGN;
break;
default: default:
Tok = TOK_COLON; Tok = TOK_COLON;
break; break;

View File

@@ -67,6 +67,7 @@ enum Token {
TOK_Y, /* Y register */ TOK_Y, /* Y register */
TOK_S, /* S register */ TOK_S, /* S register */
TOK_ASSIGN, /* := */
TOK_ULABEL, /* :++ or :-- */ TOK_ULABEL, /* :++ or :-- */
TOK_EQ, /* = */ TOK_EQ, /* = */
@@ -147,6 +148,7 @@ enum Token {
TOK_ENDMACRO, TOK_ENDMACRO,
TOK_ENDPROC, TOK_ENDPROC,
TOK_ENDREP, TOK_ENDREP,
TOK_ENDSTRUCT,
TOK_ERROR, TOK_ERROR,
TOK_EXITMACRO, TOK_EXITMACRO,
TOK_EXPORT, TOK_EXPORT,
@@ -211,9 +213,12 @@ enum Token {
TOK_STRAT, TOK_STRAT,
TOK_STRING, TOK_STRING,
TOK_STRLEN, TOK_STRLEN,
TOK_STRUCT,
TOK_SUNPLUS, TOK_SUNPLUS,
TOK_TAG,
TOK_TCOUNT, TOK_TCOUNT,
TOK_TIME, TOK_TIME,
TOK_UNION,
TOK_VERSION, TOK_VERSION,
TOK_WARNING, TOK_WARNING,
TOK_WORD, TOK_WORD,

View File

@@ -394,7 +394,7 @@ int SymIsLocalLevel (void)
void SymDef (const char* Name, ExprNode* Expr, int ZP, int Label) void SymDef (const char* Name, ExprNode* Expr, unsigned Flags)
/* Define a new symbol */ /* Define a new symbol */
{ {
/* Do we have such a symbol? */ /* Do we have such a symbol? */
@@ -422,10 +422,10 @@ void SymDef (const char* Name, ExprNode* Expr, int ZP, int Label)
S->V.Expr = Expr; S->V.Expr = Expr;
} }
S->Flags |= SF_DEFINED; S->Flags |= SF_DEFINED;
if (ZP) { if (Flags & SYM_ZP) {
S->Flags |= SF_ZP; S->Flags |= SF_ZP;
} }
if (Label) { if (Flags & SYM_LABEL) {
S->Flags |= SF_LABEL; S->Flags |= SF_LABEL;
} }

View File

@@ -59,6 +59,11 @@
#define SCOPE_GLOBAL 1 #define SCOPE_GLOBAL 1
#define SCOPE_LOCAL 2 #define SCOPE_LOCAL 2
/* Flags used in SymDef */
#define SYM_DEFAULT 0x00
#define SYM_ZP 0x01
#define SYM_LABEL 0x02
/*****************************************************************************/ /*****************************************************************************/
@@ -76,7 +81,7 @@ void SymLeaveLevel (void);
int SymIsLocalLevel (void); int SymIsLocalLevel (void);
/* Return true if we are on a local symbol table level. */ /* Return true if we are on a local symbol table level. */
void SymDef (const char* Name, ExprNode* Expr, int ZP, int Label); void SymDef (const char* Name, ExprNode* Expr, unsigned Flags);
/* Define a new symbol */ /* Define a new symbol */
SymEntry* SymRef (const char* Name, int Scope); SymEntry* SymRef (const char* Name, int Scope);