Added variable type initialization

This commit is contained in:
Justin J. Meza 2010-09-01 20:06:15 -07:00
parent 3d68f2b31b
commit a2db1d932f
885 changed files with 352 additions and 296 deletions

View File

@ -2,6 +2,7 @@ TARGET = lci
LIBS = -lm
OBJS = lexer.o tokenizer.o parser.o interpreter.o unicode.o main.o
SRCS = lexer.c tokenizer.c parser.c interpreter.c unicode.c main.c
HDRS = lexer.h tokenizer.h parser.h interpreter.h unicode.h
INSTALL = /usr/local/bin/install -c
CPPFLAGS = -O2
@ -18,17 +19,17 @@ pedantic: $(OBJS) $(LIBS)
$(CC) -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wundef -W -Wall -ansi -pedantic -g -o $(TARGET) $(OBJS) $(LIBS)
check: all
@cd $(testdir) && ./testDir.sh -q ../$(TARGET) 1.2-Tests/
@cd $(testdir) && ./testDir.sh -q ../$(TARGET) 1.3-Tests/
check-mem: all
@echo "This will take a long time! Be patient!"
@cd $(testdir) && ./testDir.sh -q -m ../$(TARGET) 1.2-Tests/
@cd $(testdir) && ./testDir.sh -q -m ../$(TARGET) 1.3-Tests/
install: all
$(INSTALL) $(TARGET) $(bindir)/$(TARGET)
TAGS: $(SRCS)
ctags $(SRCS)
TAGS: $(SRCS) $(HDRS)
ctags $(SRCS) $(HDRS)
docs: Doxyfile $(SRCS)
doxygen

View File

@ -2722,6 +2722,25 @@ ReturnObject *interpretDeclarationStmtNode(StmtNode *node, /**< [in] A point
}
if (stmt->expr)
init = interpretExprNode(stmt->expr, scope);
else if (stmt->type) {
switch (stmt->type->type) {
case CT_NIL:
init = createNilValueObject();
break;
case CT_BOOLEAN:
init = createBooleanValueObject(0);
break;
case CT_INTEGER:
init = createIntegerValueObject(0);
break;
case CT_FLOAT:
init = createFloatValueObject(0.0);
break;
case CT_STRING:
init = createStringValueObject(createString(""));
break;
}
}
else
init = createNilValueObject();
if (!init) return NULL;

View File

@ -735,7 +735,8 @@ void deleteAssignmentStmtNode(AssignmentStmtNode *node) /**< [in,out] A pointer
* \see deleteDeclarationStmtNode(DeclarationStmtNode *) */
DeclarationStmtNode *createDeclarationStmtNode(IdentifierNode *scope, /**< [in] A pointer to the scope to create the variable in. */
IdentifierNode *target, /**< [in] A pointer to the name of the variable to create. */
ExprNode *expr) /**< [in] An optional pointer to the expression to initialize \a target to. */
ExprNode *expr, /**< [in] An optional pointer to the expression to initialize \a target to. */
TypeNode *type) /**< [in] An optional pointer to the type to initialize \a target to. */
{
DeclarationStmtNode *p = malloc(sizeof(DeclarationStmtNode));
if (!p) {
@ -745,6 +746,7 @@ DeclarationStmtNode *createDeclarationStmtNode(IdentifierNode *scope, /**< [in]
p->scope = scope;
p->target = target;
p->expr = expr;
p->type = type;
return p;
}
@ -762,6 +764,7 @@ void deleteDeclarationStmtNode(DeclarationStmtNode *node) /**< [in,out] A pointe
deleteIdentifierNode(node->scope);
deleteIdentifierNode(node->target);
deleteExprNode(node->expr);
deleteTypeNode(node->type);
free(node);
}
@ -2148,6 +2151,7 @@ StmtNode *parseStmtNode(Token ***tokenp, /**< [in,out] A pointer to the p
IdentifierNode *scope = NULL;
IdentifierNode *target = NULL;
ExprNode *expr = NULL;
TypeNode *type = NULL;
DeclarationStmtNode *stmt = NULL;
#ifdef DEBUG
debug("ST_DECLARATION");
@ -2172,6 +2176,14 @@ StmtNode *parseStmtNode(Token ***tokenp, /**< [in,out] A pointer to the p
return NULL;
}
}
else if (acceptToken(&tokens, TT_ITZA)) {
type = parseTypeNode(&tokens);
if (!type) {
deleteIdentifierNode(scope);
deleteIdentifierNode(target);
return NULL;
}
}
if (!acceptToken(&tokens, TT_NEWLINE)) {
error("expected end of statement", tokens);
deleteIdentifierNode(scope);
@ -2179,7 +2191,7 @@ StmtNode *parseStmtNode(Token ***tokenp, /**< [in,out] A pointer to the p
if (expr) deleteExprNode(expr);
return NULL;
}
stmt = createDeclarationStmtNode(scope, target, expr);
stmt = createDeclarationStmtNode(scope, target, expr, type);
if (!stmt) {
deleteIdentifierNode(scope);
deleteIdentifierNode(target);

View File

@ -400,12 +400,16 @@ typedef struct {
* contents of \a expr. \a scope determines which level of scope the variable
* is to be created in.
*
* \note \a expr and \a type are mutually exclusive. If both are non-NULL,
* results are undefined.
*
* \see createDeclarationStmtNode(IdentifierNode *, IdentifierNode *, ExprNode *)
* \see deleteDeclarationStmtNode(DeclarationStmtNode *) */
typedef struct {
IdentifierNode *scope; /**< A pointer to the scope to create the variable in. */
IdentifierNode *target; /**< A pointer to the name of the variable to create. */
ExprNode *expr; /**< An optional pointer to expression to initialize \a target to. */
ExprNode *expr; /**< An optional pointer to the expression to initialize \a target to. */
TypeNode *type; /**< An optional pointer to the type to initialize \a target to. */
} DeclarationStmtNode;
/** Stores an if/then/else statement. A conditional statement checks the value
@ -552,7 +556,7 @@ void deleteInputStmtNode(InputStmtNode *);
AssignmentStmtNode *createAssignmentStmtNode(IdentifierNode *, ExprNode *);
void deleteAssignmentStmtNode(AssignmentStmtNode *);
DeclarationStmtNode *createDeclarationStmtNode(IdentifierNode *, IdentifierNode *, ExprNode *);
DeclarationStmtNode *createDeclarationStmtNode(IdentifierNode *, IdentifierNode *, ExprNode *, TypeNode *);
void deleteDeclarationStmtNode(DeclarationStmtNode *);
IfThenElseStmtNode *createIfThenElseStmtNode(BlockNode *, BlockNode *, ExprNodeList *, BlockNodeList *);

View File

@ -1 +0,0 @@
HAI 1.2 VISIBLE "Lorem "... "ipsum "... "dolor "... "sit" KTHXBYE

View File

@ -1 +0,0 @@
HAI 1.2 VISIBLE "Lorem ipsum "... "dolor sit" KTHXBYE

View File

@ -1 +0,0 @@
HAI 1.2 VISIBLE "Lorem" VISIBLE "ipsum" VISIBLE "dolor" VISIBLE "sit" KTHXBYE

View File

@ -1 +0,0 @@
HAI 1.2 VISIBLE "Lorem "… "ipsum "… "dolor "… "sit" KTHXBYE

View File

@ -1,3 +1,3 @@
HAI 1.2
HAI 1.3
VISIBLE "Lorem", VISIBLE "ipsum", VISIBLE "dolor", VISIBLE "sit"
KTHXBYE

View File

@ -1,4 +1,4 @@
HAI 1.2
HAI 1.3
VISIBLE "Lorem "...
"ipsum "...
"dolor "...

View File

@ -0,0 +1 @@
HAI 1.3 VISIBLE "Lorem "... "ipsum "... "dolor "... "sit" KTHXBYE

View File

@ -1,4 +1,4 @@
HAI 1.2
HAI 1.3
VISIBLE "Lorem "...
"ipsum "...
"dolor "...

View File

@ -1,4 +1,4 @@
HAI 1.2
HAI 1.3
VISIBLE "Lorem ipsum "...
"dolor sit"

View File

@ -0,0 +1 @@
HAI 1.3 VISIBLE "Lorem ipsum "... "dolor sit" KTHXBYE

View File

@ -0,0 +1 @@
HAI 1.3

View File

@ -1,3 +1,3 @@
HAI 1.2
HAI 1.3
VISIBLE "Lorem ipsum dolor sit"
KTHXBYE

View File

@ -1,4 +1,4 @@
HAI 1.2
HAI 1.3
VISIBLE "Lorem " "ipsum " "dolor " "sit"
VISIBLE "Lorem " "ipsum " "dolor " "sit"
VISIBLE "Lorem " "ipsum " "dolor " "sit"

View File

@ -1,4 +1,4 @@
HAI 1.2
HAI 1.3
VISIBLE "Lorem"
VISIBLE "ipsum"
VISIBLE "dolor"

View File

@ -0,0 +1 @@
HAI 1.3 VISIBLE "Lorem" VISIBLE "ipsum" VISIBLE "dolor" VISIBLE "sit" KTHXBYE

View File

@ -1,4 +1,4 @@
HAI 1.2
HAI 1.3
VISIBLE "Lorem"
VISIBLE "ipsum"
VISIBLE "dolor"

View File

@ -1,4 +1,4 @@
HAI 1.2
HAI 1.3
I HAS A var ITZ 0
IM IN YR loop
VISIBLE var

View File

@ -1,4 +1,4 @@
HAI 1.2
HAI 1.3
IM IN YR loop UPPIN YR var
VISIBLE var
BOTH SAEM var AN 9

View File

@ -1,4 +1,4 @@
HAI 1.2
HAI 1.3
IM IN YR loop NERFIN YR var
VISIBLE var
BOTH SAEM var AN -9

View File

@ -1,4 +1,4 @@
HAI 1.2
HAI 1.3
IM IN YR loop UPPIN YR var TIL BOTH SAEM var AN 10
VISIBLE var
IM OUTTA YR loop

View File

@ -1,4 +1,4 @@
HAI 1.2
HAI 1.3
IM IN YR loop NERFIN YR var WILE DIFFRINT var AN -10
VISIBLE var
IM OUTTA YR loop

View File

@ -1,4 +1,4 @@
HAI 1.2
HAI 1.3
HOW DUZ I plustwoin YR var
FOUND YR SUM OF var AN 2
IF U SAY SO

View File

@ -1,4 +1,4 @@
HAI 1.2
HAI 1.3
VISIBLE "a"
IM IN YR loop UPPIN YR var TIL BOTH SAEM var AN 10
IM OUTTA YR loop

View File

@ -1,4 +1,4 @@
HAI 1.2
HAI 1.3
IM IN YR loop TIL WIN
IM OUTTA YR loop
KTHXBYE

View File

@ -1,4 +1,4 @@
HAI 1.2
HAI 1.3
IM IN YR loop WILE FAIL
IM OUTTA YR loop
KTHXBYE

View File

@ -1,4 +1,4 @@
HAI 1.2
HAI 1.3
VISIBLE "Lorem "…
"ipsum "…
"dolor "…

View File

@ -0,0 +1 @@
HAI 1.3 VISIBLE "Lorem "… "ipsum "… "dolor "… "sit" KTHXBYE

View File

@ -1,4 +1,4 @@
HAI 1.2
HAI 1.3
VISIBLE "Lorem "…
"ipsum "…
"dolor "…

View File

@ -1,3 +1,3 @@
HAI 1.2
HAI 1.3
VISIBLE "ʇıs ɹoʃop ɯnsdı ɯǝɹo⅂"
KTHXBYE

View File

@ -1,3 +1,3 @@
HAI 1.2
HAI 1.3
VISIBLE "Lorem :(0024) ipsum :(00A2) dolor :(20AC) sit :(024B62)"
KTHXBYE

View File

@ -1,3 +1,3 @@
HAI 1.2
HAI 1.3
VISIBLE "Lorem :[DOLLAR SIGN] ipsum :[CENT SIGN] dolor :[EURO SIGN] sit"
KTHXBYE

Some files were not shown because too many files have changed in this diff Show More