-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
151 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include "nv.h" | ||
|
||
void NV_printNodeByID(const NV_ID *id) | ||
{ | ||
NV_Node *n = NV_Node_getByID(id); | ||
NV_printNode(n); | ||
} | ||
|
||
void NV_printNode(const NV_Node *n) | ||
{ | ||
if(!n){ | ||
printf("(null pointer node)"); | ||
return; | ||
} | ||
if(NV_isTreeType(&n->id, &NODEID_TREE_TYPE_ARRAY)){ | ||
NV_Array_print(&n->id); | ||
} else if(NV_isTreeType(&n->id, &NODEID_TREE_TYPE_VARIABLE)){ | ||
NV_Variable_printPrimVal(&n->id); | ||
} else if(NV_isTreeType(&n->id, &NODEID_TREE_TYPE_OP)){ | ||
NV_Op_print(&n->id); | ||
} else{ | ||
NV_Node_printPrimVal(n); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
#include "nv.h" | ||
|
||
#define NV_LANG_CHAR_LIST_LEN 3 | ||
int NV_Lang_getCharType(const NV_ID *cTypeList, char c) | ||
{ | ||
NV_ID t; | ||
int i; | ||
if(c == '\0') return -1; | ||
for(i = 0; i < NV_LANG_CHAR_LIST_LEN; i++){ | ||
t = NV_Array_getByIndex(cTypeList, i); | ||
if(NV_Node_String_strchr(NV_Node_getByID(&t), c)) break; | ||
} | ||
return i; | ||
} | ||
|
||
|
||
NV_ID NV_createCharTypeList() | ||
{ | ||
NV_ID ns; | ||
NV_ID cList = NV_Array_create(); | ||
// | ||
ns = NV_Node_createWithString(" \t\r\n"); | ||
NV_Array_push(&cList, &ns); | ||
ns = NV_Node_createWithString("#!%&-=^~|+*:.<>/"); | ||
NV_Array_push(&cList, &ns); | ||
ns = NV_Node_createWithString("(){}[],;\"`\\"); | ||
NV_Array_push(&cList, &ns); | ||
// | ||
return cList; | ||
} | ||
|
||
void NV_addOp(const NV_ID *opList, const char *token, int32_t prec, const NV_ID *func) | ||
{ | ||
NV_ID opEntry; | ||
NV_ID ePrec; | ||
opEntry = NV_Node_create(); | ||
NV_Node_createRelation( | ||
&opEntry, &RELID_TREE_TYPE, &NODEID_TREE_TYPE_OP); | ||
ePrec = NV_Node_createWithInt32(prec); | ||
NV_Node_createRelation( | ||
&opEntry, &RELID_OP_PRECEDENCE, &ePrec); | ||
NV_Node_createRelation( | ||
&opEntry, &RELID_OP_FUNC, func); | ||
|
||
// | ||
NV_Dict_addByStringKey(opList, token, &opEntry); | ||
} | ||
|
||
NV_ID NV_createOpList() | ||
{ | ||
NV_ID nv; | ||
NV_ID opList = NV_Node_createWithString("NV_OpList"); | ||
// | ||
nv = NV_Node_createWithString("NV_Op_add"); | ||
NV_addOp(&opList, "+", 100, &nv); | ||
// | ||
nv = NV_Node_createWithString("NV_Op_sub"); | ||
NV_addOp(&opList, "-", 100, &nv); | ||
// | ||
nv = NV_Node_createWithString("NV_Op_mul"); | ||
NV_addOp(&opList, "*", 200, &nv); | ||
// | ||
nv = NV_Node_createWithString("NV_Op_div"); | ||
NV_addOp(&opList, "/", 200, &nv); | ||
// | ||
nv = NV_Node_createWithString("NV_Op_mod"); | ||
NV_addOp(&opList, "%", 200, &nv); | ||
// | ||
nv = NV_Node_createWithString("NV_Op_nothing"); | ||
NV_addOp(&opList, " ", 300, &nv); | ||
// | ||
NV_Dict_print(&opList); | ||
return opList; | ||
} | ||
|
||
void NV_Op_print(const NV_ID *op) | ||
{ | ||
NV_ID eFunc; | ||
NV_ID ePrec; | ||
eFunc = NV_Node_getRelatedNodeFrom(op, &RELID_OP_FUNC); | ||
ePrec = NV_Node_getRelatedNodeFrom(op, &RELID_OP_PRECEDENCE); | ||
printf("(op "); | ||
NV_printNodeByID(&eFunc); | ||
printf("/"); | ||
NV_printNodeByID(&ePrec); | ||
printf(")"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters