aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/LuaSL/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--LuaSL/src/LuaSL_LSL_tree.h14
-rw-r--r--LuaSL/src/LuaSL_compile.c48
-rw-r--r--LuaSL/src/LuaSL_lemon_yaccer.y4
-rw-r--r--LuaSL/src/LuaSL_lexer.l4
4 files changed, 60 insertions, 10 deletions
diff --git a/LuaSL/src/LuaSL_LSL_tree.h b/LuaSL/src/LuaSL_LSL_tree.h
index 94be1a6..64832d2 100644
--- a/LuaSL/src/LuaSL_LSL_tree.h
+++ b/LuaSL/src/LuaSL_LSL_tree.h
@@ -40,6 +40,7 @@ typedef struct _allowedTypes allowedTypes;
40typedef struct _LSL_Token LSL_Token; 40typedef struct _LSL_Token LSL_Token;
41typedef struct _LSL_Text LSL_Text; 41typedef struct _LSL_Text LSL_Text;
42typedef struct _LSL_Leaf LSL_Leaf; 42typedef struct _LSL_Leaf LSL_Leaf;
43typedef struct _LSL_Numby LSL_Numby;
43typedef struct _LSL_Parenthesis LSL_Parenthesis; 44typedef struct _LSL_Parenthesis LSL_Parenthesis;
44typedef struct _LSL_Identifier LSL_Identifier; 45typedef struct _LSL_Identifier LSL_Identifier;
45typedef struct _LSL_Statement LSL_Statement; 46typedef struct _LSL_Statement LSL_Statement;
@@ -185,6 +186,7 @@ struct _LSL_Leaf
185 float vectorValue[3]; 186 float vectorValue[3];
186 float rotationValue[4]; 187 float rotationValue[4];
187 int integerValue; 188 int integerValue;
189 LSL_Numby *numbyValue;
188 LSL_Leaf *listValue; 190 LSL_Leaf *listValue;
189 const char *stringValue; 191 const char *stringValue;
190 opType operationValue; 192 opType operationValue;
@@ -199,6 +201,17 @@ struct _LSL_Leaf
199 } value; 201 } value;
200}; 202};
201 203
204struct _LSL_Numby
205{
206 LSL_Text text;
207 LSL_Type type;
208 union
209 {
210 float floatValue;
211 int integerValue;
212 } value;
213};
214
202struct _LSL_Parenthesis 215struct _LSL_Parenthesis
203{ 216{
204 LSL_Leaf *contents; 217 LSL_Leaf *contents;
@@ -403,6 +416,7 @@ LSL_Leaf *addFunctionBody(LuaSL_compiler *compiler, LSL_Leaf *function, LSL_Leaf
403LSL_Leaf *addFunctionCall(LuaSL_compiler *compiler, LSL_Leaf *identifier, LSL_Leaf *open, LSL_Leaf *params, LSL_Leaf *close); 416LSL_Leaf *addFunctionCall(LuaSL_compiler *compiler, LSL_Leaf *identifier, LSL_Leaf *open, LSL_Leaf *params, LSL_Leaf *close);
404LSL_Leaf *addIfElse(LuaSL_compiler *compiler, LSL_Leaf *ifBlock, LSL_Leaf *elseBlock); 417LSL_Leaf *addIfElse(LuaSL_compiler *compiler, LSL_Leaf *ifBlock, LSL_Leaf *elseBlock);
405LSL_Leaf *addList(LSL_Leaf *left, LSL_Leaf *list, LSL_Leaf *right); 418LSL_Leaf *addList(LSL_Leaf *left, LSL_Leaf *list, LSL_Leaf *right);
419LSL_Leaf *addNumby(LSL_Leaf *numby);
406LSL_Leaf *addOperation(LuaSL_compiler *compiler, LSL_Leaf *left, LSL_Leaf *lval, LSL_Leaf *right); 420LSL_Leaf *addOperation(LuaSL_compiler *compiler, LSL_Leaf *left, LSL_Leaf *lval, LSL_Leaf *right);
407LSL_Leaf *addParameter(LuaSL_compiler *compiler, LSL_Leaf *type, LSL_Leaf *newParam); 421LSL_Leaf *addParameter(LuaSL_compiler *compiler, LSL_Leaf *type, LSL_Leaf *newParam);
408LSL_Leaf *addParenthesis(LSL_Leaf *lval, LSL_Leaf *expr, LSL_Type type, LSL_Leaf *rval); 422LSL_Leaf *addParenthesis(LSL_Leaf *lval, LSL_Leaf *expr, LSL_Type type, LSL_Leaf *rval);
diff --git a/LuaSL/src/LuaSL_compile.c b/LuaSL/src/LuaSL_compile.c
index de23b78..73b43dd 100644
--- a/LuaSL/src/LuaSL_compile.c
+++ b/LuaSL/src/LuaSL_compile.c
@@ -710,6 +710,40 @@ LSL_Leaf *addList(LSL_Leaf *left, LSL_Leaf *list, LSL_Leaf *right)
710 return left; 710 return left;
711} 711}
712 712
713LSL_Leaf *addNumby(LSL_Leaf *numby)
714{
715 LSL_Numby *num = calloc(1, sizeof(LSL_Numby));
716
717 if ((numby) && (num))
718 {
719 num->text.text = numby->value.stringValue;
720#if LUASL_DIFF_CHECK
721 num->text.ignorable = numby->ignorable;
722 numby->ignorable = NULL;
723#endif
724 switch (numby->toKen->type)
725 {
726 case LSL_FLOAT :
727 {
728 num->value.floatValue = atof(num->text.text);
729 numby->basicType = OT_float;
730 break;
731 }
732 case LSL_INTEGER :
733 {
734 num->value.integerValue = atoi(num->text.text);
735 numby->basicType = OT_integer;
736 break;
737 }
738 default:
739 break;
740 }
741 numby->value.numbyValue = num;
742 num->type = numby->basicType;
743 }
744 return numby;
745}
746
713LSL_Leaf *addParenthesis(LSL_Leaf *lval, LSL_Leaf *expr, LSL_Type type, LSL_Leaf *rval) 747LSL_Leaf *addParenthesis(LSL_Leaf *lval, LSL_Leaf *expr, LSL_Type type, LSL_Leaf *rval)
714{ 748{
715 LSL_Parenthesis *parens = calloc(1, sizeof(LSL_Parenthesis)); 749 LSL_Parenthesis *parens = calloc(1, sizeof(LSL_Parenthesis));
@@ -1103,10 +1137,11 @@ static LSL_Leaf *evaluateFloatToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf
1103 1137
1104 if (content && result) 1138 if (content && result)
1105 { 1139 {
1106 if (LUASL_DEBUG)
1107 printf(" <%g> ", content->value.floatValue);
1108 memcpy(result, content, sizeof(LSL_Leaf)); 1140 memcpy(result, content, sizeof(LSL_Leaf));
1141 result->value.floatValue = content->value.numbyValue->value.floatValue;
1109 result->basicType = OT_float; 1142 result->basicType = OT_float;
1143 if (LUASL_DEBUG)
1144 printf(" <%g> ", content->value.floatValue);
1110 } 1145 }
1111 return result; 1146 return result;
1112} 1147}
@@ -1117,10 +1152,11 @@ static LSL_Leaf *evaluateIntegerToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Lea
1117 1152
1118 if (content && result) 1153 if (content && result)
1119 { 1154 {
1120 if (LUASL_DEBUG)
1121 printf(" <%d> ", content->value.integerValue);
1122 memcpy(result, content, sizeof(LSL_Leaf)); 1155 memcpy(result, content, sizeof(LSL_Leaf));
1156 result->value.integerValue = content->value.numbyValue->value.integerValue;
1123 result->basicType = OT_integer; 1157 result->basicType = OT_integer;
1158 if (LUASL_DEBUG)
1159 printf(" <%d> ", result->value.integerValue);
1124 } 1160 }
1125 return result; 1161 return result;
1126} 1162}
@@ -1681,7 +1717,7 @@ static void outputCrementsToken(FILE *file, outputMode mode, LSL_Leaf *content)
1681static void outputFloatToken(FILE *file, outputMode mode, LSL_Leaf *content) 1717static void outputFloatToken(FILE *file, outputMode mode, LSL_Leaf *content)
1682{ 1718{
1683 if (content) 1719 if (content)
1684 fprintf(file, "%g", content->value.floatValue); 1720 outputText(file, &(content->value.numbyValue->text), !(LSL_NOIGNORE & content->toKen->flags));
1685} 1721}
1686 1722
1687static void outputFunctionToken(FILE *file, outputMode mode, LSL_Leaf *content) 1723static void outputFunctionToken(FILE *file, outputMode mode, LSL_Leaf *content)
@@ -1734,7 +1770,7 @@ static void outputFunctionCallToken(FILE *file, outputMode mode, LSL_Leaf *conte
1734static void outputIntegerToken(FILE *file, outputMode mode, LSL_Leaf *content) 1770static void outputIntegerToken(FILE *file, outputMode mode, LSL_Leaf *content)
1735{ 1771{
1736 if (content) 1772 if (content)
1737 fprintf(file, "%d", content->value.integerValue); 1773 outputText(file, &(content->value.numbyValue->text), !(LSL_NOIGNORE & content->toKen->flags));
1738} 1774}
1739 1775
1740static void outputIdentifierToken(FILE *file, outputMode mode, LSL_Leaf *content) 1776static void outputIdentifierToken(FILE *file, outputMode mode, LSL_Leaf *content)
diff --git a/LuaSL/src/LuaSL_lemon_yaccer.y b/LuaSL/src/LuaSL_lemon_yaccer.y
index 565a431..d2731d8 100644
--- a/LuaSL/src/LuaSL_lemon_yaccer.y
+++ b/LuaSL/src/LuaSL_lemon_yaccer.y
@@ -196,9 +196,9 @@ expr(A) ::= LSL_INCREMENT_PRE(C) identifier(B). { A = addCrement(compiler,
196// Values. 196// Values.
197 197
198%nonassoc LSL_FLOAT. 198%nonassoc LSL_FLOAT.
199expr(A) ::= LSL_FLOAT(B). { B->basicType = OT_float; A = B; } 199expr(A) ::= LSL_FLOAT(B). { A = addNumby(B); }
200%nonassoc LSL_INTEGER. 200%nonassoc LSL_INTEGER.
201expr(A) ::= LSL_INTEGER(B). { B->basicType = OT_integer; A = B; } 201expr(A) ::= LSL_INTEGER(B). { A = addNumby(B); }
202%nonassoc LSL_KEY. 202%nonassoc LSL_KEY.
203expr(A) ::= LSL_KEY(B). { B->basicType = OT_key; A = B; } 203expr(A) ::= LSL_KEY(B). { B->basicType = OT_key; A = B; }
204%nonassoc LSL_LIST. 204%nonassoc LSL_LIST.
diff --git a/LuaSL/src/LuaSL_lexer.l b/LuaSL/src/LuaSL_lexer.l
index 4329bb2..adee1a7 100644
--- a/LuaSL/src/LuaSL_lexer.l
+++ b/LuaSL/src/LuaSL_lexer.l
@@ -104,8 +104,8 @@ STRING \"(\\.|[^\\"\n])*\"
104{IDENTIFIER} %{ yylval->value.stringValue = eina_stringshare_add_length(yytext, yyleng); return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_IDENTIFIER); %} 104{IDENTIFIER} %{ yylval->value.stringValue = eina_stringshare_add_length(yytext, yyleng); return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_IDENTIFIER); %}
105 105
106 /* Types. */ 106 /* Types. */
107{INTEGER} %{ yylval->value.integerValue = atoi(yytext); return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_INTEGER); %} 107{INTEGER} %{ yylval->value.stringValue = eina_stringshare_add_length(yytext, yyleng); return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_INTEGER); %}
108{FLOAT} %{ yylval->value.floatValue = atof(yytext); return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_FLOAT); %} 108{FLOAT} %{ yylval->value.stringValue = eina_stringshare_add_length(yytext, yyleng); return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_FLOAT); %}
109{KEY} %{ yylval->value.stringValue = eina_stringshare_add_length(yytext, yyleng); return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_KEY); %} 109{KEY} %{ yylval->value.stringValue = eina_stringshare_add_length(yytext, yyleng); return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_KEY); %}
110{STRING} %{ yylval->value.stringValue = eina_stringshare_add_length(yytext, yyleng); return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_STRING); %} 110{STRING} %{ yylval->value.stringValue = eina_stringshare_add_length(yytext, yyleng); return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_STRING); %}
111 111