aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--LuaSL/src/LuaSL_LSL_tree.c262
-rw-r--r--LuaSL/src/LuaSL_LSL_tree.h10
2 files changed, 129 insertions, 143 deletions
diff --git a/LuaSL/src/LuaSL_LSL_tree.c b/LuaSL/src/LuaSL_LSL_tree.c
index af6e02f..fb35490 100644
--- a/LuaSL/src/LuaSL_LSL_tree.c
+++ b/LuaSL/src/LuaSL_LSL_tree.c
@@ -9,124 +9,124 @@ static LSL_Leaf *evaluateNoToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *ri
9static LSL_Leaf *evaluateOperationToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right); 9static LSL_Leaf *evaluateOperationToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right);
10static LSL_Leaf *eveluateParenthesisToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right); 10static LSL_Leaf *eveluateParenthesisToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right);
11static LSL_Leaf *evaluateStatementToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right); 11static LSL_Leaf *evaluateStatementToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right);
12static void outputFloatToken(FILE *file, LSL_Leaf *content); 12static void outputFloatToken(FILE *file, outputMode mode, LSL_Leaf *content);
13static void outputFunctionToken(FILE *file, LSL_Leaf *content); 13static void outputFunctionToken(FILE *file, outputMode mode, LSL_Leaf *content);
14static void outputIntegerToken(FILE *file, LSL_Leaf *content); 14static void outputIntegerToken(FILE *file, outputMode mode, LSL_Leaf *content);
15static void outputParameterToken(FILE *file, LSL_Leaf *content); 15static void outputParameterToken(FILE *file, outputMode mode, LSL_Leaf *content);
16static void outputParameterListToken(FILE *file, LSL_Leaf *content); 16static void outputParameterListToken(FILE *file, outputMode mode, LSL_Leaf *content);
17static void outputParenthesisToken(FILE *file, LSL_Leaf *content); 17static void outputParenthesisToken(FILE *file, outputMode mode, LSL_Leaf *content);
18static void outputStateToken(FILE *file, LSL_Leaf *content); 18static void outputStateToken(FILE *file, outputMode mode, LSL_Leaf *content);
19static void outputStatementToken(FILE *file, LSL_Leaf *content); 19static void outputStatementToken(FILE *file, outputMode mode, LSL_Leaf *content);
20static void outputVariableToken(FILE *file, LSL_Leaf *content); 20static void outputVariableToken(FILE *file, outputMode mode, LSL_Leaf *content);
21 21
22LSL_Token LSL_Tokens[] = 22LSL_Token LSL_Tokens[] =
23{ 23{
24 // Various forms of "space". 24 // Various forms of "space".
25 {LSL_COMMENT, ST_NONE, "/*", LSL_NONE, NULL, NULL, NULL}, 25 {LSL_COMMENT, ST_NONE, "/*", LSL_NONE, NULL, NULL},
26 {LSL_COMMENT_LINE, ST_NONE, "//", LSL_NONE, NULL, NULL, NULL}, 26 {LSL_COMMENT_LINE, ST_NONE, "//", LSL_NONE, NULL, NULL},
27 {LSL_SPACE, ST_NONE, " ", LSL_NONE, NULL, NULL, NULL}, 27 {LSL_SPACE, ST_NONE, " ", LSL_NONE, NULL, NULL},
28 28
29 // Operators, in order of precedence, low to high 29 // Operators, in order of precedence, low to high
30 // Left to right, unless otherwise stated. 30 // Left to right, unless otherwise stated.
31 // According to http://wiki.secondlife.com/wiki/Category:LSL_Operators 31 // According to http://wiki.secondlife.com/wiki/Category:LSL_Operators
32 {LSL_BOOL_AND, ST_BOOLEAN, "&&", LSL_RIGHT2LEFT, NULL, NULL, evaluateOperationToken}, 32 {LSL_BOOL_AND, ST_BOOLEAN, "&&", LSL_RIGHT2LEFT, NULL, evaluateOperationToken},
33// QUIRK - Seems to be some disagreement about BOOL_AND/BOOL_OR precedence. Either they are equal, or OR is higher. 33// QUIRK - Seems to be some disagreement about BOOL_AND/BOOL_OR precedence. Either they are equal, or OR is higher.
34// QUIRK - No boolean short circuiting. 34// QUIRK - No boolean short circuiting.
35// QUIRK - Booleans and conditionals are executed right to left. Or maybe not, depending on who you believe. 35// QUIRK - Booleans and conditionals are executed right to left. Or maybe not, depending on who you believe.
36 {LSL_BOOL_OR, ST_BOOLEAN, "||", LSL_RIGHT2LEFT, NULL, NULL, evaluateOperationToken}, 36 {LSL_BOOL_OR, ST_BOOLEAN, "||", LSL_RIGHT2LEFT, NULL, evaluateOperationToken},
37 {LSL_BIT_OR, ST_BITWISE, "|", LSL_LEFT2RIGHT, NULL, NULL, evaluateOperationToken}, 37 {LSL_BIT_OR, ST_BITWISE, "|", LSL_LEFT2RIGHT, NULL, evaluateOperationToken},
38 {LSL_BIT_XOR, ST_BITWISE, "^", LSL_LEFT2RIGHT, NULL, NULL, evaluateOperationToken}, 38 {LSL_BIT_XOR, ST_BITWISE, "^", LSL_LEFT2RIGHT, NULL, evaluateOperationToken},
39 {LSL_BIT_AND, ST_BITWISE, "&", LSL_LEFT2RIGHT, NULL, NULL, evaluateOperationToken}, 39 {LSL_BIT_AND, ST_BITWISE, "&", LSL_LEFT2RIGHT, NULL, evaluateOperationToken},
40// QUIRK - Booleans and conditionals are executed right to left. Or maybe not, depending on who you believe. 40// QUIRK - Booleans and conditionals are executed right to left. Or maybe not, depending on who you believe.
41 {LSL_NOT_EQUAL, ST_EQUALITY, "!=", LSL_RIGHT2LEFT, NULL, NULL, evaluateOperationToken}, 41 {LSL_NOT_EQUAL, ST_EQUALITY, "!=", LSL_RIGHT2LEFT, NULL, evaluateOperationToken},
42 {LSL_EQUAL, ST_EQUALITY, "==", LSL_RIGHT2LEFT, NULL, NULL, evaluateOperationToken}, 42 {LSL_EQUAL, ST_EQUALITY, "==", LSL_RIGHT2LEFT, NULL, evaluateOperationToken},
43 {LSL_GREATER_EQUAL, ST_COMPARISON, ">=", LSL_RIGHT2LEFT, NULL, NULL, evaluateOperationToken}, 43 {LSL_GREATER_EQUAL, ST_COMPARISON, ">=", LSL_RIGHT2LEFT, NULL, evaluateOperationToken},
44 {LSL_LESS_EQUAL, ST_COMPARISON, "<=", LSL_RIGHT2LEFT, NULL, NULL, evaluateOperationToken}, 44 {LSL_LESS_EQUAL, ST_COMPARISON, "<=", LSL_RIGHT2LEFT, NULL, evaluateOperationToken},
45 {LSL_GREATER_THAN, ST_COMPARISON, ">", LSL_RIGHT2LEFT, NULL, NULL, evaluateOperationToken}, 45 {LSL_GREATER_THAN, ST_COMPARISON, ">", LSL_RIGHT2LEFT, NULL, evaluateOperationToken},
46 {LSL_LESS_THAN, ST_COMPARISON, "<", LSL_RIGHT2LEFT, NULL, NULL, evaluateOperationToken}, 46 {LSL_LESS_THAN, ST_COMPARISON, "<", LSL_RIGHT2LEFT, NULL, evaluateOperationToken},
47 {LSL_RIGHT_SHIFT, ST_BITWISE, ">>", LSL_LEFT2RIGHT, NULL, NULL, evaluateOperationToken}, 47 {LSL_RIGHT_SHIFT, ST_BITWISE, ">>", LSL_LEFT2RIGHT, NULL, evaluateOperationToken},
48 {LSL_LEFT_SHIFT, ST_BITWISE, "<<", LSL_LEFT2RIGHT, NULL, NULL, evaluateOperationToken}, 48 {LSL_LEFT_SHIFT, ST_BITWISE, "<<", LSL_LEFT2RIGHT, NULL, evaluateOperationToken},
49 {LSL_CONCATENATE, ST_ADD, "+", LSL_LEFT2RIGHT, NULL, NULL, evaluateOperationToken}, 49 {LSL_CONCATENATE, ST_ADD, "+", LSL_LEFT2RIGHT, NULL, evaluateOperationToken},
50 {LSL_ADD, ST_ADD, "+", LSL_LEFT2RIGHT, NULL, NULL, evaluateOperationToken}, 50 {LSL_ADD, ST_ADD, "+", LSL_LEFT2RIGHT, NULL, evaluateOperationToken},
51 {LSL_SUBTRACT, ST_SUBTRACT, "-", LSL_LEFT2RIGHT, NULL, NULL, evaluateOperationToken}, 51 {LSL_SUBTRACT, ST_SUBTRACT, "-", LSL_LEFT2RIGHT, NULL, evaluateOperationToken},
52 {LSL_CROSS_PRODUCT, ST_NONE, "%", LSL_LEFT2RIGHT, NULL, NULL, evaluateOperationToken}, 52 {LSL_CROSS_PRODUCT, ST_NONE, "%", LSL_LEFT2RIGHT, NULL, evaluateOperationToken},
53 {LSL_DOT_PRODUCT, ST_NONE, "*", LSL_LEFT2RIGHT, NULL, NULL, evaluateOperationToken}, 53 {LSL_DOT_PRODUCT, ST_NONE, "*", LSL_LEFT2RIGHT, NULL, evaluateOperationToken},
54 {LSL_MULTIPLY, ST_MULTIPLY, "*", LSL_LEFT2RIGHT, NULL, NULL, evaluateOperationToken}, 54 {LSL_MULTIPLY, ST_MULTIPLY, "*", LSL_LEFT2RIGHT, NULL, evaluateOperationToken},
55 {LSL_MODULO, ST_MODULO, "%", LSL_LEFT2RIGHT, NULL, NULL, evaluateOperationToken}, 55 {LSL_MODULO, ST_MODULO, "%", LSL_LEFT2RIGHT, NULL, evaluateOperationToken},
56 {LSL_DIVIDE, ST_MULTIPLY, "/", LSL_LEFT2RIGHT, NULL, NULL, evaluateOperationToken}, 56 {LSL_DIVIDE, ST_MULTIPLY, "/", LSL_LEFT2RIGHT, NULL, evaluateOperationToken},
57 {LSL_NEGATION, ST_NEGATE, "-", LSL_RIGHT2LEFT | LSL_UNARY, NULL, NULL, evaluateOperationToken}, 57 {LSL_NEGATION, ST_NEGATE, "-", LSL_RIGHT2LEFT | LSL_UNARY, NULL, evaluateOperationToken},
58 {LSL_BOOL_NOT, ST_BOOL_NOT, "!", LSL_RIGHT2LEFT | LSL_UNARY, NULL, NULL, evaluateOperationToken}, 58 {LSL_BOOL_NOT, ST_BOOL_NOT, "!", LSL_RIGHT2LEFT | LSL_UNARY, NULL, evaluateOperationToken},
59 {LSL_BIT_NOT, ST_BIT_NOT, "~", LSL_RIGHT2LEFT | LSL_UNARY, NULL, NULL, evaluateOperationToken}, 59 {LSL_BIT_NOT, ST_BIT_NOT, "~", LSL_RIGHT2LEFT | LSL_UNARY, NULL, evaluateOperationToken},
60 {LSL_TYPECAST_CLOSE, ST_NONE, ")", LSL_RIGHT2LEFT | LSL_UNARY, NULL, NULL, evaluateNoToken}, 60 {LSL_TYPECAST_CLOSE, ST_NONE, ")", LSL_RIGHT2LEFT | LSL_UNARY, NULL, evaluateNoToken},
61 {LSL_TYPECAST_OPEN, ST_NONE, "(", LSL_RIGHT2LEFT | LSL_UNARY, NULL, NULL, evaluateOperationToken}, 61 {LSL_TYPECAST_OPEN, ST_NONE, "(", LSL_RIGHT2LEFT | LSL_UNARY, NULL, evaluateOperationToken},
62 {LSL_ANGLE_CLOSE, ST_NONE, ">", LSL_LEFT2RIGHT | LSL_CREATION, NULL, NULL, evaluateNoToken}, 62 {LSL_ANGLE_CLOSE, ST_NONE, ">", LSL_LEFT2RIGHT | LSL_CREATION, NULL, evaluateNoToken},
63 {LSL_ANGLE_OPEN, ST_NONE, "<", LSL_LEFT2RIGHT | LSL_CREATION, NULL, NULL, evaluateOperationToken}, 63 {LSL_ANGLE_OPEN, ST_NONE, "<", LSL_LEFT2RIGHT | LSL_CREATION, NULL, evaluateOperationToken},
64 {LSL_BRACKET_CLOSE, ST_NONE, "]", LSL_INNER2OUTER | LSL_CREATION, NULL, NULL, evaluateNoToken}, 64 {LSL_BRACKET_CLOSE, ST_NONE, "]", LSL_INNER2OUTER | LSL_CREATION, NULL, evaluateNoToken},
65 {LSL_BRACKET_OPEN, ST_NONE, "[", LSL_INNER2OUTER | LSL_CREATION, NULL, NULL, evaluateOperationToken}, 65 {LSL_BRACKET_OPEN, ST_NONE, "[", LSL_INNER2OUTER | LSL_CREATION, NULL, evaluateOperationToken},
66 {LSL_PARENTHESIS_CLOSE, ST_NONE, ")", LSL_INNER2OUTER, NULL, NULL, evaluateNoToken}, 66 {LSL_PARENTHESIS_CLOSE, ST_NONE, ")", LSL_INNER2OUTER, NULL, evaluateNoToken},
67 {LSL_PARENTHESIS_OPEN, ST_NONE, "(", LSL_INNER2OUTER, outputParenthesisToken, NULL, eveluateParenthesisToken}, 67 {LSL_PARENTHESIS_OPEN, ST_NONE, "(", LSL_INNER2OUTER, outputParenthesisToken, eveluateParenthesisToken},
68 {LSL_ASSIGNMENT_CONCATENATE,ST_CONCATENATION, "+=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, NULL, NULL, evaluateOperationToken}, 68 {LSL_ASSIGNMENT_CONCATENATE,ST_CONCATENATION, "+=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, NULL, evaluateOperationToken},
69 {LSL_ASSIGNMENT_ADD, ST_CONCATENATION, "+=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, NULL, NULL, evaluateOperationToken}, 69 {LSL_ASSIGNMENT_ADD, ST_CONCATENATION, "+=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, NULL, evaluateOperationToken},
70 {LSL_ASSIGNMENT_SUBTRACT, ST_ASSIGNMENT, "-=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, NULL, NULL, evaluateOperationToken}, 70 {LSL_ASSIGNMENT_SUBTRACT, ST_ASSIGNMENT, "-=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, NULL, evaluateOperationToken},
71 {LSL_ASSIGNMENT_MULTIPLY, ST_ASSIGNMENT, "*=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, NULL, NULL, evaluateOperationToken}, 71 {LSL_ASSIGNMENT_MULTIPLY, ST_ASSIGNMENT, "*=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, NULL, evaluateOperationToken},
72 {LSL_ASSIGNMENT_MODULO, ST_MODULO, "%=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, NULL, NULL, evaluateOperationToken}, 72 {LSL_ASSIGNMENT_MODULO, ST_MODULO, "%=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, NULL, evaluateOperationToken},
73 {LSL_ASSIGNMENT_DIVIDE, ST_ASSIGNMENT, "/=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, NULL, NULL, evaluateOperationToken}, 73 {LSL_ASSIGNMENT_DIVIDE, ST_ASSIGNMENT, "/=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, NULL, evaluateOperationToken},
74 {LSL_ASSIGNMENT_PLAIN, ST_CONCATENATION, "=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, NULL, NULL, evaluateOperationToken}, 74 {LSL_ASSIGNMENT_PLAIN, ST_CONCATENATION, "=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, NULL, evaluateOperationToken},
75 {LSL_DOT, ST_NONE, ".", LSL_RIGHT2LEFT, NULL, NULL, evaluateOperationToken}, 75 {LSL_DOT, ST_NONE, ".", LSL_RIGHT2LEFT, NULL, evaluateOperationToken},
76 {LSL_DECREMENT_POST, ST_NONE, "--", LSL_RIGHT2LEFT | LSL_UNARY, NULL, NULL, evaluateOperationToken}, 76 {LSL_DECREMENT_POST, ST_NONE, "--", LSL_RIGHT2LEFT | LSL_UNARY, NULL, evaluateOperationToken},
77 {LSL_DECREMENT_PRE, ST_NONE, "--", LSL_RIGHT2LEFT | LSL_UNARY, NULL, NULL, evaluateOperationToken}, 77 {LSL_DECREMENT_PRE, ST_NONE, "--", LSL_RIGHT2LEFT | LSL_UNARY, NULL, evaluateOperationToken},
78 {LSL_INCREMENT_POST, ST_NONE, "++", LSL_RIGHT2LEFT | LSL_UNARY, NULL, NULL, evaluateOperationToken}, 78 {LSL_INCREMENT_POST, ST_NONE, "++", LSL_RIGHT2LEFT | LSL_UNARY, NULL, evaluateOperationToken},
79 {LSL_INCREMENT_PRE, ST_NONE, "++", LSL_RIGHT2LEFT | LSL_UNARY, NULL, NULL, evaluateOperationToken}, 79 {LSL_INCREMENT_PRE, ST_NONE, "++", LSL_RIGHT2LEFT | LSL_UNARY, NULL, evaluateOperationToken},
80 {LSL_COMMA, ST_NONE, ",", LSL_LEFT2RIGHT, NULL, NULL, evaluateOperationToken}, 80 {LSL_COMMA, ST_NONE, ",", LSL_LEFT2RIGHT, NULL, evaluateOperationToken},
81 81
82 {LSL_EXPRESSION, ST_NONE, "expression", LSL_NONE , NULL, NULL, NULL}, 82 {LSL_EXPRESSION, ST_NONE, "expression", LSL_NONE , NULL, NULL},
83 83
84 // Types. 84 // Types.
85 {LSL_FLOAT, ST_NONE, "float", LSL_NONE, outputFloatToken, NULL, evaluateFloatToken}, 85 {LSL_FLOAT, ST_NONE, "float", LSL_NONE, outputFloatToken, evaluateFloatToken},
86 {LSL_INTEGER, ST_NONE, "integer", LSL_NONE, outputIntegerToken, NULL, evaluateIntegerToken}, 86 {LSL_INTEGER, ST_NONE, "integer", LSL_NONE, outputIntegerToken, evaluateIntegerToken},
87 {LSL_KEY, ST_NONE, "key", LSL_NONE, NULL, NULL, NULL}, 87 {LSL_KEY, ST_NONE, "key", LSL_NONE, NULL, NULL},
88 {LSL_LIST, ST_NONE, "list", LSL_NONE, NULL, NULL, NULL}, 88 {LSL_LIST, ST_NONE, "list", LSL_NONE, NULL, NULL},
89 {LSL_ROTATION, ST_NONE, "rotation", LSL_NONE, NULL, NULL, NULL}, 89 {LSL_ROTATION, ST_NONE, "rotation", LSL_NONE, NULL, NULL},
90 {LSL_STRING, ST_NONE, "string", LSL_NONE, NULL, NULL, NULL}, 90 {LSL_STRING, ST_NONE, "string", LSL_NONE, NULL, NULL},
91 {LSL_VECTOR, ST_NONE, "vector", LSL_NONE, NULL, NULL, NULL}, 91 {LSL_VECTOR, ST_NONE, "vector", LSL_NONE, NULL, NULL},
92 92
93 // Types names. 93 // Types names.
94 {LSL_TYPE_FLOAT, ST_NONE, "float", LSL_NONE, NULL, NULL, NULL}, 94 {LSL_TYPE_FLOAT, ST_NONE, "float", LSL_NONE, NULL, NULL},
95 {LSL_TYPE_INTEGER, ST_NONE, "integer", LSL_NONE, NULL, NULL, NULL}, 95 {LSL_TYPE_INTEGER, ST_NONE, "integer", LSL_NONE, NULL, NULL},
96 {LSL_TYPE_KEY, ST_NONE, "key", LSL_NONE, NULL, NULL, NULL}, 96 {LSL_TYPE_KEY, ST_NONE, "key", LSL_NONE, NULL, NULL},
97 {LSL_TYPE_LIST, ST_NONE, "list", LSL_NONE, NULL, NULL, NULL}, 97 {LSL_TYPE_LIST, ST_NONE, "list", LSL_NONE, NULL, NULL},
98 {LSL_TYPE_ROTATION, ST_NONE, "rotation", LSL_NONE, NULL, NULL, NULL}, 98 {LSL_TYPE_ROTATION, ST_NONE, "rotation", LSL_NONE, NULL, NULL},
99 {LSL_TYPE_STRING, ST_NONE, "string", LSL_NONE, NULL, NULL, NULL}, 99 {LSL_TYPE_STRING, ST_NONE, "string", LSL_NONE, NULL, NULL},
100 {LSL_TYPE_VECTOR, ST_NONE, "vector", LSL_NONE, NULL, NULL, NULL}, 100 {LSL_TYPE_VECTOR, ST_NONE, "vector", LSL_NONE, NULL, NULL},
101 101
102 // Then the rest of the syntax tokens. 102 // Then the rest of the syntax tokens.
103 {LSL_IDENTIFIER, ST_NONE, "identifier", LSL_NONE, outputVariableToken, NULL, NULL}, 103 {LSL_IDENTIFIER, ST_NONE, "identifier", LSL_NONE, outputVariableToken, NULL},
104 104
105 {LSL_LABEL, ST_NONE, "@", LSL_NONE, NULL, NULL, NULL}, 105 {LSL_LABEL, ST_NONE, "@", LSL_NONE, NULL, NULL},
106 106
107 {LSL_DO, ST_NONE, "do", LSL_NONE, NULL, NULL, NULL}, 107 {LSL_DO, ST_NONE, "do", LSL_NONE, NULL, NULL},
108 {LSL_FOR, ST_NONE, "for", LSL_NONE, NULL, NULL, NULL}, 108 {LSL_FOR, ST_NONE, "for", LSL_NONE, NULL, NULL},
109 {LSL_ELSE_IF, ST_NONE, "else if", LSL_NONE, NULL, NULL, NULL}, 109 {LSL_ELSE_IF, ST_NONE, "else if", LSL_NONE, NULL, NULL},
110 {LSL_ELSE, ST_NONE, "else", LSL_NONE, NULL, NULL, NULL}, 110 {LSL_ELSE, ST_NONE, "else", LSL_NONE, NULL, NULL},
111 {LSL_IF, ST_NONE, "if", LSL_NONE, NULL, NULL, NULL}, 111 {LSL_IF, ST_NONE, "if", LSL_NONE, NULL, NULL},
112 {LSL_JUMP, ST_NONE, "jump", LSL_NONE, NULL, NULL, NULL}, 112 {LSL_JUMP, ST_NONE, "jump", LSL_NONE, NULL, NULL},
113 {LSL_RETURN, ST_NONE, "return", LSL_NONE, NULL, NULL, NULL}, 113 {LSL_RETURN, ST_NONE, "return", LSL_NONE, NULL, NULL},
114 {LSL_STATE_CHANGE, ST_NONE, "state", LSL_NONE, NULL, NULL, NULL}, 114 {LSL_STATE_CHANGE, ST_NONE, "state", LSL_NONE, NULL, NULL},
115 {LSL_WHILE, ST_NONE, "while", LSL_NONE, NULL, NULL, NULL}, 115 {LSL_WHILE, ST_NONE, "while", LSL_NONE, NULL, NULL},
116 {LSL_STATEMENT, ST_NONE, ";", LSL_NOIGNORE, outputStatementToken, NULL, evaluateStatementToken}, 116 {LSL_STATEMENT, ST_NONE, ";", LSL_NOIGNORE, outputStatementToken, evaluateStatementToken},
117 117
118 {LSL_BLOCK_CLOSE, ST_NONE, "}", LSL_NONE, NULL, NULL, NULL}, 118 {LSL_BLOCK_CLOSE, ST_NONE, "}", LSL_NONE, NULL, NULL},
119 {LSL_BLOCK_OPEN, ST_NONE, "{", LSL_NONE, NULL, NULL, NULL}, 119 {LSL_BLOCK_OPEN, ST_NONE, "{", LSL_NONE, NULL, NULL},
120 {LSL_PARAMETER, ST_NONE, "parameter", LSL_NONE, outputParameterToken, NULL, NULL}, 120 {LSL_PARAMETER, ST_NONE, "parameter", LSL_NONE, outputParameterToken, NULL},
121 {LSL_PARAMETER_LIST, ST_NONE, "plist", LSL_NONE, outputParameterListToken, NULL, NULL}, 121 {LSL_PARAMETER_LIST, ST_NONE, "plist", LSL_NONE, outputParameterListToken, NULL},
122 {LSL_FUNCTION, ST_NONE, "function", LSL_NONE, outputFunctionToken, NULL, NULL}, 122 {LSL_FUNCTION, ST_NONE, "function", LSL_NONE, outputFunctionToken, NULL},
123 {LSL_STATE, ST_NONE, "state", LSL_NONE, outputStateToken, NULL, NULL}, 123 {LSL_STATE, ST_NONE, "state", LSL_NONE, outputStateToken, NULL},
124 {LSL_SCRIPT, ST_NONE, "", LSL_NONE, NULL, NULL, NULL}, 124 {LSL_SCRIPT, ST_NONE, "", LSL_NONE, NULL, NULL},
125 125
126 {LSL_UNKNOWN, ST_NONE, "unknown", LSL_NONE, NULL, NULL, NULL}, 126 {LSL_UNKNOWN, ST_NONE, "unknown", LSL_NONE, NULL, NULL},
127 127
128 // A sentinal. 128 // A sentinal.
129 {999999, ST_NONE, NULL, LSL_NONE, NULL, NULL, NULL} 129 {999999, ST_NONE, NULL, LSL_NONE, NULL, NULL}
130}; 130};
131 131
132allowedTypes allowed[] = 132allowedTypes allowed[] =
@@ -770,114 +770,96 @@ static LSL_Leaf *evaluateStatementToken(LSL_Leaf *content, LSL_Leaf *left, LSL_L
770 return result; 770 return result;
771} 771}
772 772
773static void outputLeaf(FILE *file, LSL_Leaf *leaf) 773static void outputLeaf(FILE *file, outputMode mode, LSL_Leaf *leaf)
774{ 774{
775 if (leaf) 775 if (leaf)
776 { 776 {
777 outputLeaf(file, leaf->left); 777 outputLeaf(file, mode, leaf->left);
778 if ((!(LSL_NOIGNORE & leaf->token->flags)) && (leaf->ignorableText)) 778 if ((!(LSL_NOIGNORE & leaf->token->flags)) && (leaf->ignorableText))
779 fprintf(file, "%s", leaf->ignorableText); 779 fprintf(file, "%s", leaf->ignorableText);
780 if (leaf->token->output) 780 if (leaf->token->output)
781 leaf->token->output(file, leaf); 781 leaf->token->output(file, mode, leaf);
782 else 782 else
783 fprintf(file, "%s", leaf->token->token); 783 fprintf(file, "%s", leaf->token->token);
784 outputLeaf(file, leaf->right); 784 outputLeaf(file, mode, leaf->right);
785 } 785 }
786} 786}
787 787
788static void outputFloatToken(FILE *file, LSL_Leaf *content) 788static void outputFloatToken(FILE *file, outputMode mode, LSL_Leaf *content)
789{ 789{
790 if (content) 790 if (content)
791 fprintf(file, "%g", content->value.floatValue); 791 fprintf(file, "%g", content->value.floatValue);
792} 792}
793 793
794static void outputFunctionToken(FILE *file, LSL_Leaf *content) 794static void outputFunctionToken(FILE *file, outputMode mode, LSL_Leaf *content)
795{ 795{
796 if (content) 796 if (content)
797 { 797 {
798 LSL_Function *func = content->value.functionValue; 798 LSL_Function *func = content->value.functionValue;
799 799
800 outputLeaf(file, func->type); 800 outputLeaf(file, mode, func->type);
801 fprintf(file, "%s", func->name); 801 fprintf(file, "%s", func->name);
802 outputLeaf(file, func->params); 802 outputLeaf(file, mode, func->params);
803 outputLeaf(file, func->block); 803 outputLeaf(file, mode, func->block);
804 } 804 }
805} 805}
806 806
807static void outputIntegerToken(FILE *file, LSL_Leaf *content) 807static void outputIntegerToken(FILE *file, outputMode mode, LSL_Leaf *content)
808{ 808{
809 if (content) 809 if (content)
810 fprintf(file, "%d", content->value.integerValue); 810 fprintf(file, "%d", content->value.integerValue);
811} 811}
812 812
813static void outputParameterToken(FILE *file, LSL_Leaf *content) 813static void outputParameterToken(FILE *file, outputMode mode, LSL_Leaf *content)
814{ 814{
815 if (content) 815 if (content)
816 fprintf(file, "%s", content->value.parameterValue->name); 816 fprintf(file, "%s", content->value.parameterValue->name);
817} 817}
818 818
819static void outputParameterListToken(FILE *file, LSL_Leaf *content) 819static void outputParameterListToken(FILE *file, outputMode mode, LSL_Leaf *content)
820{ 820{
821 if (content) 821 if (content)
822 outputLeaf(file, content->value.listValue); 822 outputLeaf(file, mode, content->value.listValue);
823} 823}
824 824
825static void outputParenthesisToken(FILE *file, LSL_Leaf *content) 825static void outputParenthesisToken(FILE *file, outputMode mode, LSL_Leaf *content)
826{ 826{
827 if (content) 827 if (content)
828 { 828 {
829 fprintf(file, "%s", content->token->token); 829 fprintf(file, "%s", content->token->token);
830 outputLeaf(file, content->value.parenthesis->contents); 830 outputLeaf(file, mode, content->value.parenthesis->contents);
831 outputLeaf(file, content->value.parenthesis->right); 831 outputLeaf(file, mode, content->value.parenthesis->right);
832 } 832 }
833} 833}
834 834
835static void outputStateToken(FILE *file, LSL_Leaf *content) 835static void outputStateToken(FILE *file, outputMode mode, LSL_Leaf *content)
836{ 836{
837 if (content) 837 if (content)
838 { 838 {
839 LSL_State *state = content->value.stateValue; 839 LSL_State *state = content->value.stateValue;
840 840
841 fprintf(file, "%s", state->name); 841 fprintf(file, "%s", state->name);
842 outputLeaf(file, state->block); 842 outputLeaf(file, mode, state->block);
843 } 843 }
844} 844}
845 845
846static void outputStatementToken(FILE *file, LSL_Leaf *content) 846static void outputStatementToken(FILE *file, outputMode mode, LSL_Leaf *content)
847{ 847{
848 if (content) 848 if (content)
849 { 849 {
850 outputLeaf(file, content->value.statementValue->expressions); 850 outputLeaf(file, mode, content->value.statementValue->expressions);
851 if (content->ignorableText) 851 if (content->ignorableText)
852 fprintf(file, "%s", content->ignorableText); 852 fprintf(file, "%s", content->ignorableText);
853 fprintf(file, "%s", content->token->token); 853 fprintf(file, "%s", content->token->token);
854 } 854 }
855} 855}
856 856
857static void outputVariableToken(FILE *file, LSL_Leaf *content) 857static void outputVariableToken(FILE *file, outputMode mode, LSL_Leaf *content)
858{ 858{
859 if (content) 859 if (content)
860 fprintf(file, "%s", content->value.variableValue->name); 860 fprintf(file, "%s", content->value.variableValue->name);
861} 861}
862 862
863
864static void convertLeaf2Lua(FILE *file, LSL_Leaf *leaf)
865{
866 if (leaf)
867 {
868 convertLeaf2Lua(file, leaf->left);
869 if ((!(LSL_NOIGNORE & leaf->token->flags)) && (leaf->ignorableText))
870 fprintf(file, "%s", leaf->ignorableText);
871 if (leaf->token->convert)
872 leaf->token->convert(file, leaf);
873 else if (leaf->token->output)
874 leaf->token->output(file, leaf);
875 else
876 fprintf(file, "%s", leaf->token->token);
877 convertLeaf2Lua(file, leaf->right);
878 }
879}
880
881static void doneParsing(LuaSL_yyparseParam *param) 863static void doneParsing(LuaSL_yyparseParam *param)
882{ 864{
883 if (param->ast) 865 if (param->ast)
@@ -887,7 +869,7 @@ static void doneParsing(LuaSL_yyparseParam *param)
887 char outName[PATH_MAX]; 869 char outName[PATH_MAX];
888 char luaName[PATH_MAX]; 870 char luaName[PATH_MAX];
889 871
890 outputLeaf(stdout, param->ast); 872 outputLeaf(stdout, OM_LSL, param->ast);
891 printf("\n"); 873 printf("\n");
892 evaluateLeaf(param->ast, NULL, NULL); 874 evaluateLeaf(param->ast, NULL, NULL);
893 printf("\n"); 875 printf("\n");
@@ -900,7 +882,7 @@ static void doneParsing(LuaSL_yyparseParam *param)
900 if (out) 882 if (out)
901 { 883 {
902// int count; 884// int count;
903 outputLeaf(out, param->ast); 885 outputLeaf(out, OM_LSL, param->ast);
904 fclose(out); 886 fclose(out);
905 sprintf(buffer, "diff %s %s", param->fileName, outName); 887 sprintf(buffer, "diff %s %s", param->fileName, outName);
906// count = system(buffer); 888// count = system(buffer);
@@ -913,7 +895,7 @@ static void doneParsing(LuaSL_yyparseParam *param)
913 out = fopen(luaName, "w"); 895 out = fopen(luaName, "w");
914 if (out) 896 if (out)
915 { 897 {
916 convertLeaf2Lua(out, param->ast); 898 outputLeaf(out, OM_LUA, param->ast);
917 fclose(out); 899 fclose(out);
918 } 900 }
919 else 901 else
diff --git a/LuaSL/src/LuaSL_LSL_tree.h b/LuaSL/src/LuaSL_LSL_tree.h
index e9fddb7..020a92e 100644
--- a/LuaSL/src/LuaSL_LSL_tree.h
+++ b/LuaSL/src/LuaSL_LSL_tree.h
@@ -45,8 +45,13 @@ extern int lowestToken;
45 45
46typedef int LSL_Type; 46typedef int LSL_Type;
47 47
48typedef void (*convertToken2Lua) (FILE *file, LSL_Leaf *content); 48typedef enum
49typedef void (*outputToken) (FILE *file, LSL_Leaf *content); 49{
50 OM_LSL,
51 OM_LUA
52} outputMode;
53
54typedef void (*outputToken) (FILE *file, outputMode mode, LSL_Leaf *content);
50typedef LSL_Leaf * (*evaluateToken) (LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right); 55typedef LSL_Leaf * (*evaluateToken) (LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right);
51 56
52#ifndef FALSE 57#ifndef FALSE
@@ -165,7 +170,6 @@ struct _LSL_Token
165 char *token; 170 char *token;
166 LSL_Flags flags; 171 LSL_Flags flags;
167 outputToken output; 172 outputToken output;
168 convertToken2Lua convert;
169 evaluateToken evaluate; 173 evaluateToken evaluate;
170}; 174};
171 175