mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2024-11-11 15:22:15 +00:00
Add names for fallback tokens.
- Fixed: When falling back to the IDENTIFIER token, the identifier it would get was undefined, because it never got initialized.
This commit is contained in:
parent
5cc8a9c2a7
commit
11b588de4a
3 changed files with 146 additions and 118 deletions
|
@ -575,3 +575,19 @@ xx(DecoCallLineSpecial)
|
||||||
xx(DecoNameToClass)
|
xx(DecoNameToClass)
|
||||||
xx(DecoFindMultiNameState)
|
xx(DecoFindMultiNameState)
|
||||||
xx(DecoFindSingleNameState)
|
xx(DecoFindSingleNameState)
|
||||||
|
|
||||||
|
// fallback names for ZScript parser
|
||||||
|
xx(default)
|
||||||
|
xx(sbyte)
|
||||||
|
xx(byte)
|
||||||
|
xx(short)
|
||||||
|
xx(ushort)
|
||||||
|
xx(int)
|
||||||
|
xx(uint)
|
||||||
|
xx(bool)
|
||||||
|
xx(float)
|
||||||
|
xx(double)
|
||||||
|
xx(string)
|
||||||
|
xx(vector)
|
||||||
|
xx(map)
|
||||||
|
xx(array)
|
||||||
|
|
|
@ -435,7 +435,7 @@ vector_size(X) ::= LT INTCONST(A) GT.
|
||||||
/* Type names can also be used as identifiers in contexts where type names
|
/* Type names can also be used as identifiers in contexts where type names
|
||||||
* are not normally allowed. */
|
* are not normally allowed. */
|
||||||
%fallback IDENTIFIER
|
%fallback IDENTIFIER
|
||||||
SBYTE BYTE SHORT USHORT INT UINT BOOL FLOAT DOUBLE STRING VECTOR NAME.
|
SBYTE BYTE SHORT USHORT INT UINT BOOL FLOAT DOUBLE STRING VECTOR NAME MAP ARRAY VOID.
|
||||||
|
|
||||||
/* Aggregate types */
|
/* Aggregate types */
|
||||||
%type aggregate_type {ZCC_Type *}
|
%type aggregate_type {ZCC_Type *}
|
||||||
|
|
|
@ -13,12 +13,22 @@ static FString ZCCTokenName(int terminal);
|
||||||
#include "zcc-parse.h"
|
#include "zcc-parse.h"
|
||||||
#include "zcc-parse.c"
|
#include "zcc-parse.c"
|
||||||
|
|
||||||
static TMap<SWORD, SWORD> TokenMap;
|
struct TokenMapEntry
|
||||||
|
{
|
||||||
|
SWORD TokenType;
|
||||||
|
WORD TokenName;
|
||||||
|
TokenMapEntry(SWORD a, WORD b)
|
||||||
|
: TokenType(a), TokenName(b)
|
||||||
|
{ }
|
||||||
|
};
|
||||||
|
static TMap<SWORD, TokenMapEntry> TokenMap;
|
||||||
static SWORD BackTokenMap[YYERRORSYMBOL]; // YYERRORSYMBOL immediately follows the terminals described by the grammar
|
static SWORD BackTokenMap[YYERRORSYMBOL]; // YYERRORSYMBOL immediately follows the terminals described by the grammar
|
||||||
|
|
||||||
|
#define TOKENDEF2(sc, zcc, name) { TokenMapEntry tme(zcc, name); TokenMap.Insert(sc, tme); } BackTokenMap[zcc] = sc
|
||||||
|
#define TOKENDEF(sc, zcc) TOKENDEF2(sc, zcc, NAME_None)
|
||||||
|
|
||||||
static void InitTokenMap()
|
static void InitTokenMap()
|
||||||
{
|
{
|
||||||
#define TOKENDEF(sc, zcc) TokenMap.Insert(sc, zcc); BackTokenMap[zcc] = sc
|
|
||||||
TOKENDEF ('=', ZCC_EQ);
|
TOKENDEF ('=', ZCC_EQ);
|
||||||
TOKENDEF (TK_MulEq, ZCC_MULEQ);
|
TOKENDEF (TK_MulEq, ZCC_MULEQ);
|
||||||
TOKENDEF (TK_DivEq, ZCC_DIVEQ);
|
TOKENDEF (TK_DivEq, ZCC_DIVEQ);
|
||||||
|
@ -81,20 +91,20 @@ static void InitTokenMap()
|
||||||
TOKENDEF ('}', ZCC_RBRACE);
|
TOKENDEF ('}', ZCC_RBRACE);
|
||||||
TOKENDEF (TK_Struct, ZCC_STRUCT);
|
TOKENDEF (TK_Struct, ZCC_STRUCT);
|
||||||
TOKENDEF (TK_Enum, ZCC_ENUM);
|
TOKENDEF (TK_Enum, ZCC_ENUM);
|
||||||
TOKENDEF(TK_SByte, ZCC_SBYTE);
|
TOKENDEF2(TK_SByte, ZCC_SBYTE, NAME_sbyte);
|
||||||
TOKENDEF(TK_Byte, ZCC_BYTE);
|
TOKENDEF2(TK_Byte, ZCC_BYTE, NAME_byte);
|
||||||
TOKENDEF(TK_Short, ZCC_SHORT);
|
TOKENDEF2(TK_Short, ZCC_SHORT, NAME_short);
|
||||||
TOKENDEF(TK_UShort, ZCC_USHORT);
|
TOKENDEF2(TK_UShort, ZCC_USHORT, NAME_ushort);
|
||||||
TOKENDEF(TK_Int, ZCC_INT);
|
TOKENDEF2(TK_Int, ZCC_INT, NAME_int);
|
||||||
TOKENDEF(TK_UInt, ZCC_UINT);
|
TOKENDEF2(TK_UInt, ZCC_UINT, NAME_uint);
|
||||||
TOKENDEF(TK_Bool, ZCC_BOOL);
|
TOKENDEF2(TK_Bool, ZCC_BOOL, NAME_bool);
|
||||||
TOKENDEF(TK_Float, ZCC_FLOAT);
|
TOKENDEF2(TK_Float, ZCC_FLOAT, NAME_float);
|
||||||
TOKENDEF(TK_Double, ZCC_DOUBLE);
|
TOKENDEF2(TK_Double, ZCC_DOUBLE, NAME_double);
|
||||||
TOKENDEF(TK_String, ZCC_STRING);
|
TOKENDEF2(TK_String, ZCC_STRING, NAME_string);
|
||||||
TOKENDEF(TK_Vector, ZCC_VECTOR);
|
TOKENDEF2(TK_Vector, ZCC_VECTOR, NAME_vector);
|
||||||
TOKENDEF(TK_Name, ZCC_NAME);
|
TOKENDEF2(TK_Name, ZCC_NAME, NAME_Name);
|
||||||
TOKENDEF(TK_Map, ZCC_MAP);
|
TOKENDEF2(TK_Map, ZCC_MAP, NAME_map);
|
||||||
TOKENDEF(TK_Array, ZCC_ARRAY);
|
TOKENDEF2(TK_Array, ZCC_ARRAY, NAME_array);
|
||||||
TOKENDEF (TK_Void, ZCC_VOID);
|
TOKENDEF (TK_Void, ZCC_VOID);
|
||||||
TOKENDEF ('[', ZCC_LBRACKET);
|
TOKENDEF ('[', ZCC_LBRACKET);
|
||||||
TOKENDEF (']', ZCC_RBRACKET);
|
TOKENDEF (']', ZCC_RBRACKET);
|
||||||
|
@ -118,7 +128,7 @@ static void InitTokenMap()
|
||||||
TOKENDEF (TK_Else, ZCC_ELSE);
|
TOKENDEF (TK_Else, ZCC_ELSE);
|
||||||
TOKENDEF (TK_Switch, ZCC_SWITCH);
|
TOKENDEF (TK_Switch, ZCC_SWITCH);
|
||||||
TOKENDEF (TK_Case, ZCC_CASE);
|
TOKENDEF (TK_Case, ZCC_CASE);
|
||||||
TOKENDEF(TK_Default, ZCC_DEFAULT);
|
TOKENDEF2(TK_Default, ZCC_DEFAULT, NAME_default);
|
||||||
TOKENDEF (TK_Const, ZCC_CONST);
|
TOKENDEF (TK_Const, ZCC_CONST);
|
||||||
TOKENDEF (TK_Stop, ZCC_STOP);
|
TOKENDEF (TK_Stop, ZCC_STOP);
|
||||||
TOKENDEF (TK_Wait, ZCC_WAIT);
|
TOKENDEF (TK_Wait, ZCC_WAIT);
|
||||||
|
@ -132,8 +142,9 @@ static void InitTokenMap()
|
||||||
TOKENDEF (TK_IntConst, ZCC_INTCONST);
|
TOKENDEF (TK_IntConst, ZCC_INTCONST);
|
||||||
TOKENDEF (TK_FloatConst, ZCC_FLOATCONST);
|
TOKENDEF (TK_FloatConst, ZCC_FLOATCONST);
|
||||||
TOKENDEF (TK_NonWhitespace, ZCC_NWS);
|
TOKENDEF (TK_NonWhitespace, ZCC_NWS);
|
||||||
#undef TOKENDEF
|
|
||||||
}
|
}
|
||||||
|
#undef TOKENDEF
|
||||||
|
#undef TOKENDEF2
|
||||||
|
|
||||||
static void DoParse(const char *filename)
|
static void DoParse(const char *filename)
|
||||||
{
|
{
|
||||||
|
@ -202,10 +213,11 @@ static void DoParse(const char *filename)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SWORD *zcctoken = TokenMap.CheckKey(sc.TokenType);
|
TokenMapEntry *zcctoken = TokenMap.CheckKey(sc.TokenType);
|
||||||
if (zcctoken != NULL)
|
if (zcctoken != NULL)
|
||||||
{
|
{
|
||||||
tokentype = *zcctoken;
|
tokentype = zcctoken->TokenType;
|
||||||
|
value.Int = zcctoken->TokenName;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue