Added first code for a parse tree implementation.
git-svn-id: svn://svn.cc65.org/cc65/trunk@287 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
@@ -57,6 +57,7 @@
|
|||||||
|
|
||||||
|
|
||||||
/* Predefined type strings */
|
/* Predefined type strings */
|
||||||
|
type type_uchar [] = { T_UCHAR, T_END };
|
||||||
type type_int [] = { T_INT, T_END };
|
type type_int [] = { T_INT, T_END };
|
||||||
type type_uint [] = { T_UINT, T_END };
|
type type_uint [] = { T_UINT, T_END };
|
||||||
type type_long [] = { T_LONG, T_END };
|
type type_long [] = { T_LONG, T_END };
|
||||||
|
|||||||
@@ -138,6 +138,7 @@ typedef unsigned short type;
|
|||||||
#define DECODE_SIZE 5
|
#define DECODE_SIZE 5
|
||||||
|
|
||||||
/* Predefined type strings */
|
/* Predefined type strings */
|
||||||
|
extern type type_uchar [];
|
||||||
extern type type_int [];
|
extern type type_int [];
|
||||||
extern type type_uint [];
|
extern type type_uint [];
|
||||||
extern type type_long [];
|
extern type type_long [];
|
||||||
|
|||||||
57
src/cc65/exprnode.c
Normal file
57
src/cc65/exprnode.c
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
/*****************************************************************************/
|
||||||
|
/* */
|
||||||
|
/* exprnode.c */
|
||||||
|
/* */
|
||||||
|
/* Expression node structure for the cc65 C compiler */
|
||||||
|
/* */
|
||||||
|
/* */
|
||||||
|
/* */
|
||||||
|
/* (C) 2000 Ullrich von Bassewitz */
|
||||||
|
/* Wacholderweg 14 */
|
||||||
|
/* D-70597 Stuttgart */
|
||||||
|
/* EMail: uz@musoftware.de */
|
||||||
|
/* */
|
||||||
|
/* */
|
||||||
|
/* This software is provided 'as-is', without any expressed or implied */
|
||||||
|
/* warranty. In no event will the authors be held liable for any damages */
|
||||||
|
/* arising from the use of this software. */
|
||||||
|
/* */
|
||||||
|
/* Permission is granted to anyone to use this software for any purpose, */
|
||||||
|
/* including commercial applications, and to alter it and redistribute it */
|
||||||
|
/* freely, subject to the following restrictions: */
|
||||||
|
/* */
|
||||||
|
/* 1. The origin of this software must not be misrepresented; you must not */
|
||||||
|
/* claim that you wrote the original software. If you use this software */
|
||||||
|
/* in a product, an acknowledgment in the product documentation would be */
|
||||||
|
/* appreciated but is not required. */
|
||||||
|
/* 2. Altered source versions must be plainly marked as such, and must not */
|
||||||
|
/* be misrepresented as being the original software. */
|
||||||
|
/* 3. This notice may not be removed or altered from any source */
|
||||||
|
/* distribution. */
|
||||||
|
/* */
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include "exprnode.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* Code */
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void InitExprNode (ExprNode* E)
|
||||||
|
/* Initialize a new expression node */
|
||||||
|
{
|
||||||
|
E->Left = 0;
|
||||||
|
E->Right = 0;
|
||||||
|
E->NT = NT_NONE;
|
||||||
|
E->Type = 0;
|
||||||
|
E->LValue = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
169
src/cc65/exprnode.h
Normal file
169
src/cc65/exprnode.h
Normal file
@@ -0,0 +1,169 @@
|
|||||||
|
/*****************************************************************************/
|
||||||
|
/* */
|
||||||
|
/* exprnode.h */
|
||||||
|
/* */
|
||||||
|
/* Expression node structure for the cc65 C compiler */
|
||||||
|
/* */
|
||||||
|
/* */
|
||||||
|
/* */
|
||||||
|
/* (C) 2000 Ullrich von Bassewitz */
|
||||||
|
/* Wacholderweg 14 */
|
||||||
|
/* D-70597 Stuttgart */
|
||||||
|
/* EMail: uz@musoftware.de */
|
||||||
|
/* */
|
||||||
|
/* */
|
||||||
|
/* This software is provided 'as-is', without any expressed or implied */
|
||||||
|
/* warranty. In no event will the authors be held liable for any damages */
|
||||||
|
/* arising from the use of this software. */
|
||||||
|
/* */
|
||||||
|
/* Permission is granted to anyone to use this software for any purpose, */
|
||||||
|
/* including commercial applications, and to alter it and redistribute it */
|
||||||
|
/* freely, subject to the following restrictions: */
|
||||||
|
/* */
|
||||||
|
/* 1. The origin of this software must not be misrepresented; you must not */
|
||||||
|
/* claim that you wrote the original software. If you use this software */
|
||||||
|
/* in a product, an acknowledgment in the product documentation would be */
|
||||||
|
/* appreciated but is not required. */
|
||||||
|
/* 2. Altered source versions must be plainly marked as such, and must not */
|
||||||
|
/* be misrepresented as being the original software. */
|
||||||
|
/* 3. This notice may not be removed or altered from any source */
|
||||||
|
/* distribution. */
|
||||||
|
/* */
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef EXPRNODE_H
|
||||||
|
#define EXPRNODE_H
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include "datatype.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* Forwards */
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
struct SymEntry;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* Data */
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Node types */
|
||||||
|
typedef enum {
|
||||||
|
NT_NONE, /* None (invalid) op */
|
||||||
|
|
||||||
|
NT_SYM, /* Symbol */
|
||||||
|
NT_CONST, /* A constant of some sort */
|
||||||
|
|
||||||
|
NT_ICAST, /* Implicit type cast */
|
||||||
|
NT_ECAST, /* Explicit type cast */
|
||||||
|
|
||||||
|
NT_REG_A, /* A register */
|
||||||
|
NT_REG_X, /* X register */
|
||||||
|
NT_REG_Y, /* Y register */
|
||||||
|
NT_REG_AX, /* AX register */
|
||||||
|
NT_REG_EAX, /* EAX register */
|
||||||
|
|
||||||
|
NT_CALLFUNC, /* Function call */
|
||||||
|
NT_PUSH, /* Push the value onto the stack */
|
||||||
|
NT_POP, /* Pop the value from the stack */
|
||||||
|
|
||||||
|
NT_NOT, /* ~ */
|
||||||
|
NT_PLUS, /* + */
|
||||||
|
NT_MINUS, /* - */
|
||||||
|
NT_MUL, /* * */
|
||||||
|
NT_DIV, /* / */
|
||||||
|
NT_SHL, /* << */
|
||||||
|
NT_SHR, /* >> */
|
||||||
|
NT_AND, /* & */
|
||||||
|
NT_OR, /* | */
|
||||||
|
NT_XOR, /* ^ */
|
||||||
|
|
||||||
|
NT_ASSIGN, /* = */
|
||||||
|
NT_PLUS_ASSIGN, /* += */
|
||||||
|
NT_MINUS_ASSIGN, /* -= */
|
||||||
|
NT_MUL_ASSIGN, /* *= */
|
||||||
|
NT_DIV_ASSIGN, /* /= */
|
||||||
|
NT_SHL_ASSIGN, /* <<= */
|
||||||
|
NT_SHR_ASSIGN, /* >>= */
|
||||||
|
NT_AND_ASSIGN, /* &= */
|
||||||
|
NT_OR_ASSIGN, /* |= */
|
||||||
|
NT_XOR_ASSIGN, /* ^= */
|
||||||
|
|
||||||
|
NT_PRE_DEC, /* -- */
|
||||||
|
NT_POST_DEC, /* -- */
|
||||||
|
NT_PRE_INC, /* ++ */
|
||||||
|
NT_POST_INC, /* ++ */
|
||||||
|
|
||||||
|
NT_BOOL_NOT, /* ! */
|
||||||
|
NT_BOOL_OR, /* || */
|
||||||
|
NT_BOOL_AND, /* && */
|
||||||
|
|
||||||
|
NT_EQ, /* == */
|
||||||
|
NT_NE, /* != */
|
||||||
|
NT_LT, /* < */
|
||||||
|
NT_LE, /* <= */
|
||||||
|
NT_GT, /* > */
|
||||||
|
NT_GE, /* >= */
|
||||||
|
|
||||||
|
NT_DEREF, /* * and others */
|
||||||
|
|
||||||
|
NT_COUNT /* Operation count */
|
||||||
|
} nodetype_t;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Struct describing one node in an expression tree */
|
||||||
|
typedef struct ExprNode ExprNode;
|
||||||
|
struct ExprNode {
|
||||||
|
|
||||||
|
ExprNode* Left; /* Left and right leaves */
|
||||||
|
ExprNode* Right;
|
||||||
|
|
||||||
|
nodetype_t NT; /* Node type */
|
||||||
|
type* Type; /* Resulting type */
|
||||||
|
int LValue; /* True if this is an lvalue */
|
||||||
|
|
||||||
|
union {
|
||||||
|
/* Branch data */
|
||||||
|
ExprNode* Test; /* Third expr for ternary op */
|
||||||
|
|
||||||
|
/* Leave data */
|
||||||
|
long I; /* Constant int value if any */
|
||||||
|
double F; /* Constant float value if any */
|
||||||
|
struct SymEntry* Sym; /* Symbol table entry if any */
|
||||||
|
} V;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* Code */
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void InitExprNode (ExprNode* E);
|
||||||
|
/* Initialize a new expression node */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* End of exprnode.h */
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -24,6 +24,8 @@ OBJS = anonname.o \
|
|||||||
declare.o \
|
declare.o \
|
||||||
error.o \
|
error.o \
|
||||||
expr.o \
|
expr.o \
|
||||||
|
exprnode.o \
|
||||||
|
exprtree.o \
|
||||||
funcdesc.o \
|
funcdesc.o \
|
||||||
function.o \
|
function.o \
|
||||||
global.o \
|
global.o \
|
||||||
@@ -68,7 +70,7 @@ cc65: $(OBJS)
|
|||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f *~ core *.map
|
rm -f *~ core *.map
|
||||||
|
|
||||||
zap: clean
|
zap: clean
|
||||||
rm -f *.o $(EXECS) .depend
|
rm -f *.o $(EXECS) .depend
|
||||||
|
|
||||||
|
|||||||
@@ -79,6 +79,8 @@ OBJS = anonname.obj \
|
|||||||
declare.obj \
|
declare.obj \
|
||||||
error.obj \
|
error.obj \
|
||||||
expr.obj \
|
expr.obj \
|
||||||
|
exprnode.obj \
|
||||||
|
exprtree.obj \
|
||||||
funcdesc.obj \
|
funcdesc.obj \
|
||||||
function.obj \
|
function.obj \
|
||||||
global.obj \
|
global.obj \
|
||||||
@@ -136,6 +138,8 @@ FILE datatype.obj
|
|||||||
FILE declare.obj
|
FILE declare.obj
|
||||||
FILE error.obj
|
FILE error.obj
|
||||||
FILE expr.obj
|
FILE expr.obj
|
||||||
|
FILE exprnode.obj
|
||||||
|
FILE exprtree.obj
|
||||||
FILE funcdesc.obj
|
FILE funcdesc.obj
|
||||||
FILE function.obj
|
FILE function.obj
|
||||||
FILE global.obj
|
FILE global.obj
|
||||||
|
|||||||
@@ -48,8 +48,11 @@ static const struct Keyword {
|
|||||||
unsigned char Tok; /* The token */
|
unsigned char Tok; /* The token */
|
||||||
unsigned char Type; /* Token type */
|
unsigned char Type; /* Token type */
|
||||||
} Keywords [] = {
|
} Keywords [] = {
|
||||||
|
{ "__A__", TOK_A, TT_C },
|
||||||
{ "__AX__", TOK_AX, TT_C },
|
{ "__AX__", TOK_AX, TT_C },
|
||||||
{ "__EAX__", TOK_EAX, TT_C },
|
{ "__EAX__", TOK_EAX, TT_C },
|
||||||
|
{ "__X__", TOK_X, TT_C },
|
||||||
|
{ "__Y__", TOK_Y, TT_C },
|
||||||
{ "__asm__", TOK_ASM, TT_C },
|
{ "__asm__", TOK_ASM, TT_C },
|
||||||
{ "__attribute__", TOK_ATTRIBUTE, TT_C },
|
{ "__attribute__", TOK_ATTRIBUTE, TT_C },
|
||||||
{ "__far__", TOK_FAR, TT_C },
|
{ "__far__", TOK_FAR, TT_C },
|
||||||
|
|||||||
@@ -127,9 +127,12 @@ typedef enum token_t {
|
|||||||
TOK_ATTRIBUTE,
|
TOK_ATTRIBUTE,
|
||||||
TOK_FAR,
|
TOK_FAR,
|
||||||
TOK_FASTCALL,
|
TOK_FASTCALL,
|
||||||
|
TOK_A,
|
||||||
|
TOK_X,
|
||||||
|
TOK_Y,
|
||||||
TOK_AX,
|
TOK_AX,
|
||||||
TOK_EAX,
|
TOK_EAX,
|
||||||
|
|
||||||
TOK_PRAGMA
|
TOK_PRAGMA
|
||||||
} token_t;
|
} token_t;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user