From d3541b3ac5f56ba399fd8bcd155b9e0120cf9916 Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Tue, 17 Jan 2012 12:36:03 +1000 Subject: Merge the compiler into the test harness. Remove excess files. --- LuaSL/build.sh | 36 +- LuaSL/src/LuaSL.edc | 6 +- LuaSL/src/LuaSL.h | 1 + LuaSL/src/LuaSL_LSL_lexer.l | 281 -------- LuaSL/src/LuaSL_LSL_tree.c | 1047 ------------------------------ LuaSL/src/LuaSL_LSL_tree.h | 14 +- LuaSL/src/LuaSL_LSL_yaccer.y | 1474 ------------------------------------------ LuaSL/src/LuaSL_compile.c | 1126 ++++++++++++++++++++++++++++++++ LuaSL/src/LuaSL_lexer.l | 2 +- LuaSL/src/LuaSL_main.c | 7 +- 10 files changed, 1154 insertions(+), 2840 deletions(-) delete mode 100644 LuaSL/src/LuaSL_LSL_lexer.l delete mode 100644 LuaSL/src/LuaSL_LSL_tree.c delete mode 100644 LuaSL/src/LuaSL_LSL_yaccer.y (limited to 'LuaSL') diff --git a/LuaSL/build.sh b/LuaSL/build.sh index 38f09f6..65c1581 100755 --- a/LuaSL/build.sh +++ b/LuaSL/build.sh @@ -4,6 +4,7 @@ export LOCALDIR=`pwd` cd src +rm -f ../LuaSL ../LuaSL_parser ../*.o *.output *.backup ../*.edj LuaSL_lexer.h LuaSL_lexer.c LuaSL_lemon_yaccer.h LuaSL_lemon_yaccer.c LuaSL_lemon_yaccer.out if [ -d "/opt/e17" ] then @@ -47,43 +48,29 @@ libs="-lecore -levas -ledje -leet -leina" #-lrt \ #-lz -names="LuaSL_main LuaSL_compile LuaSL_utilities" - +LFLAGS="-d" EDJE_FLAGS="-id images -fd fonts" -rm -f ../LuaSL ../LuaSL_parser ../*.o *.output *.backup ../*.edj LuaSL_lexer.h LuaSL_lexer.c LuaSL_lemon_yaccer.h LuaSL_lemon_yaccer.c LuaSL_lemon_yaccer.out -command="edje_cc $EDJE_FLAGS LuaSL.edc ../LuaSL.edj" -echo $command -$command - -objects="" -for i in $names -do - command="gcc $CFLAGS -c -o ../$i.o $i.c" - echo $command - $command - objects="$objects ../$i.o" -done - -command="gcc $CFLAGS -o ../LuaSL $objects $LDFLAGS $libs" -echo $command -$command - - -names="LuaSL_LSL_tree LuaSL_lexer LuaSL_lemon_yaccer" -LFLAGS="-d" # Run lemon first, flex depends on it to define the symbol values. command="lemon -s LuaSL_lemon_yaccer.y" echo $command $command + command="flex -C --outfile=LuaSL_lexer.c --header-file=LuaSL_lexer.h LuaSL_lexer.l" echo $command $command + +command="edje_cc $EDJE_FLAGS LuaSL.edc ../LuaSL.edj" +echo $command +$command + + +names="LuaSL_main LuaSL_compile LuaSL_utilities LuaSL_lexer LuaSL_lemon_yaccer" objects="" for i in $names do @@ -92,8 +79,7 @@ do $command objects="$objects ../$i.o" done - -command="gcc $CFLAGS -o ../LuaSL_parser $objects $LDFLAGS $libs" +command="gcc $CFLAGS -o ../LuaSL $objects $LDFLAGS $libs" echo $command $command diff --git a/LuaSL/src/LuaSL.edc b/LuaSL/src/LuaSL.edc index f74395b..852de08 100644 --- a/LuaSL/src/LuaSL.edc +++ b/LuaSL/src/LuaSL.edc @@ -2,9 +2,9 @@ color_classes { color_class { name: "test_colour"; color: 255 255 255 255; } } -fonts { - font: "Vera.ttf" "default"; -} +//fonts { +// font: "Vera.ttf" "default"; +//} images { image: "bubble.png" COMP; diff --git a/LuaSL/src/LuaSL.h b/LuaSL/src/LuaSL.h index 2bb2b4a..509f155 100644 --- a/LuaSL/src/LuaSL.h +++ b/LuaSL/src/LuaSL.h @@ -56,6 +56,7 @@ typedef struct } gameGlobals; +Eina_Bool compilerSetup(); Eina_Bool compileLSL(gameGlobals *game, char *script); void loggingStartup(gameGlobals *game); diff --git a/LuaSL/src/LuaSL_LSL_lexer.l b/LuaSL/src/LuaSL_LSL_lexer.l deleted file mode 100644 index 473a427..0000000 --- a/LuaSL/src/LuaSL_LSL_lexer.l +++ /dev/null @@ -1,281 +0,0 @@ - -N [0-9] -L [a-zA-Z_] -H [a-fA-F0-9] -E [Ee][+-]?{N}+ -FS (f|F) -%e 10000 -%n 4000 -%p 5000 - -%{ - -#define excludeLexer -#include "LuaSL_LSL_tree.h" -#include "LuaSL_LSLS_yaccer.tab.h" - - -// Deal with the fact that lex/yacc generates unreachable code -#ifdef LL_WINDOWS -#pragma warning (disable : 4018) // warning C4018: signed/unsigned mismatch -#pragma warning (disable : 4702) // warning C4702: unreachable code -#endif // LL_WINDOWS - -void count(); -void line_comment(); -void block_comment(); -void parse_string(); - -#define YYLMAX 16384 -#define YY_NEVER_INTERACTIVE 1 /* stops flex from calling isatty() */ -#ifdef LL_WINDOWS -#define isatty(x) 0 /* hack for bug in cygwin flex 2.5.35 */ -#endif - -#ifdef ECHO -#undef ECHO -#endif - -#define ECHO do { } while (0) - -%} - -%option reentrant noyywrap never-interactive nounistd -%option bison-bridge - -%% -"//" { gInternalLine++; gInternalColumn = 0; line_comment(); } -"/*" { block_comment(); } - -"integer" { count(); return(INTEGER); } -"float" { count(); return(FLOAT_TYPE); } -"string" { count(); return(STRING); } -"key" { count(); return(LLKEY); } -"vector" { count(); return(VECTOR); } -"quaternion" { count(); return(QUATERNION); } -"rotation" { count(); return(QUATERNION); } -"list" { count(); return(LIST); } - -"default" { count(); yylval.sval = new char[strlen(yytext) + 1]; strcpy(yylval.sval, yytext); return(STATE_DEFAULT); } -"state" { count(); return(STATE); } -"event" { count(); return(EVENT); } -"jump" { count(); return(JUMP); } -"return" { count(); return(RETURN); } -"if" { count(); return(IF); } -"else" { count(); return(ELSE); } -"for" { count(); return(FOR); } -"do" { count(); return(DO); } -"while" { count(); return(WHILE); } - -"state_entry" { count(); return(STATE_ENTRY); } -"state_exit" { count(); return(STATE_EXIT); } -"touch_start" { count(); return(TOUCH_START); } -"touch" { count(); return(TOUCH); } -"touch_end" { count(); return(TOUCH_END); } -"collision_start" { count(); return(COLLISION_START); } -"collision" { count(); return(COLLISION); } -"collision_end" { count(); return(COLLISION_END); } -"land_collision_start" { count(); return(LAND_COLLISION_START); } -"land_collision" { count(); return(LAND_COLLISION); } -"land_collision_end" { count(); return(LAND_COLLISION_END); } -"timer" { count(); return(TIMER); } -"listen" { count(); return(CHAT); } -"sensor" { count(); return(SENSOR); } -"no_sensor" { count(); return(NO_SENSOR); } -"control" { count(); return(CONTROL); } -"print" { count(); return(PRINT); } -"at_target" { count(); return(AT_TARGET); } -"not_at_target" { count(); return(NOT_AT_TARGET); } -"at_rot_target" { count(); return(AT_ROT_TARGET); } -"not_at_rot_target" { count(); return(NOT_AT_ROT_TARGET); } -"money" { count(); return(MONEY); } -"email" { count(); return(EMAIL); } -"run_time_permissions" { count(); return(RUN_TIME_PERMISSIONS); } -"changed" { count(); return(INVENTORY); } -"attach" { count(); return(ATTACH); } -"dataserver" { count(); return(DATASERVER); } -"moving_start" { count(); return(MOVING_START); } -"moving_end" { count(); return(MOVING_END); } -"link_message" { count(); return(LINK_MESSAGE); } -"on_rez" { count(); return(REZ); } -"object_rez" { count(); return(OBJECT_REZ); } -"remote_data" { count(); return(REMOTE_DATA); } -"http_response" { count(); return(HTTP_RESPONSE); } -"http_request" { count(); return(HTTP_REQUEST); } -"." { count(); return(PERIOD); } - -0[xX]{H}+ { count(); yylval.ival = strtoul(yytext, NULL, 0); return(INTEGER_CONSTANT); } -{N}+ { count(); yylval.ival = strtoul(yytext, NULL, 10); return(INTEGER_CONSTANT); } -"TRUE" { count(); yylval.ival = 1; return(INTEGER_TRUE); } -"FALSE" { count(); yylval.ival = 0; return(INTEGER_FALSE); } - -"TOUCH_INVALID_FACE" { count(); yylval.ival = -1; return(INTEGER_CONSTANT); } -"TOUCH_INVALID_VECTOR" { count(); return(TOUCH_INVALID_VECTOR); } -"TOUCH_INVALID_TEXCOORD" { count(); return(TOUCH_INVALID_TEXCOORD); } - -{L}({L}|{N})* { count(); yylval.sval = new char[strlen(yytext) + 1]; strcpy(yylval.sval, yytext); return(IDENTIFIER); } - -{N}+{E} { count(); yylval.fval = (F32)atof(yytext); return(FP_CONSTANT); } -{N}*"."{N}+({E})?{FS}? { count(); yylval.fval = (F32)atof(yytext); return(FP_CONSTANT); } -{N}+"."{N}*({E})?{FS}? { count(); yylval.fval = (F32)atof(yytext); return(FP_CONSTANT); } - -L?\"(\\.|[^\\"])*\" { parse_string(); count(); return(STRING_CONSTANT); } - -"++" { count(); return(INC_OP); } -"--" { count(); return(DEC_OP); } -"+=" { count(); return(ADD_ASSIGN); } -"-=" { count(); return(SUB_ASSIGN); } -"*=" { count(); return(MUL_ASSIGN); } -"/=" { count(); return(DIV_ASSIGN); } -"%=" { count(); return(MOD_ASSIGN); } -";" { count(); return(';'); } -"{" { count(); return('{'); } -"}" { count(); return('}'); } -"," { count(); return(','); } -"=" { count(); return('='); } -"(" { count(); return('('); } -")" { count(); return(')'); } -"-" { count(); return('-'); } -"+" { count(); return('+'); } -"*" { count(); return('*'); } -"/" { count(); return('/'); } -"%" { count(); return('%'); } -"@" { count(); return('@'); } -":" { count(); return(':'); } -">" { count(); return('>'); } -"<" { count(); return('<'); } -"]" { count(); return(']'); } -"[" { count(); return('['); } -"==" { count(); return(EQ); } -"!=" { count(); return(NEQ); } -">=" { count(); return(GEQ); } -"<=" { count(); return(LEQ); } -"&" { count(); return('&'); } -"|" { count(); return('|'); } -"^" { count(); return('^'); } -"~" { count(); return('~'); } -"!" { count(); return('!'); } -"&&" { count(); return(BOOLEAN_AND); } -"||" { count(); return(BOOLEAN_OR); } -"<<" { count(); return(SHIFT_LEFT); } -">>" { count(); return(SHIFT_RIGHT); } - -[ \t\v\n\f] { count(); } -. { /* ignore bad characters */ } - -%% - - -// Prototype for the yacc parser entry point -int yyparse(void); - - -S32 yywrap() -{ -#if defined(FLEX_SCANNER) && !defined(LL_WINDOWS) - // get gcc to stop complaining about lack of use of yyunput - (void) yyunput; -#endif - return(1); -} - -void line_comment() -{ - char c; - - while ((c = yyinput()) != '\n' && c != 0 && c != EOF) - ; -} - -void block_comment() -{ - char c1 = 0; - char c2 = yyinput(); - while (c2 != 0 && c2 != EOF && !(c1 == '*' && c2 == '/')) { - if (c2 == '\n') - { - gInternalLine++; - gInternalColumn = 0; - } - else if (c2 == '\t') - gInternalColumn += 4 - (gInternalColumn % 8); - else - gInternalColumn++; - c1 = c2; - c2 = yyinput(); - } -} - -void count() -{ - S32 i; - - gColumn = gInternalColumn; - gLine = gInternalLine; - - for (i = 0; yytext[i] != '\0'; i++) - if (yytext[i] == '\n') - { - gInternalLine++; - gInternalColumn = 0; - } - else if (yytext[i] == '\t') - gInternalColumn += 4 - (gInternalColumn % 8); - else - gInternalColumn++; -} - -void parse_string() -{ - S32 length = (S32)strlen(yytext); - length = length - 2; - char *temp = yytext + 1; - - S32 i; - S32 escapes = 0; - S32 tabs = 0; - for (i = 0; i < length; i++) - { - if (temp[i] == '\\') - { - escapes++; - i++; - if (temp[i] == 't') - tabs++; - } - } - - S32 newlength = length - escapes + tabs*3; - yylval.sval = new char[newlength + 1]; - - char *dest = yylval.sval; - - for (i = 0; i < length; i++) - { - if (temp[i] == '\\') - { - i++; - // linefeed - if (temp[i] == 'n') - { - *dest++ = 10; - } - else if (temp[i] == 't') - { - *dest++ = ' '; - *dest++ = ' '; - *dest++ = ' '; - *dest++ = ' '; - } - else - { - *dest++ = temp[i]; - } - } - else - { - *dest++ = temp[i]; - } - } - yylval.sval[newlength] = 0; -} diff --git a/LuaSL/src/LuaSL_LSL_tree.c b/LuaSL/src/LuaSL_LSL_tree.c deleted file mode 100644 index 2a9d5d6..0000000 --- a/LuaSL/src/LuaSL_LSL_tree.c +++ /dev/null @@ -1,1047 +0,0 @@ - -#include "LuaSL_LSL_tree.h" -#include -#include - -static LSL_Leaf *evaluateFloatToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right); -static LSL_Leaf *evaluateIntegerToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right); -static LSL_Leaf *evaluateNoToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right); -static LSL_Leaf *evaluateOperationToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right); -static LSL_Leaf *eveluateParenthesisToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right); -static LSL_Leaf *evaluateStatementToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right); -static void outputFloatToken(FILE *file, outputMode mode, LSL_Leaf *content); -static void outputFunctionToken(FILE *file, outputMode mode, LSL_Leaf *content); -static void outputIntegerToken(FILE *file, outputMode mode, LSL_Leaf *content); -static void outputParameterToken(FILE *file, outputMode mode, LSL_Leaf *content); -static void outputParameterListToken(FILE *file, outputMode mode, LSL_Leaf *content); -static void outputParenthesisToken(FILE *file, outputMode mode, LSL_Leaf *content); -static void outputStateToken(FILE *file, outputMode mode, LSL_Leaf *content); -static void outputStatementToken(FILE *file, outputMode mode, LSL_Leaf *content); -static void outputVariableToken(FILE *file, outputMode mode, LSL_Leaf *content); - -LSL_Token LSL_Tokens[] = -{ - // Various forms of "space". - {LSL_COMMENT, ST_NONE, "/*", LSL_NONE, NULL, NULL}, - {LSL_COMMENT_LINE, ST_NONE, "//", LSL_NONE, NULL, NULL}, - {LSL_SPACE, ST_NONE, " ", LSL_NONE, NULL, NULL}, - - // Operators, in order of precedence, low to high - // Left to right, unless otherwise stated. - // According to http://wiki.secondlife.com/wiki/Category:LSL_Operators - {LSL_BOOL_AND, ST_BOOLEAN, "&&", LSL_RIGHT2LEFT, NULL, evaluateOperationToken}, -// QUIRK - Seems to be some disagreement about BOOL_AND/BOOL_OR precedence. Either they are equal, or OR is higher. -// QUIRK - No boolean short circuiting. -// QUIRK - Booleans and conditionals are executed right to left. Or maybe not, depending on who you believe. - {LSL_BOOL_OR, ST_BOOLEAN, "||", LSL_RIGHT2LEFT, NULL, evaluateOperationToken}, - {LSL_BIT_OR, ST_BITWISE, "|", LSL_LEFT2RIGHT, NULL, evaluateOperationToken}, - {LSL_BIT_XOR, ST_BITWISE, "^", LSL_LEFT2RIGHT, NULL, evaluateOperationToken}, - {LSL_BIT_AND, ST_BITWISE, "&", LSL_LEFT2RIGHT, NULL, evaluateOperationToken}, -// QUIRK - Booleans and conditionals are executed right to left. Or maybe not, depending on who you believe. - {LSL_NOT_EQUAL, ST_EQUALITY, "!=", LSL_RIGHT2LEFT, NULL, evaluateOperationToken}, - {LSL_EQUAL, ST_EQUALITY, "==", LSL_RIGHT2LEFT, NULL, evaluateOperationToken}, - {LSL_GREATER_EQUAL, ST_COMPARISON, ">=", LSL_RIGHT2LEFT, NULL, evaluateOperationToken}, - {LSL_LESS_EQUAL, ST_COMPARISON, "<=", LSL_RIGHT2LEFT, NULL, evaluateOperationToken}, - {LSL_GREATER_THAN, ST_COMPARISON, ">", LSL_RIGHT2LEFT, NULL, evaluateOperationToken}, - {LSL_LESS_THAN, ST_COMPARISON, "<", LSL_RIGHT2LEFT, NULL, evaluateOperationToken}, - {LSL_RIGHT_SHIFT, ST_BITWISE, ">>", LSL_LEFT2RIGHT, NULL, evaluateOperationToken}, - {LSL_LEFT_SHIFT, ST_BITWISE, "<<", LSL_LEFT2RIGHT, NULL, evaluateOperationToken}, - {LSL_CONCATENATE, ST_ADD, "+", LSL_LEFT2RIGHT, NULL, evaluateOperationToken}, - {LSL_ADD, ST_ADD, "+", LSL_LEFT2RIGHT, NULL, evaluateOperationToken}, - {LSL_SUBTRACT, ST_SUBTRACT, "-", LSL_LEFT2RIGHT, NULL, evaluateOperationToken}, - {LSL_CROSS_PRODUCT, ST_NONE, "%", LSL_LEFT2RIGHT, NULL, evaluateOperationToken}, - {LSL_DOT_PRODUCT, ST_NONE, "*", LSL_LEFT2RIGHT, NULL, evaluateOperationToken}, - {LSL_MULTIPLY, ST_MULTIPLY, "*", LSL_LEFT2RIGHT, NULL, evaluateOperationToken}, - {LSL_MODULO, ST_MODULO, "%", LSL_LEFT2RIGHT, NULL, evaluateOperationToken}, - {LSL_DIVIDE, ST_MULTIPLY, "/", LSL_LEFT2RIGHT, NULL, evaluateOperationToken}, - {LSL_NEGATION, ST_NEGATE, "-", LSL_RIGHT2LEFT | LSL_UNARY, NULL, evaluateOperationToken}, - {LSL_BOOL_NOT, ST_BOOL_NOT, "!", LSL_RIGHT2LEFT | LSL_UNARY, NULL, evaluateOperationToken}, - {LSL_BIT_NOT, ST_BIT_NOT, "~", LSL_RIGHT2LEFT | LSL_UNARY, NULL, evaluateOperationToken}, - {LSL_TYPECAST_CLOSE, ST_NONE, ")", LSL_RIGHT2LEFT | LSL_UNARY, NULL, evaluateNoToken}, - {LSL_TYPECAST_OPEN, ST_NONE, "(", LSL_RIGHT2LEFT | LSL_UNARY, NULL, evaluateOperationToken}, - {LSL_ANGLE_CLOSE, ST_NONE, ">", LSL_LEFT2RIGHT | LSL_CREATION, NULL, evaluateNoToken}, - {LSL_ANGLE_OPEN, ST_NONE, "<", LSL_LEFT2RIGHT | LSL_CREATION, NULL, evaluateOperationToken}, - {LSL_BRACKET_CLOSE, ST_NONE, "]", LSL_INNER2OUTER | LSL_CREATION, NULL, evaluateNoToken}, - {LSL_BRACKET_OPEN, ST_NONE, "[", LSL_INNER2OUTER | LSL_CREATION, NULL, evaluateOperationToken}, - {LSL_PARENTHESIS_CLOSE, ST_NONE, ")", LSL_INNER2OUTER, NULL, evaluateNoToken}, - {LSL_PARENTHESIS_OPEN, ST_NONE, "(", LSL_INNER2OUTER, outputParenthesisToken, eveluateParenthesisToken}, - {LSL_ASSIGNMENT_CONCATENATE,ST_CONCATENATION, "+=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, NULL, evaluateOperationToken}, - {LSL_ASSIGNMENT_ADD, ST_CONCATENATION, "+=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, NULL, evaluateOperationToken}, - {LSL_ASSIGNMENT_SUBTRACT, ST_ASSIGNMENT, "-=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, NULL, evaluateOperationToken}, - {LSL_ASSIGNMENT_MULTIPLY, ST_ASSIGNMENT, "*=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, NULL, evaluateOperationToken}, - {LSL_ASSIGNMENT_MODULO, ST_MODULO, "%=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, NULL, evaluateOperationToken}, - {LSL_ASSIGNMENT_DIVIDE, ST_ASSIGNMENT, "/=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, NULL, evaluateOperationToken}, - {LSL_ASSIGNMENT_PLAIN, ST_CONCATENATION, "=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, NULL, evaluateOperationToken}, - {LSL_DOT, ST_NONE, ".", LSL_RIGHT2LEFT, NULL, evaluateOperationToken}, - {LSL_DECREMENT_POST, ST_NONE, "--", LSL_RIGHT2LEFT | LSL_UNARY, NULL, evaluateOperationToken}, - {LSL_DECREMENT_PRE, ST_NONE, "--", LSL_RIGHT2LEFT | LSL_UNARY, NULL, evaluateOperationToken}, - {LSL_INCREMENT_POST, ST_NONE, "++", LSL_RIGHT2LEFT | LSL_UNARY, NULL, evaluateOperationToken}, - {LSL_INCREMENT_PRE, ST_NONE, "++", LSL_RIGHT2LEFT | LSL_UNARY, NULL, evaluateOperationToken}, - {LSL_COMMA, ST_NONE, ",", LSL_LEFT2RIGHT, NULL, evaluateOperationToken}, - - {LSL_EXPRESSION, ST_NONE, "expression", LSL_NONE , NULL, NULL}, - - // Types. - {LSL_FLOAT, ST_NONE, "float", LSL_NONE, outputFloatToken, evaluateFloatToken}, - {LSL_INTEGER, ST_NONE, "integer", LSL_NONE, outputIntegerToken, evaluateIntegerToken}, - {LSL_KEY, ST_NONE, "key", LSL_NONE, NULL, NULL}, - {LSL_LIST, ST_NONE, "list", LSL_NONE, NULL, NULL}, - {LSL_ROTATION, ST_NONE, "rotation", LSL_NONE, NULL, NULL}, - {LSL_STRING, ST_NONE, "string", LSL_NONE, NULL, NULL}, - {LSL_VECTOR, ST_NONE, "vector", LSL_NONE, NULL, NULL}, - - // Types names. - {LSL_TYPE_FLOAT, ST_NONE, "float", LSL_NONE, NULL, NULL}, - {LSL_TYPE_INTEGER, ST_NONE, "integer", LSL_NONE, NULL, NULL}, - {LSL_TYPE_KEY, ST_NONE, "key", LSL_NONE, NULL, NULL}, - {LSL_TYPE_LIST, ST_NONE, "list", LSL_NONE, NULL, NULL}, - {LSL_TYPE_ROTATION, ST_NONE, "rotation", LSL_NONE, NULL, NULL}, - {LSL_TYPE_STRING, ST_NONE, "string", LSL_NONE, NULL, NULL}, - {LSL_TYPE_VECTOR, ST_NONE, "vector", LSL_NONE, NULL, NULL}, - - // Then the rest of the syntax tokens. - {LSL_IDENTIFIER, ST_NONE, "identifier", LSL_NONE, outputVariableToken, NULL}, - - {LSL_LABEL, ST_NONE, "@", LSL_NONE, NULL, NULL}, - - {LSL_DO, ST_NONE, "do", LSL_NONE, NULL, NULL}, - {LSL_FOR, ST_NONE, "for", LSL_NONE, NULL, NULL}, - {LSL_ELSE_IF, ST_NONE, "else if", LSL_NONE, NULL, NULL}, - {LSL_ELSE, ST_NONE, "else", LSL_NONE, NULL, NULL}, - {LSL_IF, ST_NONE, "if", LSL_NONE, NULL, NULL}, - {LSL_JUMP, ST_NONE, "jump", LSL_NONE, NULL, NULL}, - {LSL_RETURN, ST_NONE, "return", LSL_NONE, NULL, NULL}, - {LSL_STATE_CHANGE, ST_NONE, "state", LSL_NONE, NULL, NULL}, - {LSL_WHILE, ST_NONE, "while", LSL_NONE, NULL, NULL}, - {LSL_STATEMENT, ST_NONE, ";", LSL_NOIGNORE, outputStatementToken, evaluateStatementToken}, - - {LSL_BLOCK_CLOSE, ST_NONE, "}", LSL_NONE, NULL, NULL}, - {LSL_BLOCK_OPEN, ST_NONE, "{", LSL_NONE, NULL, NULL}, - {LSL_PARAMETER, ST_NONE, "parameter", LSL_NONE, outputParameterToken, NULL}, - {LSL_PARAMETER_LIST, ST_NONE, "plist", LSL_NONE, outputParameterListToken, NULL}, - {LSL_FUNCTION, ST_NONE, "function", LSL_NONE, outputFunctionToken, NULL}, - {LSL_STATE, ST_NONE, "state", LSL_NONE, outputStateToken, NULL}, - {LSL_SCRIPT, ST_NONE, "", LSL_NONE, NULL, NULL}, - - {LSL_UNKNOWN, ST_NONE, "unknown", LSL_NONE, NULL, NULL}, - - // A sentinal. - {999999, ST_NONE, NULL, LSL_NONE, NULL, NULL} -}; - -allowedTypes allowed[] = -{ - {OT_nothing, "nothing", (ST_NONE)}, - - {OT_bool, "boolean", (ST_BOOL_NOT)}, - {OT_integer, "integer", (ST_BIT_NOT | ST_NEGATE)}, - {OT_float, "float", (ST_NONE)}, - {OT_key, "key", (ST_NONE)}, - {OT_list, "list", (ST_NONE)}, - {OT_rotation, "rotation", (ST_NONE)}, - {OT_string, "string", (ST_NONE)}, - {OT_vector, "vector", (ST_NONE)}, - {OT_other, "other", (ST_NONE)}, - - {OT_bool, "boolean", (ST_BOOLEAN | ST_EQUALITY)}, - {OT_integer, "integer", (ST_MULTIPLY | ST_ADD | ST_SUBTRACT | ST_EQUALITY | ST_COMPARISON | ST_CONCATENATION | ST_ASSIGNMENT | ST_MODULO | ST_BITWISE)}, - {OT_float, "float", (ST_MULTIPLY | ST_ADD | ST_SUBTRACT | ST_EQUALITY | ST_COMPARISON | ST_CONCATENATION | ST_ASSIGNMENT)}, - {OT_float, "float", (ST_MULTIPLY | ST_ADD | ST_SUBTRACT | ST_EQUALITY | ST_COMPARISON | ST_CONCATENATION | ST_ASSIGNMENT)}, - {OT_float, "float", (ST_MULTIPLY | ST_ADD | ST_SUBTRACT | ST_EQUALITY | ST_COMPARISON | ST_CONCATENATION | ST_ASSIGNMENT)}, - {OT_string, "string", (ST_ADD | ST_EQUALITY | ST_CONCATENATION)}, - {OT_string, "string", (ST_ADD | ST_EQUALITY | ST_CONCATENATION)}, - {OT_string, "string", (ST_ADD | ST_EQUALITY | ST_CONCATENATION)}, - {OT_list, "list", (ST_ADD | ST_EQUALITY | ST_CONCATENATION)}, - {OT_list, "list", (ST_ADD | ST_COMPARISON | ST_CONCATENATION)}, - {OT_list, "list", (ST_ADD | ST_COMPARISON | ST_CONCATENATION)}, - {OT_integer, "integer", (ST_ADD | ST_COMPARISON)}, - {OT_float, "float", (ST_ADD | ST_COMPARISON)}, - {OT_list, "list", (ST_ADD | ST_CONCATENATION)}, - {OT_vector, "vector", (ST_MULTIPLY | ST_ADD | ST_SUBTRACT | ST_EQUALITY | ST_CONCATENATION | ST_ASSIGNMENT | ST_MODULO)}, - {OT_vector, "vector", (ST_MULTIPLY)}, - {OT_vector, "vector", (ST_MULTIPLY)}, - {OT_rotation, "rotation", (ST_MULTIPLY | ST_ADD | ST_SUBTRACT | ST_EQUALITY | ST_CONCATENATION | ST_ASSIGNMENT)}, - {OT_other, "other", (ST_NONE)}, - {OT_invalid, "invalid", (ST_NONE)} -}; - -opType opExpr[][10] = -{ - {OT_nothing, OT_bool, OT_integer, OT_float, OT_key, OT_list, OT_rotation, OT_string, OT_vector, OT_other}, - {OT_bool, OT_boolBool, OT_invalid, OT_invalid, OT_invalid, OT_invalid, OT_invalid, OT_invalid, OT_invalid, OT_invalid}, - {OT_integer, OT_invalid, OT_intInt, OT_intFloat, OT_invalid, OT_intList, OT_invalid, OT_invalid, OT_invalid, OT_invalid}, - {OT_float, OT_invalid, OT_floatInt, OT_floatFloat, OT_invalid, OT_floatList, OT_invalid, OT_invalid, OT_invalid, OT_invalid}, - {OT_key, OT_invalid, OT_invalid, OT_invalid, OT_invalid, OT_invalid, OT_invalid, OT_keyString, OT_invalid, OT_invalid}, - {OT_list, OT_invalid, OT_listInt, OT_listFloat, OT_invalid, OT_listList, OT_invalid, OT_invalid, OT_invalid, OT_listOther}, - {OT_rotation, OT_invalid, OT_invalid, OT_invalid, OT_invalid, OT_invalid, OT_rotationRotation, OT_invalid, OT_invalid, OT_invalid}, - {OT_string, OT_invalid, OT_invalid, OT_invalid, OT_stringKey, OT_invalid, OT_invalid, OT_stringString, OT_invalid, OT_invalid}, - {OT_vector, OT_invalid, OT_invalid, OT_vectorFloat, OT_invalid, OT_invalid, OT_vectorRotation, OT_invalid, OT_vectorVector, OT_invalid}, - {OT_other, OT_invalid, OT_invalid, OT_invalid, OT_invalid, OT_invalid, OT_invalid, OT_invalid, OT_invalid, OT_otherOther} - -}; - - -LSL_Token **tokens = NULL; -int lowestToken = 999999; - - -static LSL_Leaf *newLeaf(LSL_Type type, LSL_Leaf *left, LSL_Leaf *right) -{ - LSL_Leaf *leaf = calloc(1, sizeof(LSL_Leaf)); - - if (leaf) - { - leaf->left = left; - leaf->right = right; - leaf->token = tokens[type - lowestToken]; - } - - return leaf; -} - -void burnLeaf(LSL_Leaf *leaf) -{ - if (leaf) - { - burnLeaf(leaf->left); - burnLeaf(leaf->right); - // TODO - Should free up the value to. - free(leaf->ignorableText); - free(leaf); - } -} - -LSL_Leaf *addOperation(LSL_Leaf *left, LSL_Leaf *lval, LSL_Leaf *right) -{ - if (lval) - { - opType lType, rType; - - lval->left = left; - lval->right = right; - - // Try to figure out what type of operation this is. - if (NULL == left) - lType = OT_nothing; - else - { - lType = left->basicType; - if (OT_vector < lType) - lType = allowed[lType].result; - } - if (NULL == right) - rType = OT_nothing; - else - { - rType = right->basicType; - if (OT_vector < rType) - rType = allowed[rType].result; - } - - // The basic lookup. - lval->basicType = opExpr[lType][rType]; - if (OT_invalid != lval->basicType) - { - // Check if it's an allowed operation. - if (0 == (lval->token->subType & allowed[lval->basicType].subTypes)) - { - lval->basicType = OT_invalid; - } - else - { - // Double check the corner cases. - switch (lval->token->subType) - { - case ST_BOOLEAN : - lval->basicType = OT_bool; - break; - case ST_COMPARISON : - lval->basicType = OT_bool; - break; - case ST_MULTIPLY : - if (OT_vectorVector == lval->basicType) - { - if (LSL_MULTIPLY == lval->token->type) - { - lval->basicType = OT_float; - lval->token = tokens[LSL_DOT_PRODUCT - lowestToken]; - } - else - lval->basicType = OT_vector; - } - break; - default : - break; - } - } - } - if (OT_invalid == lval->basicType) - { - char *leftType = "", *rightType = ""; - - if (left) - leftType = allowed[left->basicType].name; - if (right) - rightType = allowed[right->basicType].name; - - fprintf(stderr, "Invalid operation [%s %s %s] @ line %d column %d\n", leftType, lval->token->token, rightType, lval->line, lval->column); - } - } - - return lval; -} - -LSL_Leaf *addParameter(LSL_Leaf *type, LSL_Leaf *identifier) -{ - LSL_Identifier *result = calloc(1, sizeof(LSL_Identifier)); - - if ( (identifier) && (result)) - { - result->name = identifier->value.stringValue; - identifier->value.variableValue = result; - identifier->token = tokens[LSL_PARAMETER - lowestToken]; - identifier->left = type; - if (type) - { - identifier->basicType = type->basicType; - result->value.basicType = type->basicType; - } - } - return identifier; -} - -LSL_Leaf *collectParameters(LSL_Leaf *list, LSL_Leaf *comma, LSL_Leaf *newParam) -{ - LSL_Leaf *newList = newLeaf(LSL_PARAMETER_LIST, NULL, NULL); - - if (newList) - { - newList->left = list; - newList->value.listValue = newParam; - if ((list) && (list->value.listValue)) - { - list->value.listValue->right = comma; - } - } - - return newList; -} - -LSL_Leaf *addFunction(LSL_Leaf *type, LSL_Leaf *identifier, LSL_Leaf *open, LSL_Leaf *params, LSL_Leaf *close, LSL_Leaf *block) -{ - LSL_Function *func = calloc(1, sizeof(LSL_Function)); - - if (func) - { - if (identifier) - { - char *temp = identifier->value.stringValue; - - identifier->token = tokens[LSL_FUNCTION - lowestToken]; - identifier->value.functionValue = func; - identifier->value.functionValue->name = temp; - identifier->value.functionValue->block = block; - func->type = type; - if (type) - identifier->basicType = type->basicType; - else - identifier->basicType = OT_nothing; - func->params = addParenthesis(open, params, LSL_PARAMETER_LIST, close); - } - } - return identifier; -} - -LSL_Leaf *addParenthesis(LSL_Leaf *lval, LSL_Leaf *expr, LSL_Type type, LSL_Leaf *rval) -{ - LSL_Parenthesis *parens = malloc(sizeof(LSL_Parenthesis)); - - if (parens) - { - parens->left = lval; - parens->contents = expr; - parens->type = type; - parens->right = rval; - if (lval) - { - lval->value.parenthesis = parens; - if (expr) - lval->basicType = expr->basicType; - } - } - return lval; -} - -LSL_Leaf *addState(LuaSL_yyparseParam *param, LSL_Leaf *identifier, LSL_Leaf *block) -{ - LSL_State *result = calloc(1, sizeof(LSL_State)); - - if ((identifier) && (result)) - { - result->name = identifier->value.stringValue; - result->block = block; - identifier->value.stateValue = result; - param->script.scount++; - param->script.states = realloc(param->script.states, param->script.scount * sizeof(LSL_State *)); - param->script.states[param->script.scount - 1] = result; - } - - return identifier; -} - -LSL_Leaf *addStatement(LSL_Leaf *lval, LSL_Type type, LSL_Leaf *expr) -{ - LSL_Statement *stat = malloc(sizeof(LSL_Statement)); - - if (stat) - { - stat->type = type; - stat->expressions = expr; - if (lval) - lval->value.statementValue = stat; - } - - return lval; -} - -LSL_Leaf *addTypecast(LSL_Leaf *lval, LSL_Leaf *type, LSL_Leaf *rval, LSL_Leaf *expr) -{ - LSL_Parenthesis *parens = malloc(sizeof(LSL_Parenthesis)); - - if (parens) - { - parens->left = lval; - parens->contents = expr; - parens->type = LSL_TYPECAST_OPEN; - parens->right = rval; - if (lval) - { - lval->value.parenthesis = parens; - if (type) - lval->basicType = type->basicType; - lval->token = tokens[LSL_TYPECAST_OPEN - lowestToken]; - } - if (rval) - { - rval->token = tokens[LSL_TYPECAST_CLOSE - lowestToken]; - } - } - return lval; -} - -LSL_Leaf *addVariable(LuaSL_yyparseParam *param, LSL_Leaf *type, LSL_Leaf *identifier, LSL_Leaf *assignment, LSL_Leaf *expr) -{ - LSL_Identifier *result = calloc(1, sizeof(LSL_Identifier)); - - if ( (identifier) && (result)) - { - result->name = identifier->value.stringValue; - identifier->value.variableValue = result; - identifier->left = type; - identifier->right = assignment; - if (assignment) - assignment->right = expr; - if (type) - { - identifier->basicType = type->basicType; - result->value.basicType = type->basicType; - } - if (param->currentBlock) - { - param->currentBlock->vcount++; - param->currentBlock->variables = realloc(param->currentBlock->variables, param->currentBlock->vcount * sizeof(LSL_Identifier *)); - param->currentBlock->variables[param->currentBlock->vcount - 1] = result; - } - else - { - param->script.vcount++; - param->script.variables = realloc(param->script.variables, param->script.vcount * sizeof(LSL_Identifier *)); - param->script.variables[param->script.vcount - 1] = result; - } - } - - return identifier; -} - -void beginBlock(LuaSL_yyparseParam *param, LSL_Leaf *block) -{ - LSL_Block *blok = malloc(sizeof(LSL_Block)); - - if (blok) - { - block->value.blockValue = blok; - blok->outerBlock = param->currentBlock; - param->currentBlock = blok; - } -} - -void endBlock(LuaSL_yyparseParam *param, LSL_Leaf *block) -{ - param->currentBlock = param->currentBlock->outerBlock; -} - -static LSL_Leaf *evaluateLeaf(LSL_Leaf *leaf, LSL_Leaf *left, LSL_Leaf *right) -{ - LSL_Leaf *result = NULL; - - if (leaf) - { - LSL_Leaf *lresult = NULL; - LSL_Leaf *rresult = NULL; - - if (LSL_RIGHT2LEFT & leaf->token->flags) - { - rresult = evaluateLeaf(leaf->right, left, right); - if (!(LSL_UNARY & leaf->token->flags)) - lresult = evaluateLeaf(leaf->left, left, right); - } - else // Assume left to right. - { - lresult = evaluateLeaf(leaf->left, left, right); - if (!(LSL_UNARY & leaf->token->flags)) - rresult = evaluateLeaf(leaf->right, left, right); - } - - if (leaf->token->evaluate) - result = leaf->token->evaluate(leaf, lresult, rresult); - else - { - result = calloc(1, sizeof(LSL_Leaf)); - if (rresult && result) - memcpy(result, rresult, sizeof(LSL_Leaf)); - } - - if (lresult) - free(lresult); - if (rresult) - free(rresult); - } - - return result; -} - -static LSL_Leaf *evaluateFloatToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right) -{ - LSL_Leaf *result = malloc(sizeof(LSL_Leaf)); - - if (content && result) - { -#ifdef LUASL_DEBUG - printf(" <%g> ", content->value.floatValue); -#endif - memcpy(result, content, sizeof(LSL_Leaf)); - result->basicType = OT_float; - } - return result; -} - -static LSL_Leaf *evaluateIntegerToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right) -{ - LSL_Leaf *result = malloc(sizeof(LSL_Leaf)); - - if (content && result) - { -#ifdef LUASL_DEBUG - printf(" <%d> ", content->value.integerValue); -#endif - memcpy(result, content, sizeof(LSL_Leaf)); - result->basicType = OT_integer; - } - return result; -} - -static LSL_Leaf *evaluateNoToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right) -{ - // Do nothing, that's the point. - - return content; -} - -/* Typecasting - -LSL is statically typed, so stored values are not converted, only the values used in expressions are. -Lua is dynamically typed, so stored values are changed (sometimes I think). - -LSL implicitly typecasts - There is a shitload of QUIRKs about this. Apparently some don't work anyway. - integer -> float (Says in lslwiki that precision is never lost, which is bullshit, since they are both 32 bit. Would be true if the float is 64 bit. Lua suggest to use 64 bit floats to emulate 32 bit integers.) - string -> key - Some functions need help with this or the other way around. - string -> vector (Maybe, should test that.) - vector -> string (Maybe, should test that.) - Also happens when getting stuff from lists. - -Explicit type casting - - string -> integer - Leading spaces are ignored, as are any characters after the run of digits. - All other strings convert to 0. - Which means "" and " " convert to 0. - Strings in hexadecimal format will work. - keys <-> string - No other typecasting can be done with keys. - float -> string - You get a bunch of trailing 0s. - -QUIRK - I have seen cases where a double explicit typecast was needed in SL, but was considered to be invalid syntax in OS. - -Any binary operation involving a float and an integer implicitly casts the integer to float. - -A boolean operation deals with TRUE (1) and FALSE (0). Any non zero value is a TRUE (generally sigh). -Bitwise operations only apply to integers. The shifts are arithmatic, not logical. Right shifted bits are dropped, left shifts the sign bit. - -integer = integer0 % integer1; // Apparently only applies to integers, but works fine on floats in OS. -string = string0 + string1; // Concatenation. -list = list0 + list1; // Concatenation. Also works if either is not a list, it's promoted to a list first. -list = (list=[]) + list + ["new_item"]; // Voodoo needed for old LSL, works in Mono but not needed, does not work in OS. Works for strings to. -bool = list == != int // Only compares the lengths, probably applies to the other conditionals to. -vector = vector0 + vector1; // Add elements together. -vector = vector0 - vector1; // Subtract elements of vector1 from elements of vector0. -float = vector0 * vector1; // A dot product of the vectors. -vector = vector0 % vector1; // A cross product of the vectors. -vector = vector * float; // Scale the vector, works the other way around I think. Works for integer to, but it will end up being cast to float. -vector = vector / float; // Scale the vector, works the other way around I think. Works for integer to, but it will end up being cast to float. -vector = vector * rotation; // Rotate the vector by the rotation. Other way around wont compile. -vector = vector / rotation; // Rotate the vector by the rotation, in the opposite direction. Other way around wont compile. -rotation = llGetRot() * rotation; // Rotate an object around the global axis. -rotation = rotation * llGetLocalRot(); // Rotate an object around the local axis. -rotation = rotation0 * rotation1; // Add two rotations, so the result is as if you applied each rotation one after the other. - // Division rotates in the opposite direction. -rotation = rotation0 + rotation1; // Similar to vector, but it's a meaningless thing as far as rotations go. -rotation = rotation0 - rotation1; // Similar to vector, but it's a meaningless thing as far as rotations go. - -A boolean operator results in a boolean value. (any types) -A comparison operator results in a boolean value. (any types) -A bitwise operator results in an integer value. (intInt or int) -A dot product operator results in a float value. (vector * vector) -A vectorFloat results in a vector value. - -*/ - -static LSL_Leaf *evaluateOperationToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right) -{ - LSL_Leaf *result = calloc(1, sizeof(LSL_Leaf)); - - if (content && result) - { -#ifdef LUASL_DEBUG - printf(" [%s] ", content->token->token); -#endif - - memcpy(result, content, sizeof(LSL_Leaf)); - - // Figure out the type of the operation. - if (OT_vector < result->basicType) - result->basicType = allowed[result->basicType].result; - - switch (result->basicType) - { - case OT_float : - { - float fleft = left->value.floatValue; - float fright = right->value.floatValue; - - // Do the casting. - if (OT_floatInt == content->basicType) - fright = right->value.integerValue; - if (OT_intFloat == content->basicType) - fleft = left->value.integerValue; - switch (result->token->type) - { - case LSL_COMMA : - case LSL_INCREMENT_PRE : - case LSL_INCREMENT_POST : - case LSL_DECREMENT_PRE : - case LSL_DECREMENT_POST : - case LSL_ASSIGNMENT_PLAIN : - case LSL_ASSIGNMENT_DIVIDE : - case LSL_ASSIGNMENT_MULTIPLY : - case LSL_ASSIGNMENT_SUBTRACT : - case LSL_ASSIGNMENT_ADD : - case LSL_BRACKET_OPEN : - case LSL_BRACKET_CLOSE : - case LSL_ANGLE_OPEN : - case LSL_ANGLE_CLOSE : - case LSL_TYPECAST_OPEN : - case LSL_TYPECAST_CLOSE : - case LSL_DOT_PRODUCT : - break; - case LSL_NEGATION : result->value.floatValue = 0 - fright; break; - case LSL_DIVIDE : result->value.floatValue = fleft / fright; break; - case LSL_MULTIPLY : result->value.floatValue = fleft * fright; break; - case LSL_SUBTRACT : result->value.floatValue = fleft - fright; break; - case LSL_ADD : result->value.floatValue = fleft + fright; break; - case LSL_LESS_THAN : result->value.floatValue = fleft < fright; break; - case LSL_GREATER_THAN : result->value.floatValue = fleft > fright; break; - case LSL_LESS_EQUAL : result->value.floatValue = fleft <= fright; break; - case LSL_GREATER_EQUAL : result->value.floatValue = fleft >= fright; break; - case LSL_EQUAL : result->value.floatValue = fleft == fright; break; - case LSL_NOT_EQUAL : result->value.floatValue = fleft != fright; break; - } -#ifdef LUASL_DEBUG - printf(" (=%g) ", result->value.floatValue); -#endif - break; - } - - case OT_integer : - { - switch (result->token->type) - { - case LSL_COMMA : - case LSL_INCREMENT_PRE : - case LSL_INCREMENT_POST : - case LSL_DECREMENT_PRE : - case LSL_DECREMENT_POST : - case LSL_DOT : - case LSL_ASSIGNMENT_PLAIN : - case LSL_ASSIGNMENT_DIVIDE : - case LSL_ASSIGNMENT_MODULO : - case LSL_ASSIGNMENT_MULTIPLY : - case LSL_ASSIGNMENT_SUBTRACT : - case LSL_ASSIGNMENT_ADD : - case LSL_BRACKET_OPEN : - case LSL_BRACKET_CLOSE : - case LSL_ANGLE_OPEN : - case LSL_ANGLE_CLOSE : - case LSL_TYPECAST_OPEN : - case LSL_TYPECAST_CLOSE : - break; - case LSL_BIT_NOT : result->value.integerValue = ~ right->value.integerValue; break; - case LSL_BOOL_NOT : result->value.integerValue = ! right->value.integerValue; break; - case LSL_NEGATION : result->value.integerValue = 0 - right->value.integerValue; break; - case LSL_DIVIDE : result->value.integerValue = left->value.integerValue / right->value.integerValue; break; - case LSL_MODULO : result->value.integerValue = left->value.integerValue % right->value.integerValue; break; - case LSL_MULTIPLY : result->value.integerValue = left->value.integerValue * right->value.integerValue; break; - case LSL_SUBTRACT : result->value.integerValue = left->value.integerValue - right->value.integerValue; break; - case LSL_ADD : result->value.integerValue = left->value.integerValue + right->value.integerValue; break; - case LSL_LEFT_SHIFT : result->value.integerValue = left->value.integerValue << right->value.integerValue; break; - case LSL_RIGHT_SHIFT : result->value.integerValue = left->value.integerValue >> right->value.integerValue; break; - case LSL_LESS_THAN : result->value.integerValue = left->value.integerValue < right->value.integerValue; break; - case LSL_GREATER_THAN : result->value.integerValue = left->value.integerValue > right->value.integerValue; break; - case LSL_LESS_EQUAL : result->value.integerValue = left->value.integerValue <= right->value.integerValue; break; - case LSL_GREATER_EQUAL : result->value.integerValue = left->value.integerValue >= right->value.integerValue; break; - case LSL_EQUAL : result->value.integerValue = left->value.integerValue == right->value.integerValue; break; - case LSL_NOT_EQUAL : result->value.integerValue = left->value.integerValue != right->value.integerValue; break; - case LSL_BIT_AND : result->value.integerValue = left->value.integerValue & right->value.integerValue; break; - case LSL_BIT_XOR : result->value.integerValue = left->value.integerValue ^ right->value.integerValue; break; - case LSL_BIT_OR : result->value.integerValue = left->value.integerValue | right->value.integerValue; break; - case LSL_BOOL_OR : result->value.integerValue = left->value.integerValue || right->value.integerValue; break; - case LSL_BOOL_AND : result->value.integerValue = left->value.integerValue && right->value.integerValue; break; - } -#ifdef LUASL_DEBUG - printf(" (=%d) ", result->value.integerValue); -#endif - break; - } - - default : - break; - } - } - return result; -} - -static LSL_Leaf *eveluateParenthesisToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right) -{ - LSL_Leaf *result = NULL; - - if (content) - { - if (LSL_PARAMETER_LIST != content->value.parenthesis->type) - result = evaluateLeaf(content->value.parenthesis->contents, left, right); - } - return result; -} - - -static LSL_Leaf *evaluateStatementToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right) -{ - LSL_Leaf *result = NULL; - - if (content) - { - result = evaluateLeaf(content->value.statementValue->expressions, left, right); - if (result) - { - switch (result->basicType) - { - case OT_float : printf("\nResult is the float %g.\n", result->value.floatValue); break; - case OT_integer : printf("\nResult is the integer %d.\n", result->value.integerValue); break; - default : printf("\nResult of an unknown type [%d] %d!\n", result->basicType, result->value.integerValue); break; - } - free(result); - result = NULL; - } - if (left) - left->value.integerValue = 0; - if (right) - right->value.integerValue = 0; - } - return result; -} - -static void outputLeaf(FILE *file, outputMode mode, LSL_Leaf *leaf) -{ - if (leaf) - { - outputLeaf(file, mode, leaf->left); - if ((!(LSL_NOIGNORE & leaf->token->flags)) && (leaf->ignorableText)) - fprintf(file, "%s", leaf->ignorableText); - if (leaf->token->output) - leaf->token->output(file, mode, leaf); - else - fprintf(file, "%s", leaf->token->token); - outputLeaf(file, mode, leaf->right); - } -} - -static void outputFloatToken(FILE *file, outputMode mode, LSL_Leaf *content) -{ - if (content) - fprintf(file, "%g", content->value.floatValue); -} - -static void outputFunctionToken(FILE *file, outputMode mode, LSL_Leaf *content) -{ - if (content) - { - LSL_Function *func = content->value.functionValue; - - outputLeaf(file, mode, func->type); - fprintf(file, "%s", func->name); - outputLeaf(file, mode, func->params); - outputLeaf(file, mode, func->block); - } -} - -static void outputIntegerToken(FILE *file, outputMode mode, LSL_Leaf *content) -{ - if (content) - fprintf(file, "%d", content->value.integerValue); -} - -static void outputParameterToken(FILE *file, outputMode mode, LSL_Leaf *content) -{ - if (content) - fprintf(file, "%s", content->value.parameterValue->name); -} - -static void outputParameterListToken(FILE *file, outputMode mode, LSL_Leaf *content) -{ - if (content) - outputLeaf(file, mode, content->value.listValue); -} - -static void outputParenthesisToken(FILE *file, outputMode mode, LSL_Leaf *content) -{ - if (content) - { - fprintf(file, "%s", content->token->token); - outputLeaf(file, mode, content->value.parenthesis->contents); - outputLeaf(file, mode, content->value.parenthesis->right); - } -} - -static void outputStateToken(FILE *file, outputMode mode, LSL_Leaf *content) -{ - if (content) - { - LSL_State *state = content->value.stateValue; - - fprintf(file, "%s", state->name); - outputLeaf(file, mode, state->block); - } -} - -static void outputStatementToken(FILE *file, outputMode mode, LSL_Leaf *content) -{ - if (content) - { - outputLeaf(file, mode, content->value.statementValue->expressions); - if (content->ignorableText) - fprintf(file, "%s", content->ignorableText); - fprintf(file, "%s", content->token->token); - } -} - -static void outputVariableToken(FILE *file, outputMode mode, LSL_Leaf *content) -{ - if (content) - fprintf(file, "%s", content->value.variableValue->name); -} - -static void doneParsing(LuaSL_yyparseParam *param) -{ - if (param->ast) - { - FILE *out; - char buffer[PATH_MAX]; - char outName[PATH_MAX]; - char luaName[PATH_MAX]; - - outputLeaf(stdout, OM_LSL, param->ast); - printf("\n"); - evaluateLeaf(param->ast, NULL, NULL); - printf("\n"); - - strcpy(outName, param->fileName); - strcat(outName, "2"); - strcpy(luaName, param->fileName); - strcat(luaName, ".lua"); - out = fopen(outName, "w"); - if (out) - { -// int count; - outputLeaf(out, OM_LSL, param->ast); - fclose(out); - sprintf(buffer, "diff %s %s", param->fileName, outName); -// count = system(buffer); -// printf("Return value of %s is %d\n", buffer, count); -// if (0 != count) -// fprintf(stderr, "%s says they are different!\n", buffer); - } - else - fprintf(stderr, "Unable to open file %s for writing!\n", outName); - out = fopen(luaName, "w"); - if (out) - { - outputLeaf(out, OM_LUA, param->ast); - fclose(out); - } - else - fprintf(stderr, "Unable to open file %s for writing!\n", luaName); - } -} - -static int nextFile(LuaSL_yyparseParam *param) -{ - if (NULL != param->file) - { - fclose(param->file); - param->file = NULL; - } - if (--(param->argc) > 0 && *++(param->argv) != '\0') - { - strncpy(param->fileName, *(param->argv), PATH_MAX - 1); - param->fileName[PATH_MAX - 1] = '\0'; - param->file = fopen(param->fileName, "r"); - if (NULL == param->file) - { - fprintf(stderr, "Error opening file %s.\n", param->fileName); - return FALSE; - } - printf("Opened %s.\n", param->fileName); - burnLeaf(param->ast); - param->ast = NULL; - param->lval = calloc(1, sizeof(LSL_Leaf)); - // Text editors usually start counting at 1, even programmers editors. - param->column = 1; - param->line = 1; - return TRUE; - } -/* - if ('\0' == fileName[0]) - { -//strcpy(fileName, "test.lsl"); - - count = read(STDIN_FILENO, fileName, PATH_MAX - 1); - if (0 > count) - { - printf("Error in stdin!\n"); - return 1; - } - else if (0 == count) - { - printf("No bytes in stdin!\n"); - return 1; - } - else - { - fileName[count] = '\0'; - printf("Filename %s in stdin.\n", fileName); - } - - } -*/ - - return FALSE; -} - -char *test[] = {"test2.lsl", "test2.lsl"}; - -int main(int argc, char **argv) -{ -// char *programName = argv[0]; - int i; - - // Figure out what numbers yacc gave to our tokens. - for (i = 0; LSL_Tokens[i].token != NULL; i++) - { - if (lowestToken > LSL_Tokens[i].type) - lowestToken = LSL_Tokens[i].type; - } - tokens = calloc(i + 1, sizeof(LSL_Token *)); - if (tokens) - { - LuaSL_yyparseParam param; - - // Sort the token table. - for (i = 0; LSL_Tokens[i].token != NULL; i++) - { - int j = LSL_Tokens[i].type - lowestToken; - - tokens[j] = &(LSL_Tokens[i]); - } - - // First time setup. - if (1 == argc) - { - // Fake a test file if there is none. Mostly for ddd. - argc++; - argv = test; - } - memset(¶m, 0, sizeof(param)); - param.argc = argc; - param.argv = argv; - - // Loop through the files. - while (nextFile(¶m)) - { - void *pParser = ParseAlloc(malloc); - int yv; - -#ifdef LUASL_DEBUG -// yydebug= 5; -#endif - if (yylex_init_extra(¶m, &(param.scanner))) - return 1; -#ifdef LUASL_DEBUG - yyset_debug(1, param.scanner); -#endif - yyset_in(param.file, param.scanner); -#ifdef LUASL_DEBUG - ParseTrace(stdout, "LSL_lemon "); -#endif - // on EOF yylex will return 0 - while((yv = yylex(param.lval, param.scanner)) != 0) - { - Parse(pParser, yv, param.lval, ¶m); - if (LSL_SCRIPT == yv) - break; - param.lval = calloc(1, sizeof(LSL_Leaf)); - } - - yylex_destroy(param.scanner); - Parse (pParser, 0, param.lval, ¶m); - ParseFree(pParser, free); - doneParsing(¶m); - } - } - else - { - fprintf(stderr, "No memory for tokens!"); - return 1; - } - - return 0; -} - diff --git a/LuaSL/src/LuaSL_LSL_tree.h b/LuaSL/src/LuaSL_LSL_tree.h index 84610b6..b287b8f 100644 --- a/LuaSL/src/LuaSL_LSL_tree.h +++ b/LuaSL/src/LuaSL_LSL_tree.h @@ -54,13 +54,13 @@ typedef enum typedef void (*outputToken) (FILE *file, outputMode mode, LSL_Leaf *content); typedef LSL_Leaf * (*evaluateToken) (LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right); -#ifndef FALSE -typedef enum -{ - FALSE = 0, - TRUE = 1 -} boolean; -#endif +//#ifndef FALSE +//typedef enum +//{ +// FALSE = 0, +// TRUE = 1 +//} boolean; +//#endif typedef enum { diff --git a/LuaSL/src/LuaSL_LSL_yaccer.y b/LuaSL/src/LuaSL_LSL_yaccer.y deleted file mode 100644 index 8cc433d..0000000 --- a/LuaSL/src/LuaSL_LSL_yaccer.y +++ /dev/null @@ -1,1474 +0,0 @@ -%{ - -#include "LuaSL_LSL_tree.h" - -//int yylex(void); -//int yyparse( void ); -//int yyerror(const char *fmt, ...); - -#if LL_LINUX -// broken yacc codegen... --ryan. - #define getenv getenv_workaround -#endif - -#ifdef LL_WINDOWS - #pragma warning (disable : 4702) // warning C4702: unreachable code - #pragma warning( disable : 4065 ) // warning: switch statement contains 'default' but no 'case' labels -#endif - -%} - - -%token INTEGER -%token FLOAT_TYPE -%token STRING -%token LLKEY -%token VECTOR -%token QUATERNION -%token LIST - -%token STATE -%token EVENT -%token JUMP -%token RETURN - -%token STATE_ENTRY -%token STATE_EXIT -%token TOUCH_START -%token TOUCH -%token TOUCH_END -%token COLLISION_START -%token COLLISION -%token COLLISION_END -%token LAND_COLLISION_START -%token LAND_COLLISION -%token LAND_COLLISION_END -%token TIMER -%token CHAT -%token SENSOR -%token NO_SENSOR -%token CONTROL -%token AT_TARGET -%token NOT_AT_TARGET -%token AT_ROT_TARGET -%token NOT_AT_ROT_TARGET -%token MONEY -%token EMAIL -%token RUN_TIME_PERMISSIONS -%token INVENTORY -%token ATTACH -%token DATASERVER -%token MOVING_START -%token MOVING_END -%token REZ -%token OBJECT_REZ -%token LINK_MESSAGE -%token REMOTE_DATA -%token HTTP_RESPONSE -%token HTTP_REQUEST - -%token IDENTIFIER -%token STATE_DEFAULT - -%token INTEGER_CONSTANT -%token INTEGER_TRUE -%token INTEGER_FALSE - -%token FP_CONSTANT - -%token STRING_CONSTANT - -%token INC_OP -%token DEC_OP -%token ADD_ASSIGN -%token SUB_ASSIGN -%token MUL_ASSIGN -%token DIV_ASSIGN -%token MOD_ASSIGN - -%token EQ -%token NEQ -%token GEQ -%token LEQ - -%token BOOLEAN_AND -%token BOOLEAN_OR - -%token SHIFT_LEFT -%token SHIFT_RIGHT - -%token IF -%token ELSE -%token FOR -%token DO -%token WHILE - -%token PRINT - -%token PERIOD - -%token ZERO_VECTOR -%token ZERO_ROTATION - -%token TOUCH_INVALID_VECTOR -%token TOUCH_INVALID_TEXCOORD - -%nonassoc LOWER_THAN_ELSE -%nonassoc ELSE - - -%type