summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2021-08-15 16:05:11 +0000
committerAndreas Baumann <mail@andreasbaumann.cc>2021-08-15 16:05:11 +0000
commit5dc6889265cb5f0c385778f075279ed8012023a0 (patch)
tree946aba2be38bc73ee3f0fa3750ee8dc2815a4d74
parent9ba1bb3d2007b37e3392208ef027f88d78e51c3e (diff)
downloadcompilertests-5dc6889265cb5f0c385778f075279ed8012023a0.tar.gz
compilertests-5dc6889265cb5f0c385778f075279ed8012023a0.tar.bz2
added NULL and EOF (-1 as emum initialized in c4)
-rw-r--r--miniany/c4.c10
-rw-r--r--miniany/cc.c16
-rw-r--r--miniany/libc-freestanding.c7
-rw-r--r--miniany/test1.c6
4 files changed, 29 insertions, 10 deletions
diff --git a/miniany/c4.c b/miniany/c4.c
index a6d24d3..a36fb4a 100644
--- a/miniany/c4.c
+++ b/miniany/c4.c
@@ -357,7 +357,7 @@ int main(int argc, char **argv)
{
int fd, bt, ty, poolsz, *idmain;
int *pc, *sp, *bp, a, cycle; // vm registers
- int i, *t; // temps
+ int i, *t, neg; // temps
--argc; ++argv;
if (argc > 0 && **argv == '-' && (*argv)[1] == 's') { src = 1; --argc; ++argv; }
@@ -377,13 +377,14 @@ int main(int argc, char **argv)
memset(data, 0, poolsz);
p = "char else enum if int return sizeof do while "
- "EOF EXIT_SUCCESS EXIT_FAILURE "
+ "EOF EXIT_SUCCESS EXIT_FAILURE NULL "
"open read close printf malloc free memset memcmp getchar putstring putnl putchar putint isspace isdigit isalnum isalpha strcmp exit void main";
i = Char; while (i <= While) { next(); id[Tk] = i++; } // add keywords to symbol table
// add library constants
next(); id[Class] = Num; id[Type] = INT; id[Val] = -1;
next(); id[Class] = Num; id[Type] = INT; id[Val] = 0;
next(); id[Class] = Num; id[Type] = INT; id[Val] = 1;
+ next(); id[Class] = Num; id[Type] = INT; id[Val] = (int)NULL;
i = OPEN; while (i <= EXIT) { next(); id[Class] = Sys; id[Type] = INT; id[Val] = i++; } // add library to symbol table
next(); id[Tk] = Char; // handle void type
next(); idmain = id; // keep track of main
@@ -411,8 +412,13 @@ int main(int argc, char **argv)
next();
if (tk == Assign) {
next();
+ neg = 0;
+ if (tk == Sub) { next(); neg =1; }
if (tk != Num) { printf("%d: bad enum initializer\n", line); return -1; }
i = ival;
+ if (neg) {
+ i = -ival;
+ }
next();
}
id[Class] = Num; id[Type] = INT; id[Val] = i++;
diff --git a/miniany/cc.c b/miniany/cc.c
index ebdebdb..e5b30c7 100644
--- a/miniany/cc.c
+++ b/miniany/cc.c
@@ -8,8 +8,7 @@ int token;
int DEBUG_SCANNER;
enum {
- MAX_IDENT_LEN = 20,
- TEST = -1
+ MAX_IDENT_LEN = 20
};
void pushBack( int c )
@@ -254,11 +253,23 @@ void parseExpression( )
}
}
+//~ struct Symbol {
+ //~ char *name;
+//~ };
+
+//~ struct Symbol *symbol;
+
+void newSymbol( char *s )
+{
+
+}
+
void parseDeclaration( )
{
expect( S_INT, "int" );
expect( S_IDENT, "identifier" );
putstring( "Adding glob: " ); putstring( ident ); putnl( );
+ newSymbol( ident );
expect( S_SEMICOLON, ";" );
}
@@ -287,6 +298,7 @@ int main( int argc, char **argv )
row = 1;
pushback = 0;
DEBUG_SCANNER = 1;
+ //~ symbol = NULL;
ident = "12345678901234567890";
token = getToken( );
diff --git a/miniany/libc-freestanding.c b/miniany/libc-freestanding.c
index ffed093..fdec615 100644
--- a/miniany/libc-freestanding.c
+++ b/miniany/libc-freestanding.c
@@ -65,13 +65,8 @@ enum {
SYSCALL_WRITE = 4
};
-/* EOF = -1 is a const expression for c4 */
-/* EOF = 0xFFFFFFFF clang doesn't like this */
-/* EOF = 0xFFFFFFFF gcc overflow in conversion from 'enum <anonymous>' to 'int' changes value from '4294967295' to '-1' */
-/* EOF = 256, this is not standard, but doesn't really matter in freestanding mode,
- * code should really not relly on the fact what the value of EOF is (-1 usually) */
enum {
- EOF = 256
+ EOF = -1
};
int errno;
diff --git a/miniany/test1.c b/miniany/test1.c
new file mode 100644
index 0000000..ba8dd4f
--- /dev/null
+++ b/miniany/test1.c
@@ -0,0 +1,6 @@
+/* test1 */
+
+int i;
+int i;
+
+i = 12+25/5-2*3; // another comment