summaryrefslogtreecommitdiff
path: root/minie
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2018-12-28 12:42:24 +0100
committerAndreas Baumann <mail@andreasbaumann.cc>2018-12-28 12:42:24 +0100
commitcb4b6b710f5f553c2775e1d5481aab9c4319b1aa (patch)
tree4b43d2ee87e00ec9e15f47729f8cf516186d4405 /minie
parent4c640f3dbc1c9f95578ff7ebe9110002d8b0434d (diff)
downloadcompilertests-cb4b6b710f5f553c2775e1d5481aab9c4319b1aa.tar.gz
compilertests-cb4b6b710f5f553c2775e1d5481aab9c4319b1aa.tar.bz2
added logical operators
Diffstat (limited to 'minie')
-rw-r--r--minie/DESIGN2
-rw-r--r--minie/README2
-rwxr-xr-xminie/build.sh6
-rw-r--r--minie/e2c.c32
-rw-r--r--minie/test4.e2
5 files changed, 33 insertions, 11 deletions
diff --git a/minie/DESIGN b/minie/DESIGN
index beb46de..5c1116b 100644
--- a/minie/DESIGN
+++ b/minie/DESIGN
@@ -12,7 +12,7 @@ Starting with a C compiler is too hard, has too many quirks.
We want minimal code we duplicate in more than one language.
-We don't want to maintain to much code in the old language.
+We don't want to maintain too much code in the old language.
Every tool should possibly be written in the new language.
diff --git a/minie/README b/minie/README
index 9905329..9775777 100644
--- a/minie/README
+++ b/minie/README
@@ -22,4 +22,4 @@ test5: basic system input/output, import of pseudo module 'system'
test6: internal function 'length', system functions for stdio and stdin
test7: a proper string length function using 'length' and introducing
a function taking array of arbitrary length
-
+test8: loops
diff --git a/minie/build.sh b/minie/build.sh
index 37bbb6e..441631b 100755
--- a/minie/build.sh
+++ b/minie/build.sh
@@ -1,6 +1,10 @@
#!/bin/bash
-gcc -g -O0 -Wall -pedantic -std=c89 -Wno-return-type -o e2c e2c.c
+gcc -m32 -g -O0 -Wall -pedantic -std=c89 -Wno-return-type -o e2c e2c.c
+#tcc -o e2c e2c.c
+# broken, at least on ArchLinux and CVS version
+#pcc -o e2c e2c.c
+#clang -O0 -Wall -pedantic -std=c89 -Wno-return-type -o e2c e2c.c
./e2c < test1.e
./e2c < test2.e
./e2c < test3.e
diff --git a/minie/e2c.c b/minie/e2c.c
index f5394e6..f9215be 100644
--- a/minie/e2c.c
+++ b/minie/e2c.c
@@ -52,6 +52,9 @@ typedef enum {
S_minus,
S_star,
S_slash,
+ S_and,
+ S_or,
+ S_not,
S_lparen,
S_rparen,
S_lbracket,
@@ -92,6 +95,9 @@ char *symname[S_eof+1] = {
"-",
"*",
"/",
+ "and",
+ "or",
+ "not",
"(",
")",
"[",
@@ -115,7 +121,7 @@ static void Err( char *s, va_list args )
fflush( stderr );
}
-static void Halt( )
+static void Halt( void )
{
exit( EXIT_FAILURE );
}
@@ -284,6 +290,8 @@ next:
identifier( );
if( strcmp( ident, "array" ) == 0 ) {
return S_array;
+ } else if( strcmp( ident, "and" ) == 0 ) {
+ return S_and;
}
return S_ident;
case 'b':
@@ -336,11 +344,16 @@ next:
return S_ident;
case 'n':
identifier( );
+ if( strcmp( ident, "not" ) == 0 ) {
+ return S_not;
+ }
return S_ident;
case 'o':
identifier( );
if( strcmp( ident, "of" ) == 0 ) {
return S_of;
+ } else if( strcmp( ident, "or" ) == 0 ) {
+ return S_or;
}
return S_ident;
case 'p':
@@ -544,7 +557,7 @@ static Type symbols[MAX_SYMBOLS];
static void insert_symbol( Type type, char *name )
{
if( nof_symbols >= MAX_SYMBOLS ) {
- Halt( "Symbol table exhausted, increase MAX_SYMBOLS and recompile e2c" );
+ Abort( "Symbol table exhausted, increase MAX_SYMBOLS and recompile e2c" );
}
symbols[nof_symbols] = type;
@@ -719,6 +732,9 @@ static void factor( void )
} else if( sym == S_minus ) {
sym = getSym( );
emit( "-" );
+ } else if( sym == S_not ) {
+ sym = getSym( );
+ emit( "!" );
}
if( sym == S_number ) {
emit( "%d", num );
@@ -764,9 +780,10 @@ static void factor( void )
static void term( void )
{
factor( );
- while( sym == S_star || sym == S_slash ) {
+ while( sym == S_star || sym == S_slash || sym == S_and ) {
if( sym == S_star ) emit( "*" );
if( sym == S_slash ) emit( "/" );
+ if( sym == S_and ) emit( " && " );
sym = getSym( );
factor( );
}
@@ -775,9 +792,10 @@ static void term( void )
static void simpleExpression( void )
{
term( );
- while( sym == S_plus || sym == S_minus ) {
+ while( sym == S_plus || sym == S_minus || sym == S_or ) {
if( sym == S_plus ) emit( "+" );
if( sym == S_minus ) emit( "-" );
+ if( sym == S_or ) emit( " || " );
sym = getSym( );
term( );
}
@@ -1115,7 +1133,7 @@ static void procedureDeclaration( void )
sym = getSym( );
do {
if( nof_params >= MAX_PARAMETERS ) {
- Halt( "Too many parameters in definition of procedure" );
+ Abort( "Too many parameters in definition of procedure" );
}
identifier( );
strncpy( params[nof_params].name, ident, MAX_IDENT_LEN );
@@ -1144,13 +1162,13 @@ static void procedureDeclaration( void )
}
/* do not allow empty parameter lists in C++ style */
if( nof_params == 0 ) {
- Halt( "Empty parameter list must not be enclosed with ( )" );
+ Abort( "Empty parameter list must not be enclosed with ( )" );
}
} else if( sym == S_semicolon ) {
strncpy( return_type, "void", MAX_IDENT_LEN );
/* skip, ok */
} else {
- Halt( "Expected '(' after procedure declaration" );
+ Abort( "Expected '(' after procedure declaration" );
}
Expect( S_semicolon );
emit( "%s %s( ", return_type, procName );
diff --git a/minie/test4.e b/minie/test4.e
index ef8ff87..1914b02 100644
--- a/minie/test4.e
+++ b/minie/test4.e
@@ -16,7 +16,7 @@ begin
z := x;
c := 45;
x := c;
- b := c < y;
+ b := ( x < y ) and not ( z = x );
if b do
if true do
res := 1;