summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--NEW3
-rw-r--r--README14
-rw-r--r--TODO1
-rw-r--r--docs/help.txt2
-rw-r--r--docs/pod/fype.1.gzbin6086 -> 6050 bytes
-rw-r--r--docs/pod/fype.html15
-rw-r--r--docs/pod/fype.man27
-rw-r--r--docs/pod/fype.pod16
-rw-r--r--docs/pod/fype.tex18
-rw-r--r--docs/pod/fype.txt14
-rw-r--r--docs/stats.txt6
-rw-r--r--docs/version.txt2
-rw-r--r--examples/broken/bitwise.fy17
-rw-r--r--src/build.h2
-rw-r--r--src/core/function.c147
-rw-r--r--src/core/interpret.c54
-rw-r--r--src/core/scanner.c19
-rw-r--r--src/core/scanner.h1
-rw-r--r--src/core/token.c27
-rw-r--r--src/core/token.h7
-rw-r--r--src/defines.h1
-rw-r--r--tmp/test.fy4
-rw-r--r--tmp/test.out38
24 files changed, 311 insertions, 126 deletions
diff --git a/Makefile b/Makefile
index 8f8cb62..375de0f 100644
--- a/Makefile
+++ b/Makefile
@@ -31,7 +31,7 @@ SRCS!=find ./src -name '*.c'
OBJS=$(SRCS:.c=.o)
CC?=cc
#CC=mingw32-gcc
-DEBUG=-g3 -ggdb3
+#DEBUG=-g3 -ggdb3
CFLAGS+=-c -Wall -std=c99 -pedantic $(DEBUG)
LDADD+=
HEADER?=docs/header.txt
diff --git a/NEW b/NEW
index e2c5c01..9305f98 100644
--- a/NEW
+++ b/NEW
@@ -1,4 +1,3 @@
Undocumented new features:
undef keyword
- No more segfault: fype -e '1'
- Spaces are not needed any more
+ bitwise ops
diff --git a/README b/README
index 3f61d8b..3cc7d20 100644
--- a/README
+++ b/README
@@ -223,6 +223,7 @@ BUILT IN FUNCTIONS
(*integer*) *any* >= *any*
(*integer*) *any* < *any*
(*integer*) *any* > *any*
+ (*integer*) not *any*
Definedness
(*integer*) defined *identifier*
@@ -233,14 +234,11 @@ BUILT IN FUNCTIONS
otherwise 0 is returned.
Bitwise
- Bitwise operators do not work ATM. The fix is on its way!
-
- (*any*) *any* << *any*
- (*any*) *any* >> *any*
- (*any*) *any* and *any*
- (*any*) *any* or *any*
- (*any*) *any* xor *any*
- (*any*) not *any*
+ (*integer*) *any* :< *any*
+ (*integer*) *any* :> *any*
+ (*integer*) *any* and *any*
+ (*integer*) *any* or *any*
+ (*integer*) *any* xor *any*
Numeric
(*number*) neg *number*
diff --git a/TODO b/TODO
index f3c9905..781e7d0 100644
--- a/TODO
+++ b/TODO
@@ -1,6 +1,5 @@
Todo's (not in any specific order)
-Scanner: separate between token (e.g. allow 1+2)
Arrays
Closures
Function arguments and return values
diff --git a/docs/help.txt b/docs/help.txt
index b99b60f..987ab7d 100644
--- a/docs/help.txt
+++ b/docs/help.txt
@@ -1,4 +1,4 @@
-Fype v0.0-devel Build 9136
+Fype v0.0-devel Build 9199
Copyright by Paul C. Buetow (2005 - 2008) <fype@dev.buetow.org>
-e Executes given code string (see synopses)
-h Prints this help
diff --git a/docs/pod/fype.1.gz b/docs/pod/fype.1.gz
index c270197..8491141 100644
--- a/docs/pod/fype.1.gz
+++ b/docs/pod/fype.1.gz
Binary files differ
diff --git a/docs/pod/fype.html b/docs/pod/fype.html
index b47abe9..66c2303 100644
--- a/docs/pod/fype.html
+++ b/docs/pod/fype.html
@@ -349,6 +349,8 @@ not.</p>
<dt><strong><a name="item__28integer_29_any__3e_any">(<em>integer</em>) <em>any</em> <strong>&gt;</strong> <em>any</em></a></strong>
+<dt><strong><a name="item__28integer_29_not_any">(<em>integer</em>) <strong>not</strong> <em>any</em></a></strong>
+
</dl>
<p>
</p>
@@ -370,19 +372,16 @@ not.</p>
<p>
</p>
<h2><a name="bitwise">Bitwise</a></h2>
-<p>Bitwise operators do not work ATM. The fix is on its way!</p>
<dl>
-<dt><strong><a name="item__28any_29_any__3c_3c_any">(<em>any</em>) <em>any</em> <strong>&lt;&lt;</strong> <em>any</em></a></strong>
-
-<dt><strong><a name="item__28any_29_any__3e_3e_any">(<em>any</em>) <em>any</em> <strong>&gt;&gt;</strong> <em>any</em></a></strong>
+<dt><strong><a name="item__28integer_29_any__3a_3c_any">(<em>integer</em>) <em>any</em> <strong>:&lt;</strong> <em>any</em></a></strong>
-<dt><strong><a name="item__28any_29_any_and_any">(<em>any</em>) <em>any</em> <strong>and</strong> <em>any</em></a></strong>
+<dt><strong><a name="item__28integer_29_any__3a_3e_any">(<em>integer</em>) <em>any</em> <strong>:&gt;</strong> <em>any</em></a></strong>
-<dt><strong><a name="item__28any_29_any_or_any">(<em>any</em>) <em>any</em> <strong>or</strong> <em>any</em></a></strong>
+<dt><strong><a name="item__28integer_29_any_and_any">(<em>integer</em>) <em>any</em> <strong>and</strong> <em>any</em></a></strong>
-<dt><strong><a name="item__28any_29_any_xor_any">(<em>any</em>) <em>any</em> <strong>xor</strong> <em>any</em></a></strong>
+<dt><strong><a name="item__28integer_29_any_or_any">(<em>integer</em>) <em>any</em> <strong>or</strong> <em>any</em></a></strong>
-<dt><strong><a name="item__28any_29_not_any">(<em>any</em>) <strong>not</strong> <em>any</em></a></strong>
+<dt><strong><a name="item__28integer_29_any_xor_any">(<em>integer</em>) <em>any</em> <strong>xor</strong> <em>any</em></a></strong>
</dl>
<p>
diff --git a/docs/pod/fype.man b/docs/pod/fype.man
index 0a04c66..22eec38 100644
--- a/docs/pod/fype.man
+++ b/docs/pod/fype.man
@@ -129,7 +129,7 @@
.\" ========================================================================
.\"
.IX Title "FYPE 1"
-.TH FYPE 1 "2008-04-25" "Fype v0.0-devel Build 8860" "The Fype Users Manual Page"
+.TH FYPE 1 "2008-08-25" "Fype v0.0-devel Build 9175" "The Fype Users Manual Page"
.SH "NAME"
\&\fBFype\fR is \fBf\fRor \fBy\fRour \fBp\fRrogram \fBe\fRxecution
.PP
@@ -365,6 +365,8 @@ Special string behavior: A string will get auto convertet into an \fIinteger\fR.
.IX Item "(integer) any < any"
.IP "(\fIinteger\fR) \fIany\fR \fB>\fR \fIany\fR" 4
.IX Item "(integer) any > any"
+.IP "(\fIinteger\fR) \fBnot\fR \fIany\fR" 4
+.IX Item "(integer) not any"
.PD
.Sh "Definedness"
.IX Subsection "Definedness"
@@ -376,20 +378,17 @@ Returns 1 if \fIidentifier\fR has been defined. Returns 0 else.
Tries to undefine/delete the \fIidentifier\fR. Returns 1 if success, otherwise 0 is returned.
.Sh "Bitwise"
.IX Subsection "Bitwise"
-Bitwise operators do not work \s-1ATM\s0. The fix is on its way!
-.IP "(\fIany\fR) \fIany\fR \fB<<\fR \fIany\fR" 4
-.IX Item "(any) any << any"
+.IP "(\fIinteger\fR) \fIany\fR \fB:<\fR \fIany\fR" 4
+.IX Item "(integer) any :< any"
.PD 0
-.IP "(\fIany\fR) \fIany\fR \fB>>\fR \fIany\fR" 4
-.IX Item "(any) any >> any"
-.IP "(\fIany\fR) \fIany\fR \fBand\fR \fIany\fR" 4
-.IX Item "(any) any and any"
-.IP "(\fIany\fR) \fIany\fR \fBor\fR \fIany\fR" 4
-.IX Item "(any) any or any"
-.IP "(\fIany\fR) \fIany\fR \fBxor\fR \fIany\fR" 4
-.IX Item "(any) any xor any"
-.IP "(\fIany\fR) \fBnot\fR \fIany\fR" 4
-.IX Item "(any) not any"
+.IP "(\fIinteger\fR) \fIany\fR \fB:>\fR \fIany\fR" 4
+.IX Item "(integer) any :> any"
+.IP "(\fIinteger\fR) \fIany\fR \fBand\fR \fIany\fR" 4
+.IX Item "(integer) any and any"
+.IP "(\fIinteger\fR) \fIany\fR \fBor\fR \fIany\fR" 4
+.IX Item "(integer) any or any"
+.IP "(\fIinteger\fR) \fIany\fR \fBxor\fR \fIany\fR" 4
+.IX Item "(integer) any xor any"
.PD
.Sh "Numeric"
.IX Subsection "Numeric"
diff --git a/docs/pod/fype.pod b/docs/pod/fype.pod
index 6628322..33e50f5 100644
--- a/docs/pod/fype.pod
+++ b/docs/pod/fype.pod
@@ -251,6 +251,8 @@ Special string behavior: A string will get auto convertet into an I<integer>.
=item (I<integer>) I<any> B<E<gt>> I<any>
+=item (I<integer>) B<not> I<any>
+
=back
=head2 Definedness
@@ -269,21 +271,17 @@ Tries to undefine/delete the I<identifier>. Returns 1 if success, otherwise 0 is
=head2 Bitwise
-Bitwise operators do not work ATM. The fix is on its way!
-
=over
-=item (I<any>) I<any> B<<<> I<any>
-
-=item (I<any>) I<any> B<E<gt>E<gt>> I<any>
+=item (I<integer>) I<any> B<:<> I<any>
-=item (I<any>) I<any> B<and> I<any>
+=item (I<integer>) I<any> B<:E<gt>> I<any>
-=item (I<any>) I<any> B<or> I<any>
+=item (I<integer>) I<any> B<and> I<any>
-=item (I<any>) I<any> B<xor> I<any>
+=item (I<integer>) I<any> B<or> I<any>
-=item (I<any>) B<not> I<any>
+=item (I<integer>) I<any> B<xor> I<any>
=back
diff --git a/docs/pod/fype.tex b/docs/pod/fype.tex
index a14a509..0558ff3 100644
--- a/docs/pod/fype.tex
+++ b/docs/pod/fype.tex
@@ -293,7 +293,8 @@ Special string behavior: A string will get auto convertet into an \textit{intege
\item[{(\textit{integer}) \textit{any} \textbf{$<$=}}] \textbf{\textit{any}}
\item[{(\textit{integer}) \textit{any} \textbf{$>$=}}] \textbf{\textit{any}}
\item[{(\textit{integer}) \textit{any} \textbf{$<$}}] \textbf{\textit{any}}
-\item[{(\textit{integer}) \textit{any} \textbf{$>$}}] \textbf{\textit{any}}\end{description}
+\item[{(\textit{integer}) \textit{any} \textbf{$>$}}] \textbf{\textit{any}}
+\item[{(\textit{integer}) \textbf{not} \textit{any}}] \mbox{}\end{description}
\subsection*{Definedness\label{Definedness}\index{Definedness}}
\begin{description}
@@ -308,18 +309,13 @@ Tries to undefine/delete the \textit{identifier}. Returns 1 if success, otherwis
\end{description}
\subsection*{Bitwise\label{Bitwise}\index{Bitwise}}
-
-
-Bitwise operators do not work ATM. The fix is on its way!
-
\begin{description}
-\item[{(\textit{any}) \textit{any} \textbf{$<$$<$}}] \textbf{\textit{any}}
-\item[{(\textit{any}) \textit{any} \textbf{$>$$>$}}] \textbf{\textit{any}}
-\item[{(\textit{any}) \textit{any} \textbf{and}}] \textbf{\textit{any}}
-\item[{(\textit{any}) \textit{any} \textbf{or}}] \textbf{\textit{any}}
-\item[{(\textit{any}) \textit{any} \textbf{xor}}] \textbf{\textit{any}}
-\item[{(\textit{any}) \textbf{not} \textit{any}}] \mbox{}\end{description}
+\item[{(\textit{integer}) \textit{any} \textbf{:$<$}}] \textbf{\textit{any}}
+\item[{(\textit{integer}) \textit{any} \textbf{:$>$}}] \textbf{\textit{any}}
+\item[{(\textit{integer}) \textit{any} \textbf{and}}] \textbf{\textit{any}}
+\item[{(\textit{integer}) \textit{any} \textbf{or}}] \textbf{\textit{any}}
+\item[{(\textit{integer}) \textit{any} \textbf{xor}}] \textbf{\textit{any}}\end{description}
\subsection*{Numeric\label{Numeric}\index{Numeric}}
\begin{description}
diff --git a/docs/pod/fype.txt b/docs/pod/fype.txt
index 3f61d8b..3cc7d20 100644
--- a/docs/pod/fype.txt
+++ b/docs/pod/fype.txt
@@ -223,6 +223,7 @@ BUILT IN FUNCTIONS
(*integer*) *any* >= *any*
(*integer*) *any* < *any*
(*integer*) *any* > *any*
+ (*integer*) not *any*
Definedness
(*integer*) defined *identifier*
@@ -233,14 +234,11 @@ BUILT IN FUNCTIONS
otherwise 0 is returned.
Bitwise
- Bitwise operators do not work ATM. The fix is on its way!
-
- (*any*) *any* << *any*
- (*any*) *any* >> *any*
- (*any*) *any* and *any*
- (*any*) *any* or *any*
- (*any*) *any* xor *any*
- (*any*) not *any*
+ (*integer*) *any* :< *any*
+ (*integer*) *any* :> *any*
+ (*integer*) *any* and *any*
+ (*integer*) *any* or *any*
+ (*integer*) *any* xor *any*
Numeric
(*number*) neg *number*
diff --git a/docs/stats.txt b/docs/stats.txt
index 50cfed4..d6ec4b2 100644
--- a/docs/stats.txt
+++ b/docs/stats.txt
@@ -1,4 +1,4 @@
===> Num of C source files : 42
-===> Num of C source lines : 7252
-===> Num of Fype source examples : 13
-===> Num of Fype source lines : 320
+===> Num of C source lines : 7448
+===> Num of Fype source examples : 14
+===> Num of Fype source lines : 353
diff --git a/docs/version.txt b/docs/version.txt
index cb62366..bea7532 100644
--- a/docs/version.txt
+++ b/docs/version.txt
@@ -1 +1 @@
-Fype v0.0-devel Build 9136
+Fype v0.0-devel Build 9199
diff --git a/examples/broken/bitwise.fy b/examples/broken/bitwise.fy
index b124590..03fda6c 100644
--- a/examples/broken/bitwise.fy
+++ b/examples/broken/bitwise.fy
@@ -14,18 +14,19 @@ assert 1 == (say 0 or 1);
assert 0 == (put 1 xor 1);
assert 1 == (say 1 xor 0);
-# Prints "-1" (see "not" operator of NASM why so)
-assert (neg 1) == (say not 0);
-
# Prints "82\n"
-assert 8 == (put 2 << 2);
-assert 2 == (say 8 >> 2);
+assert 8 == (put 2 :< 2);
+assert 2 == (say 8 :> 2);
# A bit more complex, prints "9\n"
-assert 9 == (say 1 << 5 >> 5 or 2 and 5 xor 8);
+assert 9 == (say 1 :< 5 :> 5 or 2 and 5 xor 8);
# Same result, but with parenthesis:
-assert 9 == (say ((((1 << 5) >> 5) or 2) and 5) xor 8);
+assert 9 == (say ((((1 :< 5) :> 5) or 2) and 5) xor 8);
# Different parenthesis, different result: "1\n"
-assert 1 == (say 1 << 5 >> 5 or 2 and (5 xor 8));
+assert 1 == (say 1 :< 5 :> 5 or 2 and (5 xor 8));
+
+# Prints "-1"
+assert (neg 1) == (say neg not 0);
+
diff --git a/src/build.h b/src/build.h
index 8be647b..5da306c 100644
--- a/src/build.h
+++ b/src/build.h
@@ -35,7 +35,7 @@
#ifndef BUILD_H
#define BUILD_H
-#define BUILDNR 9136
+#define BUILDNR 9200
#define OS_FREEBSD
#endif
diff --git a/src/core/function.c b/src/core/function.c
index 39971a1..fda40b8 100644
--- a/src/core/function.c
+++ b/src/core/function.c
@@ -111,6 +111,18 @@ _process(Interpret *p_interpret, Token *p_token_store, Token *p_token_op,
break;
}
break;
+ case TT_DDOT:
+ switch (tt_op2) {
+ case TT_LT:
+ tt_op = TT_LSHIFT;
+ break;
+ case TT_GT:
+ tt_op = TT_RSHIFT;
+ break;
+ default:
+ break;
+ }
+ break;
default:
break;
}
@@ -371,6 +383,117 @@ _process(Interpret *p_interpret, Token *p_token_store, Token *p_token_op,
NO_DEFAULT;
}
break;
+ case TT_AND:
+ switch (tt_highest) {
+ case TT_INTEGER:
+ token_set_ival(p_token_store,
+ (int) token_get_ival(p_token_next) &
+ token_get_ival(p_token_store));
+ break;
+ case TT_DOUBLE:
+ token_set_ival(p_token_store,
+ (int) token_get_dval(p_token_next) &
+ (int) token_get_dval(p_token_store));
+ token_set_tt(p_token_store, TT_INTEGER);
+ break;
+ case TT_STRING:
+ token_set_ival(p_token_store,
+ atoi(token_get_val(p_token_next)) &
+ atoi(token_get_val(p_token_store)));
+ token_set_tt(p_token_store, TT_INTEGER);
+ break;
+ NO_DEFAULT;
+ }
+ break;
+ case TT_OR:
+ switch (tt_highest) {
+ case TT_INTEGER:
+ token_set_ival(p_token_store,
+ (int) token_get_ival(p_token_next) |
+ token_get_ival(p_token_store));
+ break;
+ case TT_DOUBLE:
+ token_set_ival(p_token_store,
+ (int) token_get_dval(p_token_next) |
+ (int) token_get_dval(p_token_store));
+ token_set_tt(p_token_store, TT_INTEGER);
+ break;
+ case TT_STRING:
+ token_set_ival(p_token_store,
+ atoi(token_get_val(p_token_next)) |
+ atoi(token_get_val(p_token_store)));
+ token_set_tt(p_token_store, TT_INTEGER);
+ break;
+ NO_DEFAULT;
+ }
+ break;
+ case TT_XOR:
+ switch (tt_highest) {
+ case TT_INTEGER:
+ token_set_ival(p_token_store,
+ (int) token_get_ival(p_token_next) ^
+ token_get_ival(p_token_store));
+ break;
+ case TT_DOUBLE:
+ token_set_ival(p_token_store,
+ (int) token_get_dval(p_token_next) ^
+ (int) token_get_dval(p_token_store));
+ token_set_tt(p_token_store, TT_INTEGER);
+ break;
+ case TT_STRING:
+ token_set_ival(p_token_store,
+ atoi(token_get_val(p_token_next)) ^
+ atoi(token_get_val(p_token_store)));
+ token_set_tt(p_token_store, TT_INTEGER);
+ break;
+ NO_DEFAULT;
+ }
+ break;
+ case TT_LSHIFT:
+ switch (tt_highest) {
+ case TT_INTEGER:
+ token_set_ival(p_token_store,
+ (int) token_get_ival(p_token_next) <<
+ token_get_ival(p_token_store));
+ break;
+ case TT_DOUBLE:
+ token_set_ival(p_token_store,
+ (int) token_get_dval(p_token_next) <<
+ (int) token_get_dval(p_token_store));
+ token_set_tt(p_token_store, TT_INTEGER);
+ break;
+ case TT_STRING:
+ token_set_ival(p_token_store,
+ atoi(token_get_val(p_token_next)) <<
+ atoi(token_get_val(p_token_store)));
+ token_set_tt(p_token_store, TT_INTEGER);
+ break;
+ NO_DEFAULT;
+ }
+ break;
+ case TT_RSHIFT:
+ switch (tt_highest) {
+ case TT_INTEGER:
+ token_set_ival(p_token_store,
+ (int) token_get_ival(p_token_next) >>
+ token_get_ival(p_token_store));
+ break;
+ case TT_DOUBLE:
+ token_set_ival(p_token_store,
+ (int) token_get_dval(p_token_next) >>
+ (int) token_get_dval(p_token_store));
+ token_set_tt(p_token_store, TT_INTEGER);
+ break;
+ case TT_STRING:
+ token_set_ival(p_token_store,
+ atoi(token_get_val(p_token_next)) >>
+ atoi(token_get_val(p_token_store)));
+ token_set_tt(p_token_store, TT_INTEGER);
+ break;
+ NO_DEFAULT;
+ }
+ break;
+
default:
_FUNCTION_ERROR("No such function/operator", p_token_op);
}
@@ -449,6 +572,9 @@ function_is_buildin(Token *p_token_ident) {
if (strcmp("yes", token_get_val(p_token_ident)) == 0)
return (true);
+ if (strcmp("not", token_get_val(p_token_ident)) == 0)
+ return (true);
+
return (false);
}
@@ -665,6 +791,27 @@ function_process_buildin(Interpret *p_interpret, Token *p_token_ident,
}
stack_push(p_stack_args, p_token);
+
+ } else if (strcmp("not", token_get_val(p_token_ident)) == 0) {
+ if (0 == stack_size(p_stack_args))
+ _FUNCTION_ERROR("No argument given", p_token_ident);
+
+ Token *p_token = token_new_copy(stack_pop(p_stack_args));
+ stack_push(p_stack_args, p_token);
+
+ switch (token_get_tt(p_token)) {
+ case TT_INTEGER:
+ token_set_ival(p_token, !token_get_ival(p_token));
+ break;
+ case TT_DOUBLE:
+ token_set_dval(p_token, !token_get_dval(p_token));
+ break;
+ case TT_STRING:
+ token_set_ival(p_token, !atoi(token_get_val(p_token)));
+ token_set_tt(p_token, TT_INTEGER);
+ break;
+ NO_DEFAULT;
+ }
}
}
diff --git a/src/core/interpret.c b/src/core/interpret.c
index 25f4a0d..5aa07ef 100644
--- a/src/core/interpret.c
+++ b/src/core/interpret.c
@@ -174,7 +174,10 @@ int
_var_decl(Interpret *p_interpret) {
_CHECK TRACK
- if (p_interpret->tt == TT_MY) {
+ switch (p_interpret->tt) {
+ //case TT_ARR: //TODO cleanup TT_ARR
+ case TT_MY:
+ {
if (_NEXT_TT != TT_IDENT)
_INTERPRET_ERROR("'my' expects identifier", p_interpret->p_token);
@@ -196,6 +199,9 @@ _var_decl(Interpret *p_interpret) {
_INTERPRET_ERROR("Expected ';' after", p_token_ident);
}
}
+ default:
+ break;
+ }
return (0);
}
@@ -220,7 +226,8 @@ _var_assign(Interpret *p_interpret) {
p_interpret->p_stack = stack_new();
if (_expression_(p_interpret)) {
- function_process_buildin(p_interpret, p_token, p_interpret->p_stack);
+ function_process_buildin(p_interpret, p_token,
+ p_interpret->p_stack);
stack_merge(p_stack, p_interpret->p_stack);
stack_delete(p_interpret->p_stack);
@@ -605,9 +612,6 @@ _compare(Interpret *p_interpret) {
_Bool b_flag = true;
do {
- /*
- ! = < > !! != !< !> =! == =< => <! <= << <> >! >= >< >>
- */
switch (p_interpret->tt) {
case TT_NOT:
case TT_ASSIGN:
@@ -659,17 +663,30 @@ _sum(Interpret *p_interpret) {
_Bool b_flag = true;
do {
+ Token *p_token_op2 = NULL, *p_token_tmp = NULL;
+
switch (p_interpret->tt) {
+ case TT_DDOT:
+ p_token_tmp = p_interpret->p_token;
+ _NEXT
case TT_ADD:
case TT_SUB:
+ case TT_AND:
+ case TT_OR:
+ case TT_XOR:
{
Token *p_token_op = p_interpret->p_token;
_NEXT
+ if (p_token_tmp != NULL) {
+ p_token_op2 = p_token_op;
+ p_token_op = p_token_tmp;;
+ }
+
if (!_product(p_interpret))
_INTERPRET_ERROR("Expected product", p_token_op);
- function_process(p_interpret, p_token_op, NULL,
+ function_process(p_interpret, p_token_op, p_token_op2,
p_interpret->p_stack, 2);
}
@@ -735,9 +752,8 @@ _product2(Interpret *p_interpret) {
_Bool b_flag = true;
do {
- switch (p_interpret->tt) {
- case TT_ASSIGN:
- {
+ if (p_interpret->tt == TT_ASSIGN
+ && IS_NOT_OPERATOR(_NEXT_TT)) {
Token *p_token = p_interpret->p_token;
Token *p_token_temp = p_interpret->p_token_prev;
_NEXT
@@ -750,15 +766,10 @@ _product2(Interpret *p_interpret) {
p_interpret->p_stack, 2);
p_interpret->p_token_temp = NULL;
- }
- break; /* case */
-
- default:
+ } else {
b_flag = false;
break;
-
- } /* switch */
-
+ } /* if */
} while (b_flag);
return (1);
@@ -901,6 +912,17 @@ _term(Interpret *p_interpret) {
}
break;
+ case TT_PARANT_AL:
+ {
+ Token *p_token = p_interpret->p_token;
+ _NEXT
+
+ Token *p_token_arr = token_new_array(ARRAY_SIZE);
+ stack_push(p_interpret->p_stack, p_token_arr);
+ _INTERPRET_ERROR("arrays not yet fully implemented", p_token_arr);
+ }
+ break;
+
case TT_PARANT_L:
{
Token *p_token = p_interpret->p_token;
diff --git a/src/core/scanner.c b/src/core/scanner.c
index 2e599eb..49026c2 100644
--- a/src/core/scanner.c
+++ b/src/core/scanner.c
@@ -37,7 +37,7 @@
#include <ctype.h>
#include <string.h>
-const char _TOKENENDS[] = "})+-*/={(<>;:,.!";
+const char _TOKENENDS[] = "}])+-*/={([<>;:,.!";
#define _ADD_SEMICOLON_INDEX 2
int _CODESTR_INDEX = 0;
@@ -70,6 +70,7 @@ scanner_new(List *p_list_token, Tupel *p_tupel_argv) {
p_scanner->i_current_pos_nr = 0;
p_scanner->i_num_tokenends = strlen(_TOKENENDS);
+ p_scanner->tt_last = TT_NONE;
return p_scanner;
}
@@ -208,7 +209,7 @@ scanner_run(Fype *p_fype) {
}
{
int i_num_nl = 0;
- _Bool flag = false;
+ //_Bool flag = false;
do {
c = _scanner_get_next_char(p_scanner);
if ( c == '\n' ) {
@@ -226,7 +227,7 @@ scanner_run(Fype *p_fype) {
c_token[i_token_len-1] = '"';
} else {
- flag = true;
+ //flag = true;
break;
}
@@ -244,8 +245,8 @@ scanner_run(Fype *p_fype) {
if (i_num_nl)
p_scanner->i_current_line_nr += i_num_nl;
- if (flag)
- _add_semicolon_to_list(p_scanner);
+ //if (flag)
+ // _add_semicolon_to_list(p_scanner);
}
break;
@@ -267,17 +268,19 @@ scanner_run(Fype *p_fype) {
default:
if (i_token_len) {
+ TokenType tt_cur = scanner_get_tt_cur(c_token);
+ if (tt_cur == TT_PARANT_CR && p_scanner->tt_last == TT_STRING)
+ _add_semicolon_to_list(p_scanner);
+
char d = c_token[i_token_len-1];
if ((!isalpha(d) && !isdigit(d) /*&& d != '-'*/) &&
(isalpha(c) || isdigit(c))) {
- TokenType tt_cur = scanner_get_tt_cur(c_token);
scanner_add_token(p_scanner, &c_token, &i_token_len, tt_cur);
} else {
for (int i = 0; i < p_scanner->i_num_tokenends; ++i) {
if (_TOKENENDS[i] == c) {
- TokenType tt_cur = scanner_get_tt_cur(c_token);
scanner_add_token(p_scanner, &c_token, &i_token_len, tt_cur);
if (i < _ADD_SEMICOLON_INDEX)
_add_semicolon_to_list(p_scanner);
@@ -342,6 +345,8 @@ scanner_add_token(Scanner *p_scanner, char **cc_token, int *p_token_len,
*cc_token = malloc(sizeof(char));
(*cc_token)[0] = 0;
*p_token_len = 0;
+
+ p_scanner->tt_last = tt_cur;
}
TokenType
diff --git a/src/core/scanner.h b/src/core/scanner.h
index f5f91ad..4626595 100644
--- a/src/core/scanner.h
+++ b/src/core/scanner.h
@@ -55,6 +55,7 @@ typedef struct {
char *c_codestring;
FILE *fp;
List *p_list_token;
+ TokenType tt_last;
} Scanner;
Scanner *scanner_new(List *p_list_token, Tupel *p_tupel_argv);
diff --git a/src/core/token.c b/src/core/token.c
index 437ed6c..1a2aec9 100644
--- a/src/core/token.c
+++ b/src/core/token.c
@@ -57,11 +57,14 @@ get_tt(char *c_token) {
CHECK("proc") TT_PROC;
CHECK("func") TT_FUNC;
CHECK("my") TT_MY;
- CHECK("not") TT_NOT;
+ CHECK("arr") TT_ARR;
+ CHECK("!") TT_NOT;
CHECK("!=") TT_NEQ;
CHECK("=~") TT_RE;
CHECK("(") TT_PARANT_L;
CHECK(")") TT_PARANT_R;
+ CHECK("[") TT_PARANT_AL;
+ CHECK("]") TT_PARANT_AR;
CHECK("*") TT_MULT;
CHECK("+") TT_ADD;
CHECK("++") TT_INCR;
@@ -102,6 +105,7 @@ tt_get_name(TokenType tt_cur) {
CASE(TT_IDENT, "TT_IDENT")
CASE(TT_DOUBLE,"TT_DOUBLE")
CASE(TT_STRING,"TT_STRING")
+ CASE(TT_ARRAY,"TT_ARRAY")
CASE(TT_INTEGER,"TT_INTEGER")
CASE(TT_BOOL,"TT_BOOL")
CASE(END_ASSIGNABLES, "END_ASSIGNABLES")
@@ -119,6 +123,7 @@ tt_get_name(TokenType tt_cur) {
CASE(TT_PROC,"TT_PROC")
CASE(TT_FUNC,"TT_FUNC")
CASE(TT_MY,"TT_MY")
+ CASE(TT_ARR,"TT_ARR")
CASE(TT_WHILE,"TT_WHILE")
CASE(TT_UNTIL,"TT_UNTIL")
CASE(TT_NEXT,"TT_NEXT")
@@ -131,6 +136,8 @@ tt_get_name(TokenType tt_cur) {
CASE(START_PARANTS, "START_PARANTS")
CASE(TT_PARANT_CL,"TT_PARANT_CL")
CASE(TT_PARANT_CR,"TT_PARANT_CR")
+ CASE(TT_PARANT_AL,"TT_PARANT_AL")
+ CASE(TT_PARANT_AR,"TT_PARANT_AR")
CASE(TT_PARANT_L,"TT_PARANT_L")
CASE(TT_PARANT_R,"TT_PARANT_R")
CASE(END_PARANTS, "END_PARANTS")
@@ -186,6 +193,7 @@ token_new(char *c_val, TokenType tt_cur, int i_line_nr, int i_pos_nr, char *c_fi
p_token->i_line_nr = i_line_nr;
p_token->i_pos_nr = i_pos_nr;
p_token->c_filename = c_filename;
+ p_token->p_array = NULL;
switch (tt_cur) {
case TT_INTEGER:
@@ -196,6 +204,11 @@ token_new(char *c_val, TokenType tt_cur, int i_line_nr, int i_pos_nr, char *c_fi
p_token->d_val = atof(c_val);
break;
}
+ case TT_ARRAY:
+ {
+ p_token->p_array = array_new();
+ break;
+ }
NO_DEFAULT;
}
@@ -231,6 +244,15 @@ token_new_string(char *c_val) {
return (p_token);
}
+Token*
+token_new_array(int i_size) {
+ Token *p_token = token_new_dummy();
+ token_set_tt(p_token, TT_ARRAY);
+ array_resize(p_token->p_array, i_size);
+
+ return (p_token);
+}
+
Token*
token_new_(char *c_val, TokenType tt_cur, char *c_filename) {
@@ -322,6 +344,9 @@ token_delete(Token *p_token) {
if (p_token->c_val)
free(p_token->c_val);
+ if (p_token->p_array)
+ array_delete(p_token->p_array);
+
free(p_token);
}
#ifdef DEBUG_TOKEN_REFCOUNT
diff --git a/src/core/token.h b/src/core/token.h
index b73398b..caf4854 100644
--- a/src/core/token.h
+++ b/src/core/token.h
@@ -36,6 +36,7 @@
#define TOKEN_H
#include "../defines.h"
+#include "../data/array.h"
#define IS_TERMINAL(t) (START_TERMINALS < t && t < END_TERMINALS)
#define IS_NOT_TERMINAL(t) !IS_TERMINAL(t)
@@ -86,6 +87,7 @@ typedef enum {
TT_DOUBLE,
END_NUMERICAL,
TT_STRING,
+ TT_ARRAY,
END_ASSIGNABLES,
TT_IDENT,
END_TYPES,
@@ -101,6 +103,7 @@ typedef enum {
TT_PROC,
TT_FUNC,
TT_MY,
+ TT_ARR,
TT_WHILE,
TT_UNTIL,
TT_NEXT,
@@ -112,6 +115,8 @@ typedef enum {
START_PARANTS,
TT_PARANT_CL,
TT_PARANT_CR,
+ TT_PARANT_AL,
+ TT_PARANT_AR,
TT_PARANT_L,
TT_PARANT_R,
END_PARANTS,
@@ -160,12 +165,14 @@ typedef struct {
char *c_filename;
unsigned int u_token_id;
int i_ref_count;
+ Array *p_array;
} Token;
Token* token_new(char *c_val, TokenType tt_cur, int i_line_nr, int i_pos_nr, char *c_filename);
Token* token_new_integer(int i_val);
Token* token_new_couble(double d_val);
Token* token_new_string(char *c_val);
+Token* token_new_array(int i_size);
Token* token_new_copy(Token *p_token);
Token* token_new_(char *c_val, TokenType tt_cur, char *c_filename);
Token* token_new_dummy();
diff --git a/src/defines.h b/src/defines.h
index 17e4933..a7eabd7 100644
--- a/src/defines.h
+++ b/src/defines.h
@@ -45,6 +45,7 @@
#define COPYRIGHT "Copyright by Paul C. Buetow (2005 - 2008) <fype@dev.buetow.org>"
#define FYPE
#define GRAMMAR_MAP_SIZES 128
+#define ARRAY_SIZE 16
#define HASH_MAXOCC 5
#define HASH_MKEYLEN 32
#define HASH_SCALE 10
diff --git a/tmp/test.fy b/tmp/test.fy
index bef7188..afe2cec 100644
--- a/tmp/test.fy
+++ b/tmp/test.fy
@@ -1,5 +1,3 @@
-my foo = 0;
-say foo;
-say 2 * 4.5 + 1 + gc;
+my foo = [1, 2.2, "3"];
diff --git a/tmp/test.out b/tmp/test.out
index 080145f..1cd7e60 100644
--- a/tmp/test.out
+++ b/tmp/test.out
@@ -1,25 +1,17 @@
-my foo = 0;
+arr foo = [1, 2.2, "3"];
say foo;
-
-say 2 * 4.5 + 1 + gc;
-Token (id=00000, line=00001, pos=0003, type=TT_MY, val=my, ival=0, dval=0.000000, refs=1)
-Token (id=00001, line=00001, pos=0007, type=TT_IDENT, val=foo, ival=0, dval=0.000000, refs=1)
-Token (id=00002, line=00001, pos=0009, type=TT_ASSIGN, val==, ival=0, dval=0.000000, refs=1)
-Token (id=00003, line=00001, pos=0011, type=TT_INTEGER, val=0, ival=0, dval=0.000000, refs=1)
-Token (id=00004, line=00001, pos=0012, type=TT_SEMICOLON, val=;, ival=0, dval=0.000000, refs=1)
-Token (id=00005, line=00003, pos=0004, type=TT_IDENT, val=say, ival=0, dval=0.000000, refs=1)
-Token (id=00006, line=00003, pos=0008, type=TT_IDENT, val=foo, ival=0, dval=0.000000, refs=1)
-Token (id=00007, line=00003, pos=0009, type=TT_SEMICOLON, val=;, ival=0, dval=0.000000, refs=1)
-Token (id=00008, line=00005, pos=0004, type=TT_IDENT, val=say, ival=0, dval=0.000000, refs=1)
-Token (id=00009, line=00005, pos=0006, type=TT_INTEGER, val=2, ival=2, dval=0.000000, refs=1)
-Token (id=00010, line=00005, pos=0008, type=TT_MULT, val=*, ival=0, dval=0.000000, refs=1)
-Token (id=00013, line=00005, pos=0012, type=TT_DOUBLE, val=4.5, ival=5, dval=4.500000, refs=1)
-Token (id=00014, line=00005, pos=0014, type=TT_ADD, val=+, ival=0, dval=0.000000, refs=1)
-Token (id=00015, line=00005, pos=0016, type=TT_INTEGER, val=1, ival=1, dval=0.000000, refs=1)
-Token (id=00016, line=00005, pos=0018, type=TT_ADD, val=+, ival=0, dval=0.000000, refs=1)
-Token (id=00017, line=00005, pos=0021, type=TT_IDENT, val=gc, ival=0, dval=0.000000, refs=1)
-Token (id=00018, line=00005, pos=0022, type=TT_SEMICOLON, val=;, ival=0, dval=0.000000, refs=1)
-0
-ICOUNT 4
-9
+Token (id=00000, line=00002, pos=0004, type=TT_ARR, val=arr, ival=0, dval=0.000000, refs=1)
+Token (id=00001, line=00002, pos=0008, type=TT_IDENT, val=foo, ival=0, dval=0.000000, refs=1)
+Token (id=00002, line=00002, pos=0010, type=TT_ASSIGN, val==, ival=0, dval=0.000000, refs=1)
+Token (id=00003, line=00002, pos=0012, type=TT_PARANT_AL, val=[, ival=0, dval=0.000000, refs=1)
+Token (id=00004, line=00002, pos=0013, type=TT_INTEGER, val=1, ival=1, dval=0.000000, refs=1)
+Token (id=00005, line=00002, pos=0014, type=TT_COMMA, val=,, ival=0, dval=0.000000, refs=1)
+Token (id=00008, line=00002, pos=0018, type=TT_DOUBLE, val=2.2, ival=2, dval=2.200000, refs=1)
+Token (id=00009, line=00002, pos=0019, type=TT_COMMA, val=,, ival=0, dval=0.000000, refs=1)
+Token (id=00010, line=00002, pos=0020, type=TT_STRING, val=3, ival=0, dval=0.000000, refs=1)
+Token (id=00011, line=00002, pos=0022, type=TT_PARANT_AR, val=], ival=0, dval=0.000000, refs=1)
+Token (id=00012, line=00002, pos=0023, type=TT_SEMICOLON, val=;, ival=0, dval=0.000000, refs=1)
+Token (id=00013, line=00003, pos=0004, type=TT_IDENT, val=say, ival=0, dval=0.000000, refs=1)
+Token (id=00014, line=00003, pos=0008, type=TT_IDENT, val=foo, ival=0, dval=0.000000, refs=1)
+Token (id=00015, line=00003, pos=0009, type=TT_SEMICOLON, val=;, ival=0, dval=0.000000, refs=1)