#------------------------------------------------------------------------------
# Nums
-foo = 1
+foo := 1
foo = 1.0
# Char
# Macro Definition and Usage
#------------------------------------------------------------------------------
-% if [
+@ if [
(E B B) : exec_if($1, $2, $3),
(E B) : exec_if($1, $2)
]
-if (1==1)
+if (1 < 2)
{
print(1 + 1)
}{
# Delayed Evaluation
#------------------------------------------------------------------------------
-% delay [
+@ delay [
(E) : make_promise({ $1 })
]
-% force [
+@ force [
(E) : $1()
]
;------------------------------------------------------------------------------
; Built-in Operators
;------------------------------------------------------------------------------
-(define ADD +)
-(define SUB -)
-(define MUL *)
-(define DIV /)
-(define NOT not)
-(define EQ equal?)
(define (NE a b) (not (equal? a b)))
-(define LT <)
-(define GT >)
-(define LTE <=)
-(define GTE >=)
-(define FN_CALL apply)
(define (ARRY_IDX coll idx)
(cond
((list? coll)
;------------------------------------------------------------------------------
; Built-in datatype constructors
;------------------------------------------------------------------------------
-(define VECTOR vector)
-(define LIST list)
-(define PARAMS list)
(define (MAP . args) (alist->hash-table args))
-(define (MACRO) '())
;------------------------------------------------------------------------------
; Import necessary libs
using namespace std;
-#define NUM_SINGLE_CHAR_MATCHES 14
+#define NUM_SINGLE_CHAR_MATCHES 12
SingleCharMatch_T Single_Character_Matches[ NUM_SINGLE_CHAR_MATCHES ] = {
{ '[', LBRACK },
{ ']', RBRACK },
{ '-', SUB },
{ '*', MUL },
{ '/', DIV },
- { '%', MACRO },
- { ':', SEP },
{ '.', MEMB },
};
|| (current == '<')
|| (current == '>')
|| (current == '|')
- || (current == '&'));
+ || (current == '&')
+ || (current == ':')
+ || (current == '@'));
}
bool DLLexer::isStringChar(void)
consume();
tok = Token(AND, line, column);
}
+ else if(last == ':')
+ {
+ if(current == '=')
+ {
+ consume();
+ tok = Token(DEFN, line, column);
+ }
+ else
+ {
+ tok = Token(SEP, line, column);
+ }
+ }
+ else if(last == '@')
+ {
+ if(current == '=')
+ {
+ consume();
+ tok = Token(IMPORT, line, column);
+ }
+ else
+ {
+ tok = Token(MACRO, line, column);
+ }
+ }
else
{
throw Exception(line,column);
GT = 26,
LTE = 27,
GTE = 28,
- ASSIGN = 29,
- ADD = 30,
- SUB = 31,
- MUL = 32,
- DIV = 33,
- MEMB = 34,
+ ADD = 29,
+ SUB = 30,
+ MUL = 31,
+ DIV = 32,
+ DEFN = 33,
+ ASSIGN = 34,
+ MEMB = 35,
+ SEP = 36,
+ ARRY_IDX = 37,
+ MACRO = 38,
+ IMPORT = 39,
// AST "Virtual" Node Types
- MACRO = 40,
- SEP = 41,
- PROGRAM = 42,
- BLOCK = 43,
- FN_CALL = 44,
- PARAMS = 45,
- ARRY_IDX = 46,
- PATT = 47,
+ PROGRAM = 40,
+ BLOCK = 41,
+ FN_CALL = 42,
+ PARAMS = 43,
+ PATT = 44,
} eTokenTypes;
typedef struct {
AST* DLParser::AssignExpr(void)
{
AST* ret = LogicalExpr();
- if(lookaheadType(1) == ASSIGN)
+ if(lookaheadType(1) == DEFN)
+ {
+ match(DEFN);
+ ret = new AST(DEFN, 2, ret, LogicalExpr());
+ }
+ else if(lookaheadType(1) == ASSIGN)
{
match(ASSIGN);
ret = new AST(ASSIGN, 2, ret, LogicalExpr());
output.close();
// Compile the temporary file with chicken scheme
- system( string("csc -O5 " + temp_fname).c_str() );
+ system( string("csc -O5 -v " + temp_fname).c_str() );
+ cout << "Removing temporary files..." << endl;
(void)remove( temp_fname.c_str() );
}
else
case CHAR:
ret << "CHAR "; break;
case ADD:
- ret << "ADD "; break;
+ ret << "+ "; break;
case SUB:
- ret << "SUB "; break;
+ ret << "- "; break;
case MUL:
- ret << "MUL "; break;
+ ret << "* "; break;
case DIV:
- ret << "DIV "; break;
+ ret << "/ "; break;
case AND:
ret << "and "; break;
case OR:
ret << "or "; break;
case NOT:
- ret << "NOT "; break;
+ ret << "not "; break;
case EQ:
- ret << "EQ "; break;
+ ret << "equal? "; break;
case NE:
ret << "NE "; break;
case LT:
- ret << "LT "; break;
+ ret << "< "; break;
case GT:
- ret << "GT "; break;
+ ret << "> "; break;
case LTE:
- ret << "LTE "; break;
+ ret << "<= "; break;
case GTE:
- ret << "GTE "; break;
- case MACRO:
- ret << "MACRO "; break;
- case ASSIGN:
+ ret << ">= "; break;
+ case DEFN:
ret << "define "; break;
+ case ASSIGN:
+ ret << "set! "; break;
case PROGRAM:
ret << "begin "; break;
case VECTOR:
- ret << "VECTOR "; break;
+ ret << "vector "; break;
case LIST:
- ret << "LIST "; break;
+ ret << "list "; break;
case BLOCK:
ret << "begin "; break;
case FUNC:
ret << "lambda "; break;
case FN_CALL:
- ret << "FN_CALL "; break;
+ ret << "apply "; break;
case ARRY_IDX:
ret << "ARRY_IDX "; break;
case SEP:
ret << "cons "; break;
case MEMB:
ret << "hash-table-ref "; break;
+
+ // Print nothing for the following nodes
+ case MACRO:
case PARAMS:
break;
+
+ // Print out the type id (this will probably cause an error but also
+ // alert us to the fact that it is not properly handled)
default:
ret << type; break;
}
void Scheme::beforeChildren(AST* cur, int depth)
{
- if (cur->type() == MEMB)
+ if( cur->type() != MACRO )
{
- cur->children()->back()->type(STRING);
- }
+ if (cur->type() == MEMB)
+ {
+ cur->children()->back()->type(STRING);
+ }
- if( isDatatype( cur->type() ) )
- {
- printDatatype( cur );
- }
- else
- {
- stream << "(" << typeToString( cur->type() ) << cur->text();
+ if( isDatatype( cur->type() ) )
+ {
+ printDatatype( cur );
+ }
+ else
+ {
+ stream << "(" << typeToString( cur->type() ) << cur->text();
+ }
}
}
void Scheme::afterChildren(AST* cur, int depth)
{
- if( !isDatatype( cur->type() ) )
+ if( !isDatatype( cur->type() ) && (cur->type() != MACRO))
{
stream << ")";
}