]> git.sur5r.net Git - cc65/commitdiff
Added first code for a parse tree implementation.
authorcuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Wed, 16 Aug 2000 09:10:50 +0000 (09:10 +0000)
committercuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Wed, 16 Aug 2000 09:10:50 +0000 (09:10 +0000)
git-svn-id: svn://svn.cc65.org/cc65/trunk@287 b7a2c559-68d2-44c3-8de9-860c34a00d81

src/cc65/datatype.c
src/cc65/datatype.h
src/cc65/exprnode.c [new file with mode: 0644]
src/cc65/exprnode.h [new file with mode: 0644]
src/cc65/make/gcc.mak
src/cc65/make/watcom.mak
src/cc65/scanner.c
src/cc65/scanner.h

index ba2fa33ff823d775a916537b6336e2592556c7c1..ac86cfa4963b564838862a40287c8c611c799705 100644 (file)
@@ -57,6 +57,7 @@
 
 
 /* Predefined type strings */
+type type_uchar []             = { T_UCHAR,    T_END };
 type type_int []       = { T_INT,      T_END };
 type type_uint []      = { T_UINT,     T_END };
 type type_long []      = { T_LONG,     T_END };
index a710dc9e138ae28a2d7b79a03b459929107fd16c..9224c78d82ccbedce8ef934aef7e482798967b39 100644 (file)
@@ -138,6 +138,7 @@ typedef unsigned short type;
 #define DECODE_SIZE            5
 
 /* Predefined type strings */
+extern type type_uchar [];
 extern type type_int [];
 extern type type_uint [];
 extern type type_long [];
diff --git a/src/cc65/exprnode.c b/src/cc65/exprnode.c
new file mode 100644 (file)
index 0000000..d8bc2ed
--- /dev/null
@@ -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;
+}
+
+
+
diff --git a/src/cc65/exprnode.h b/src/cc65/exprnode.h
new file mode 100644 (file)
index 0000000..969ee75
--- /dev/null
@@ -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
+
+
+
+
+
index cc6f8b086d06edfa1f89e525505aa6e2e5cb55cd..314d7415b945f9396176e09592c1835b0e670dd2 100644 (file)
@@ -24,6 +24,8 @@ OBJS =        anonname.o      \
        declare.o       \
        error.o         \
        expr.o          \
+       exprnode.o      \
+       exprtree.o      \
        funcdesc.o      \
        function.o      \
        global.o        \
@@ -68,7 +70,7 @@ cc65: $(OBJS)
 
 clean:
        rm -f *~ core *.map
-
+                        
 zap:   clean
        rm -f *.o $(EXECS) .depend
 
index 000f33a4bef1a64301b0a608f85b9073bcd16f06..2e7b041798272d3ba3afbd4c2a8f69a925359fb1 100644 (file)
@@ -79,6 +79,8 @@ OBJS =        anonname.obj    \
        declare.obj     \
        error.obj       \
        expr.obj        \
+       exprnode.obj    \
+       exprtree.obj    \
        funcdesc.obj    \
        function.obj    \
        global.obj      \
@@ -136,6 +138,8 @@ FILE datatype.obj
 FILE declare.obj
 FILE error.obj
 FILE expr.obj
+FILE exprnode.obj
+FILE exprtree.obj
 FILE funcdesc.obj
 FILE function.obj
 FILE global.obj
index 95d01b39ff38e30b71c79a87040cb1cf85b538be..c981ad9f89d123ed0517d492c4e3bd0ed4a38553 100644 (file)
@@ -48,8 +48,11 @@ static const struct Keyword {
     unsigned char   Tok;       /* The token */
     unsigned char   Type;              /* Token type */
 } Keywords [] = {
+    { "__A__",         TOK_A,          TT_C    },
     { "__AX__",                TOK_AX,         TT_C    },
     { "__EAX__",               TOK_EAX,        TT_C    },
+    { "__X__",                 TOK_X,          TT_C    },
+    { "__Y__",                 TOK_Y,          TT_C    },
     { "__asm__",               TOK_ASM,        TT_C    },
     { "__attribute__", TOK_ATTRIBUTE,  TT_C    },
     { "__far__",       TOK_FAR,        TT_C    },
index a707e4d1492364d31ce4534c221eb2bf147cd995..db10cb9b909b1f39c7e1ee636d4db6d4354812e6 100644 (file)
@@ -127,9 +127,12 @@ typedef enum token_t {
     TOK_ATTRIBUTE,
     TOK_FAR,
     TOK_FASTCALL,
+    TOK_A,
+    TOK_X,
+    TOK_Y,       
     TOK_AX,
     TOK_EAX,
-           
+
     TOK_PRAGMA
 } token_t;