From 36f559ecb726cdfe9bbdc11a15970ff3135f34c5 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 27 Nov 2016 12:18:06 +0100 Subject: [PATCH] - fixed bad definition of struct grammar which tried to resolve from right to left, creating large amounts of recursion and strange problems with PlayerInfo. - added a command line option to generate a parser trace file. - fixed a syntax error in player.txt. --- src/scripting/zscript/zcc-parse.lemon | 2 +- src/scripting/zscript/zcc_parser.cpp | 20 +++++++++++--------- wadsrc/static/zscript/shared/player.txt | 2 +- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/scripting/zscript/zcc-parse.lemon b/src/scripting/zscript/zcc-parse.lemon index d22746cf89..ccd7e6e845 100644 --- a/src/scripting/zscript/zcc-parse.lemon +++ b/src/scripting/zscript/zcc-parse.lemon @@ -299,7 +299,7 @@ opt_struct_body(X) ::= error. { X = NULL; } struct_body(X) ::= struct_member(X). -struct_body(X) ::= struct_member(A) struct_body(B). { X = A; /*X-overwrites-A*/ AppendTreeNodeSibling(X, B); } +struct_body(X) ::= struct_body(A) struct_member(B). { X = A; /*X-overwrites-A*/ AppendTreeNodeSibling(X, B); } struct_member(X) ::= declarator(A). { X = A; /*X-overwrites-A*/ } struct_member(X) ::= enum_def(A). { X = A; /*X-overwrites-A*/ } diff --git a/src/scripting/zscript/zcc_parser.cpp b/src/scripting/zscript/zcc_parser.cpp index 9d24d0cb10..989ec10aef 100644 --- a/src/scripting/zscript/zcc_parser.cpp +++ b/src/scripting/zscript/zcc_parser.cpp @@ -302,12 +302,15 @@ static void DoParse(int lumpnum) parser = ZCCParseAlloc(malloc); ZCCParseState state; -//#define TRACE -#ifdef TRACE // this costs a lot of time and should only be activated when it's really needed. - FILE *f = fopen("trace.txt", "w"); - char prompt = '\0'; - ZCCParseTrace(f, &prompt); -#endif + + FILE *f = nullptr; + const char *tracefile = Args->CheckValue("-tracefile"); + if (tracefile != nullptr) + { + f = fopen(tracefile, "w"); + char prompt = '\0'; + ZCCParseTrace(f, &prompt); + } sc.OpenLumpNum(lumpnum); auto saved = sc.SavePos(); @@ -341,6 +344,7 @@ static void DoParse(int lumpnum) } } + if (f) fprintf(f, "Starting parsing %s\n", sc.String); ParseSingleFile(sc.String, 0, parser, state); } } @@ -356,12 +360,10 @@ static void DoParse(int lumpnum) I_Error("%d errors while parsing %s", FScriptPosition::ErrorCounter, Wads.GetLumpFullPath(lumpnum).GetChars()); } -#ifdef TRACE - if (f != NULL) + if (f != nullptr) { fclose(f); } -#endif // Make a dump of the AST before running the compiler for diagnostic purposes. if (Args->CheckParm("-dumpast")) diff --git a/wadsrc/static/zscript/shared/player.txt b/wadsrc/static/zscript/shared/player.txt index 136feb32e1..c7615e9c20 100644 --- a/wadsrc/static/zscript/shared/player.txt +++ b/wadsrc/static/zscript/shared/player.txt @@ -228,7 +228,7 @@ FWeaponSlots weapons; native bool UndoPlayerMorph(playerinfo player, int unmorphflag = 0, bool force = false); native bool PoisonPlayer(Actor poisoner, Actor source, int poison); - native PoisonDamage(Actor source, int damage, bool playPainSound) + native void PoisonDamage(Actor source, int damage, bool playPainSound); native void SetPsprite(int id, State stat, bool pending = false); native void SetSafeFlash(Weapon weap, State flashstate, int index); native PSprite GetPSprite(int id);