finish lexer optimization

This commit is contained in:
xensik 2022-01-30 14:45:07 +01:00
parent 8b62635131
commit 30aab69283
45 changed files with 10357 additions and 10545 deletions

View File

@ -41,6 +41,14 @@ using namespace xsk::gsc;
xsk::gsc::h1::parser::symbol_type H1lex(xsk::gsc::h1::lexer& lexer); xsk::gsc::h1::parser::symbol_type H1lex(xsk::gsc::h1::lexer& lexer);
} }
%token HSDEFINE "#define"
%token HSUNDEF "#undef"
%token HSIFDEF "#ifdef"
%token HSIFNDEF "#ifndef"
%token HSIF "#if"
%token HSELIF "#elif"
%token HSELSE "#else"
%token HSENDIF "#endif"
%token DEVBEGIN "/#" %token DEVBEGIN "/#"
%token DEVEND "#/" %token DEVEND "#/"
%token INLINE "#inline" %token INLINE "#inline"
@ -283,7 +291,7 @@ declaration
decl_usingtree decl_usingtree
: USINGTREE LPAREN expr_string RPAREN SEMICOLON : USINGTREE LPAREN expr_string RPAREN SEMICOLON
{ lexer.restrict_header(@$); $$ = std::make_unique<ast::decl_usingtree>(@$, std::move($3)); } { lexer.ban_header(@$); $$ = std::make_unique<ast::decl_usingtree>(@$, std::move($3)); }
; ;
decl_constant decl_constant
@ -293,7 +301,7 @@ decl_constant
decl_thread decl_thread
: expr_identifier LPAREN expr_parameters RPAREN stmt_block : expr_identifier LPAREN expr_parameters RPAREN stmt_block
{ lexer.restrict_header(@$); $$ = std::make_unique<ast::decl_thread>(@$, std::move($1), std::move($3), std::move($5)); } { lexer.ban_header(@$); $$ = std::make_unique<ast::decl_thread>(@$, std::move($1), std::move($3), std::move($5)); }
; ;
stmt stmt

View File

@ -39,6 +39,14 @@ using namespace xsk::gsc;
xsk::gsc::h2::parser::symbol_type H2lex(xsk::gsc::h2::lexer& lexer); xsk::gsc::h2::parser::symbol_type H2lex(xsk::gsc::h2::lexer& lexer);
} }
%token HSDEFINE "#define"
%token HSUNDEF "#undef"
%token HSIFDEF "#ifdef"
%token HSIFNDEF "#ifndef"
%token HSIF "#if"
%token HSELIF "#elif"
%token HSELSE "#else"
%token HSENDIF "#endif"
%token DEVBEGIN "/#" %token DEVBEGIN "/#"
%token DEVEND "#/" %token DEVEND "#/"
%token INLINE "#inline" %token INLINE "#inline"
@ -281,7 +289,7 @@ declaration
decl_usingtree decl_usingtree
: USINGTREE LPAREN expr_string RPAREN SEMICOLON : USINGTREE LPAREN expr_string RPAREN SEMICOLON
{ lexer.restrict_header(@$); $$ = std::make_unique<ast::decl_usingtree>(@$, std::move($3)); } { lexer.ban_header(@$); $$ = std::make_unique<ast::decl_usingtree>(@$, std::move($3)); }
; ;
decl_constant decl_constant
@ -291,7 +299,7 @@ decl_constant
decl_thread decl_thread
: expr_identifier LPAREN expr_parameters RPAREN stmt_block : expr_identifier LPAREN expr_parameters RPAREN stmt_block
{ lexer.restrict_header(@$); $$ = std::make_unique<ast::decl_thread>(@$, std::move($1), std::move($3), std::move($5)); } { lexer.ban_header(@$); $$ = std::make_unique<ast::decl_thread>(@$, std::move($1), std::move($3), std::move($5)); }
; ;
stmt stmt

View File

@ -39,6 +39,14 @@ using namespace xsk::gsc;
xsk::gsc::iw5::parser::symbol_type IW5lex(xsk::gsc::iw5::lexer& lexer); xsk::gsc::iw5::parser::symbol_type IW5lex(xsk::gsc::iw5::lexer& lexer);
} }
%token HSDEFINE "#define"
%token HSUNDEF "#undef"
%token HSIFDEF "#ifdef"
%token HSIFNDEF "#ifndef"
%token HSIF "#if"
%token HSELIF "#elif"
%token HSELSE "#else"
%token HSENDIF "#endif"
%token DEVBEGIN "/#" %token DEVBEGIN "/#"
%token DEVEND "#/" %token DEVEND "#/"
%token INLINE "#inline" %token INLINE "#inline"
@ -279,7 +287,7 @@ declaration
decl_usingtree decl_usingtree
: USINGTREE LPAREN expr_string RPAREN SEMICOLON : USINGTREE LPAREN expr_string RPAREN SEMICOLON
{ lexer.restrict_header(@$); $$ = std::make_unique<ast::decl_usingtree>(@$, std::move($3)); } { lexer.ban_header(@$); $$ = std::make_unique<ast::decl_usingtree>(@$, std::move($3)); }
; ;
decl_constant decl_constant
@ -289,7 +297,7 @@ decl_constant
decl_thread decl_thread
: expr_identifier LPAREN expr_parameters RPAREN stmt_block : expr_identifier LPAREN expr_parameters RPAREN stmt_block
{ lexer.restrict_header(@$); $$ = std::make_unique<ast::decl_thread>(@$, std::move($1), std::move($3), std::move($5)); } { lexer.ban_header(@$); $$ = std::make_unique<ast::decl_thread>(@$, std::move($1), std::move($3), std::move($5)); }
; ;
stmt stmt

View File

@ -39,6 +39,14 @@ using namespace xsk::gsc;
xsk::gsc::iw6::parser::symbol_type IW6lex(xsk::gsc::iw6::lexer& lexer); xsk::gsc::iw6::parser::symbol_type IW6lex(xsk::gsc::iw6::lexer& lexer);
} }
%token HSDEFINE "#define"
%token HSUNDEF "#undef"
%token HSIFDEF "#ifdef"
%token HSIFNDEF "#ifndef"
%token HSIF "#if"
%token HSELIF "#elif"
%token HSELSE "#else"
%token HSENDIF "#endif"
%token DEVBEGIN "/#" %token DEVBEGIN "/#"
%token DEVEND "#/" %token DEVEND "#/"
%token INLINE "#inline" %token INLINE "#inline"
@ -279,7 +287,7 @@ declaration
decl_usingtree decl_usingtree
: USINGTREE LPAREN expr_string RPAREN SEMICOLON : USINGTREE LPAREN expr_string RPAREN SEMICOLON
{ lexer.restrict_header(@$); $$ = std::make_unique<ast::decl_usingtree>(@$, std::move($3)); } { lexer.ban_header(@$); $$ = std::make_unique<ast::decl_usingtree>(@$, std::move($3)); }
; ;
decl_constant decl_constant
@ -289,7 +297,7 @@ decl_constant
decl_thread decl_thread
: expr_identifier LPAREN expr_parameters RPAREN stmt_block : expr_identifier LPAREN expr_parameters RPAREN stmt_block
{ lexer.restrict_header(@$); $$ = std::make_unique<ast::decl_thread>(@$, std::move($1), std::move($3), std::move($5)); } { lexer.ban_header(@$); $$ = std::make_unique<ast::decl_thread>(@$, std::move($1), std::move($3), std::move($5)); }
; ;
stmt stmt

View File

@ -39,6 +39,14 @@ using namespace xsk::gsc;
xsk::gsc::iw7::parser::symbol_type IW7lex(xsk::gsc::iw7::lexer& lexer); xsk::gsc::iw7::parser::symbol_type IW7lex(xsk::gsc::iw7::lexer& lexer);
} }
%token HSDEFINE "#define"
%token HSUNDEF "#undef"
%token HSIFDEF "#ifdef"
%token HSIFNDEF "#ifndef"
%token HSIF "#if"
%token HSELIF "#elif"
%token HSELSE "#else"
%token HSENDIF "#endif"
%token DEVBEGIN "/#" %token DEVBEGIN "/#"
%token DEVEND "#/" %token DEVEND "#/"
%token INLINE "#inline" %token INLINE "#inline"
@ -279,7 +287,7 @@ declaration
decl_usingtree decl_usingtree
: USINGTREE LPAREN expr_string RPAREN SEMICOLON : USINGTREE LPAREN expr_string RPAREN SEMICOLON
{ lexer.restrict_header(@$); $$ = std::make_unique<ast::decl_usingtree>(@$, std::move($3)); } { lexer.ban_header(@$); $$ = std::make_unique<ast::decl_usingtree>(@$, std::move($3)); }
; ;
decl_constant decl_constant
@ -289,7 +297,7 @@ decl_constant
decl_thread decl_thread
: expr_identifier LPAREN expr_parameters RPAREN stmt_block : expr_identifier LPAREN expr_parameters RPAREN stmt_block
{ lexer.restrict_header(@$); $$ = std::make_unique<ast::decl_thread>(@$, std::move($1), std::move($3), std::move($5)); } { lexer.ban_header(@$); $$ = std::make_unique<ast::decl_thread>(@$, std::move($1), std::move($3), std::move($5)); }
; ;
stmt stmt

View File

@ -39,6 +39,14 @@ using namespace xsk::gsc;
xsk::gsc::iw8::parser::symbol_type IW8lex(xsk::gsc::iw8::lexer& lexer); xsk::gsc::iw8::parser::symbol_type IW8lex(xsk::gsc::iw8::lexer& lexer);
} }
%token HSDEFINE "#define"
%token HSUNDEF "#undef"
%token HSIFDEF "#ifdef"
%token HSIFNDEF "#ifndef"
%token HSIF "#if"
%token HSELIF "#elif"
%token HSELSE "#else"
%token HSENDIF "#endif"
%token DEVBEGIN "/#" %token DEVBEGIN "/#"
%token DEVEND "#/" %token DEVEND "#/"
%token INLINE "#inline" %token INLINE "#inline"
@ -285,7 +293,7 @@ declaration
decl_usingtree decl_usingtree
: USINGTREE LPAREN expr_string RPAREN SEMICOLON : USINGTREE LPAREN expr_string RPAREN SEMICOLON
{ lexer.restrict_header(@$); $$ = std::make_unique<ast::decl_usingtree>(@$, std::move($3)); } { lexer.ban_header(@$); $$ = std::make_unique<ast::decl_usingtree>(@$, std::move($3)); }
; ;
decl_constant decl_constant
@ -295,7 +303,7 @@ decl_constant
decl_thread decl_thread
: expr_identifier LPAREN expr_parameters RPAREN stmt_block : expr_identifier LPAREN expr_parameters RPAREN stmt_block
{ lexer.restrict_header(@$); $$ = std::make_unique<ast::decl_thread>(@$, std::move($1), std::move($3), std::move($5)); } { lexer.ban_header(@$); $$ = std::make_unique<ast::decl_thread>(@$, std::move($1), std::move($3), std::move($5)); }
; ;
stmt stmt

View File

@ -39,6 +39,14 @@ using namespace xsk::gsc;
xsk::gsc::s1::parser::symbol_type S1lex(xsk::gsc::s1::lexer& lexer); xsk::gsc::s1::parser::symbol_type S1lex(xsk::gsc::s1::lexer& lexer);
} }
%token HSDEFINE "#define"
%token HSUNDEF "#undef"
%token HSIFDEF "#ifdef"
%token HSIFNDEF "#ifndef"
%token HSIF "#if"
%token HSELIF "#elif"
%token HSELSE "#else"
%token HSENDIF "#endif"
%token DEVBEGIN "/#" %token DEVBEGIN "/#"
%token DEVEND "#/" %token DEVEND "#/"
%token INLINE "#inline" %token INLINE "#inline"
@ -281,7 +289,7 @@ declaration
decl_usingtree decl_usingtree
: USINGTREE LPAREN expr_string RPAREN SEMICOLON : USINGTREE LPAREN expr_string RPAREN SEMICOLON
{ lexer.restrict_header(@$); $$ = std::make_unique<ast::decl_usingtree>(@$, std::move($3)); } { lexer.ban_header(@$); $$ = std::make_unique<ast::decl_usingtree>(@$, std::move($3)); }
; ;
decl_constant decl_constant
@ -291,7 +299,7 @@ decl_constant
decl_thread decl_thread
: expr_identifier LPAREN expr_parameters RPAREN stmt_block : expr_identifier LPAREN expr_parameters RPAREN stmt_block
{ lexer.restrict_header(@$); $$ = std::make_unique<ast::decl_thread>(@$, std::move($1), std::move($3), std::move($5)); } { lexer.ban_header(@$); $$ = std::make_unique<ast::decl_thread>(@$, std::move($1), std::move($3), std::move($5)); }
; ;
stmt stmt

View File

@ -39,6 +39,14 @@ using namespace xsk::gsc;
xsk::gsc::s2::parser::symbol_type S2lex(xsk::gsc::s2::lexer& lexer); xsk::gsc::s2::parser::symbol_type S2lex(xsk::gsc::s2::lexer& lexer);
} }
%token HSDEFINE "#define"
%token HSUNDEF "#undef"
%token HSIFDEF "#ifdef"
%token HSIFNDEF "#ifndef"
%token HSIF "#if"
%token HSELIF "#elif"
%token HSELSE "#else"
%token HSENDIF "#endif"
%token DEVBEGIN "/#" %token DEVBEGIN "/#"
%token DEVEND "#/" %token DEVEND "#/"
%token INLINE "#inline" %token INLINE "#inline"
@ -281,7 +289,7 @@ declaration
decl_usingtree decl_usingtree
: USINGTREE LPAREN expr_string RPAREN SEMICOLON : USINGTREE LPAREN expr_string RPAREN SEMICOLON
{ lexer.restrict_header(@$); $$ = std::make_unique<ast::decl_usingtree>(@$, std::move($3)); } { lexer.ban_header(@$); $$ = std::make_unique<ast::decl_usingtree>(@$, std::move($3)); }
; ;
decl_constant decl_constant
@ -291,7 +299,7 @@ decl_constant
decl_thread decl_thread
: expr_identifier LPAREN expr_parameters RPAREN stmt_block : expr_identifier LPAREN expr_parameters RPAREN stmt_block
{ lexer.restrict_header(@$); $$ = std::make_unique<ast::decl_thread>(@$, std::move($1), std::move($3), std::move($5)); } { lexer.ban_header(@$); $$ = std::make_unique<ast::decl_thread>(@$, std::move($1), std::move($3), std::move($5)); }
; ;
stmt stmt

View File

@ -39,6 +39,14 @@ using namespace xsk::gsc;
xsk::gsc::s4::parser::symbol_type S4lex(xsk::gsc::s4::lexer& lexer); xsk::gsc::s4::parser::symbol_type S4lex(xsk::gsc::s4::lexer& lexer);
} }
%token HSDEFINE "#define"
%token HSUNDEF "#undef"
%token HSIFDEF "#ifdef"
%token HSIFNDEF "#ifndef"
%token HSIF "#if"
%token HSELIF "#elif"
%token HSELSE "#else"
%token HSENDIF "#endif"
%token DEVBEGIN "/#" %token DEVBEGIN "/#"
%token DEVEND "#/" %token DEVEND "#/"
%token INLINE "#inline" %token INLINE "#inline"
@ -285,7 +293,7 @@ declaration
decl_usingtree decl_usingtree
: USINGTREE LPAREN expr_string RPAREN SEMICOLON : USINGTREE LPAREN expr_string RPAREN SEMICOLON
{ lexer.restrict_header(@$); $$ = std::make_unique<ast::decl_usingtree>(@$, std::move($3)); } { lexer.ban_header(@$); $$ = std::make_unique<ast::decl_usingtree>(@$, std::move($3)); }
; ;
decl_constant decl_constant
@ -295,7 +303,7 @@ decl_constant
decl_thread decl_thread
: expr_identifier LPAREN expr_parameters RPAREN stmt_block : expr_identifier LPAREN expr_parameters RPAREN stmt_block
{ lexer.restrict_header(@$); $$ = std::make_unique<ast::decl_thread>(@$, std::move($1), std::move($3), std::move($5)); } { lexer.ban_header(@$); $$ = std::make_unique<ast::decl_thread>(@$, std::move($1), std::move($3), std::move($5)); }
; ;
stmt stmt

View File

@ -16,57 +16,6 @@ xsk::gsc::h1::parser::symbol_type H1lex(xsk::gsc::h1::lexer& lexer)
namespace xsk::gsc::h1 namespace xsk::gsc::h1
{ {
enum class keyword
{
/* KW_pre_define,
KW_pre_undef,
KW_pre_ifdef,
KW_pre_ifndef,
KW_pre_if,
KW_pre_elif,
KW_pre_else,
KW_pre_endif,*/
KW_pre_inline,
KW_pre_include,
KW_pre_using_animtree,
KW_pre_animtree,
KW_endon,
KW_notify,
KW_wait,
KW_waittill,
KW_waittillmatch,
KW_waittillframeend,
KW_waitframe,
KW_if,
KW_else,
KW_do,
KW_while,
KW_for,
KW_foreach,
KW_in,
KW_switch,
KW_case,
KW_default,
KW_break,
KW_continue,
KW_return,
KW_breakpoint,
KW_prof_begin,
KW_prof_end,
KW_thread,
KW_childthread,
KW_thisthread,
KW_call,
KW_true,
KW_false,
KW_undefined,
KW_game,
KW_self,
KW_anim,
KW_level,
KW_INVALID,
};
buffer::buffer() : length(0) buffer::buffer() : length(0)
{ {
data = static_cast<char*>(std::malloc(max_buf_size)); data = static_cast<char*>(std::malloc(max_buf_size));
@ -129,7 +78,7 @@ void reader::advance()
} }
} }
lexer::lexer(const std::string& name, const char* data, size_t size) : indev_(false), loc_(xsk::gsc::location(&name)), lexer::lexer(const std::string& name, const char* data, size_t size) : indev_(false), loc_(location(&name)),
mode_(build::dev), header_top_(0), locs_(std::stack<location>()), readers_(std::stack<reader>()) mode_(build::dev), header_top_(0), locs_(std::stack<location>()), readers_(std::stack<reader>())
{ {
reader_.init(data, size); reader_.init(data, size);
@ -140,7 +89,7 @@ void lexer::push_header(const std::string& file)
try try
{ {
if (header_top_++ >= 10) if (header_top_++ >= 10)
throw xsk::gsc::error("maximum gsh depth exceeded '10'"); throw comp_error(loc_, "maximum gsh depth exceeded '10'");
auto data = resolver::file_data(file + ".gsh"); auto data = resolver::file_data(file + ".gsh");
@ -151,7 +100,7 @@ void lexer::push_header(const std::string& file)
} }
catch (const std::exception& e) catch (const std::exception& e)
{ {
throw xsk::gsc::error("parsing header file '" + file + "': " + e.what()); throw error("parsing header file '" + file + "': " + e.what());
} }
} }
@ -164,7 +113,7 @@ void lexer::pop_header()
readers_.pop(); readers_.pop();
} }
void lexer::restrict_header(const xsk::gsc::location& loc) void lexer::ban_header(const location& loc)
{ {
if (header_top_ > 0) if (header_top_ > 0)
{ {
@ -172,7 +121,7 @@ void lexer::restrict_header(const xsk::gsc::location& loc)
} }
} }
auto lexer::lex() -> xsk::gsc::h1::parser::symbol_type auto lexer::lex() -> parser::symbol_type
{ {
buffer_.length = 0; buffer_.length = 0;
state_ = state::start; state_ = state::start;
@ -193,7 +142,7 @@ auto lexer::lex() -> xsk::gsc::h1::parser::symbol_type
if (header_top_ > 0) if (header_top_ > 0)
pop_header(); pop_header();
else else
return h1::parser::make_H1EOF(loc_); return parser::make_H1EOF(loc_);
} }
reader_.advance(); reader_.advance();
@ -211,22 +160,22 @@ auto lexer::lex() -> xsk::gsc::h1::parser::symbol_type
continue; continue;
case '/': case '/':
if (curr != '/' && curr != '*' && curr != '#' && curr != '=') if (curr != '/' && curr != '*' && curr != '#' && curr != '=')
return h1::parser::make_DIV(loc_); return parser::make_DIV(loc_);
reader_.advance(); reader_.advance();
if (last == '=') if (last == '=')
return h1::parser::make_ASSIGN_DIV(loc_); return parser::make_ASSIGN_DIV(loc_);
if (last == '#') if (last == '#')
{ {
if (indev_) if (indev_)
throw comp_error(loc_, "cannot recurse devblock ('/#')"); throw comp_error(loc_, "cannot recurse devblock ('/#')");
if (mode_ == xsk::gsc::build::dev) if (mode_ == build::dev)
{ {
indev_ = true; indev_ = true;
return h1::parser::make_DEVBEGIN(loc_); return parser::make_DEVBEGIN(loc_);
} }
else else
{ {
@ -290,7 +239,7 @@ auto lexer::lex() -> xsk::gsc::h1::parser::symbol_type
indev_ = false; indev_ = false;
reader_.advance(); reader_.advance();
return h1::parser::make_DEVEND(loc_); return parser::make_DEVEND(loc_);
} }
buffer_.push(last); buffer_.push(last);
@ -303,12 +252,12 @@ auto lexer::lex() -> xsk::gsc::h1::parser::symbol_type
goto lex_name; goto lex_name;
case '*': case '*':
if (curr != '/' && curr != '=') if (curr != '/' && curr != '=')
return h1::parser::make_MUL(loc_); return parser::make_MUL(loc_);
reader_.advance(); reader_.advance();
if (last == '=') if (last == '=')
return h1::parser::make_ASSIGN_MUL(loc_); return parser::make_ASSIGN_MUL(loc_);
throw comp_error(loc_, "unmatched multiline comment end ('*/')"); throw comp_error(loc_, "unmatched multiline comment end ('*/')");
case '"': case '"':
@ -323,127 +272,127 @@ auto lexer::lex() -> xsk::gsc::h1::parser::symbol_type
state_ = state::field; state_ = state::field;
goto lex_name_or_number; goto lex_name_or_number;
case '(': case '(':
return h1::parser::make_LPAREN(loc_); return parser::make_LPAREN(loc_);
case ')': case ')':
return h1::parser::make_RPAREN(loc_); return parser::make_RPAREN(loc_);
case '{': case '{':
return h1::parser::make_LBRACE(loc_); return parser::make_LBRACE(loc_);
case '}': case '}':
return h1::parser::make_RBRACE(loc_); return parser::make_RBRACE(loc_);
case '[': case '[':
return h1::parser::make_LBRACKET(loc_); return parser::make_LBRACKET(loc_);
case ']': case ']':
return h1::parser::make_RBRACKET(loc_); return parser::make_RBRACKET(loc_);
case ',': case ',':
return h1::parser::make_COMMA(loc_); return parser::make_COMMA(loc_);
case ';': case ';':
return h1::parser::make_SEMICOLON(loc_); return parser::make_SEMICOLON(loc_);
case ':': case ':':
if (curr != ':') if (curr != ':')
return h1::parser::make_COLON(loc_); return parser::make_COLON(loc_);
reader_.advance(); reader_.advance();
return h1::parser::make_DOUBLECOLON(loc_); return parser::make_DOUBLECOLON(loc_);
case '?': case '?':
return h1::parser::make_QMARK(loc_); return parser::make_QMARK(loc_);
case '=': case '=':
if (curr != '=') if (curr != '=')
return h1::parser::make_ASSIGN(loc_); return parser::make_ASSIGN(loc_);
reader_.advance(); reader_.advance();
return h1::parser::make_EQUALITY(loc_); return parser::make_EQUALITY(loc_);
case '+': case '+':
if (curr != '+' && curr != '=') if (curr != '+' && curr != '=')
return h1::parser::make_ADD(loc_); return parser::make_ADD(loc_);
reader_.advance(); reader_.advance();
if (last == '+') if (last == '+')
return h1::parser::make_INCREMENT(loc_); return parser::make_INCREMENT(loc_);
return h1::parser::make_ASSIGN_ADD(loc_); return parser::make_ASSIGN_ADD(loc_);
case '-': case '-':
if (curr != '-' && curr != '=') if (curr != '-' && curr != '=')
return h1::parser::make_SUB(loc_); return parser::make_SUB(loc_);
reader_.advance(); reader_.advance();
if (last == '-') if (last == '-')
return h1::parser::make_DECREMENT(loc_); return parser::make_DECREMENT(loc_);
return h1::parser::make_ASSIGN_SUB(loc_); return parser::make_ASSIGN_SUB(loc_);
case '%': case '%':
if (curr != '=') if (curr != '=')
return h1::parser::make_MOD(loc_); return parser::make_MOD(loc_);
reader_.advance(); reader_.advance();
return h1::parser::make_ASSIGN_MOD(loc_); return parser::make_ASSIGN_MOD(loc_);
case '|': case '|':
if (curr != '|' && curr != '=') if (curr != '|' && curr != '=')
return h1::parser::make_BITWISE_OR(loc_); return parser::make_BITWISE_OR(loc_);
reader_.advance(); reader_.advance();
if (last == '|') if (last == '|')
return h1::parser::make_OR(loc_); return parser::make_OR(loc_);
return h1::parser::make_ASSIGN_BW_OR(loc_); return parser::make_ASSIGN_BW_OR(loc_);
case '&': case '&':
if (curr != '&' && curr != '=' && curr != '"' && curr != '\'') if (curr != '&' && curr != '=' && curr != '"' && curr != '\'')
return h1::parser::make_BITWISE_AND(loc_); return parser::make_BITWISE_AND(loc_);
reader_.advance(); reader_.advance();
if (last == '&') if (last == '&')
return h1::parser::make_AND(loc_); return parser::make_AND(loc_);
if (last == '=') if (last == '=')
return h1::parser::make_ASSIGN_BW_AND(loc_); return parser::make_ASSIGN_BW_AND(loc_);
state_ = state::localize; state_ = state::localize;
goto lex_string; goto lex_string;
case '^': case '^':
if (curr != '=') if (curr != '=')
return h1::parser::make_BITWISE_EXOR(loc_); return parser::make_BITWISE_EXOR(loc_);
reader_.advance(); reader_.advance();
return h1::parser::make_ASSIGN_BW_EXOR(loc_); return parser::make_ASSIGN_BW_EXOR(loc_);
case '!': case '!':
if (curr != '=') if (curr != '=')
return h1::parser::make_NOT(loc_); return parser::make_NOT(loc_);
reader_.advance(); reader_.advance();
return h1::parser::make_INEQUALITY(loc_); return parser::make_INEQUALITY(loc_);
case '~': case '~':
return h1::parser::make_COMPLEMENT(loc_); return parser::make_COMPLEMENT(loc_);
case '<': case '<':
if (curr != '<' && curr != '=') if (curr != '<' && curr != '=')
return h1::parser::make_LESS(loc_); return parser::make_LESS(loc_);
reader_.advance(); reader_.advance();
if (last == '=') if (last == '=')
return h1::parser::make_LESS_EQUAL(loc_); return parser::make_LESS_EQUAL(loc_);
if (curr != '=') if (curr != '=')
return h1::parser::make_LSHIFT(loc_); return parser::make_LSHIFT(loc_);
reader_.advance(); reader_.advance();
return h1::parser::make_ASSIGN_LSHIFT(loc_); return parser::make_ASSIGN_LSHIFT(loc_);
case '>': case '>':
if (curr != '>' && curr != '=') if (curr != '>' && curr != '=')
return h1::parser::make_GREATER(loc_); return parser::make_GREATER(loc_);
reader_.advance(); reader_.advance();
if (last == '=') if (last == '=')
return h1::parser::make_GREATER_EQUAL(loc_); return parser::make_GREATER_EQUAL(loc_);
if (curr != '=') if (curr != '=')
return h1::parser::make_RSHIFT(loc_); return parser::make_RSHIFT(loc_);
reader_.advance(); reader_.advance();
return h1::parser::make_ASSIGN_RSHIFT(loc_); return parser::make_ASSIGN_RSHIFT(loc_);
default: default:
lex_name_or_number: lex_name_or_number:
if (last >= '0' && last <= '9') if (last >= '0' && last <= '9')
@ -496,9 +445,9 @@ lex_string:
} }
if (state_ == state::localize) if (state_ == state::localize)
return h1::parser::make_ISTRING(std::string(buffer_.data, buffer_.length), loc_); return parser::make_ISTRING(std::string(buffer_.data, buffer_.length), loc_);
return h1::parser::make_STRING(std::string(buffer_.data, buffer_.length), loc_); return parser::make_STRING(std::string(buffer_.data, buffer_.length), loc_);
lex_name: lex_name:
buffer_.push(last); buffer_.push(last);
@ -533,44 +482,55 @@ lex_name:
if (std::string_view(buffer_.data, buffer_.length) == "size") if (std::string_view(buffer_.data, buffer_.length) == "size")
{ {
return h1::parser::make_SIZE(loc_); return parser::make_SIZE(loc_);
} }
return h1::parser::make_FIELD(std::string(buffer_.data, buffer_.length), loc_); return parser::make_FIELD(std::string(buffer_.data, buffer_.length), loc_);
} }
else if (state_ == state::preprocessor) else if (state_ == state::preprocessor)
{ {
if (path) if (path)
throw comp_error(loc_, "invalid preprocessor directive"); throw comp_error(loc_, "invalid preprocessor directive");
auto key = get_keyword(std::string_view(buffer_.data, buffer_.length)); auto token = parser::token::H1UNDEF;
if (key != keyword::KW_INVALID) if (buffer_.length < 16)
return keyword_token(key); {
const auto& itr = keyword_map.find(std::string_view(buffer_.data, buffer_.length));
// TODO: call preprocessor(key); if(itr != keyword_map.end())
{
if (itr->second > parser::token::HSENDIF)
return parser::symbol_type(itr->second, loc_);
token = itr->second;
}
}
// TODO: call preprocessor(token);
throw comp_error(loc_, "unknown preprocessor directive"); throw comp_error(loc_, "unknown preprocessor directive");
state_ = state::start; state_ = state::start;
continue; continue;
} }
else else
{ {
auto key = get_keyword(std::string_view(buffer_.data, buffer_.length)); if (buffer_.length < 17)
{
const auto& itr = keyword_map.find(std::string_view(buffer_.data, buffer_.length));
if (key != keyword::KW_INVALID) if(itr != keyword_map.end())
return keyword_token(key); return parser::symbol_type(itr->second, loc_);
}
if (path) if (path)
{ {
if (buffer_.data[buffer_.length - 1] == '/') if (buffer_.data[buffer_.length - 1] == '/')
throw comp_error(loc_, "invalid path end '\\'"); throw comp_error(loc_, "invalid path end '\\'");
//return h1::parser::make_PATH(xsk::gsc::h1::resolver::make_token(std::string_view(buffer_.data, buffer_.length)), loc_); return parser::make_PATH(resolver::make_token(std::string_view(buffer_.data, buffer_.length)), loc_);
return h1::parser::make_PATH(std::string(buffer_.data, buffer_.length), loc_);
} }
//return h1::parser::make_IDENTIFIER(xsk::gsc::h1::resolver::make_token(std::string_view(buffer_.data, buffer_.length)), loc_); return parser::make_IDENTIFIER(resolver::make_token(std::string_view(buffer_.data, buffer_.length)), loc_);
return h1::parser::make_IDENTIFIER(std::string(buffer_.data, buffer_.length), loc_);
} }
lex_number: lex_number:
@ -621,9 +581,9 @@ lex_number:
throw comp_error(loc_, "invalid number literal"); throw comp_error(loc_, "invalid number literal");
if (state_ == state::field || dot || flt) if (state_ == state::field || dot || flt)
return h1::parser::make_FLOAT(std::string(buffer_.data, buffer_.length), loc_); return parser::make_FLOAT(std::string(buffer_.data, buffer_.length), loc_);
return h1::parser::make_INTEGER(std::string(buffer_.data, buffer_.length), loc_); return parser::make_INTEGER(std::string(buffer_.data, buffer_.length), loc_);
} }
else if (curr == 'o') else if (curr == 'o')
{ {
@ -655,7 +615,7 @@ lex_number:
if (last == '\'' || buffer_.length <= 0) if (last == '\'' || buffer_.length <= 0)
throw comp_error(loc_, "invalid octal literal"); throw comp_error(loc_, "invalid octal literal");
return h1::parser::make_INTEGER(xsk::utils::string::oct_to_dec(buffer_.data), loc_); return parser::make_INTEGER(xsk::utils::string::oct_to_dec(buffer_.data), loc_);
} }
else if (curr == 'b') else if (curr == 'b')
{ {
@ -689,7 +649,7 @@ lex_number:
if (last == '\'' || buffer_.length < 3) if (last == '\'' || buffer_.length < 3)
throw comp_error(loc_, "invalid binary literal"); throw comp_error(loc_, "invalid binary literal");
return h1::parser::make_INTEGER(xsk::utils::string::bin_to_dec(buffer_.data), loc_); return parser::make_INTEGER(xsk::utils::string::bin_to_dec(buffer_.data), loc_);
} }
else if (curr == 'x') else if (curr == 'x')
{ {
@ -723,176 +683,60 @@ lex_number:
if (last == '\'' || buffer_.length < 3) if (last == '\'' || buffer_.length < 3)
throw comp_error(loc_, "invalid hexadecimal literal"); throw comp_error(loc_, "invalid hexadecimal literal");
return h1::parser::make_INTEGER(xsk::utils::string::hex_to_dec(buffer_.data), loc_); return parser::make_INTEGER(xsk::utils::string::hex_to_dec(buffer_.data), loc_);
} }
// cant get here! // cant get here!
} }
} }
auto lexer::keyword_token(keyword k) -> xsk::gsc::h1::parser::symbol_type const std::unordered_map<std::string_view, parser::token::token_kind_type> lexer::keyword_map
{
switch (k)
{
case keyword::KW_pre_inline:
return h1::parser::make_INLINE(loc_);
case keyword::KW_pre_include:
return h1::parser::make_INCLUDE(loc_);
case keyword::KW_pre_using_animtree:
return h1::parser::make_USINGTREE(loc_);
case keyword::KW_pre_animtree:
return h1::parser::make_ANIMTREE(loc_);
case keyword::KW_endon:
return h1::parser::make_ENDON(loc_);
case keyword::KW_notify:
return h1::parser::make_NOTIFY(loc_);
case keyword::KW_wait:
return h1::parser::make_WAIT(loc_);
case keyword::KW_waittill:
return h1::parser::make_WAITTILL(loc_);
case keyword::KW_waittillmatch:
return h1::parser::make_WAITTILLMATCH(loc_);
case keyword::KW_waittillframeend:
return h1::parser::make_WAITTILLFRAMEEND(loc_);
case keyword::KW_waitframe:
return h1::parser::make_WAITFRAME(loc_);
case keyword::KW_if:
return h1::parser::make_IF(loc_);
case keyword::KW_else:
return h1::parser::make_ELSE(loc_);
case keyword::KW_do:
return h1::parser::make_DO(loc_);
case keyword::KW_while:
return h1::parser::make_WHILE(loc_);
case keyword::KW_for:
return h1::parser::make_FOR(loc_);
case keyword::KW_foreach:
return h1::parser::make_FOREACH(loc_);
case keyword::KW_in:
return h1::parser::make_IN(loc_);
case keyword::KW_switch:
return h1::parser::make_SWITCH(loc_);
case keyword::KW_case:
return h1::parser::make_CASE(loc_);
case keyword::KW_default:
return h1::parser::make_DEFAULT(loc_);
case keyword::KW_break:
return h1::parser::make_BREAK(loc_);
case keyword::KW_continue:
return h1::parser::make_CONTINUE(loc_);
case keyword::KW_return:
return h1::parser::make_RETURN(loc_);
case keyword::KW_breakpoint:
return h1::parser::make_BREAKPOINT(loc_);
case keyword::KW_prof_begin:
return h1::parser::make_PROFBEGIN(loc_);
case keyword::KW_prof_end:
return h1::parser::make_PROFEND(loc_);
case keyword::KW_thread:
return h1::parser::make_THREAD(loc_);
case keyword::KW_childthread:
return h1::parser::make_CHILDTHREAD(loc_);
case keyword::KW_thisthread:
return h1::parser::make_THISTHREAD(loc_);
case keyword::KW_call:
return h1::parser::make_CALL(loc_);
case keyword::KW_true:
return h1::parser::make_TRUE(loc_);
case keyword::KW_false:
return h1::parser::make_FALSE(loc_);
case keyword::KW_undefined:
return h1::parser::make_UNDEFINED(loc_);
case keyword::KW_game:
return h1::parser::make_GAME(loc_);
case keyword::KW_self:
return h1::parser::make_SELF(loc_);
case keyword::KW_anim:
return h1::parser::make_ANIM(loc_);
case keyword::KW_level:
return h1::parser::make_LEVEL(loc_);
default:
throw error("gsc lexer: INVALID KEYWORD TOKEN!");
}
}
auto lexer::keyword_is_token(keyword k) -> bool
{
switch (k)
{
/* case keyword::KW_pre_define:
case keyword::KW_pre_undef:
case keyword::KW_pre_ifdef:
case keyword::KW_pre_ifndef:
case keyword::KW_pre_if:
case keyword::KW_pre_elif:
case keyword::KW_pre_else:
case keyword::KW_pre_endif:*/
case keyword::KW_INVALID:
return false;
default:
return true;
}
}
auto lexer::get_keyword(std::string_view str) -> keyword
{
auto itr = keywords.find(str);
if(itr != keywords.end())
{
return itr->second;
}
return keyword::KW_INVALID;
}
std::unordered_map<std::string_view, keyword> lexer::keywords
{{ {{
/* { "#define", keyword::KW_pre_define }, { "#define", parser::token::HSDEFINE },
{ "#undef", keyword::KW_pre_undef }, { "#undef", parser::token::HSUNDEF },
{ "#ifdef", keyword::KW_pre_ifdef }, { "#ifdef", parser::token::HSIFDEF },
{ "#ifndef", keyword::KW_pre_ifndef }, { "#ifndef", parser::token::HSIFNDEF },
{ "#if", keyword::KW_pre_if }, { "#if", parser::token::HSIF },
{ "#elif", keyword::KW_pre_elif }, { "#elif", parser::token::HSELIF },
{ "#else", keyword::KW_pre_else }, { "#else", parser::token::HSELSE },
{ "#endif", keyword::KW_pre_endif },*/ { "#endif", parser::token::HSENDIF },
{ "#inline", keyword::KW_pre_inline }, { "#inline", parser::token::INLINE },
{ "#include", keyword::KW_pre_include }, { "#include", parser::token::INCLUDE },
{ "#using_animtree", keyword::KW_pre_using_animtree }, { "#using_animtree", parser::token::USINGTREE },
{ "#animtree", keyword::KW_pre_animtree }, { "#animtree", parser::token::ANIMTREE },
{ "endon", keyword::KW_endon }, { "endon", parser::token::ENDON },
{ "notify", keyword::KW_notify }, { "notify", parser::token::NOTIFY },
{ "wait", keyword::KW_wait }, { "wait", parser::token::WAIT },
{ "waittill", keyword::KW_waittill }, { "waittill", parser::token::WAITTILL },
{ "waittillmatch", keyword::KW_waittillmatch }, { "waittillmatch", parser::token::WAITTILLMATCH },
{ "waittillframeend", keyword::KW_waittillframeend }, { "waittillframeend", parser::token::WAITTILLFRAMEEND },
{ "waitframe", keyword::KW_waitframe }, { "waitframe", parser::token::WAITFRAME },
{ "if", keyword::KW_if }, { "if", parser::token::IF },
{ "else", keyword::KW_else }, { "else", parser::token::ELSE },
{ "do", keyword::KW_do }, { "do", parser::token::DO },
{ "while", keyword::KW_while }, { "while", parser::token::WHILE },
{ "for", keyword::KW_for }, { "for", parser::token::FOR },
{ "foreach", keyword::KW_foreach }, { "foreach", parser::token::FOREACH },
{ "in", keyword::KW_in }, { "in", parser::token::IN },
{ "switch", keyword::KW_switch }, { "switch", parser::token::SWITCH },
{ "case", keyword::KW_case }, { "case", parser::token::CASE },
{ "default", keyword::KW_default }, { "default", parser::token::DEFAULT },
{ "break", keyword::KW_break }, { "break", parser::token::BREAK },
{ "continue", keyword::KW_continue }, { "continue", parser::token::CONTINUE },
{ "return", keyword::KW_return }, { "return", parser::token::RETURN },
{ "breakpoint", keyword::KW_breakpoint }, { "breakpoint", parser::token::BREAKPOINT },
{ "prof_begin", keyword::KW_prof_begin }, { "prof_begin", parser::token::PROFBEGIN },
{ "prof_end", keyword::KW_prof_end }, { "prof_end", parser::token::PROFEND },
{ "thread", keyword::KW_thread }, { "thread", parser::token::THREAD },
{ "childthread", keyword::KW_childthread }, { "childthread", parser::token::CHILDTHREAD },
{ "thisthread", keyword::KW_thisthread }, { "thisthread", parser::token::THISTHREAD },
{ "call", keyword::KW_call }, { "call", parser::token::CALL },
{ "true", keyword::KW_true }, { "true", parser::token::TRUE },
{ "false", keyword::KW_false }, { "false", parser::token::FALSE },
{ "undefined", keyword::KW_undefined }, { "undefined", parser::token::UNDEFINED },
{ "game", keyword::KW_game }, { "game", parser::token::GAME },
{ "self", keyword::KW_self }, { "self", parser::token::SELF },
{ "anim", keyword::KW_anim }, { "anim", parser::token::ANIM },
{ "level", keyword::KW_level }, { "level", parser::token::LEVEL },
}}; }};
} // namespace xsk::gsc::h1 } // namespace xsk::gsc::h1

View File

@ -10,8 +10,6 @@
namespace xsk::gsc::h1 namespace xsk::gsc::h1
{ {
enum class keyword;
constexpr size_t max_buf_size = 0x2000; constexpr size_t max_buf_size = 0x2000;
struct buffer struct buffer
@ -53,26 +51,22 @@ class lexer
reader reader_; reader reader_;
buffer buffer_; buffer buffer_;
location loc_; location loc_;
build mode_;
std::stack<location> locs_; std::stack<location> locs_;
std::stack<reader> readers_; std::stack<reader> readers_;
std::uint32_t header_top_; std::uint32_t header_top_;
state state_; state state_;
build mode_;
bool indev_; bool indev_;
public: public:
lexer(const std::string& name, const char* data, size_t size); lexer(const std::string& name, const char* data, size_t size);
auto lex() -> xsk::gsc::h1::parser::symbol_type; auto lex() -> parser::symbol_type;
void push_header(const std::string& file); void push_header(const std::string& file);
void pop_header(); void pop_header();
void restrict_header(const xsk::gsc::location& loc); void ban_header(const location& loc);
private: private:
auto keyword_token(keyword k) -> xsk::gsc::h1::parser::symbol_type; static const std::unordered_map<std::string_view, parser::token::token_kind_type> keyword_map;
static auto keyword_is_token(keyword k) -> bool;
static auto get_keyword(std::string_view str) -> keyword;
static std::unordered_map<std::string_view, keyword> keywords;
}; };
} // namespace xsk::gsc::h1 } // namespace xsk::gsc::h1

File diff suppressed because it is too large Load Diff

View File

@ -679,109 +679,117 @@ namespace xsk { namespace gsc { namespace h1 {
H1EOF = 0, // "end of file" H1EOF = 0, // "end of file"
H1error = 1, // error H1error = 1, // error
H1UNDEF = 2, // "invalid token" H1UNDEF = 2, // "invalid token"
DEVBEGIN = 3, // "/#" HSDEFINE = 3, // "#define"
DEVEND = 4, // "#/" HSUNDEF = 4, // "#undef"
INLINE = 5, // "#inline" HSIFDEF = 5, // "#ifdef"
INCLUDE = 6, // "#include" HSIFNDEF = 6, // "#ifndef"
USINGTREE = 7, // "#using_animtree" HSIF = 7, // "#if"
ANIMTREE = 8, // "#animtree" HSELIF = 8, // "#elif"
ENDON = 9, // "endon" HSELSE = 9, // "#else"
NOTIFY = 10, // "notify" HSENDIF = 10, // "#endif"
WAIT = 11, // "wait" DEVBEGIN = 11, // "/#"
WAITTILL = 12, // "waittill" DEVEND = 12, // "#/"
WAITTILLMATCH = 13, // "waittillmatch" INLINE = 13, // "#inline"
WAITTILLFRAMEEND = 14, // "waittillframeend" INCLUDE = 14, // "#include"
WAITFRAME = 15, // "waitframe" USINGTREE = 15, // "#using_animtree"
IF = 16, // "if" ANIMTREE = 16, // "#animtree"
ELSE = 17, // "else" ENDON = 17, // "endon"
DO = 18, // "do" NOTIFY = 18, // "notify"
WHILE = 19, // "while" WAIT = 19, // "wait"
FOR = 20, // "for" WAITTILL = 20, // "waittill"
FOREACH = 21, // "foreach" WAITTILLMATCH = 21, // "waittillmatch"
IN = 22, // "in" WAITTILLFRAMEEND = 22, // "waittillframeend"
SWITCH = 23, // "switch" WAITFRAME = 23, // "waitframe"
CASE = 24, // "case" IF = 24, // "if"
DEFAULT = 25, // "default" ELSE = 25, // "else"
BREAK = 26, // "break" DO = 26, // "do"
CONTINUE = 27, // "continue" WHILE = 27, // "while"
RETURN = 28, // "return" FOR = 28, // "for"
BREAKPOINT = 29, // "breakpoint" FOREACH = 29, // "foreach"
PROFBEGIN = 30, // "prof_begin" IN = 30, // "in"
PROFEND = 31, // "prof_end" SWITCH = 31, // "switch"
THREAD = 32, // "thread" CASE = 32, // "case"
CHILDTHREAD = 33, // "childthread" DEFAULT = 33, // "default"
THISTHREAD = 34, // "thisthread" BREAK = 34, // "break"
CALL = 35, // "call" CONTINUE = 35, // "continue"
TRUE = 36, // "true" RETURN = 36, // "return"
FALSE = 37, // "false" BREAKPOINT = 37, // "breakpoint"
UNDEFINED = 38, // "undefined" PROFBEGIN = 38, // "prof_begin"
SIZE = 39, // ".size" PROFEND = 39, // "prof_end"
GAME = 40, // "game" THREAD = 40, // "thread"
SELF = 41, // "self" CHILDTHREAD = 41, // "childthread"
ANIM = 42, // "anim" THISTHREAD = 42, // "thisthread"
LEVEL = 43, // "level" CALL = 43, // "call"
LPAREN = 44, // "(" TRUE = 44, // "true"
RPAREN = 45, // ")" FALSE = 45, // "false"
LBRACE = 46, // "{" UNDEFINED = 46, // "undefined"
RBRACE = 47, // "}" SIZE = 47, // ".size"
LBRACKET = 48, // "[" GAME = 48, // "game"
RBRACKET = 49, // "]" SELF = 49, // "self"
COMMA = 50, // "," ANIM = 50, // "anim"
DOT = 51, // "." LEVEL = 51, // "level"
DOUBLECOLON = 52, // "::" LPAREN = 52, // "("
COLON = 53, // ":" RPAREN = 53, // ")"
SEMICOLON = 54, // ";" LBRACE = 54, // "{"
QMARK = 55, // "?" RBRACE = 55, // "}"
INCREMENT = 56, // "++" LBRACKET = 56, // "["
DECREMENT = 57, // "--" RBRACKET = 57, // "]"
LSHIFT = 58, // "<<" COMMA = 58, // ","
RSHIFT = 59, // ">>" DOT = 59, // "."
OR = 60, // "||" DOUBLECOLON = 60, // "::"
AND = 61, // "&&" COLON = 61, // ":"
EQUALITY = 62, // "==" SEMICOLON = 62, // ";"
INEQUALITY = 63, // "!=" QMARK = 63, // "?"
LESS_EQUAL = 64, // "<=" INCREMENT = 64, // "++"
GREATER_EQUAL = 65, // ">=" DECREMENT = 65, // "--"
LESS = 66, // "<" LSHIFT = 66, // "<<"
GREATER = 67, // ">" RSHIFT = 67, // ">>"
NOT = 68, // "!" OR = 68, // "||"
COMPLEMENT = 69, // "~" AND = 69, // "&&"
ASSIGN = 70, // "=" EQUALITY = 70, // "=="
ASSIGN_ADD = 71, // "+=" INEQUALITY = 71, // "!="
ASSIGN_SUB = 72, // "-=" LESS_EQUAL = 72, // "<="
ASSIGN_MUL = 73, // "*=" GREATER_EQUAL = 73, // ">="
ASSIGN_DIV = 74, // "/=" LESS = 74, // "<"
ASSIGN_MOD = 75, // "%=" GREATER = 75, // ">"
ASSIGN_BW_OR = 76, // "|=" NOT = 76, // "!"
ASSIGN_BW_AND = 77, // "&=" COMPLEMENT = 77, // "~"
ASSIGN_BW_EXOR = 78, // "^=" ASSIGN = 78, // "="
ASSIGN_RSHIFT = 79, // ">>=" ASSIGN_ADD = 79, // "+="
ASSIGN_LSHIFT = 80, // "<<=" ASSIGN_SUB = 80, // "-="
BITWISE_OR = 81, // "|" ASSIGN_MUL = 81, // "*="
BITWISE_AND = 82, // "&" ASSIGN_DIV = 82, // "/="
BITWISE_EXOR = 83, // "^" ASSIGN_MOD = 83, // "%="
ADD = 84, // "+" ASSIGN_BW_OR = 84, // "|="
SUB = 85, // "-" ASSIGN_BW_AND = 85, // "&="
MUL = 86, // "*" ASSIGN_BW_EXOR = 86, // "^="
DIV = 87, // "/" ASSIGN_RSHIFT = 87, // ">>="
MOD = 88, // "%" ASSIGN_LSHIFT = 88, // "<<="
FIELD = 89, // "field" BITWISE_OR = 89, // "|"
PATH = 90, // "path" BITWISE_AND = 90, // "&"
IDENTIFIER = 91, // "identifier" BITWISE_EXOR = 91, // "^"
STRING = 92, // "string literal" ADD = 92, // "+"
ISTRING = 93, // "localized string" SUB = 93, // "-"
COLOR = 94, // "color" MUL = 94, // "*"
FLOAT = 95, // "float" DIV = 95, // "/"
INTEGER = 96, // "integer" MOD = 96, // "%"
ADD_ARRAY = 97, // ADD_ARRAY FIELD = 97, // "field"
THEN = 98, // THEN PATH = 98, // "path"
TERN = 99, // TERN IDENTIFIER = 99, // "identifier"
NEG = 100, // NEG STRING = 100, // "string literal"
ANIMREF = 101, // ANIMREF ISTRING = 101, // "localized string"
PREINC = 102, // PREINC COLOR = 102, // "color"
PREDEC = 103, // PREDEC FLOAT = 103, // "float"
POSTINC = 104, // POSTINC INTEGER = 104, // "integer"
POSTDEC = 105 // POSTDEC ADD_ARRAY = 105, // ADD_ARRAY
THEN = 106, // THEN
TERN = 107, // TERN
NEG = 108, // NEG
ANIMREF = 109, // ANIMREF
PREINC = 110, // PREINC
PREDEC = 111, // PREDEC
POSTINC = 112, // POSTINC
POSTDEC = 113 // POSTDEC
}; };
/// Backward compatibility alias (Bison 3.6). /// Backward compatibility alias (Bison 3.6).
typedef token_kind_type yytokentype; typedef token_kind_type yytokentype;
@ -798,195 +806,203 @@ namespace xsk { namespace gsc { namespace h1 {
{ {
enum symbol_kind_type enum symbol_kind_type
{ {
YYNTOKENS = 106, ///< Number of tokens. YYNTOKENS = 114, ///< Number of tokens.
S_YYEMPTY = -2, S_YYEMPTY = -2,
S_YYEOF = 0, // "end of file" S_YYEOF = 0, // "end of file"
S_YYerror = 1, // error S_YYerror = 1, // error
S_YYUNDEF = 2, // "invalid token" S_YYUNDEF = 2, // "invalid token"
S_DEVBEGIN = 3, // "/#" S_HSDEFINE = 3, // "#define"
S_DEVEND = 4, // "#/" S_HSUNDEF = 4, // "#undef"
S_INLINE = 5, // "#inline" S_HSIFDEF = 5, // "#ifdef"
S_INCLUDE = 6, // "#include" S_HSIFNDEF = 6, // "#ifndef"
S_USINGTREE = 7, // "#using_animtree" S_HSIF = 7, // "#if"
S_ANIMTREE = 8, // "#animtree" S_HSELIF = 8, // "#elif"
S_ENDON = 9, // "endon" S_HSELSE = 9, // "#else"
S_NOTIFY = 10, // "notify" S_HSENDIF = 10, // "#endif"
S_WAIT = 11, // "wait" S_DEVBEGIN = 11, // "/#"
S_WAITTILL = 12, // "waittill" S_DEVEND = 12, // "#/"
S_WAITTILLMATCH = 13, // "waittillmatch" S_INLINE = 13, // "#inline"
S_WAITTILLFRAMEEND = 14, // "waittillframeend" S_INCLUDE = 14, // "#include"
S_WAITFRAME = 15, // "waitframe" S_USINGTREE = 15, // "#using_animtree"
S_IF = 16, // "if" S_ANIMTREE = 16, // "#animtree"
S_ELSE = 17, // "else" S_ENDON = 17, // "endon"
S_DO = 18, // "do" S_NOTIFY = 18, // "notify"
S_WHILE = 19, // "while" S_WAIT = 19, // "wait"
S_FOR = 20, // "for" S_WAITTILL = 20, // "waittill"
S_FOREACH = 21, // "foreach" S_WAITTILLMATCH = 21, // "waittillmatch"
S_IN = 22, // "in" S_WAITTILLFRAMEEND = 22, // "waittillframeend"
S_SWITCH = 23, // "switch" S_WAITFRAME = 23, // "waitframe"
S_CASE = 24, // "case" S_IF = 24, // "if"
S_DEFAULT = 25, // "default" S_ELSE = 25, // "else"
S_BREAK = 26, // "break" S_DO = 26, // "do"
S_CONTINUE = 27, // "continue" S_WHILE = 27, // "while"
S_RETURN = 28, // "return" S_FOR = 28, // "for"
S_BREAKPOINT = 29, // "breakpoint" S_FOREACH = 29, // "foreach"
S_PROFBEGIN = 30, // "prof_begin" S_IN = 30, // "in"
S_PROFEND = 31, // "prof_end" S_SWITCH = 31, // "switch"
S_THREAD = 32, // "thread" S_CASE = 32, // "case"
S_CHILDTHREAD = 33, // "childthread" S_DEFAULT = 33, // "default"
S_THISTHREAD = 34, // "thisthread" S_BREAK = 34, // "break"
S_CALL = 35, // "call" S_CONTINUE = 35, // "continue"
S_TRUE = 36, // "true" S_RETURN = 36, // "return"
S_FALSE = 37, // "false" S_BREAKPOINT = 37, // "breakpoint"
S_UNDEFINED = 38, // "undefined" S_PROFBEGIN = 38, // "prof_begin"
S_SIZE = 39, // ".size" S_PROFEND = 39, // "prof_end"
S_GAME = 40, // "game" S_THREAD = 40, // "thread"
S_SELF = 41, // "self" S_CHILDTHREAD = 41, // "childthread"
S_ANIM = 42, // "anim" S_THISTHREAD = 42, // "thisthread"
S_LEVEL = 43, // "level" S_CALL = 43, // "call"
S_LPAREN = 44, // "(" S_TRUE = 44, // "true"
S_RPAREN = 45, // ")" S_FALSE = 45, // "false"
S_LBRACE = 46, // "{" S_UNDEFINED = 46, // "undefined"
S_RBRACE = 47, // "}" S_SIZE = 47, // ".size"
S_LBRACKET = 48, // "[" S_GAME = 48, // "game"
S_RBRACKET = 49, // "]" S_SELF = 49, // "self"
S_COMMA = 50, // "," S_ANIM = 50, // "anim"
S_DOT = 51, // "." S_LEVEL = 51, // "level"
S_DOUBLECOLON = 52, // "::" S_LPAREN = 52, // "("
S_COLON = 53, // ":" S_RPAREN = 53, // ")"
S_SEMICOLON = 54, // ";" S_LBRACE = 54, // "{"
S_QMARK = 55, // "?" S_RBRACE = 55, // "}"
S_INCREMENT = 56, // "++" S_LBRACKET = 56, // "["
S_DECREMENT = 57, // "--" S_RBRACKET = 57, // "]"
S_LSHIFT = 58, // "<<" S_COMMA = 58, // ","
S_RSHIFT = 59, // ">>" S_DOT = 59, // "."
S_OR = 60, // "||" S_DOUBLECOLON = 60, // "::"
S_AND = 61, // "&&" S_COLON = 61, // ":"
S_EQUALITY = 62, // "==" S_SEMICOLON = 62, // ";"
S_INEQUALITY = 63, // "!=" S_QMARK = 63, // "?"
S_LESS_EQUAL = 64, // "<=" S_INCREMENT = 64, // "++"
S_GREATER_EQUAL = 65, // ">=" S_DECREMENT = 65, // "--"
S_LESS = 66, // "<" S_LSHIFT = 66, // "<<"
S_GREATER = 67, // ">" S_RSHIFT = 67, // ">>"
S_NOT = 68, // "!" S_OR = 68, // "||"
S_COMPLEMENT = 69, // "~" S_AND = 69, // "&&"
S_ASSIGN = 70, // "=" S_EQUALITY = 70, // "=="
S_ASSIGN_ADD = 71, // "+=" S_INEQUALITY = 71, // "!="
S_ASSIGN_SUB = 72, // "-=" S_LESS_EQUAL = 72, // "<="
S_ASSIGN_MUL = 73, // "*=" S_GREATER_EQUAL = 73, // ">="
S_ASSIGN_DIV = 74, // "/=" S_LESS = 74, // "<"
S_ASSIGN_MOD = 75, // "%=" S_GREATER = 75, // ">"
S_ASSIGN_BW_OR = 76, // "|=" S_NOT = 76, // "!"
S_ASSIGN_BW_AND = 77, // "&=" S_COMPLEMENT = 77, // "~"
S_ASSIGN_BW_EXOR = 78, // "^=" S_ASSIGN = 78, // "="
S_ASSIGN_RSHIFT = 79, // ">>=" S_ASSIGN_ADD = 79, // "+="
S_ASSIGN_LSHIFT = 80, // "<<=" S_ASSIGN_SUB = 80, // "-="
S_BITWISE_OR = 81, // "|" S_ASSIGN_MUL = 81, // "*="
S_BITWISE_AND = 82, // "&" S_ASSIGN_DIV = 82, // "/="
S_BITWISE_EXOR = 83, // "^" S_ASSIGN_MOD = 83, // "%="
S_ADD = 84, // "+" S_ASSIGN_BW_OR = 84, // "|="
S_SUB = 85, // "-" S_ASSIGN_BW_AND = 85, // "&="
S_MUL = 86, // "*" S_ASSIGN_BW_EXOR = 86, // "^="
S_DIV = 87, // "/" S_ASSIGN_RSHIFT = 87, // ">>="
S_MOD = 88, // "%" S_ASSIGN_LSHIFT = 88, // "<<="
S_FIELD = 89, // "field" S_BITWISE_OR = 89, // "|"
S_PATH = 90, // "path" S_BITWISE_AND = 90, // "&"
S_IDENTIFIER = 91, // "identifier" S_BITWISE_EXOR = 91, // "^"
S_STRING = 92, // "string literal" S_ADD = 92, // "+"
S_ISTRING = 93, // "localized string" S_SUB = 93, // "-"
S_COLOR = 94, // "color" S_MUL = 94, // "*"
S_FLOAT = 95, // "float" S_DIV = 95, // "/"
S_INTEGER = 96, // "integer" S_MOD = 96, // "%"
S_ADD_ARRAY = 97, // ADD_ARRAY S_FIELD = 97, // "field"
S_THEN = 98, // THEN S_PATH = 98, // "path"
S_TERN = 99, // TERN S_IDENTIFIER = 99, // "identifier"
S_NEG = 100, // NEG S_STRING = 100, // "string literal"
S_ANIMREF = 101, // ANIMREF S_ISTRING = 101, // "localized string"
S_PREINC = 102, // PREINC S_COLOR = 102, // "color"
S_PREDEC = 103, // PREDEC S_FLOAT = 103, // "float"
S_POSTINC = 104, // POSTINC S_INTEGER = 104, // "integer"
S_POSTDEC = 105, // POSTDEC S_ADD_ARRAY = 105, // ADD_ARRAY
S_YYACCEPT = 106, // $accept S_THEN = 106, // THEN
S_root = 107, // root S_TERN = 107, // TERN
S_program = 108, // program S_NEG = 108, // NEG
S_inline = 109, // inline S_ANIMREF = 109, // ANIMREF
S_include = 110, // include S_PREINC = 110, // PREINC
S_declaration = 111, // declaration S_PREDEC = 111, // PREDEC
S_decl_usingtree = 112, // decl_usingtree S_POSTINC = 112, // POSTINC
S_decl_constant = 113, // decl_constant S_POSTDEC = 113, // POSTDEC
S_decl_thread = 114, // decl_thread S_YYACCEPT = 114, // $accept
S_stmt = 115, // stmt S_root = 115, // root
S_stmt_dev = 116, // stmt_dev S_program = 116, // program
S_stmt_block = 117, // stmt_block S_inline = 117, // inline
S_stmt_list = 118, // stmt_list S_include = 118, // include
S_stmt_expr = 119, // stmt_expr S_declaration = 119, // declaration
S_stmt_call = 120, // stmt_call S_decl_usingtree = 120, // decl_usingtree
S_stmt_assign = 121, // stmt_assign S_decl_constant = 121, // decl_constant
S_stmt_endon = 122, // stmt_endon S_decl_thread = 122, // decl_thread
S_stmt_notify = 123, // stmt_notify S_stmt = 123, // stmt
S_stmt_wait = 124, // stmt_wait S_stmt_dev = 124, // stmt_dev
S_stmt_waittill = 125, // stmt_waittill S_stmt_block = 125, // stmt_block
S_stmt_waittillmatch = 126, // stmt_waittillmatch S_stmt_list = 126, // stmt_list
S_stmt_waittillframeend = 127, // stmt_waittillframeend S_stmt_expr = 127, // stmt_expr
S_stmt_waitframe = 128, // stmt_waitframe S_stmt_call = 128, // stmt_call
S_stmt_if = 129, // stmt_if S_stmt_assign = 129, // stmt_assign
S_stmt_ifelse = 130, // stmt_ifelse S_stmt_endon = 130, // stmt_endon
S_stmt_while = 131, // stmt_while S_stmt_notify = 131, // stmt_notify
S_stmt_dowhile = 132, // stmt_dowhile S_stmt_wait = 132, // stmt_wait
S_stmt_for = 133, // stmt_for S_stmt_waittill = 133, // stmt_waittill
S_stmt_foreach = 134, // stmt_foreach S_stmt_waittillmatch = 134, // stmt_waittillmatch
S_stmt_switch = 135, // stmt_switch S_stmt_waittillframeend = 135, // stmt_waittillframeend
S_stmt_case = 136, // stmt_case S_stmt_waitframe = 136, // stmt_waitframe
S_stmt_default = 137, // stmt_default S_stmt_if = 137, // stmt_if
S_stmt_break = 138, // stmt_break S_stmt_ifelse = 138, // stmt_ifelse
S_stmt_continue = 139, // stmt_continue S_stmt_while = 139, // stmt_while
S_stmt_return = 140, // stmt_return S_stmt_dowhile = 140, // stmt_dowhile
S_stmt_breakpoint = 141, // stmt_breakpoint S_stmt_for = 141, // stmt_for
S_stmt_prof_begin = 142, // stmt_prof_begin S_stmt_foreach = 142, // stmt_foreach
S_stmt_prof_end = 143, // stmt_prof_end S_stmt_switch = 143, // stmt_switch
S_expr = 144, // expr S_stmt_case = 144, // stmt_case
S_expr_or_empty = 145, // expr_or_empty S_stmt_default = 145, // stmt_default
S_expr_assign = 146, // expr_assign S_stmt_break = 146, // stmt_break
S_expr_increment = 147, // expr_increment S_stmt_continue = 147, // stmt_continue
S_expr_decrement = 148, // expr_decrement S_stmt_return = 148, // stmt_return
S_expr_ternary = 149, // expr_ternary S_stmt_breakpoint = 149, // stmt_breakpoint
S_expr_binary = 150, // expr_binary S_stmt_prof_begin = 150, // stmt_prof_begin
S_expr_primitive = 151, // expr_primitive S_stmt_prof_end = 151, // stmt_prof_end
S_expr_complement = 152, // expr_complement S_expr = 152, // expr
S_expr_not = 153, // expr_not S_expr_or_empty = 153, // expr_or_empty
S_expr_call = 154, // expr_call S_expr_assign = 154, // expr_assign
S_expr_method = 155, // expr_method S_expr_increment = 155, // expr_increment
S_expr_function = 156, // expr_function S_expr_decrement = 156, // expr_decrement
S_expr_pointer = 157, // expr_pointer S_expr_ternary = 157, // expr_ternary
S_expr_add_array = 158, // expr_add_array S_expr_binary = 158, // expr_binary
S_expr_parameters = 159, // expr_parameters S_expr_primitive = 159, // expr_primitive
S_expr_arguments = 160, // expr_arguments S_expr_complement = 160, // expr_complement
S_expr_arguments_no_empty = 161, // expr_arguments_no_empty S_expr_not = 161, // expr_not
S_expr_reference = 162, // expr_reference S_expr_call = 162, // expr_call
S_expr_array = 163, // expr_array S_expr_method = 163, // expr_method
S_expr_field = 164, // expr_field S_expr_function = 164, // expr_function
S_expr_size = 165, // expr_size S_expr_pointer = 165, // expr_pointer
S_expr_paren = 166, // expr_paren S_expr_add_array = 166, // expr_add_array
S_expr_object = 167, // expr_object S_expr_parameters = 167, // expr_parameters
S_expr_thisthread = 168, // expr_thisthread S_expr_arguments = 168, // expr_arguments
S_expr_empty_array = 169, // expr_empty_array S_expr_arguments_no_empty = 169, // expr_arguments_no_empty
S_expr_undefined = 170, // expr_undefined S_expr_reference = 170, // expr_reference
S_expr_game = 171, // expr_game S_expr_array = 171, // expr_array
S_expr_self = 172, // expr_self S_expr_field = 172, // expr_field
S_expr_anim = 173, // expr_anim S_expr_size = 173, // expr_size
S_expr_level = 174, // expr_level S_expr_paren = 174, // expr_paren
S_expr_animation = 175, // expr_animation S_expr_object = 175, // expr_object
S_expr_animtree = 176, // expr_animtree S_expr_thisthread = 176, // expr_thisthread
S_expr_identifier = 177, // expr_identifier S_expr_empty_array = 177, // expr_empty_array
S_expr_path = 178, // expr_path S_expr_undefined = 178, // expr_undefined
S_expr_istring = 179, // expr_istring S_expr_game = 179, // expr_game
S_expr_string = 180, // expr_string S_expr_self = 180, // expr_self
S_expr_color = 181, // expr_color S_expr_anim = 181, // expr_anim
S_expr_vector = 182, // expr_vector S_expr_level = 182, // expr_level
S_expr_float = 183, // expr_float S_expr_animation = 183, // expr_animation
S_expr_integer = 184, // expr_integer S_expr_animtree = 184, // expr_animtree
S_expr_false = 185, // expr_false S_expr_identifier = 185, // expr_identifier
S_expr_true = 186 // expr_true S_expr_path = 186, // expr_path
S_expr_istring = 187, // expr_istring
S_expr_string = 188, // expr_string
S_expr_color = 189, // expr_color
S_expr_vector = 190, // expr_vector
S_expr_float = 191, // expr_float
S_expr_integer = 192, // expr_integer
S_expr_false = 193, // expr_false
S_expr_true = 194 // expr_true
}; };
}; };
@ -2781,6 +2797,126 @@ switch (yykind)
return symbol_type (token::H1UNDEF, l); return symbol_type (token::H1UNDEF, l);
} }
#endif #endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_HSDEFINE (location_type l)
{
return symbol_type (token::HSDEFINE, std::move (l));
}
#else
static
symbol_type
make_HSDEFINE (const location_type& l)
{
return symbol_type (token::HSDEFINE, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_HSUNDEF (location_type l)
{
return symbol_type (token::HSUNDEF, std::move (l));
}
#else
static
symbol_type
make_HSUNDEF (const location_type& l)
{
return symbol_type (token::HSUNDEF, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_HSIFDEF (location_type l)
{
return symbol_type (token::HSIFDEF, std::move (l));
}
#else
static
symbol_type
make_HSIFDEF (const location_type& l)
{
return symbol_type (token::HSIFDEF, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_HSIFNDEF (location_type l)
{
return symbol_type (token::HSIFNDEF, std::move (l));
}
#else
static
symbol_type
make_HSIFNDEF (const location_type& l)
{
return symbol_type (token::HSIFNDEF, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_HSIF (location_type l)
{
return symbol_type (token::HSIF, std::move (l));
}
#else
static
symbol_type
make_HSIF (const location_type& l)
{
return symbol_type (token::HSIF, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_HSELIF (location_type l)
{
return symbol_type (token::HSELIF, std::move (l));
}
#else
static
symbol_type
make_HSELIF (const location_type& l)
{
return symbol_type (token::HSELIF, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_HSELSE (location_type l)
{
return symbol_type (token::HSELSE, std::move (l));
}
#else
static
symbol_type
make_HSELSE (const location_type& l)
{
return symbol_type (token::HSELSE, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_HSENDIF (location_type l)
{
return symbol_type (token::HSENDIF, std::move (l));
}
#else
static
symbol_type
make_HSENDIF (const location_type& l)
{
return symbol_type (token::HSENDIF, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS #if 201103L <= YY_CPLUSPLUS
static static
symbol_type symbol_type
@ -5364,7 +5500,7 @@ switch (yykind)
#line 13 "parser.ypp" #line 13 "parser.ypp"
} } } // xsk::gsc::h1 } } } // xsk::gsc::h1
#line 5368 "parser.hpp" #line 5504 "parser.hpp"

View File

@ -16,58 +16,6 @@ xsk::gsc::h2::parser::symbol_type H2lex(xsk::gsc::h2::lexer& lexer)
namespace xsk::gsc::h2 namespace xsk::gsc::h2
{ {
enum class keyword
{
/* KW_pre_define,
KW_pre_undef,
KW_pre_ifdef,
KW_pre_ifndef,
KW_pre_if,
KW_pre_elif,
KW_pre_else,
KW_pre_endif,*/
KW_pre_inline,
KW_pre_include,
KW_pre_using_animtree,
KW_pre_animtree,
KW_endon,
KW_notify,
KW_wait,
KW_waittill,
KW_waittillmatch,
KW_waittillframeend,
KW_waitframe,
KW_if,
KW_else,
KW_do,
KW_while,
KW_for,
KW_foreach,
KW_in,
KW_switch,
KW_case,
KW_default,
KW_break,
KW_continue,
KW_return,
KW_breakpoint,
KW_prof_begin,
KW_prof_end,
KW_thread,
KW_childthread,
KW_thisthread,
KW_call,
KW_true,
KW_false,
KW_undefined,
KW_dotsize,
KW_game,
KW_self,
KW_anim,
KW_level,
KW_INVALID,
};
buffer::buffer() : length(0) buffer::buffer() : length(0)
{ {
data = static_cast<char*>(std::malloc(max_buf_size)); data = static_cast<char*>(std::malloc(max_buf_size));
@ -130,7 +78,7 @@ void reader::advance()
} }
} }
lexer::lexer(const std::string& name, const char* data, size_t size) : indev_(false), loc_(xsk::gsc::location(&name)), lexer::lexer(const std::string& name, const char* data, size_t size) : indev_(false), loc_(location(&name)),
mode_(build::dev), header_top_(0), locs_(std::stack<location>()), readers_(std::stack<reader>()) mode_(build::dev), header_top_(0), locs_(std::stack<location>()), readers_(std::stack<reader>())
{ {
reader_.init(data, size); reader_.init(data, size);
@ -141,7 +89,7 @@ void lexer::push_header(const std::string& file)
try try
{ {
if (header_top_++ >= 10) if (header_top_++ >= 10)
throw xsk::gsc::error("maximum gsh depth exceeded '10'"); throw comp_error(loc_, "maximum gsh depth exceeded '10'");
auto data = resolver::file_data(file + ".gsh"); auto data = resolver::file_data(file + ".gsh");
@ -152,7 +100,7 @@ void lexer::push_header(const std::string& file)
} }
catch (const std::exception& e) catch (const std::exception& e)
{ {
throw xsk::gsc::error("parsing header file '" + file + "': " + e.what()); throw error("parsing header file '" + file + "': " + e.what());
} }
} }
@ -165,7 +113,7 @@ void lexer::pop_header()
readers_.pop(); readers_.pop();
} }
void lexer::restrict_header(const xsk::gsc::location& loc) void lexer::ban_header(const location& loc)
{ {
if (header_top_ > 0) if (header_top_ > 0)
{ {
@ -173,7 +121,7 @@ void lexer::restrict_header(const xsk::gsc::location& loc)
} }
} }
auto lexer::lex() -> xsk::gsc::h2::parser::symbol_type auto lexer::lex() -> parser::symbol_type
{ {
buffer_.length = 0; buffer_.length = 0;
state_ = state::start; state_ = state::start;
@ -194,7 +142,7 @@ auto lexer::lex() -> xsk::gsc::h2::parser::symbol_type
if (header_top_ > 0) if (header_top_ > 0)
pop_header(); pop_header();
else else
return h2::parser::make_H2EOF(loc_); return parser::make_H2EOF(loc_);
} }
reader_.advance(); reader_.advance();
@ -212,22 +160,22 @@ auto lexer::lex() -> xsk::gsc::h2::parser::symbol_type
continue; continue;
case '/': case '/':
if (curr != '/' && curr != '*' && curr != '#' && curr != '=') if (curr != '/' && curr != '*' && curr != '#' && curr != '=')
return h2::parser::make_DIV(loc_); return parser::make_DIV(loc_);
reader_.advance(); reader_.advance();
if (last == '=') if (last == '=')
return h2::parser::make_ASSIGN_DIV(loc_); return parser::make_ASSIGN_DIV(loc_);
if (last == '#') if (last == '#')
{ {
if (indev_) if (indev_)
throw comp_error(loc_, "cannot recurse devblock ('/#')"); throw comp_error(loc_, "cannot recurse devblock ('/#')");
if (mode_ == xsk::gsc::build::dev) if (mode_ == build::dev)
{ {
indev_ = true; indev_ = true;
return h2::parser::make_DEVBEGIN(loc_); return parser::make_DEVBEGIN(loc_);
} }
else else
{ {
@ -291,7 +239,7 @@ auto lexer::lex() -> xsk::gsc::h2::parser::symbol_type
indev_ = false; indev_ = false;
reader_.advance(); reader_.advance();
return h2::parser::make_DEVEND(loc_); return parser::make_DEVEND(loc_);
} }
buffer_.push(last); buffer_.push(last);
@ -304,12 +252,12 @@ auto lexer::lex() -> xsk::gsc::h2::parser::symbol_type
goto lex_name; goto lex_name;
case '*': case '*':
if (curr != '/' && curr != '=') if (curr != '/' && curr != '=')
return h2::parser::make_MUL(loc_); return parser::make_MUL(loc_);
reader_.advance(); reader_.advance();
if (last == '=') if (last == '=')
return h2::parser::make_ASSIGN_MUL(loc_); return parser::make_ASSIGN_MUL(loc_);
throw comp_error(loc_, "unmatched multiline comment end ('*/')"); throw comp_error(loc_, "unmatched multiline comment end ('*/')");
case '"': case '"':
@ -324,127 +272,127 @@ auto lexer::lex() -> xsk::gsc::h2::parser::symbol_type
state_ = state::field; state_ = state::field;
goto lex_name_or_number; goto lex_name_or_number;
case '(': case '(':
return h2::parser::make_LPAREN(loc_); return parser::make_LPAREN(loc_);
case ')': case ')':
return h2::parser::make_RPAREN(loc_); return parser::make_RPAREN(loc_);
case '{': case '{':
return h2::parser::make_LBRACE(loc_); return parser::make_LBRACE(loc_);
case '}': case '}':
return h2::parser::make_RBRACE(loc_); return parser::make_RBRACE(loc_);
case '[': case '[':
return h2::parser::make_LBRACKET(loc_); return parser::make_LBRACKET(loc_);
case ']': case ']':
return h2::parser::make_RBRACKET(loc_); return parser::make_RBRACKET(loc_);
case ',': case ',':
return h2::parser::make_COMMA(loc_); return parser::make_COMMA(loc_);
case ';': case ';':
return h2::parser::make_SEMICOLON(loc_); return parser::make_SEMICOLON(loc_);
case ':': case ':':
if (curr != ':') if (curr != ':')
return h2::parser::make_COLON(loc_); return parser::make_COLON(loc_);
reader_.advance(); reader_.advance();
return h2::parser::make_DOUBLECOLON(loc_); return parser::make_DOUBLECOLON(loc_);
case '?': case '?':
return h2::parser::make_QMARK(loc_); return parser::make_QMARK(loc_);
case '=': case '=':
if (curr != '=') if (curr != '=')
return h2::parser::make_ASSIGN(loc_); return parser::make_ASSIGN(loc_);
reader_.advance(); reader_.advance();
return h2::parser::make_EQUALITY(loc_); return parser::make_EQUALITY(loc_);
case '+': case '+':
if (curr != '+' && curr != '=') if (curr != '+' && curr != '=')
return h2::parser::make_ADD(loc_); return parser::make_ADD(loc_);
reader_.advance(); reader_.advance();
if (last == '+') if (last == '+')
return h2::parser::make_INCREMENT(loc_); return parser::make_INCREMENT(loc_);
return h2::parser::make_ASSIGN_ADD(loc_); return parser::make_ASSIGN_ADD(loc_);
case '-': case '-':
if (curr != '-' && curr != '=') if (curr != '-' && curr != '=')
return h2::parser::make_SUB(loc_); return parser::make_SUB(loc_);
reader_.advance(); reader_.advance();
if (last == '-') if (last == '-')
return h2::parser::make_DECREMENT(loc_); return parser::make_DECREMENT(loc_);
return h2::parser::make_ASSIGN_SUB(loc_); return parser::make_ASSIGN_SUB(loc_);
case '%': case '%':
if (curr != '=') if (curr != '=')
return h2::parser::make_MOD(loc_); return parser::make_MOD(loc_);
reader_.advance(); reader_.advance();
return h2::parser::make_ASSIGN_MOD(loc_); return parser::make_ASSIGN_MOD(loc_);
case '|': case '|':
if (curr != '|' && curr != '=') if (curr != '|' && curr != '=')
return h2::parser::make_BITWISE_OR(loc_); return parser::make_BITWISE_OR(loc_);
reader_.advance(); reader_.advance();
if (last == '|') if (last == '|')
return h2::parser::make_OR(loc_); return parser::make_OR(loc_);
return h2::parser::make_ASSIGN_BW_OR(loc_); return parser::make_ASSIGN_BW_OR(loc_);
case '&': case '&':
if (curr != '&' && curr != '=' && curr != '"' && curr != '\'') if (curr != '&' && curr != '=' && curr != '"' && curr != '\'')
return h2::parser::make_BITWISE_AND(loc_); return parser::make_BITWISE_AND(loc_);
reader_.advance(); reader_.advance();
if (last == '&') if (last == '&')
return h2::parser::make_AND(loc_); return parser::make_AND(loc_);
if (last == '=') if (last == '=')
return h2::parser::make_ASSIGN_BW_AND(loc_); return parser::make_ASSIGN_BW_AND(loc_);
state_ = state::localize; state_ = state::localize;
goto lex_string; goto lex_string;
case '^': case '^':
if (curr != '=') if (curr != '=')
return h2::parser::make_BITWISE_EXOR(loc_); return parser::make_BITWISE_EXOR(loc_);
reader_.advance(); reader_.advance();
return h2::parser::make_ASSIGN_BW_EXOR(loc_); return parser::make_ASSIGN_BW_EXOR(loc_);
case '!': case '!':
if (curr != '=') if (curr != '=')
return h2::parser::make_NOT(loc_); return parser::make_NOT(loc_);
reader_.advance(); reader_.advance();
return h2::parser::make_INEQUALITY(loc_); return parser::make_INEQUALITY(loc_);
case '~': case '~':
return h2::parser::make_COMPLEMENT(loc_); return parser::make_COMPLEMENT(loc_);
case '<': case '<':
if (curr != '<' && curr != '=') if (curr != '<' && curr != '=')
return h2::parser::make_LESS(loc_); return parser::make_LESS(loc_);
reader_.advance(); reader_.advance();
if (last == '=') if (last == '=')
return h2::parser::make_LESS_EQUAL(loc_); return parser::make_LESS_EQUAL(loc_);
if (curr != '=') if (curr != '=')
return h2::parser::make_LSHIFT(loc_); return parser::make_LSHIFT(loc_);
reader_.advance(); reader_.advance();
return h2::parser::make_ASSIGN_LSHIFT(loc_); return parser::make_ASSIGN_LSHIFT(loc_);
case '>': case '>':
if (curr != '>' && curr != '=') if (curr != '>' && curr != '=')
return h2::parser::make_GREATER(loc_); return parser::make_GREATER(loc_);
reader_.advance(); reader_.advance();
if (last == '=') if (last == '=')
return h2::parser::make_GREATER_EQUAL(loc_); return parser::make_GREATER_EQUAL(loc_);
if (curr != '=') if (curr != '=')
return h2::parser::make_RSHIFT(loc_); return parser::make_RSHIFT(loc_);
reader_.advance(); reader_.advance();
return h2::parser::make_ASSIGN_RSHIFT(loc_); return parser::make_ASSIGN_RSHIFT(loc_);
default: default:
lex_name_or_number: lex_name_or_number:
if (last >= '0' && last <= '9') if (last >= '0' && last <= '9')
@ -497,9 +445,9 @@ lex_string:
} }
if (state_ == state::localize) if (state_ == state::localize)
return h2::parser::make_ISTRING(std::string(buffer_.data, buffer_.length), loc_); return parser::make_ISTRING(std::string(buffer_.data, buffer_.length), loc_);
return h2::parser::make_STRING(std::string(buffer_.data, buffer_.length), loc_); return parser::make_STRING(std::string(buffer_.data, buffer_.length), loc_);
lex_name: lex_name:
buffer_.push(last); buffer_.push(last);
@ -534,44 +482,55 @@ lex_name:
if (std::string_view(buffer_.data, buffer_.length) == "size") if (std::string_view(buffer_.data, buffer_.length) == "size")
{ {
return h2::parser::make_SIZE(loc_); return parser::make_SIZE(loc_);
} }
return h2::parser::make_FIELD(std::string(buffer_.data, buffer_.length), loc_); return parser::make_FIELD(std::string(buffer_.data, buffer_.length), loc_);
} }
else if (state_ == state::preprocessor) else if (state_ == state::preprocessor)
{ {
if (path) if (path)
throw comp_error(loc_, "invalid preprocessor directive"); throw comp_error(loc_, "invalid preprocessor directive");
auto key = get_keyword(std::string_view(buffer_.data, buffer_.length)); auto token = parser::token::H2UNDEF;
if (key != keyword::KW_INVALID) if (buffer_.length < 16)
return keyword_token(key); {
const auto& itr = keyword_map.find(std::string_view(buffer_.data, buffer_.length));
// TODO: call preprocessor(key); if(itr != keyword_map.end())
{
if (itr->second > parser::token::HSENDIF)
return parser::symbol_type(itr->second, loc_);
token = itr->second;
}
}
// TODO: call preprocessor(token);
throw comp_error(loc_, "unknown preprocessor directive"); throw comp_error(loc_, "unknown preprocessor directive");
state_ = state::start; state_ = state::start;
continue; continue;
} }
else else
{ {
auto key = get_keyword(std::string_view(buffer_.data, buffer_.length)); if (buffer_.length < 17)
{
const auto& itr = keyword_map.find(std::string_view(buffer_.data, buffer_.length));
if (key != keyword::KW_INVALID) if(itr != keyword_map.end())
return keyword_token(key); return parser::symbol_type(itr->second, loc_);
}
if (path) if (path)
{ {
if (buffer_.data[buffer_.length - 1] == '/') if (buffer_.data[buffer_.length - 1] == '/')
throw comp_error(loc_, "invalid path end '\\'"); throw comp_error(loc_, "invalid path end '\\'");
//return h2::parser::make_PATH(xsk::gsc::h2::resolver::make_token(std::string_view(buffer_.data, buffer_.length)), loc_); return parser::make_PATH(resolver::make_token(std::string_view(buffer_.data, buffer_.length)), loc_);
return h2::parser::make_PATH(std::string(buffer_.data, buffer_.length), loc_);
} }
//return h2::parser::make_IDENTIFIER(xsk::gsc::h2::resolver::make_token(std::string_view(buffer_.data, buffer_.length)), loc_); return parser::make_IDENTIFIER(resolver::make_token(std::string_view(buffer_.data, buffer_.length)), loc_);
return h2::parser::make_IDENTIFIER(std::string(buffer_.data, buffer_.length), loc_);
} }
lex_number: lex_number:
@ -622,9 +581,9 @@ lex_number:
throw comp_error(loc_, "invalid number literal"); throw comp_error(loc_, "invalid number literal");
if (state_ == state::field || dot || flt) if (state_ == state::field || dot || flt)
return h2::parser::make_FLOAT(std::string(buffer_.data, buffer_.length), loc_); return parser::make_FLOAT(std::string(buffer_.data, buffer_.length), loc_);
return h2::parser::make_INTEGER(std::string(buffer_.data, buffer_.length), loc_); return parser::make_INTEGER(std::string(buffer_.data, buffer_.length), loc_);
} }
else if (curr == 'o') else if (curr == 'o')
{ {
@ -656,7 +615,7 @@ lex_number:
if (last == '\'' || buffer_.length <= 0) if (last == '\'' || buffer_.length <= 0)
throw comp_error(loc_, "invalid octal literal"); throw comp_error(loc_, "invalid octal literal");
return h2::parser::make_INTEGER(xsk::utils::string::oct_to_dec(buffer_.data), loc_); return parser::make_INTEGER(xsk::utils::string::oct_to_dec(buffer_.data), loc_);
} }
else if (curr == 'b') else if (curr == 'b')
{ {
@ -690,7 +649,7 @@ lex_number:
if (last == '\'' || buffer_.length < 3) if (last == '\'' || buffer_.length < 3)
throw comp_error(loc_, "invalid binary literal"); throw comp_error(loc_, "invalid binary literal");
return h2::parser::make_INTEGER(xsk::utils::string::bin_to_dec(buffer_.data), loc_); return parser::make_INTEGER(xsk::utils::string::bin_to_dec(buffer_.data), loc_);
} }
else if (curr == 'x') else if (curr == 'x')
{ {
@ -724,179 +683,60 @@ lex_number:
if (last == '\'' || buffer_.length < 3) if (last == '\'' || buffer_.length < 3)
throw comp_error(loc_, "invalid hexadecimal literal"); throw comp_error(loc_, "invalid hexadecimal literal");
return h2::parser::make_INTEGER(xsk::utils::string::hex_to_dec(buffer_.data), loc_); return parser::make_INTEGER(xsk::utils::string::hex_to_dec(buffer_.data), loc_);
} }
// cant get here! // cant get here!
} }
} }
auto lexer::keyword_token(keyword k) -> xsk::gsc::h2::parser::symbol_type const std::unordered_map<std::string_view, parser::token::token_kind_type> lexer::keyword_map
{
switch (k)
{
case keyword::KW_pre_inline:
return h2::parser::make_INLINE(loc_);
case keyword::KW_pre_include:
return h2::parser::make_INCLUDE(loc_);
case keyword::KW_pre_using_animtree:
return h2::parser::make_USINGTREE(loc_);
case keyword::KW_pre_animtree:
return h2::parser::make_ANIMTREE(loc_);
case keyword::KW_endon:
return h2::parser::make_ENDON(loc_);
case keyword::KW_notify:
return h2::parser::make_NOTIFY(loc_);
case keyword::KW_wait:
return h2::parser::make_WAIT(loc_);
case keyword::KW_waittill:
return h2::parser::make_WAITTILL(loc_);
case keyword::KW_waittillmatch:
return h2::parser::make_WAITTILLMATCH(loc_);
case keyword::KW_waittillframeend:
return h2::parser::make_WAITTILLFRAMEEND(loc_);
case keyword::KW_waitframe:
return h2::parser::make_WAITFRAME(loc_);
case keyword::KW_if:
return h2::parser::make_IF(loc_);
case keyword::KW_else:
return h2::parser::make_ELSE(loc_);
case keyword::KW_do:
return h2::parser::make_DO(loc_);
case keyword::KW_while:
return h2::parser::make_WHILE(loc_);
case keyword::KW_for:
return h2::parser::make_FOR(loc_);
case keyword::KW_foreach:
return h2::parser::make_FOREACH(loc_);
case keyword::KW_in:
return h2::parser::make_IN(loc_);
case keyword::KW_switch:
return h2::parser::make_SWITCH(loc_);
case keyword::KW_case:
return h2::parser::make_CASE(loc_);
case keyword::KW_default:
return h2::parser::make_DEFAULT(loc_);
case keyword::KW_break:
return h2::parser::make_BREAK(loc_);
case keyword::KW_continue:
return h2::parser::make_CONTINUE(loc_);
case keyword::KW_return:
return h2::parser::make_RETURN(loc_);
case keyword::KW_breakpoint:
return h2::parser::make_BREAKPOINT(loc_);
case keyword::KW_prof_begin:
return h2::parser::make_PROFBEGIN(loc_);
case keyword::KW_prof_end:
return h2::parser::make_PROFEND(loc_);
case keyword::KW_thread:
return h2::parser::make_THREAD(loc_);
case keyword::KW_childthread:
return h2::parser::make_CHILDTHREAD(loc_);
case keyword::KW_thisthread:
return h2::parser::make_THISTHREAD(loc_);
case keyword::KW_call:
return h2::parser::make_CALL(loc_);
case keyword::KW_true:
return h2::parser::make_TRUE(loc_);
case keyword::KW_false:
return h2::parser::make_FALSE(loc_);
case keyword::KW_undefined:
return h2::parser::make_UNDEFINED(loc_);
case keyword::KW_dotsize:
return h2::parser::make_SIZE(loc_);
case keyword::KW_game:
return h2::parser::make_GAME(loc_);
case keyword::KW_self:
return h2::parser::make_SELF(loc_);
case keyword::KW_anim:
return h2::parser::make_ANIM(loc_);
case keyword::KW_level:
return h2::parser::make_LEVEL(loc_);
default:
throw error("gsc lexer: INVALID KEYWORD TOKEN!");
}
}
auto lexer::keyword_is_token(keyword k) -> bool
{
switch (k)
{
/* case keyword::KW_pre_define:
case keyword::KW_pre_undef:
case keyword::KW_pre_ifdef:
case keyword::KW_pre_ifndef:
case keyword::KW_pre_if:
case keyword::KW_pre_elif:
case keyword::KW_pre_else:
case keyword::KW_pre_endif:*/
case keyword::KW_INVALID:
return false;
default:
return true;
}
}
auto lexer::get_keyword(std::string_view str) -> keyword
{
auto itr = keywords.find(str);
if(itr != keywords.end())
{
return itr->second;
}
return keyword::KW_INVALID;
}
std::unordered_map<std::string_view, keyword> lexer::keywords
{{ {{
/* { "#define", keyword::KW_pre_define }, { "#define", parser::token::HSDEFINE },
{ "#undef", keyword::KW_pre_undef }, { "#undef", parser::token::HSUNDEF },
{ "#ifdef", keyword::KW_pre_ifdef }, { "#ifdef", parser::token::HSIFDEF },
{ "#ifndef", keyword::KW_pre_ifndef }, { "#ifndef", parser::token::HSIFNDEF },
{ "#if", keyword::KW_pre_if }, { "#if", parser::token::HSIF },
{ "#elif", keyword::KW_pre_elif }, { "#elif", parser::token::HSELIF },
{ "#else", keyword::KW_pre_else }, { "#else", parser::token::HSELSE },
{ "#endif", keyword::KW_pre_endif },*/ { "#endif", parser::token::HSENDIF },
{ "#inline", keyword::KW_pre_inline }, { "#inline", parser::token::INLINE },
{ "#include", keyword::KW_pre_include }, { "#include", parser::token::INCLUDE },
{ "#using_animtree", keyword::KW_pre_using_animtree }, { "#using_animtree", parser::token::USINGTREE },
{ "#animtree", keyword::KW_pre_animtree }, { "#animtree", parser::token::ANIMTREE },
{ "endon", keyword::KW_endon }, { "endon", parser::token::ENDON },
{ "notify", keyword::KW_notify }, { "notify", parser::token::NOTIFY },
{ "wait", keyword::KW_wait }, { "wait", parser::token::WAIT },
{ "waittill", keyword::KW_waittill }, { "waittill", parser::token::WAITTILL },
{ "waittillmatch", keyword::KW_waittillmatch }, { "waittillmatch", parser::token::WAITTILLMATCH },
{ "waittillframeend", keyword::KW_waittillframeend }, { "waittillframeend", parser::token::WAITTILLFRAMEEND },
{ "waitframe", keyword::KW_waitframe }, { "waitframe", parser::token::WAITFRAME },
{ "if", keyword::KW_if }, { "if", parser::token::IF },
{ "else", keyword::KW_else }, { "else", parser::token::ELSE },
{ "do", keyword::KW_do }, { "do", parser::token::DO },
{ "while", keyword::KW_while }, { "while", parser::token::WHILE },
{ "for", keyword::KW_for }, { "for", parser::token::FOR },
{ "foreach", keyword::KW_foreach }, { "foreach", parser::token::FOREACH },
{ "in", keyword::KW_in }, { "in", parser::token::IN },
{ "switch", keyword::KW_switch }, { "switch", parser::token::SWITCH },
{ "case", keyword::KW_case }, { "case", parser::token::CASE },
{ "default", keyword::KW_default }, { "default", parser::token::DEFAULT },
{ "break", keyword::KW_break }, { "break", parser::token::BREAK },
{ "continue", keyword::KW_continue }, { "continue", parser::token::CONTINUE },
{ "return", keyword::KW_return }, { "return", parser::token::RETURN },
{ "breakpoint", keyword::KW_breakpoint }, { "breakpoint", parser::token::BREAKPOINT },
{ "prof_begin", keyword::KW_prof_begin }, { "prof_begin", parser::token::PROFBEGIN },
{ "prof_end", keyword::KW_prof_end }, { "prof_end", parser::token::PROFEND },
{ "thread", keyword::KW_thread }, { "thread", parser::token::THREAD },
{ "childthread", keyword::KW_childthread }, { "childthread", parser::token::CHILDTHREAD },
{ "thisthread", keyword::KW_thisthread }, { "thisthread", parser::token::THISTHREAD },
{ "call", keyword::KW_call }, { "call", parser::token::CALL },
{ "true", keyword::KW_true }, { "true", parser::token::TRUE },
{ "false", keyword::KW_false }, { "false", parser::token::FALSE },
{ "undefined", keyword::KW_undefined }, { "undefined", parser::token::UNDEFINED },
{ ".size", keyword::KW_dotsize }, { "game", parser::token::GAME },
{ "game", keyword::KW_game }, { "self", parser::token::SELF },
{ "self", keyword::KW_self }, { "anim", parser::token::ANIM },
{ "anim", keyword::KW_anim }, { "level", parser::token::LEVEL },
{ "level", keyword::KW_level },
}}; }};
} // namespace xsk::gsc::h2 } // namespace xsk::gsc::h2

View File

@ -8,8 +8,6 @@
namespace xsk::gsc::h2 namespace xsk::gsc::h2
{ {
enum class keyword;
constexpr size_t max_buf_size = 0x2000; constexpr size_t max_buf_size = 0x2000;
struct buffer struct buffer
@ -51,26 +49,22 @@ class lexer
reader reader_; reader reader_;
buffer buffer_; buffer buffer_;
location loc_; location loc_;
build mode_;
std::stack<location> locs_; std::stack<location> locs_;
std::stack<reader> readers_; std::stack<reader> readers_;
std::uint32_t header_top_; std::uint32_t header_top_;
state state_; state state_;
build mode_;
bool indev_; bool indev_;
public: public:
lexer(const std::string& name, const char* data, size_t size); lexer(const std::string& name, const char* data, size_t size);
auto lex() -> xsk::gsc::h2::parser::symbol_type; auto lex() -> parser::symbol_type;
void push_header(const std::string& file); void push_header(const std::string& file);
void pop_header(); void pop_header();
void restrict_header(const xsk::gsc::location& loc); void ban_header(const location& loc);
private: private:
auto keyword_token(keyword k) -> xsk::gsc::h2::parser::symbol_type; static const std::unordered_map<std::string_view, parser::token::token_kind_type> keyword_map;
static auto keyword_is_token(keyword k) -> bool;
static auto get_keyword(std::string_view str) -> keyword;
static std::unordered_map<std::string_view, keyword> keywords;
}; };
} // namespace xsk::gsc::h2 } // namespace xsk::gsc::h2

File diff suppressed because it is too large Load Diff

View File

@ -677,109 +677,117 @@ namespace xsk { namespace gsc { namespace h2 {
H2EOF = 0, // "end of file" H2EOF = 0, // "end of file"
H2error = 1, // error H2error = 1, // error
H2UNDEF = 2, // "invalid token" H2UNDEF = 2, // "invalid token"
DEVBEGIN = 3, // "/#" HSDEFINE = 3, // "#define"
DEVEND = 4, // "#/" HSUNDEF = 4, // "#undef"
INLINE = 5, // "#inline" HSIFDEF = 5, // "#ifdef"
INCLUDE = 6, // "#include" HSIFNDEF = 6, // "#ifndef"
USINGTREE = 7, // "#using_animtree" HSIF = 7, // "#if"
ANIMTREE = 8, // "#animtree" HSELIF = 8, // "#elif"
ENDON = 9, // "endon" HSELSE = 9, // "#else"
NOTIFY = 10, // "notify" HSENDIF = 10, // "#endif"
WAIT = 11, // "wait" DEVBEGIN = 11, // "/#"
WAITTILL = 12, // "waittill" DEVEND = 12, // "#/"
WAITTILLMATCH = 13, // "waittillmatch" INLINE = 13, // "#inline"
WAITTILLFRAMEEND = 14, // "waittillframeend" INCLUDE = 14, // "#include"
WAITFRAME = 15, // "waitframe" USINGTREE = 15, // "#using_animtree"
IF = 16, // "if" ANIMTREE = 16, // "#animtree"
ELSE = 17, // "else" ENDON = 17, // "endon"
DO = 18, // "do" NOTIFY = 18, // "notify"
WHILE = 19, // "while" WAIT = 19, // "wait"
FOR = 20, // "for" WAITTILL = 20, // "waittill"
FOREACH = 21, // "foreach" WAITTILLMATCH = 21, // "waittillmatch"
IN = 22, // "in" WAITTILLFRAMEEND = 22, // "waittillframeend"
SWITCH = 23, // "switch" WAITFRAME = 23, // "waitframe"
CASE = 24, // "case" IF = 24, // "if"
DEFAULT = 25, // "default" ELSE = 25, // "else"
BREAK = 26, // "break" DO = 26, // "do"
CONTINUE = 27, // "continue" WHILE = 27, // "while"
RETURN = 28, // "return" FOR = 28, // "for"
BREAKPOINT = 29, // "breakpoint" FOREACH = 29, // "foreach"
PROFBEGIN = 30, // "prof_begin" IN = 30, // "in"
PROFEND = 31, // "prof_end" SWITCH = 31, // "switch"
THREAD = 32, // "thread" CASE = 32, // "case"
CHILDTHREAD = 33, // "childthread" DEFAULT = 33, // "default"
THISTHREAD = 34, // "thisthread" BREAK = 34, // "break"
CALL = 35, // "call" CONTINUE = 35, // "continue"
TRUE = 36, // "true" RETURN = 36, // "return"
FALSE = 37, // "false" BREAKPOINT = 37, // "breakpoint"
UNDEFINED = 38, // "undefined" PROFBEGIN = 38, // "prof_begin"
SIZE = 39, // ".size" PROFEND = 39, // "prof_end"
GAME = 40, // "game" THREAD = 40, // "thread"
SELF = 41, // "self" CHILDTHREAD = 41, // "childthread"
ANIM = 42, // "anim" THISTHREAD = 42, // "thisthread"
LEVEL = 43, // "level" CALL = 43, // "call"
LPAREN = 44, // "(" TRUE = 44, // "true"
RPAREN = 45, // ")" FALSE = 45, // "false"
LBRACE = 46, // "{" UNDEFINED = 46, // "undefined"
RBRACE = 47, // "}" SIZE = 47, // ".size"
LBRACKET = 48, // "[" GAME = 48, // "game"
RBRACKET = 49, // "]" SELF = 49, // "self"
COMMA = 50, // "," ANIM = 50, // "anim"
DOT = 51, // "." LEVEL = 51, // "level"
DOUBLECOLON = 52, // "::" LPAREN = 52, // "("
COLON = 53, // ":" RPAREN = 53, // ")"
SEMICOLON = 54, // ";" LBRACE = 54, // "{"
QMARK = 55, // "?" RBRACE = 55, // "}"
INCREMENT = 56, // "++" LBRACKET = 56, // "["
DECREMENT = 57, // "--" RBRACKET = 57, // "]"
LSHIFT = 58, // "<<" COMMA = 58, // ","
RSHIFT = 59, // ">>" DOT = 59, // "."
OR = 60, // "||" DOUBLECOLON = 60, // "::"
AND = 61, // "&&" COLON = 61, // ":"
EQUALITY = 62, // "==" SEMICOLON = 62, // ";"
INEQUALITY = 63, // "!=" QMARK = 63, // "?"
LESS_EQUAL = 64, // "<=" INCREMENT = 64, // "++"
GREATER_EQUAL = 65, // ">=" DECREMENT = 65, // "--"
LESS = 66, // "<" LSHIFT = 66, // "<<"
GREATER = 67, // ">" RSHIFT = 67, // ">>"
NOT = 68, // "!" OR = 68, // "||"
COMPLEMENT = 69, // "~" AND = 69, // "&&"
ASSIGN = 70, // "=" EQUALITY = 70, // "=="
ASSIGN_ADD = 71, // "+=" INEQUALITY = 71, // "!="
ASSIGN_SUB = 72, // "-=" LESS_EQUAL = 72, // "<="
ASSIGN_MUL = 73, // "*=" GREATER_EQUAL = 73, // ">="
ASSIGN_DIV = 74, // "/=" LESS = 74, // "<"
ASSIGN_MOD = 75, // "%=" GREATER = 75, // ">"
ASSIGN_BW_OR = 76, // "|=" NOT = 76, // "!"
ASSIGN_BW_AND = 77, // "&=" COMPLEMENT = 77, // "~"
ASSIGN_BW_EXOR = 78, // "^=" ASSIGN = 78, // "="
ASSIGN_RSHIFT = 79, // ">>=" ASSIGN_ADD = 79, // "+="
ASSIGN_LSHIFT = 80, // "<<=" ASSIGN_SUB = 80, // "-="
BITWISE_OR = 81, // "|" ASSIGN_MUL = 81, // "*="
BITWISE_AND = 82, // "&" ASSIGN_DIV = 82, // "/="
BITWISE_EXOR = 83, // "^" ASSIGN_MOD = 83, // "%="
ADD = 84, // "+" ASSIGN_BW_OR = 84, // "|="
SUB = 85, // "-" ASSIGN_BW_AND = 85, // "&="
MUL = 86, // "*" ASSIGN_BW_EXOR = 86, // "^="
DIV = 87, // "/" ASSIGN_RSHIFT = 87, // ">>="
MOD = 88, // "%" ASSIGN_LSHIFT = 88, // "<<="
FIELD = 89, // "field" BITWISE_OR = 89, // "|"
PATH = 90, // "path" BITWISE_AND = 90, // "&"
IDENTIFIER = 91, // "identifier" BITWISE_EXOR = 91, // "^"
STRING = 92, // "string literal" ADD = 92, // "+"
ISTRING = 93, // "localized string" SUB = 93, // "-"
COLOR = 94, // "color" MUL = 94, // "*"
FLOAT = 95, // "float" DIV = 95, // "/"
INTEGER = 96, // "integer" MOD = 96, // "%"
ADD_ARRAY = 97, // ADD_ARRAY FIELD = 97, // "field"
THEN = 98, // THEN PATH = 98, // "path"
TERN = 99, // TERN IDENTIFIER = 99, // "identifier"
NEG = 100, // NEG STRING = 100, // "string literal"
ANIMREF = 101, // ANIMREF ISTRING = 101, // "localized string"
PREINC = 102, // PREINC COLOR = 102, // "color"
PREDEC = 103, // PREDEC FLOAT = 103, // "float"
POSTINC = 104, // POSTINC INTEGER = 104, // "integer"
POSTDEC = 105 // POSTDEC ADD_ARRAY = 105, // ADD_ARRAY
THEN = 106, // THEN
TERN = 107, // TERN
NEG = 108, // NEG
ANIMREF = 109, // ANIMREF
PREINC = 110, // PREINC
PREDEC = 111, // PREDEC
POSTINC = 112, // POSTINC
POSTDEC = 113 // POSTDEC
}; };
/// Backward compatibility alias (Bison 3.6). /// Backward compatibility alias (Bison 3.6).
typedef token_kind_type yytokentype; typedef token_kind_type yytokentype;
@ -796,195 +804,203 @@ namespace xsk { namespace gsc { namespace h2 {
{ {
enum symbol_kind_type enum symbol_kind_type
{ {
YYNTOKENS = 106, ///< Number of tokens. YYNTOKENS = 114, ///< Number of tokens.
S_YYEMPTY = -2, S_YYEMPTY = -2,
S_YYEOF = 0, // "end of file" S_YYEOF = 0, // "end of file"
S_YYerror = 1, // error S_YYerror = 1, // error
S_YYUNDEF = 2, // "invalid token" S_YYUNDEF = 2, // "invalid token"
S_DEVBEGIN = 3, // "/#" S_HSDEFINE = 3, // "#define"
S_DEVEND = 4, // "#/" S_HSUNDEF = 4, // "#undef"
S_INLINE = 5, // "#inline" S_HSIFDEF = 5, // "#ifdef"
S_INCLUDE = 6, // "#include" S_HSIFNDEF = 6, // "#ifndef"
S_USINGTREE = 7, // "#using_animtree" S_HSIF = 7, // "#if"
S_ANIMTREE = 8, // "#animtree" S_HSELIF = 8, // "#elif"
S_ENDON = 9, // "endon" S_HSELSE = 9, // "#else"
S_NOTIFY = 10, // "notify" S_HSENDIF = 10, // "#endif"
S_WAIT = 11, // "wait" S_DEVBEGIN = 11, // "/#"
S_WAITTILL = 12, // "waittill" S_DEVEND = 12, // "#/"
S_WAITTILLMATCH = 13, // "waittillmatch" S_INLINE = 13, // "#inline"
S_WAITTILLFRAMEEND = 14, // "waittillframeend" S_INCLUDE = 14, // "#include"
S_WAITFRAME = 15, // "waitframe" S_USINGTREE = 15, // "#using_animtree"
S_IF = 16, // "if" S_ANIMTREE = 16, // "#animtree"
S_ELSE = 17, // "else" S_ENDON = 17, // "endon"
S_DO = 18, // "do" S_NOTIFY = 18, // "notify"
S_WHILE = 19, // "while" S_WAIT = 19, // "wait"
S_FOR = 20, // "for" S_WAITTILL = 20, // "waittill"
S_FOREACH = 21, // "foreach" S_WAITTILLMATCH = 21, // "waittillmatch"
S_IN = 22, // "in" S_WAITTILLFRAMEEND = 22, // "waittillframeend"
S_SWITCH = 23, // "switch" S_WAITFRAME = 23, // "waitframe"
S_CASE = 24, // "case" S_IF = 24, // "if"
S_DEFAULT = 25, // "default" S_ELSE = 25, // "else"
S_BREAK = 26, // "break" S_DO = 26, // "do"
S_CONTINUE = 27, // "continue" S_WHILE = 27, // "while"
S_RETURN = 28, // "return" S_FOR = 28, // "for"
S_BREAKPOINT = 29, // "breakpoint" S_FOREACH = 29, // "foreach"
S_PROFBEGIN = 30, // "prof_begin" S_IN = 30, // "in"
S_PROFEND = 31, // "prof_end" S_SWITCH = 31, // "switch"
S_THREAD = 32, // "thread" S_CASE = 32, // "case"
S_CHILDTHREAD = 33, // "childthread" S_DEFAULT = 33, // "default"
S_THISTHREAD = 34, // "thisthread" S_BREAK = 34, // "break"
S_CALL = 35, // "call" S_CONTINUE = 35, // "continue"
S_TRUE = 36, // "true" S_RETURN = 36, // "return"
S_FALSE = 37, // "false" S_BREAKPOINT = 37, // "breakpoint"
S_UNDEFINED = 38, // "undefined" S_PROFBEGIN = 38, // "prof_begin"
S_SIZE = 39, // ".size" S_PROFEND = 39, // "prof_end"
S_GAME = 40, // "game" S_THREAD = 40, // "thread"
S_SELF = 41, // "self" S_CHILDTHREAD = 41, // "childthread"
S_ANIM = 42, // "anim" S_THISTHREAD = 42, // "thisthread"
S_LEVEL = 43, // "level" S_CALL = 43, // "call"
S_LPAREN = 44, // "(" S_TRUE = 44, // "true"
S_RPAREN = 45, // ")" S_FALSE = 45, // "false"
S_LBRACE = 46, // "{" S_UNDEFINED = 46, // "undefined"
S_RBRACE = 47, // "}" S_SIZE = 47, // ".size"
S_LBRACKET = 48, // "[" S_GAME = 48, // "game"
S_RBRACKET = 49, // "]" S_SELF = 49, // "self"
S_COMMA = 50, // "," S_ANIM = 50, // "anim"
S_DOT = 51, // "." S_LEVEL = 51, // "level"
S_DOUBLECOLON = 52, // "::" S_LPAREN = 52, // "("
S_COLON = 53, // ":" S_RPAREN = 53, // ")"
S_SEMICOLON = 54, // ";" S_LBRACE = 54, // "{"
S_QMARK = 55, // "?" S_RBRACE = 55, // "}"
S_INCREMENT = 56, // "++" S_LBRACKET = 56, // "["
S_DECREMENT = 57, // "--" S_RBRACKET = 57, // "]"
S_LSHIFT = 58, // "<<" S_COMMA = 58, // ","
S_RSHIFT = 59, // ">>" S_DOT = 59, // "."
S_OR = 60, // "||" S_DOUBLECOLON = 60, // "::"
S_AND = 61, // "&&" S_COLON = 61, // ":"
S_EQUALITY = 62, // "==" S_SEMICOLON = 62, // ";"
S_INEQUALITY = 63, // "!=" S_QMARK = 63, // "?"
S_LESS_EQUAL = 64, // "<=" S_INCREMENT = 64, // "++"
S_GREATER_EQUAL = 65, // ">=" S_DECREMENT = 65, // "--"
S_LESS = 66, // "<" S_LSHIFT = 66, // "<<"
S_GREATER = 67, // ">" S_RSHIFT = 67, // ">>"
S_NOT = 68, // "!" S_OR = 68, // "||"
S_COMPLEMENT = 69, // "~" S_AND = 69, // "&&"
S_ASSIGN = 70, // "=" S_EQUALITY = 70, // "=="
S_ASSIGN_ADD = 71, // "+=" S_INEQUALITY = 71, // "!="
S_ASSIGN_SUB = 72, // "-=" S_LESS_EQUAL = 72, // "<="
S_ASSIGN_MUL = 73, // "*=" S_GREATER_EQUAL = 73, // ">="
S_ASSIGN_DIV = 74, // "/=" S_LESS = 74, // "<"
S_ASSIGN_MOD = 75, // "%=" S_GREATER = 75, // ">"
S_ASSIGN_BW_OR = 76, // "|=" S_NOT = 76, // "!"
S_ASSIGN_BW_AND = 77, // "&=" S_COMPLEMENT = 77, // "~"
S_ASSIGN_BW_EXOR = 78, // "^=" S_ASSIGN = 78, // "="
S_ASSIGN_RSHIFT = 79, // ">>=" S_ASSIGN_ADD = 79, // "+="
S_ASSIGN_LSHIFT = 80, // "<<=" S_ASSIGN_SUB = 80, // "-="
S_BITWISE_OR = 81, // "|" S_ASSIGN_MUL = 81, // "*="
S_BITWISE_AND = 82, // "&" S_ASSIGN_DIV = 82, // "/="
S_BITWISE_EXOR = 83, // "^" S_ASSIGN_MOD = 83, // "%="
S_ADD = 84, // "+" S_ASSIGN_BW_OR = 84, // "|="
S_SUB = 85, // "-" S_ASSIGN_BW_AND = 85, // "&="
S_MUL = 86, // "*" S_ASSIGN_BW_EXOR = 86, // "^="
S_DIV = 87, // "/" S_ASSIGN_RSHIFT = 87, // ">>="
S_MOD = 88, // "%" S_ASSIGN_LSHIFT = 88, // "<<="
S_FIELD = 89, // "field" S_BITWISE_OR = 89, // "|"
S_PATH = 90, // "path" S_BITWISE_AND = 90, // "&"
S_IDENTIFIER = 91, // "identifier" S_BITWISE_EXOR = 91, // "^"
S_STRING = 92, // "string literal" S_ADD = 92, // "+"
S_ISTRING = 93, // "localized string" S_SUB = 93, // "-"
S_COLOR = 94, // "color" S_MUL = 94, // "*"
S_FLOAT = 95, // "float" S_DIV = 95, // "/"
S_INTEGER = 96, // "integer" S_MOD = 96, // "%"
S_ADD_ARRAY = 97, // ADD_ARRAY S_FIELD = 97, // "field"
S_THEN = 98, // THEN S_PATH = 98, // "path"
S_TERN = 99, // TERN S_IDENTIFIER = 99, // "identifier"
S_NEG = 100, // NEG S_STRING = 100, // "string literal"
S_ANIMREF = 101, // ANIMREF S_ISTRING = 101, // "localized string"
S_PREINC = 102, // PREINC S_COLOR = 102, // "color"
S_PREDEC = 103, // PREDEC S_FLOAT = 103, // "float"
S_POSTINC = 104, // POSTINC S_INTEGER = 104, // "integer"
S_POSTDEC = 105, // POSTDEC S_ADD_ARRAY = 105, // ADD_ARRAY
S_YYACCEPT = 106, // $accept S_THEN = 106, // THEN
S_root = 107, // root S_TERN = 107, // TERN
S_program = 108, // program S_NEG = 108, // NEG
S_inline = 109, // inline S_ANIMREF = 109, // ANIMREF
S_include = 110, // include S_PREINC = 110, // PREINC
S_declaration = 111, // declaration S_PREDEC = 111, // PREDEC
S_decl_usingtree = 112, // decl_usingtree S_POSTINC = 112, // POSTINC
S_decl_constant = 113, // decl_constant S_POSTDEC = 113, // POSTDEC
S_decl_thread = 114, // decl_thread S_YYACCEPT = 114, // $accept
S_stmt = 115, // stmt S_root = 115, // root
S_stmt_dev = 116, // stmt_dev S_program = 116, // program
S_stmt_block = 117, // stmt_block S_inline = 117, // inline
S_stmt_list = 118, // stmt_list S_include = 118, // include
S_stmt_expr = 119, // stmt_expr S_declaration = 119, // declaration
S_stmt_call = 120, // stmt_call S_decl_usingtree = 120, // decl_usingtree
S_stmt_assign = 121, // stmt_assign S_decl_constant = 121, // decl_constant
S_stmt_endon = 122, // stmt_endon S_decl_thread = 122, // decl_thread
S_stmt_notify = 123, // stmt_notify S_stmt = 123, // stmt
S_stmt_wait = 124, // stmt_wait S_stmt_dev = 124, // stmt_dev
S_stmt_waittill = 125, // stmt_waittill S_stmt_block = 125, // stmt_block
S_stmt_waittillmatch = 126, // stmt_waittillmatch S_stmt_list = 126, // stmt_list
S_stmt_waittillframeend = 127, // stmt_waittillframeend S_stmt_expr = 127, // stmt_expr
S_stmt_waitframe = 128, // stmt_waitframe S_stmt_call = 128, // stmt_call
S_stmt_if = 129, // stmt_if S_stmt_assign = 129, // stmt_assign
S_stmt_ifelse = 130, // stmt_ifelse S_stmt_endon = 130, // stmt_endon
S_stmt_while = 131, // stmt_while S_stmt_notify = 131, // stmt_notify
S_stmt_dowhile = 132, // stmt_dowhile S_stmt_wait = 132, // stmt_wait
S_stmt_for = 133, // stmt_for S_stmt_waittill = 133, // stmt_waittill
S_stmt_foreach = 134, // stmt_foreach S_stmt_waittillmatch = 134, // stmt_waittillmatch
S_stmt_switch = 135, // stmt_switch S_stmt_waittillframeend = 135, // stmt_waittillframeend
S_stmt_case = 136, // stmt_case S_stmt_waitframe = 136, // stmt_waitframe
S_stmt_default = 137, // stmt_default S_stmt_if = 137, // stmt_if
S_stmt_break = 138, // stmt_break S_stmt_ifelse = 138, // stmt_ifelse
S_stmt_continue = 139, // stmt_continue S_stmt_while = 139, // stmt_while
S_stmt_return = 140, // stmt_return S_stmt_dowhile = 140, // stmt_dowhile
S_stmt_breakpoint = 141, // stmt_breakpoint S_stmt_for = 141, // stmt_for
S_stmt_prof_begin = 142, // stmt_prof_begin S_stmt_foreach = 142, // stmt_foreach
S_stmt_prof_end = 143, // stmt_prof_end S_stmt_switch = 143, // stmt_switch
S_expr = 144, // expr S_stmt_case = 144, // stmt_case
S_expr_or_empty = 145, // expr_or_empty S_stmt_default = 145, // stmt_default
S_expr_assign = 146, // expr_assign S_stmt_break = 146, // stmt_break
S_expr_increment = 147, // expr_increment S_stmt_continue = 147, // stmt_continue
S_expr_decrement = 148, // expr_decrement S_stmt_return = 148, // stmt_return
S_expr_ternary = 149, // expr_ternary S_stmt_breakpoint = 149, // stmt_breakpoint
S_expr_binary = 150, // expr_binary S_stmt_prof_begin = 150, // stmt_prof_begin
S_expr_primitive = 151, // expr_primitive S_stmt_prof_end = 151, // stmt_prof_end
S_expr_complement = 152, // expr_complement S_expr = 152, // expr
S_expr_not = 153, // expr_not S_expr_or_empty = 153, // expr_or_empty
S_expr_call = 154, // expr_call S_expr_assign = 154, // expr_assign
S_expr_method = 155, // expr_method S_expr_increment = 155, // expr_increment
S_expr_function = 156, // expr_function S_expr_decrement = 156, // expr_decrement
S_expr_pointer = 157, // expr_pointer S_expr_ternary = 157, // expr_ternary
S_expr_add_array = 158, // expr_add_array S_expr_binary = 158, // expr_binary
S_expr_parameters = 159, // expr_parameters S_expr_primitive = 159, // expr_primitive
S_expr_arguments = 160, // expr_arguments S_expr_complement = 160, // expr_complement
S_expr_arguments_no_empty = 161, // expr_arguments_no_empty S_expr_not = 161, // expr_not
S_expr_reference = 162, // expr_reference S_expr_call = 162, // expr_call
S_expr_array = 163, // expr_array S_expr_method = 163, // expr_method
S_expr_field = 164, // expr_field S_expr_function = 164, // expr_function
S_expr_size = 165, // expr_size S_expr_pointer = 165, // expr_pointer
S_expr_paren = 166, // expr_paren S_expr_add_array = 166, // expr_add_array
S_expr_object = 167, // expr_object S_expr_parameters = 167, // expr_parameters
S_expr_thisthread = 168, // expr_thisthread S_expr_arguments = 168, // expr_arguments
S_expr_empty_array = 169, // expr_empty_array S_expr_arguments_no_empty = 169, // expr_arguments_no_empty
S_expr_undefined = 170, // expr_undefined S_expr_reference = 170, // expr_reference
S_expr_game = 171, // expr_game S_expr_array = 171, // expr_array
S_expr_self = 172, // expr_self S_expr_field = 172, // expr_field
S_expr_anim = 173, // expr_anim S_expr_size = 173, // expr_size
S_expr_level = 174, // expr_level S_expr_paren = 174, // expr_paren
S_expr_animation = 175, // expr_animation S_expr_object = 175, // expr_object
S_expr_animtree = 176, // expr_animtree S_expr_thisthread = 176, // expr_thisthread
S_expr_identifier = 177, // expr_identifier S_expr_empty_array = 177, // expr_empty_array
S_expr_path = 178, // expr_path S_expr_undefined = 178, // expr_undefined
S_expr_istring = 179, // expr_istring S_expr_game = 179, // expr_game
S_expr_string = 180, // expr_string S_expr_self = 180, // expr_self
S_expr_color = 181, // expr_color S_expr_anim = 181, // expr_anim
S_expr_vector = 182, // expr_vector S_expr_level = 182, // expr_level
S_expr_float = 183, // expr_float S_expr_animation = 183, // expr_animation
S_expr_integer = 184, // expr_integer S_expr_animtree = 184, // expr_animtree
S_expr_false = 185, // expr_false S_expr_identifier = 185, // expr_identifier
S_expr_true = 186 // expr_true S_expr_path = 186, // expr_path
S_expr_istring = 187, // expr_istring
S_expr_string = 188, // expr_string
S_expr_color = 189, // expr_color
S_expr_vector = 190, // expr_vector
S_expr_float = 191, // expr_float
S_expr_integer = 192, // expr_integer
S_expr_false = 193, // expr_false
S_expr_true = 194 // expr_true
}; };
}; };
@ -2779,6 +2795,126 @@ switch (yykind)
return symbol_type (token::H2UNDEF, l); return symbol_type (token::H2UNDEF, l);
} }
#endif #endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_HSDEFINE (location_type l)
{
return symbol_type (token::HSDEFINE, std::move (l));
}
#else
static
symbol_type
make_HSDEFINE (const location_type& l)
{
return symbol_type (token::HSDEFINE, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_HSUNDEF (location_type l)
{
return symbol_type (token::HSUNDEF, std::move (l));
}
#else
static
symbol_type
make_HSUNDEF (const location_type& l)
{
return symbol_type (token::HSUNDEF, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_HSIFDEF (location_type l)
{
return symbol_type (token::HSIFDEF, std::move (l));
}
#else
static
symbol_type
make_HSIFDEF (const location_type& l)
{
return symbol_type (token::HSIFDEF, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_HSIFNDEF (location_type l)
{
return symbol_type (token::HSIFNDEF, std::move (l));
}
#else
static
symbol_type
make_HSIFNDEF (const location_type& l)
{
return symbol_type (token::HSIFNDEF, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_HSIF (location_type l)
{
return symbol_type (token::HSIF, std::move (l));
}
#else
static
symbol_type
make_HSIF (const location_type& l)
{
return symbol_type (token::HSIF, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_HSELIF (location_type l)
{
return symbol_type (token::HSELIF, std::move (l));
}
#else
static
symbol_type
make_HSELIF (const location_type& l)
{
return symbol_type (token::HSELIF, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_HSELSE (location_type l)
{
return symbol_type (token::HSELSE, std::move (l));
}
#else
static
symbol_type
make_HSELSE (const location_type& l)
{
return symbol_type (token::HSELSE, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_HSENDIF (location_type l)
{
return symbol_type (token::HSENDIF, std::move (l));
}
#else
static
symbol_type
make_HSENDIF (const location_type& l)
{
return symbol_type (token::HSENDIF, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS #if 201103L <= YY_CPLUSPLUS
static static
symbol_type symbol_type
@ -5362,7 +5498,7 @@ switch (yykind)
#line 13 "parser.ypp" #line 13 "parser.ypp"
} } } // xsk::gsc::h2 } } } // xsk::gsc::h2
#line 5366 "parser.hpp" #line 5502 "parser.hpp"

View File

@ -16,57 +16,6 @@ xsk::gsc::iw5::parser::symbol_type IW5lex(xsk::gsc::iw5::lexer& lexer)
namespace xsk::gsc::iw5 namespace xsk::gsc::iw5
{ {
enum class keyword
{
/* KW_pre_define,
KW_pre_undef,
KW_pre_ifdef,
KW_pre_ifndef,
KW_pre_if,
KW_pre_elif,
KW_pre_else,
KW_pre_endif,*/
KW_pre_inline,
KW_pre_include,
KW_pre_using_animtree,
KW_pre_animtree,
KW_endon,
KW_notify,
KW_wait,
KW_waittill,
KW_waittillmatch,
KW_waittillframeend,
KW_if,
KW_else,
KW_do,
KW_while,
KW_for,
KW_foreach,
KW_in,
KW_switch,
KW_case,
KW_default,
KW_break,
KW_continue,
KW_return,
KW_breakpoint,
KW_prof_begin,
KW_prof_end,
KW_thread,
KW_childthread,
KW_thisthread,
KW_call,
KW_true,
KW_false,
KW_undefined,
KW_dotsize,
KW_game,
KW_self,
KW_anim,
KW_level,
KW_INVALID,
};
buffer::buffer() : length(0) buffer::buffer() : length(0)
{ {
data = static_cast<char*>(std::malloc(max_buf_size)); data = static_cast<char*>(std::malloc(max_buf_size));
@ -129,7 +78,7 @@ void reader::advance()
} }
} }
lexer::lexer(const std::string& name, const char* data, size_t size) : indev_(false), loc_(xsk::gsc::location(&name)), lexer::lexer(const std::string& name, const char* data, size_t size) : indev_(false), loc_(location(&name)),
mode_(build::dev), header_top_(0), locs_(std::stack<location>()), readers_(std::stack<reader>()) mode_(build::dev), header_top_(0), locs_(std::stack<location>()), readers_(std::stack<reader>())
{ {
reader_.init(data, size); reader_.init(data, size);
@ -140,7 +89,7 @@ void lexer::push_header(const std::string& file)
try try
{ {
if (header_top_++ >= 10) if (header_top_++ >= 10)
throw xsk::gsc::error("maximum gsh depth exceeded '10'"); throw comp_error(loc_, "maximum gsh depth exceeded '10'");
auto data = resolver::file_data(file + ".gsh"); auto data = resolver::file_data(file + ".gsh");
@ -151,7 +100,7 @@ void lexer::push_header(const std::string& file)
} }
catch (const std::exception& e) catch (const std::exception& e)
{ {
throw xsk::gsc::error("parsing header file '" + file + "': " + e.what()); throw error("parsing header file '" + file + "': " + e.what());
} }
} }
@ -164,7 +113,7 @@ void lexer::pop_header()
readers_.pop(); readers_.pop();
} }
void lexer::restrict_header(const xsk::gsc::location& loc) void lexer::ban_header(const location& loc)
{ {
if (header_top_ > 0) if (header_top_ > 0)
{ {
@ -172,7 +121,7 @@ void lexer::restrict_header(const xsk::gsc::location& loc)
} }
} }
auto lexer::lex() -> xsk::gsc::iw5::parser::symbol_type auto lexer::lex() -> parser::symbol_type
{ {
buffer_.length = 0; buffer_.length = 0;
state_ = state::start; state_ = state::start;
@ -193,7 +142,7 @@ auto lexer::lex() -> xsk::gsc::iw5::parser::symbol_type
if (header_top_ > 0) if (header_top_ > 0)
pop_header(); pop_header();
else else
return iw5::parser::make_IW5EOF(loc_); return parser::make_IW5EOF(loc_);
} }
reader_.advance(); reader_.advance();
@ -211,22 +160,22 @@ auto lexer::lex() -> xsk::gsc::iw5::parser::symbol_type
continue; continue;
case '/': case '/':
if (curr != '/' && curr != '*' && curr != '#' && curr != '=') if (curr != '/' && curr != '*' && curr != '#' && curr != '=')
return iw5::parser::make_DIV(loc_); return parser::make_DIV(loc_);
reader_.advance(); reader_.advance();
if (last == '=') if (last == '=')
return iw5::parser::make_ASSIGN_DIV(loc_); return parser::make_ASSIGN_DIV(loc_);
if (last == '#') if (last == '#')
{ {
if (indev_) if (indev_)
throw comp_error(loc_, "cannot recurse devblock ('/#')"); throw comp_error(loc_, "cannot recurse devblock ('/#')");
if (mode_ == xsk::gsc::build::dev) if (mode_ == build::dev)
{ {
indev_ = true; indev_ = true;
return iw5::parser::make_DEVBEGIN(loc_); return parser::make_DEVBEGIN(loc_);
} }
else else
{ {
@ -290,7 +239,7 @@ auto lexer::lex() -> xsk::gsc::iw5::parser::symbol_type
indev_ = false; indev_ = false;
reader_.advance(); reader_.advance();
return iw5::parser::make_DEVEND(loc_); return parser::make_DEVEND(loc_);
} }
buffer_.push(last); buffer_.push(last);
@ -303,12 +252,12 @@ auto lexer::lex() -> xsk::gsc::iw5::parser::symbol_type
goto lex_name; goto lex_name;
case '*': case '*':
if (curr != '/' && curr != '=') if (curr != '/' && curr != '=')
return iw5::parser::make_MUL(loc_); return parser::make_MUL(loc_);
reader_.advance(); reader_.advance();
if (last == '=') if (last == '=')
return iw5::parser::make_ASSIGN_MUL(loc_); return parser::make_ASSIGN_MUL(loc_);
throw comp_error(loc_, "unmatched multiline comment end ('*/')"); throw comp_error(loc_, "unmatched multiline comment end ('*/')");
case '"': case '"':
@ -323,127 +272,127 @@ auto lexer::lex() -> xsk::gsc::iw5::parser::symbol_type
state_ = state::field; state_ = state::field;
goto lex_name_or_number; goto lex_name_or_number;
case '(': case '(':
return iw5::parser::make_LPAREN(loc_); return parser::make_LPAREN(loc_);
case ')': case ')':
return iw5::parser::make_RPAREN(loc_); return parser::make_RPAREN(loc_);
case '{': case '{':
return iw5::parser::make_LBRACE(loc_); return parser::make_LBRACE(loc_);
case '}': case '}':
return iw5::parser::make_RBRACE(loc_); return parser::make_RBRACE(loc_);
case '[': case '[':
return iw5::parser::make_LBRACKET(loc_); return parser::make_LBRACKET(loc_);
case ']': case ']':
return iw5::parser::make_RBRACKET(loc_); return parser::make_RBRACKET(loc_);
case ',': case ',':
return iw5::parser::make_COMMA(loc_); return parser::make_COMMA(loc_);
case ';': case ';':
return iw5::parser::make_SEMICOLON(loc_); return parser::make_SEMICOLON(loc_);
case ':': case ':':
if (curr != ':') if (curr != ':')
return iw5::parser::make_COLON(loc_); return parser::make_COLON(loc_);
reader_.advance(); reader_.advance();
return iw5::parser::make_DOUBLECOLON(loc_); return parser::make_DOUBLECOLON(loc_);
case '?': case '?':
return iw5::parser::make_QMARK(loc_); return parser::make_QMARK(loc_);
case '=': case '=':
if (curr != '=') if (curr != '=')
return iw5::parser::make_ASSIGN(loc_); return parser::make_ASSIGN(loc_);
reader_.advance(); reader_.advance();
return iw5::parser::make_EQUALITY(loc_); return parser::make_EQUALITY(loc_);
case '+': case '+':
if (curr != '+' && curr != '=') if (curr != '+' && curr != '=')
return iw5::parser::make_ADD(loc_); return parser::make_ADD(loc_);
reader_.advance(); reader_.advance();
if (last == '+') if (last == '+')
return iw5::parser::make_INCREMENT(loc_); return parser::make_INCREMENT(loc_);
return iw5::parser::make_ASSIGN_ADD(loc_); return parser::make_ASSIGN_ADD(loc_);
case '-': case '-':
if (curr != '-' && curr != '=') if (curr != '-' && curr != '=')
return iw5::parser::make_SUB(loc_); return parser::make_SUB(loc_);
reader_.advance(); reader_.advance();
if (last == '-') if (last == '-')
return iw5::parser::make_DECREMENT(loc_); return parser::make_DECREMENT(loc_);
return iw5::parser::make_ASSIGN_SUB(loc_); return parser::make_ASSIGN_SUB(loc_);
case '%': case '%':
if (curr != '=') if (curr != '=')
return iw5::parser::make_MOD(loc_); return parser::make_MOD(loc_);
reader_.advance(); reader_.advance();
return iw5::parser::make_ASSIGN_MOD(loc_); return parser::make_ASSIGN_MOD(loc_);
case '|': case '|':
if (curr != '|' && curr != '=') if (curr != '|' && curr != '=')
return iw5::parser::make_BITWISE_OR(loc_); return parser::make_BITWISE_OR(loc_);
reader_.advance(); reader_.advance();
if (last == '|') if (last == '|')
return iw5::parser::make_OR(loc_); return parser::make_OR(loc_);
return iw5::parser::make_ASSIGN_BW_OR(loc_); return parser::make_ASSIGN_BW_OR(loc_);
case '&': case '&':
if (curr != '&' && curr != '=' && curr != '"' && curr != '\'') if (curr != '&' && curr != '=' && curr != '"' && curr != '\'')
return iw5::parser::make_BITWISE_AND(loc_); return parser::make_BITWISE_AND(loc_);
reader_.advance(); reader_.advance();
if (last == '&') if (last == '&')
return iw5::parser::make_AND(loc_); return parser::make_AND(loc_);
if (last == '=') if (last == '=')
return iw5::parser::make_ASSIGN_BW_AND(loc_); return parser::make_ASSIGN_BW_AND(loc_);
state_ = state::localize; state_ = state::localize;
goto lex_string; goto lex_string;
case '^': case '^':
if (curr != '=') if (curr != '=')
return iw5::parser::make_BITWISE_EXOR(loc_); return parser::make_BITWISE_EXOR(loc_);
reader_.advance(); reader_.advance();
return iw5::parser::make_ASSIGN_BW_EXOR(loc_); return parser::make_ASSIGN_BW_EXOR(loc_);
case '!': case '!':
if (curr != '=') if (curr != '=')
return iw5::parser::make_NOT(loc_); return parser::make_NOT(loc_);
reader_.advance(); reader_.advance();
return iw5::parser::make_INEQUALITY(loc_); return parser::make_INEQUALITY(loc_);
case '~': case '~':
return iw5::parser::make_COMPLEMENT(loc_); return parser::make_COMPLEMENT(loc_);
case '<': case '<':
if (curr != '<' && curr != '=') if (curr != '<' && curr != '=')
return iw5::parser::make_LESS(loc_); return parser::make_LESS(loc_);
reader_.advance(); reader_.advance();
if (last == '=') if (last == '=')
return iw5::parser::make_LESS_EQUAL(loc_); return parser::make_LESS_EQUAL(loc_);
if (curr != '=') if (curr != '=')
return iw5::parser::make_LSHIFT(loc_); return parser::make_LSHIFT(loc_);
reader_.advance(); reader_.advance();
return iw5::parser::make_ASSIGN_LSHIFT(loc_); return parser::make_ASSIGN_LSHIFT(loc_);
case '>': case '>':
if (curr != '>' && curr != '=') if (curr != '>' && curr != '=')
return iw5::parser::make_GREATER(loc_); return parser::make_GREATER(loc_);
reader_.advance(); reader_.advance();
if (last == '=') if (last == '=')
return iw5::parser::make_GREATER_EQUAL(loc_); return parser::make_GREATER_EQUAL(loc_);
if (curr != '=') if (curr != '=')
return iw5::parser::make_RSHIFT(loc_); return parser::make_RSHIFT(loc_);
reader_.advance(); reader_.advance();
return iw5::parser::make_ASSIGN_RSHIFT(loc_); return parser::make_ASSIGN_RSHIFT(loc_);
default: default:
lex_name_or_number: lex_name_or_number:
if (last >= '0' && last <= '9') if (last >= '0' && last <= '9')
@ -496,9 +445,9 @@ lex_string:
} }
if (state_ == state::localize) if (state_ == state::localize)
return iw5::parser::make_ISTRING(std::string(buffer_.data, buffer_.length), loc_); return parser::make_ISTRING(std::string(buffer_.data, buffer_.length), loc_);
return iw5::parser::make_STRING(std::string(buffer_.data, buffer_.length), loc_); return parser::make_STRING(std::string(buffer_.data, buffer_.length), loc_);
lex_name: lex_name:
buffer_.push(last); buffer_.push(last);
@ -533,44 +482,55 @@ lex_name:
if (std::string_view(buffer_.data, buffer_.length) == "size") if (std::string_view(buffer_.data, buffer_.length) == "size")
{ {
return iw5::parser::make_SIZE(loc_); return parser::make_SIZE(loc_);
} }
return iw5::parser::make_FIELD(std::string(buffer_.data, buffer_.length), loc_); return parser::make_FIELD(std::string(buffer_.data, buffer_.length), loc_);
} }
else if (state_ == state::preprocessor) else if (state_ == state::preprocessor)
{ {
if (path) if (path)
throw comp_error(loc_, "invalid preprocessor directive"); throw comp_error(loc_, "invalid preprocessor directive");
auto key = get_keyword(std::string_view(buffer_.data, buffer_.length)); auto token = parser::token::IW5UNDEF;
if (key != keyword::KW_INVALID) if (buffer_.length < 16)
return keyword_token(key); {
const auto& itr = keyword_map.find(std::string_view(buffer_.data, buffer_.length));
// TODO: call preprocessor(key); if(itr != keyword_map.end())
{
if (itr->second > parser::token::HSENDIF)
return parser::symbol_type(itr->second, loc_);
token = itr->second;
}
}
// TODO: call preprocessor(token);
throw comp_error(loc_, "unknown preprocessor directive"); throw comp_error(loc_, "unknown preprocessor directive");
state_ = state::start; state_ = state::start;
continue; continue;
} }
else else
{ {
auto key = get_keyword(std::string_view(buffer_.data, buffer_.length)); if (buffer_.length < 17)
{
const auto& itr = keyword_map.find(std::string_view(buffer_.data, buffer_.length));
if (key != keyword::KW_INVALID) if(itr != keyword_map.end())
return keyword_token(key); return parser::symbol_type(itr->second, loc_);
}
if (path) if (path)
{ {
if (buffer_.data[buffer_.length - 1] == '/') if (buffer_.data[buffer_.length - 1] == '/')
throw comp_error(loc_, "invalid path end '\\'"); throw comp_error(loc_, "invalid path end '\\'");
//return iw5::parser::make_PATH(xsk::gsc::iw5::resolver::make_token(std::string_view(buffer_.data, buffer_.length)), loc_); return parser::make_PATH(resolver::make_token(std::string_view(buffer_.data, buffer_.length)), loc_);
return iw5::parser::make_PATH(std::string(buffer_.data, buffer_.length), loc_);
} }
//return iw5::parser::make_IDENTIFIER(xsk::gsc::iw5::resolver::make_token(std::string_view(buffer_.data, buffer_.length)), loc_); return parser::make_IDENTIFIER(resolver::make_token(std::string_view(buffer_.data, buffer_.length)), loc_);
return iw5::parser::make_IDENTIFIER(std::string(buffer_.data, buffer_.length), loc_);
} }
lex_number: lex_number:
@ -621,9 +581,9 @@ lex_number:
throw comp_error(loc_, "invalid number literal"); throw comp_error(loc_, "invalid number literal");
if (state_ == state::field || dot || flt) if (state_ == state::field || dot || flt)
return iw5::parser::make_FLOAT(std::string(buffer_.data, buffer_.length), loc_); return parser::make_FLOAT(std::string(buffer_.data, buffer_.length), loc_);
return iw5::parser::make_INTEGER(std::string(buffer_.data, buffer_.length), loc_); return parser::make_INTEGER(std::string(buffer_.data, buffer_.length), loc_);
} }
else if (curr == 'o') else if (curr == 'o')
{ {
@ -655,7 +615,7 @@ lex_number:
if (last == '\'' || buffer_.length <= 0) if (last == '\'' || buffer_.length <= 0)
throw comp_error(loc_, "invalid octal literal"); throw comp_error(loc_, "invalid octal literal");
return iw5::parser::make_INTEGER(xsk::utils::string::oct_to_dec(buffer_.data), loc_); return parser::make_INTEGER(xsk::utils::string::oct_to_dec(buffer_.data), loc_);
} }
else if (curr == 'b') else if (curr == 'b')
{ {
@ -689,7 +649,7 @@ lex_number:
if (last == '\'' || buffer_.length < 3) if (last == '\'' || buffer_.length < 3)
throw comp_error(loc_, "invalid binary literal"); throw comp_error(loc_, "invalid binary literal");
return iw5::parser::make_INTEGER(xsk::utils::string::bin_to_dec(buffer_.data), loc_); return parser::make_INTEGER(xsk::utils::string::bin_to_dec(buffer_.data), loc_);
} }
else if (curr == 'x') else if (curr == 'x')
{ {
@ -723,176 +683,59 @@ lex_number:
if (last == '\'' || buffer_.length < 3) if (last == '\'' || buffer_.length < 3)
throw comp_error(loc_, "invalid hexadecimal literal"); throw comp_error(loc_, "invalid hexadecimal literal");
return iw5::parser::make_INTEGER(xsk::utils::string::hex_to_dec(buffer_.data), loc_); return parser::make_INTEGER(xsk::utils::string::hex_to_dec(buffer_.data), loc_);
} }
// cant get here! // cant get here!
} }
} }
auto lexer::keyword_token(keyword k) -> xsk::gsc::iw5::parser::symbol_type const std::unordered_map<std::string_view, parser::token::token_kind_type> lexer::keyword_map
{
switch (k)
{
case keyword::KW_pre_inline:
return iw5::parser::make_INLINE(loc_);
case keyword::KW_pre_include:
return iw5::parser::make_INCLUDE(loc_);
case keyword::KW_pre_using_animtree:
return iw5::parser::make_USINGTREE(loc_);
case keyword::KW_pre_animtree:
return iw5::parser::make_ANIMTREE(loc_);
case keyword::KW_endon:
return iw5::parser::make_ENDON(loc_);
case keyword::KW_notify:
return iw5::parser::make_NOTIFY(loc_);
case keyword::KW_wait:
return iw5::parser::make_WAIT(loc_);
case keyword::KW_waittill:
return iw5::parser::make_WAITTILL(loc_);
case keyword::KW_waittillmatch:
return iw5::parser::make_WAITTILLMATCH(loc_);
case keyword::KW_waittillframeend:
return iw5::parser::make_WAITTILLFRAMEEND(loc_);
case keyword::KW_if:
return iw5::parser::make_IF(loc_);
case keyword::KW_else:
return iw5::parser::make_ELSE(loc_);
case keyword::KW_do:
return iw5::parser::make_DO(loc_);
case keyword::KW_while:
return iw5::parser::make_WHILE(loc_);
case keyword::KW_for:
return iw5::parser::make_FOR(loc_);
case keyword::KW_foreach:
return iw5::parser::make_FOREACH(loc_);
case keyword::KW_in:
return iw5::parser::make_IN(loc_);
case keyword::KW_switch:
return iw5::parser::make_SWITCH(loc_);
case keyword::KW_case:
return iw5::parser::make_CASE(loc_);
case keyword::KW_default:
return iw5::parser::make_DEFAULT(loc_);
case keyword::KW_break:
return iw5::parser::make_BREAK(loc_);
case keyword::KW_continue:
return iw5::parser::make_CONTINUE(loc_);
case keyword::KW_return:
return iw5::parser::make_RETURN(loc_);
case keyword::KW_breakpoint:
return iw5::parser::make_BREAKPOINT(loc_);
case keyword::KW_prof_begin:
return iw5::parser::make_PROFBEGIN(loc_);
case keyword::KW_prof_end:
return iw5::parser::make_PROFEND(loc_);
case keyword::KW_thread:
return iw5::parser::make_THREAD(loc_);
case keyword::KW_childthread:
return iw5::parser::make_CHILDTHREAD(loc_);
case keyword::KW_thisthread:
return iw5::parser::make_THISTHREAD(loc_);
case keyword::KW_call:
return iw5::parser::make_CALL(loc_);
case keyword::KW_true:
return iw5::parser::make_TRUE(loc_);
case keyword::KW_false:
return iw5::parser::make_FALSE(loc_);
case keyword::KW_undefined:
return iw5::parser::make_UNDEFINED(loc_);
case keyword::KW_dotsize:
return iw5::parser::make_SIZE(loc_);
case keyword::KW_game:
return iw5::parser::make_GAME(loc_);
case keyword::KW_self:
return iw5::parser::make_SELF(loc_);
case keyword::KW_anim:
return iw5::parser::make_ANIM(loc_);
case keyword::KW_level:
return iw5::parser::make_LEVEL(loc_);
default:
throw error("gsc lexer: INVALID KEYWORD TOKEN!");
}
}
auto lexer::keyword_is_token(keyword k) -> bool
{
switch (k)
{
/* case keyword::KW_pre_define:
case keyword::KW_pre_undef:
case keyword::KW_pre_ifdef:
case keyword::KW_pre_ifndef:
case keyword::KW_pre_if:
case keyword::KW_pre_elif:
case keyword::KW_pre_else:
case keyword::KW_pre_endif:*/
case keyword::KW_INVALID:
return false;
default:
return true;
}
}
auto lexer::get_keyword(std::string_view str) -> keyword
{
auto itr = keywords.find(str);
if(itr != keywords.end())
{
return itr->second;
}
return keyword::KW_INVALID;
}
std::unordered_map<std::string_view, keyword> lexer::keywords
{{ {{
/* { "#define", keyword::KW_pre_define }, { "#define", parser::token::HSDEFINE },
{ "#undef", keyword::KW_pre_undef }, { "#undef", parser::token::HSUNDEF },
{ "#ifdef", keyword::KW_pre_ifdef }, { "#ifdef", parser::token::HSIFDEF },
{ "#ifndef", keyword::KW_pre_ifndef }, { "#ifndef", parser::token::HSIFNDEF },
{ "#if", keyword::KW_pre_if }, { "#if", parser::token::HSIF },
{ "#elif", keyword::KW_pre_elif }, { "#elif", parser::token::HSELIF },
{ "#else", keyword::KW_pre_else }, { "#else", parser::token::HSELSE },
{ "#endif", keyword::KW_pre_endif },*/ { "#endif", parser::token::HSENDIF },
{ "#inline", keyword::KW_pre_inline }, { "#inline", parser::token::INLINE },
{ "#include", keyword::KW_pre_include }, { "#include", parser::token::INCLUDE },
{ "#using_animtree", keyword::KW_pre_using_animtree }, { "#using_animtree", parser::token::USINGTREE },
{ "#animtree", keyword::KW_pre_animtree }, { "#animtree", parser::token::ANIMTREE },
{ "endon", keyword::KW_endon }, { "endon", parser::token::ENDON },
{ "notify", keyword::KW_notify }, { "notify", parser::token::NOTIFY },
{ "wait", keyword::KW_wait }, { "wait", parser::token::WAIT },
{ "waittill", keyword::KW_waittill }, { "waittill", parser::token::WAITTILL },
{ "waittillmatch", keyword::KW_waittillmatch }, { "waittillmatch", parser::token::WAITTILLMATCH },
{ "waittillframeend", keyword::KW_waittillframeend }, { "waittillframeend", parser::token::WAITTILLFRAMEEND },
{ "if", keyword::KW_if }, { "if", parser::token::IF },
{ "else", keyword::KW_else }, { "else", parser::token::ELSE },
{ "do", keyword::KW_do }, { "do", parser::token::DO },
{ "while", keyword::KW_while }, { "while", parser::token::WHILE },
{ "for", keyword::KW_for }, { "for", parser::token::FOR },
{ "foreach", keyword::KW_foreach }, { "foreach", parser::token::FOREACH },
{ "in", keyword::KW_in }, { "in", parser::token::IN },
{ "switch", keyword::KW_switch }, { "switch", parser::token::SWITCH },
{ "case", keyword::KW_case }, { "case", parser::token::CASE },
{ "default", keyword::KW_default }, { "default", parser::token::DEFAULT },
{ "break", keyword::KW_break }, { "break", parser::token::BREAK },
{ "continue", keyword::KW_continue }, { "continue", parser::token::CONTINUE },
{ "return", keyword::KW_return }, { "return", parser::token::RETURN },
{ "breakpoint", keyword::KW_breakpoint }, { "breakpoint", parser::token::BREAKPOINT },
{ "prof_begin", keyword::KW_prof_begin }, { "prof_begin", parser::token::PROFBEGIN },
{ "prof_end", keyword::KW_prof_end }, { "prof_end", parser::token::PROFEND },
{ "thread", keyword::KW_thread }, { "thread", parser::token::THREAD },
{ "childthread", keyword::KW_childthread }, { "childthread", parser::token::CHILDTHREAD },
{ "thisthread", keyword::KW_thisthread }, { "thisthread", parser::token::THISTHREAD },
{ "call", keyword::KW_call }, { "call", parser::token::CALL },
{ "true", keyword::KW_true }, { "true", parser::token::TRUE },
{ "false", keyword::KW_false }, { "false", parser::token::FALSE },
{ "undefined", keyword::KW_undefined }, { "undefined", parser::token::UNDEFINED },
{ ".size", keyword::KW_dotsize }, { "game", parser::token::GAME },
{ "game", keyword::KW_game }, { "self", parser::token::SELF },
{ "self", keyword::KW_self }, { "anim", parser::token::ANIM },
{ "anim", keyword::KW_anim }, { "level", parser::token::LEVEL },
{ "level", keyword::KW_level },
}}; }};
} // namespace xsk::gsc::iw5 } // namespace xsk::gsc::iw5

View File

@ -10,8 +10,6 @@
namespace xsk::gsc::iw5 namespace xsk::gsc::iw5
{ {
enum class keyword;
constexpr size_t max_buf_size = 0x2000; constexpr size_t max_buf_size = 0x2000;
struct buffer struct buffer
@ -53,26 +51,22 @@ class lexer
reader reader_; reader reader_;
buffer buffer_; buffer buffer_;
location loc_; location loc_;
build mode_;
std::stack<location> locs_; std::stack<location> locs_;
std::stack<reader> readers_; std::stack<reader> readers_;
std::uint32_t header_top_; std::uint32_t header_top_;
state state_; state state_;
build mode_;
bool indev_; bool indev_;
public: public:
lexer(const std::string& name, const char* data, size_t size); lexer(const std::string& name, const char* data, size_t size);
auto lex() -> xsk::gsc::iw5::parser::symbol_type; auto lex() -> parser::symbol_type;
void push_header(const std::string& file); void push_header(const std::string& file);
void pop_header(); void pop_header();
void restrict_header(const xsk::gsc::location& loc); void ban_header(const location& loc);
private: private:
auto keyword_token(keyword k) -> xsk::gsc::iw5::parser::symbol_type; static const std::unordered_map<std::string_view, parser::token::token_kind_type> keyword_map;
static auto keyword_is_token(keyword k) -> bool;
static auto get_keyword(std::string_view str) -> keyword;
static std::unordered_map<std::string_view, keyword> keywords;
}; };
} // namespace xsk::gsc::iw5 } // namespace xsk::gsc::iw5

File diff suppressed because it is too large Load Diff

View File

@ -674,108 +674,116 @@ namespace xsk { namespace gsc { namespace iw5 {
IW5EOF = 0, // "end of file" IW5EOF = 0, // "end of file"
IW5error = 1, // error IW5error = 1, // error
IW5UNDEF = 2, // "invalid token" IW5UNDEF = 2, // "invalid token"
DEVBEGIN = 3, // "/#" HSDEFINE = 3, // "#define"
DEVEND = 4, // "#/" HSUNDEF = 4, // "#undef"
INLINE = 5, // "#inline" HSIFDEF = 5, // "#ifdef"
INCLUDE = 6, // "#include" HSIFNDEF = 6, // "#ifndef"
USINGTREE = 7, // "#using_animtree" HSIF = 7, // "#if"
ANIMTREE = 8, // "#animtree" HSELIF = 8, // "#elif"
ENDON = 9, // "endon" HSELSE = 9, // "#else"
NOTIFY = 10, // "notify" HSENDIF = 10, // "#endif"
WAIT = 11, // "wait" DEVBEGIN = 11, // "/#"
WAITTILL = 12, // "waittill" DEVEND = 12, // "#/"
WAITTILLMATCH = 13, // "waittillmatch" INLINE = 13, // "#inline"
WAITTILLFRAMEEND = 14, // "waittillframeend" INCLUDE = 14, // "#include"
IF = 15, // "if" USINGTREE = 15, // "#using_animtree"
ELSE = 16, // "else" ANIMTREE = 16, // "#animtree"
DO = 17, // "do" ENDON = 17, // "endon"
WHILE = 18, // "while" NOTIFY = 18, // "notify"
FOR = 19, // "for" WAIT = 19, // "wait"
FOREACH = 20, // "foreach" WAITTILL = 20, // "waittill"
IN = 21, // "in" WAITTILLMATCH = 21, // "waittillmatch"
SWITCH = 22, // "switch" WAITTILLFRAMEEND = 22, // "waittillframeend"
CASE = 23, // "case" IF = 23, // "if"
DEFAULT = 24, // "default" ELSE = 24, // "else"
BREAK = 25, // "break" DO = 25, // "do"
CONTINUE = 26, // "continue" WHILE = 26, // "while"
RETURN = 27, // "return" FOR = 27, // "for"
BREAKPOINT = 28, // "breakpoint" FOREACH = 28, // "foreach"
PROFBEGIN = 29, // "prof_begin" IN = 29, // "in"
PROFEND = 30, // "prof_end" SWITCH = 30, // "switch"
THREAD = 31, // "thread" CASE = 31, // "case"
CHILDTHREAD = 32, // "childthread" DEFAULT = 32, // "default"
THISTHREAD = 33, // "thisthread" BREAK = 33, // "break"
CALL = 34, // "call" CONTINUE = 34, // "continue"
TRUE = 35, // "true" RETURN = 35, // "return"
FALSE = 36, // "false" BREAKPOINT = 36, // "breakpoint"
UNDEFINED = 37, // "undefined" PROFBEGIN = 37, // "prof_begin"
SIZE = 38, // ".size" PROFEND = 38, // "prof_end"
GAME = 39, // "game" THREAD = 39, // "thread"
SELF = 40, // "self" CHILDTHREAD = 40, // "childthread"
ANIM = 41, // "anim" THISTHREAD = 41, // "thisthread"
LEVEL = 42, // "level" CALL = 42, // "call"
LPAREN = 43, // "(" TRUE = 43, // "true"
RPAREN = 44, // ")" FALSE = 44, // "false"
LBRACE = 45, // "{" UNDEFINED = 45, // "undefined"
RBRACE = 46, // "}" SIZE = 46, // ".size"
LBRACKET = 47, // "[" GAME = 47, // "game"
RBRACKET = 48, // "]" SELF = 48, // "self"
COMMA = 49, // "," ANIM = 49, // "anim"
DOT = 50, // "." LEVEL = 50, // "level"
DOUBLECOLON = 51, // "::" LPAREN = 51, // "("
COLON = 52, // ":" RPAREN = 52, // ")"
SEMICOLON = 53, // ";" LBRACE = 53, // "{"
QMARK = 54, // "?" RBRACE = 54, // "}"
INCREMENT = 55, // "++" LBRACKET = 55, // "["
DECREMENT = 56, // "--" RBRACKET = 56, // "]"
LSHIFT = 57, // "<<" COMMA = 57, // ","
RSHIFT = 58, // ">>" DOT = 58, // "."
OR = 59, // "||" DOUBLECOLON = 59, // "::"
AND = 60, // "&&" COLON = 60, // ":"
EQUALITY = 61, // "==" SEMICOLON = 61, // ";"
INEQUALITY = 62, // "!=" QMARK = 62, // "?"
LESS_EQUAL = 63, // "<=" INCREMENT = 63, // "++"
GREATER_EQUAL = 64, // ">=" DECREMENT = 64, // "--"
LESS = 65, // "<" LSHIFT = 65, // "<<"
GREATER = 66, // ">" RSHIFT = 66, // ">>"
NOT = 67, // "!" OR = 67, // "||"
COMPLEMENT = 68, // "~" AND = 68, // "&&"
ASSIGN = 69, // "=" EQUALITY = 69, // "=="
ASSIGN_ADD = 70, // "+=" INEQUALITY = 70, // "!="
ASSIGN_SUB = 71, // "-=" LESS_EQUAL = 71, // "<="
ASSIGN_MUL = 72, // "*=" GREATER_EQUAL = 72, // ">="
ASSIGN_DIV = 73, // "/=" LESS = 73, // "<"
ASSIGN_MOD = 74, // "%=" GREATER = 74, // ">"
ASSIGN_BW_OR = 75, // "|=" NOT = 75, // "!"
ASSIGN_BW_AND = 76, // "&=" COMPLEMENT = 76, // "~"
ASSIGN_BW_EXOR = 77, // "^=" ASSIGN = 77, // "="
ASSIGN_RSHIFT = 78, // ">>=" ASSIGN_ADD = 78, // "+="
ASSIGN_LSHIFT = 79, // "<<=" ASSIGN_SUB = 79, // "-="
BITWISE_OR = 80, // "|" ASSIGN_MUL = 80, // "*="
BITWISE_AND = 81, // "&" ASSIGN_DIV = 81, // "/="
BITWISE_EXOR = 82, // "^" ASSIGN_MOD = 82, // "%="
ADD = 83, // "+" ASSIGN_BW_OR = 83, // "|="
SUB = 84, // "-" ASSIGN_BW_AND = 84, // "&="
MUL = 85, // "*" ASSIGN_BW_EXOR = 85, // "^="
DIV = 86, // "/" ASSIGN_RSHIFT = 86, // ">>="
MOD = 87, // "%" ASSIGN_LSHIFT = 87, // "<<="
FIELD = 88, // "field" BITWISE_OR = 88, // "|"
PATH = 89, // "path" BITWISE_AND = 89, // "&"
IDENTIFIER = 90, // "identifier" BITWISE_EXOR = 90, // "^"
STRING = 91, // "string literal" ADD = 91, // "+"
ISTRING = 92, // "localized string" SUB = 92, // "-"
COLOR = 93, // "color" MUL = 93, // "*"
FLOAT = 94, // "float" DIV = 94, // "/"
INTEGER = 95, // "integer" MOD = 95, // "%"
ADD_ARRAY = 96, // ADD_ARRAY FIELD = 96, // "field"
THEN = 97, // THEN PATH = 97, // "path"
TERN = 98, // TERN IDENTIFIER = 98, // "identifier"
NEG = 99, // NEG STRING = 99, // "string literal"
ANIMREF = 100, // ANIMREF ISTRING = 100, // "localized string"
PREINC = 101, // PREINC COLOR = 101, // "color"
PREDEC = 102, // PREDEC FLOAT = 102, // "float"
POSTINC = 103, // POSTINC INTEGER = 103, // "integer"
POSTDEC = 104 // POSTDEC ADD_ARRAY = 104, // ADD_ARRAY
THEN = 105, // THEN
TERN = 106, // TERN
NEG = 107, // NEG
ANIMREF = 108, // ANIMREF
PREINC = 109, // PREINC
PREDEC = 110, // PREDEC
POSTINC = 111, // POSTINC
POSTDEC = 112 // POSTDEC
}; };
/// Backward compatibility alias (Bison 3.6). /// Backward compatibility alias (Bison 3.6).
typedef token_kind_type yytokentype; typedef token_kind_type yytokentype;
@ -792,193 +800,201 @@ namespace xsk { namespace gsc { namespace iw5 {
{ {
enum symbol_kind_type enum symbol_kind_type
{ {
YYNTOKENS = 105, ///< Number of tokens. YYNTOKENS = 113, ///< Number of tokens.
S_YYEMPTY = -2, S_YYEMPTY = -2,
S_YYEOF = 0, // "end of file" S_YYEOF = 0, // "end of file"
S_YYerror = 1, // error S_YYerror = 1, // error
S_YYUNDEF = 2, // "invalid token" S_YYUNDEF = 2, // "invalid token"
S_DEVBEGIN = 3, // "/#" S_HSDEFINE = 3, // "#define"
S_DEVEND = 4, // "#/" S_HSUNDEF = 4, // "#undef"
S_INLINE = 5, // "#inline" S_HSIFDEF = 5, // "#ifdef"
S_INCLUDE = 6, // "#include" S_HSIFNDEF = 6, // "#ifndef"
S_USINGTREE = 7, // "#using_animtree" S_HSIF = 7, // "#if"
S_ANIMTREE = 8, // "#animtree" S_HSELIF = 8, // "#elif"
S_ENDON = 9, // "endon" S_HSELSE = 9, // "#else"
S_NOTIFY = 10, // "notify" S_HSENDIF = 10, // "#endif"
S_WAIT = 11, // "wait" S_DEVBEGIN = 11, // "/#"
S_WAITTILL = 12, // "waittill" S_DEVEND = 12, // "#/"
S_WAITTILLMATCH = 13, // "waittillmatch" S_INLINE = 13, // "#inline"
S_WAITTILLFRAMEEND = 14, // "waittillframeend" S_INCLUDE = 14, // "#include"
S_IF = 15, // "if" S_USINGTREE = 15, // "#using_animtree"
S_ELSE = 16, // "else" S_ANIMTREE = 16, // "#animtree"
S_DO = 17, // "do" S_ENDON = 17, // "endon"
S_WHILE = 18, // "while" S_NOTIFY = 18, // "notify"
S_FOR = 19, // "for" S_WAIT = 19, // "wait"
S_FOREACH = 20, // "foreach" S_WAITTILL = 20, // "waittill"
S_IN = 21, // "in" S_WAITTILLMATCH = 21, // "waittillmatch"
S_SWITCH = 22, // "switch" S_WAITTILLFRAMEEND = 22, // "waittillframeend"
S_CASE = 23, // "case" S_IF = 23, // "if"
S_DEFAULT = 24, // "default" S_ELSE = 24, // "else"
S_BREAK = 25, // "break" S_DO = 25, // "do"
S_CONTINUE = 26, // "continue" S_WHILE = 26, // "while"
S_RETURN = 27, // "return" S_FOR = 27, // "for"
S_BREAKPOINT = 28, // "breakpoint" S_FOREACH = 28, // "foreach"
S_PROFBEGIN = 29, // "prof_begin" S_IN = 29, // "in"
S_PROFEND = 30, // "prof_end" S_SWITCH = 30, // "switch"
S_THREAD = 31, // "thread" S_CASE = 31, // "case"
S_CHILDTHREAD = 32, // "childthread" S_DEFAULT = 32, // "default"
S_THISTHREAD = 33, // "thisthread" S_BREAK = 33, // "break"
S_CALL = 34, // "call" S_CONTINUE = 34, // "continue"
S_TRUE = 35, // "true" S_RETURN = 35, // "return"
S_FALSE = 36, // "false" S_BREAKPOINT = 36, // "breakpoint"
S_UNDEFINED = 37, // "undefined" S_PROFBEGIN = 37, // "prof_begin"
S_SIZE = 38, // ".size" S_PROFEND = 38, // "prof_end"
S_GAME = 39, // "game" S_THREAD = 39, // "thread"
S_SELF = 40, // "self" S_CHILDTHREAD = 40, // "childthread"
S_ANIM = 41, // "anim" S_THISTHREAD = 41, // "thisthread"
S_LEVEL = 42, // "level" S_CALL = 42, // "call"
S_LPAREN = 43, // "(" S_TRUE = 43, // "true"
S_RPAREN = 44, // ")" S_FALSE = 44, // "false"
S_LBRACE = 45, // "{" S_UNDEFINED = 45, // "undefined"
S_RBRACE = 46, // "}" S_SIZE = 46, // ".size"
S_LBRACKET = 47, // "[" S_GAME = 47, // "game"
S_RBRACKET = 48, // "]" S_SELF = 48, // "self"
S_COMMA = 49, // "," S_ANIM = 49, // "anim"
S_DOT = 50, // "." S_LEVEL = 50, // "level"
S_DOUBLECOLON = 51, // "::" S_LPAREN = 51, // "("
S_COLON = 52, // ":" S_RPAREN = 52, // ")"
S_SEMICOLON = 53, // ";" S_LBRACE = 53, // "{"
S_QMARK = 54, // "?" S_RBRACE = 54, // "}"
S_INCREMENT = 55, // "++" S_LBRACKET = 55, // "["
S_DECREMENT = 56, // "--" S_RBRACKET = 56, // "]"
S_LSHIFT = 57, // "<<" S_COMMA = 57, // ","
S_RSHIFT = 58, // ">>" S_DOT = 58, // "."
S_OR = 59, // "||" S_DOUBLECOLON = 59, // "::"
S_AND = 60, // "&&" S_COLON = 60, // ":"
S_EQUALITY = 61, // "==" S_SEMICOLON = 61, // ";"
S_INEQUALITY = 62, // "!=" S_QMARK = 62, // "?"
S_LESS_EQUAL = 63, // "<=" S_INCREMENT = 63, // "++"
S_GREATER_EQUAL = 64, // ">=" S_DECREMENT = 64, // "--"
S_LESS = 65, // "<" S_LSHIFT = 65, // "<<"
S_GREATER = 66, // ">" S_RSHIFT = 66, // ">>"
S_NOT = 67, // "!" S_OR = 67, // "||"
S_COMPLEMENT = 68, // "~" S_AND = 68, // "&&"
S_ASSIGN = 69, // "=" S_EQUALITY = 69, // "=="
S_ASSIGN_ADD = 70, // "+=" S_INEQUALITY = 70, // "!="
S_ASSIGN_SUB = 71, // "-=" S_LESS_EQUAL = 71, // "<="
S_ASSIGN_MUL = 72, // "*=" S_GREATER_EQUAL = 72, // ">="
S_ASSIGN_DIV = 73, // "/=" S_LESS = 73, // "<"
S_ASSIGN_MOD = 74, // "%=" S_GREATER = 74, // ">"
S_ASSIGN_BW_OR = 75, // "|=" S_NOT = 75, // "!"
S_ASSIGN_BW_AND = 76, // "&=" S_COMPLEMENT = 76, // "~"
S_ASSIGN_BW_EXOR = 77, // "^=" S_ASSIGN = 77, // "="
S_ASSIGN_RSHIFT = 78, // ">>=" S_ASSIGN_ADD = 78, // "+="
S_ASSIGN_LSHIFT = 79, // "<<=" S_ASSIGN_SUB = 79, // "-="
S_BITWISE_OR = 80, // "|" S_ASSIGN_MUL = 80, // "*="
S_BITWISE_AND = 81, // "&" S_ASSIGN_DIV = 81, // "/="
S_BITWISE_EXOR = 82, // "^" S_ASSIGN_MOD = 82, // "%="
S_ADD = 83, // "+" S_ASSIGN_BW_OR = 83, // "|="
S_SUB = 84, // "-" S_ASSIGN_BW_AND = 84, // "&="
S_MUL = 85, // "*" S_ASSIGN_BW_EXOR = 85, // "^="
S_DIV = 86, // "/" S_ASSIGN_RSHIFT = 86, // ">>="
S_MOD = 87, // "%" S_ASSIGN_LSHIFT = 87, // "<<="
S_FIELD = 88, // "field" S_BITWISE_OR = 88, // "|"
S_PATH = 89, // "path" S_BITWISE_AND = 89, // "&"
S_IDENTIFIER = 90, // "identifier" S_BITWISE_EXOR = 90, // "^"
S_STRING = 91, // "string literal" S_ADD = 91, // "+"
S_ISTRING = 92, // "localized string" S_SUB = 92, // "-"
S_COLOR = 93, // "color" S_MUL = 93, // "*"
S_FLOAT = 94, // "float" S_DIV = 94, // "/"
S_INTEGER = 95, // "integer" S_MOD = 95, // "%"
S_ADD_ARRAY = 96, // ADD_ARRAY S_FIELD = 96, // "field"
S_THEN = 97, // THEN S_PATH = 97, // "path"
S_TERN = 98, // TERN S_IDENTIFIER = 98, // "identifier"
S_NEG = 99, // NEG S_STRING = 99, // "string literal"
S_ANIMREF = 100, // ANIMREF S_ISTRING = 100, // "localized string"
S_PREINC = 101, // PREINC S_COLOR = 101, // "color"
S_PREDEC = 102, // PREDEC S_FLOAT = 102, // "float"
S_POSTINC = 103, // POSTINC S_INTEGER = 103, // "integer"
S_POSTDEC = 104, // POSTDEC S_ADD_ARRAY = 104, // ADD_ARRAY
S_YYACCEPT = 105, // $accept S_THEN = 105, // THEN
S_root = 106, // root S_TERN = 106, // TERN
S_program = 107, // program S_NEG = 107, // NEG
S_inline = 108, // inline S_ANIMREF = 108, // ANIMREF
S_include = 109, // include S_PREINC = 109, // PREINC
S_declaration = 110, // declaration S_PREDEC = 110, // PREDEC
S_decl_usingtree = 111, // decl_usingtree S_POSTINC = 111, // POSTINC
S_decl_constant = 112, // decl_constant S_POSTDEC = 112, // POSTDEC
S_decl_thread = 113, // decl_thread S_YYACCEPT = 113, // $accept
S_stmt = 114, // stmt S_root = 114, // root
S_stmt_dev = 115, // stmt_dev S_program = 115, // program
S_stmt_block = 116, // stmt_block S_inline = 116, // inline
S_stmt_list = 117, // stmt_list S_include = 117, // include
S_stmt_expr = 118, // stmt_expr S_declaration = 118, // declaration
S_stmt_call = 119, // stmt_call S_decl_usingtree = 119, // decl_usingtree
S_stmt_assign = 120, // stmt_assign S_decl_constant = 120, // decl_constant
S_stmt_endon = 121, // stmt_endon S_decl_thread = 121, // decl_thread
S_stmt_notify = 122, // stmt_notify S_stmt = 122, // stmt
S_stmt_wait = 123, // stmt_wait S_stmt_dev = 123, // stmt_dev
S_stmt_waittill = 124, // stmt_waittill S_stmt_block = 124, // stmt_block
S_stmt_waittillmatch = 125, // stmt_waittillmatch S_stmt_list = 125, // stmt_list
S_stmt_waittillframeend = 126, // stmt_waittillframeend S_stmt_expr = 126, // stmt_expr
S_stmt_if = 127, // stmt_if S_stmt_call = 127, // stmt_call
S_stmt_ifelse = 128, // stmt_ifelse S_stmt_assign = 128, // stmt_assign
S_stmt_while = 129, // stmt_while S_stmt_endon = 129, // stmt_endon
S_stmt_dowhile = 130, // stmt_dowhile S_stmt_notify = 130, // stmt_notify
S_stmt_for = 131, // stmt_for S_stmt_wait = 131, // stmt_wait
S_stmt_foreach = 132, // stmt_foreach S_stmt_waittill = 132, // stmt_waittill
S_stmt_switch = 133, // stmt_switch S_stmt_waittillmatch = 133, // stmt_waittillmatch
S_stmt_case = 134, // stmt_case S_stmt_waittillframeend = 134, // stmt_waittillframeend
S_stmt_default = 135, // stmt_default S_stmt_if = 135, // stmt_if
S_stmt_break = 136, // stmt_break S_stmt_ifelse = 136, // stmt_ifelse
S_stmt_continue = 137, // stmt_continue S_stmt_while = 137, // stmt_while
S_stmt_return = 138, // stmt_return S_stmt_dowhile = 138, // stmt_dowhile
S_stmt_breakpoint = 139, // stmt_breakpoint S_stmt_for = 139, // stmt_for
S_stmt_prof_begin = 140, // stmt_prof_begin S_stmt_foreach = 140, // stmt_foreach
S_stmt_prof_end = 141, // stmt_prof_end S_stmt_switch = 141, // stmt_switch
S_expr = 142, // expr S_stmt_case = 142, // stmt_case
S_expr_or_empty = 143, // expr_or_empty S_stmt_default = 143, // stmt_default
S_expr_assign = 144, // expr_assign S_stmt_break = 144, // stmt_break
S_expr_increment = 145, // expr_increment S_stmt_continue = 145, // stmt_continue
S_expr_decrement = 146, // expr_decrement S_stmt_return = 146, // stmt_return
S_expr_ternary = 147, // expr_ternary S_stmt_breakpoint = 147, // stmt_breakpoint
S_expr_binary = 148, // expr_binary S_stmt_prof_begin = 148, // stmt_prof_begin
S_expr_primitive = 149, // expr_primitive S_stmt_prof_end = 149, // stmt_prof_end
S_expr_complement = 150, // expr_complement S_expr = 150, // expr
S_expr_not = 151, // expr_not S_expr_or_empty = 151, // expr_or_empty
S_expr_call = 152, // expr_call S_expr_assign = 152, // expr_assign
S_expr_method = 153, // expr_method S_expr_increment = 153, // expr_increment
S_expr_function = 154, // expr_function S_expr_decrement = 154, // expr_decrement
S_expr_pointer = 155, // expr_pointer S_expr_ternary = 155, // expr_ternary
S_expr_add_array = 156, // expr_add_array S_expr_binary = 156, // expr_binary
S_expr_parameters = 157, // expr_parameters S_expr_primitive = 157, // expr_primitive
S_expr_arguments = 158, // expr_arguments S_expr_complement = 158, // expr_complement
S_expr_arguments_no_empty = 159, // expr_arguments_no_empty S_expr_not = 159, // expr_not
S_expr_reference = 160, // expr_reference S_expr_call = 160, // expr_call
S_expr_array = 161, // expr_array S_expr_method = 161, // expr_method
S_expr_field = 162, // expr_field S_expr_function = 162, // expr_function
S_expr_size = 163, // expr_size S_expr_pointer = 163, // expr_pointer
S_expr_paren = 164, // expr_paren S_expr_add_array = 164, // expr_add_array
S_expr_object = 165, // expr_object S_expr_parameters = 165, // expr_parameters
S_expr_thisthread = 166, // expr_thisthread S_expr_arguments = 166, // expr_arguments
S_expr_empty_array = 167, // expr_empty_array S_expr_arguments_no_empty = 167, // expr_arguments_no_empty
S_expr_undefined = 168, // expr_undefined S_expr_reference = 168, // expr_reference
S_expr_game = 169, // expr_game S_expr_array = 169, // expr_array
S_expr_self = 170, // expr_self S_expr_field = 170, // expr_field
S_expr_anim = 171, // expr_anim S_expr_size = 171, // expr_size
S_expr_level = 172, // expr_level S_expr_paren = 172, // expr_paren
S_expr_animation = 173, // expr_animation S_expr_object = 173, // expr_object
S_expr_animtree = 174, // expr_animtree S_expr_thisthread = 174, // expr_thisthread
S_expr_identifier = 175, // expr_identifier S_expr_empty_array = 175, // expr_empty_array
S_expr_path = 176, // expr_path S_expr_undefined = 176, // expr_undefined
S_expr_istring = 177, // expr_istring S_expr_game = 177, // expr_game
S_expr_string = 178, // expr_string S_expr_self = 178, // expr_self
S_expr_color = 179, // expr_color S_expr_anim = 179, // expr_anim
S_expr_vector = 180, // expr_vector S_expr_level = 180, // expr_level
S_expr_float = 181, // expr_float S_expr_animation = 181, // expr_animation
S_expr_integer = 182, // expr_integer S_expr_animtree = 182, // expr_animtree
S_expr_false = 183, // expr_false S_expr_identifier = 183, // expr_identifier
S_expr_true = 184 // expr_true S_expr_path = 184, // expr_path
S_expr_istring = 185, // expr_istring
S_expr_string = 186, // expr_string
S_expr_color = 187, // expr_color
S_expr_vector = 188, // expr_vector
S_expr_float = 189, // expr_float
S_expr_integer = 190, // expr_integer
S_expr_false = 191, // expr_false
S_expr_true = 192 // expr_true
}; };
}; };
@ -2751,6 +2767,126 @@ switch (yykind)
return symbol_type (token::IW5UNDEF, l); return symbol_type (token::IW5UNDEF, l);
} }
#endif #endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_HSDEFINE (location_type l)
{
return symbol_type (token::HSDEFINE, std::move (l));
}
#else
static
symbol_type
make_HSDEFINE (const location_type& l)
{
return symbol_type (token::HSDEFINE, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_HSUNDEF (location_type l)
{
return symbol_type (token::HSUNDEF, std::move (l));
}
#else
static
symbol_type
make_HSUNDEF (const location_type& l)
{
return symbol_type (token::HSUNDEF, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_HSIFDEF (location_type l)
{
return symbol_type (token::HSIFDEF, std::move (l));
}
#else
static
symbol_type
make_HSIFDEF (const location_type& l)
{
return symbol_type (token::HSIFDEF, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_HSIFNDEF (location_type l)
{
return symbol_type (token::HSIFNDEF, std::move (l));
}
#else
static
symbol_type
make_HSIFNDEF (const location_type& l)
{
return symbol_type (token::HSIFNDEF, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_HSIF (location_type l)
{
return symbol_type (token::HSIF, std::move (l));
}
#else
static
symbol_type
make_HSIF (const location_type& l)
{
return symbol_type (token::HSIF, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_HSELIF (location_type l)
{
return symbol_type (token::HSELIF, std::move (l));
}
#else
static
symbol_type
make_HSELIF (const location_type& l)
{
return symbol_type (token::HSELIF, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_HSELSE (location_type l)
{
return symbol_type (token::HSELSE, std::move (l));
}
#else
static
symbol_type
make_HSELSE (const location_type& l)
{
return symbol_type (token::HSELSE, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_HSENDIF (location_type l)
{
return symbol_type (token::HSENDIF, std::move (l));
}
#else
static
symbol_type
make_HSENDIF (const location_type& l)
{
return symbol_type (token::HSENDIF, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS #if 201103L <= YY_CPLUSPLUS
static static
symbol_type symbol_type
@ -5311,7 +5447,7 @@ switch (yykind)
#line 13 "parser.ypp" #line 13 "parser.ypp"
} } } // xsk::gsc::iw5 } } } // xsk::gsc::iw5
#line 5315 "parser.hpp" #line 5451 "parser.hpp"

View File

@ -16,57 +16,6 @@ xsk::gsc::iw6::parser::symbol_type IW6lex(xsk::gsc::iw6::lexer& lexer)
namespace xsk::gsc::iw6 namespace xsk::gsc::iw6
{ {
enum class keyword
{
/* KW_pre_define,
KW_pre_undef,
KW_pre_ifdef,
KW_pre_ifndef,
KW_pre_if,
KW_pre_elif,
KW_pre_else,
KW_pre_endif,*/
KW_pre_inline,
KW_pre_include,
KW_pre_using_animtree,
KW_pre_animtree,
KW_endon,
KW_notify,
KW_wait,
KW_waittill,
KW_waittillmatch,
KW_waittillframeend,
KW_if,
KW_else,
KW_do,
KW_while,
KW_for,
KW_foreach,
KW_in,
KW_switch,
KW_case,
KW_default,
KW_break,
KW_continue,
KW_return,
KW_breakpoint,
KW_prof_begin,
KW_prof_end,
KW_thread,
KW_childthread,
KW_thisthread,
KW_call,
KW_true,
KW_false,
KW_undefined,
KW_dotsize,
KW_game,
KW_self,
KW_anim,
KW_level,
KW_INVALID,
};
buffer::buffer() : length(0) buffer::buffer() : length(0)
{ {
data = static_cast<char*>(std::malloc(max_buf_size)); data = static_cast<char*>(std::malloc(max_buf_size));
@ -129,7 +78,7 @@ void reader::advance()
} }
} }
lexer::lexer(const std::string& name, const char* data, size_t size) : indev_(false), loc_(xsk::gsc::location(&name)), lexer::lexer(const std::string& name, const char* data, size_t size) : indev_(false), loc_(location(&name)),
mode_(build::dev), header_top_(0), locs_(std::stack<location>()), readers_(std::stack<reader>()) mode_(build::dev), header_top_(0), locs_(std::stack<location>()), readers_(std::stack<reader>())
{ {
reader_.init(data, size); reader_.init(data, size);
@ -140,7 +89,7 @@ void lexer::push_header(const std::string& file)
try try
{ {
if (header_top_++ >= 10) if (header_top_++ >= 10)
throw xsk::gsc::error("maximum gsh depth exceeded '10'"); throw comp_error(loc_, "maximum gsh depth exceeded '10'");
auto data = resolver::file_data(file + ".gsh"); auto data = resolver::file_data(file + ".gsh");
@ -151,7 +100,7 @@ void lexer::push_header(const std::string& file)
} }
catch (const std::exception& e) catch (const std::exception& e)
{ {
throw xsk::gsc::error("parsing header file '" + file + "': " + e.what()); throw error("parsing header file '" + file + "': " + e.what());
} }
} }
@ -164,7 +113,7 @@ void lexer::pop_header()
readers_.pop(); readers_.pop();
} }
void lexer::restrict_header(const xsk::gsc::location& loc) void lexer::ban_header(const location& loc)
{ {
if (header_top_ > 0) if (header_top_ > 0)
{ {
@ -172,7 +121,7 @@ void lexer::restrict_header(const xsk::gsc::location& loc)
} }
} }
auto lexer::lex() -> xsk::gsc::iw6::parser::symbol_type auto lexer::lex() -> parser::symbol_type
{ {
buffer_.length = 0; buffer_.length = 0;
state_ = state::start; state_ = state::start;
@ -193,7 +142,7 @@ auto lexer::lex() -> xsk::gsc::iw6::parser::symbol_type
if (header_top_ > 0) if (header_top_ > 0)
pop_header(); pop_header();
else else
return iw6::parser::make_IW6EOF(loc_); return parser::make_IW6EOF(loc_);
} }
reader_.advance(); reader_.advance();
@ -211,22 +160,22 @@ auto lexer::lex() -> xsk::gsc::iw6::parser::symbol_type
continue; continue;
case '/': case '/':
if (curr != '/' && curr != '*' && curr != '#' && curr != '=') if (curr != '/' && curr != '*' && curr != '#' && curr != '=')
return iw6::parser::make_DIV(loc_); return parser::make_DIV(loc_);
reader_.advance(); reader_.advance();
if (last == '=') if (last == '=')
return iw6::parser::make_ASSIGN_DIV(loc_); return parser::make_ASSIGN_DIV(loc_);
if (last == '#') if (last == '#')
{ {
if (indev_) if (indev_)
throw comp_error(loc_, "cannot recurse devblock ('/#')"); throw comp_error(loc_, "cannot recurse devblock ('/#')");
if (mode_ == xsk::gsc::build::dev) if (mode_ == build::dev)
{ {
indev_ = true; indev_ = true;
return iw6::parser::make_DEVBEGIN(loc_); return parser::make_DEVBEGIN(loc_);
} }
else else
{ {
@ -290,7 +239,7 @@ auto lexer::lex() -> xsk::gsc::iw6::parser::symbol_type
indev_ = false; indev_ = false;
reader_.advance(); reader_.advance();
return iw6::parser::make_DEVEND(loc_); return parser::make_DEVEND(loc_);
} }
buffer_.push(last); buffer_.push(last);
@ -303,12 +252,12 @@ auto lexer::lex() -> xsk::gsc::iw6::parser::symbol_type
goto lex_name; goto lex_name;
case '*': case '*':
if (curr != '/' && curr != '=') if (curr != '/' && curr != '=')
return iw6::parser::make_MUL(loc_); return parser::make_MUL(loc_);
reader_.advance(); reader_.advance();
if (last == '=') if (last == '=')
return iw6::parser::make_ASSIGN_MUL(loc_); return parser::make_ASSIGN_MUL(loc_);
throw comp_error(loc_, "unmatched multiline comment end ('*/')"); throw comp_error(loc_, "unmatched multiline comment end ('*/')");
case '"': case '"':
@ -323,127 +272,127 @@ auto lexer::lex() -> xsk::gsc::iw6::parser::symbol_type
state_ = state::field; state_ = state::field;
goto lex_name_or_number; goto lex_name_or_number;
case '(': case '(':
return iw6::parser::make_LPAREN(loc_); return parser::make_LPAREN(loc_);
case ')': case ')':
return iw6::parser::make_RPAREN(loc_); return parser::make_RPAREN(loc_);
case '{': case '{':
return iw6::parser::make_LBRACE(loc_); return parser::make_LBRACE(loc_);
case '}': case '}':
return iw6::parser::make_RBRACE(loc_); return parser::make_RBRACE(loc_);
case '[': case '[':
return iw6::parser::make_LBRACKET(loc_); return parser::make_LBRACKET(loc_);
case ']': case ']':
return iw6::parser::make_RBRACKET(loc_); return parser::make_RBRACKET(loc_);
case ',': case ',':
return iw6::parser::make_COMMA(loc_); return parser::make_COMMA(loc_);
case ';': case ';':
return iw6::parser::make_SEMICOLON(loc_); return parser::make_SEMICOLON(loc_);
case ':': case ':':
if (curr != ':') if (curr != ':')
return iw6::parser::make_COLON(loc_); return parser::make_COLON(loc_);
reader_.advance(); reader_.advance();
return iw6::parser::make_DOUBLECOLON(loc_); return parser::make_DOUBLECOLON(loc_);
case '?': case '?':
return iw6::parser::make_QMARK(loc_); return parser::make_QMARK(loc_);
case '=': case '=':
if (curr != '=') if (curr != '=')
return iw6::parser::make_ASSIGN(loc_); return parser::make_ASSIGN(loc_);
reader_.advance(); reader_.advance();
return iw6::parser::make_EQUALITY(loc_); return parser::make_EQUALITY(loc_);
case '+': case '+':
if (curr != '+' && curr != '=') if (curr != '+' && curr != '=')
return iw6::parser::make_ADD(loc_); return parser::make_ADD(loc_);
reader_.advance(); reader_.advance();
if (last == '+') if (last == '+')
return iw6::parser::make_INCREMENT(loc_); return parser::make_INCREMENT(loc_);
return iw6::parser::make_ASSIGN_ADD(loc_); return parser::make_ASSIGN_ADD(loc_);
case '-': case '-':
if (curr != '-' && curr != '=') if (curr != '-' && curr != '=')
return iw6::parser::make_SUB(loc_); return parser::make_SUB(loc_);
reader_.advance(); reader_.advance();
if (last == '-') if (last == '-')
return iw6::parser::make_DECREMENT(loc_); return parser::make_DECREMENT(loc_);
return iw6::parser::make_ASSIGN_SUB(loc_); return parser::make_ASSIGN_SUB(loc_);
case '%': case '%':
if (curr != '=') if (curr != '=')
return iw6::parser::make_MOD(loc_); return parser::make_MOD(loc_);
reader_.advance(); reader_.advance();
return iw6::parser::make_ASSIGN_MOD(loc_); return parser::make_ASSIGN_MOD(loc_);
case '|': case '|':
if (curr != '|' && curr != '=') if (curr != '|' && curr != '=')
return iw6::parser::make_BITWISE_OR(loc_); return parser::make_BITWISE_OR(loc_);
reader_.advance(); reader_.advance();
if (last == '|') if (last == '|')
return iw6::parser::make_OR(loc_); return parser::make_OR(loc_);
return iw6::parser::make_ASSIGN_BW_OR(loc_); return parser::make_ASSIGN_BW_OR(loc_);
case '&': case '&':
if (curr != '&' && curr != '=' && curr != '"' && curr != '\'') if (curr != '&' && curr != '=' && curr != '"' && curr != '\'')
return iw6::parser::make_BITWISE_AND(loc_); return parser::make_BITWISE_AND(loc_);
reader_.advance(); reader_.advance();
if (last == '&') if (last == '&')
return iw6::parser::make_AND(loc_); return parser::make_AND(loc_);
if (last == '=') if (last == '=')
return iw6::parser::make_ASSIGN_BW_AND(loc_); return parser::make_ASSIGN_BW_AND(loc_);
state_ = state::localize; state_ = state::localize;
goto lex_string; goto lex_string;
case '^': case '^':
if (curr != '=') if (curr != '=')
return iw6::parser::make_BITWISE_EXOR(loc_); return parser::make_BITWISE_EXOR(loc_);
reader_.advance(); reader_.advance();
return iw6::parser::make_ASSIGN_BW_EXOR(loc_); return parser::make_ASSIGN_BW_EXOR(loc_);
case '!': case '!':
if (curr != '=') if (curr != '=')
return iw6::parser::make_NOT(loc_); return parser::make_NOT(loc_);
reader_.advance(); reader_.advance();
return iw6::parser::make_INEQUALITY(loc_); return parser::make_INEQUALITY(loc_);
case '~': case '~':
return iw6::parser::make_COMPLEMENT(loc_); return parser::make_COMPLEMENT(loc_);
case '<': case '<':
if (curr != '<' && curr != '=') if (curr != '<' && curr != '=')
return iw6::parser::make_LESS(loc_); return parser::make_LESS(loc_);
reader_.advance(); reader_.advance();
if (last == '=') if (last == '=')
return iw6::parser::make_LESS_EQUAL(loc_); return parser::make_LESS_EQUAL(loc_);
if (curr != '=') if (curr != '=')
return iw6::parser::make_LSHIFT(loc_); return parser::make_LSHIFT(loc_);
reader_.advance(); reader_.advance();
return iw6::parser::make_ASSIGN_LSHIFT(loc_); return parser::make_ASSIGN_LSHIFT(loc_);
case '>': case '>':
if (curr != '>' && curr != '=') if (curr != '>' && curr != '=')
return iw6::parser::make_GREATER(loc_); return parser::make_GREATER(loc_);
reader_.advance(); reader_.advance();
if (last == '=') if (last == '=')
return iw6::parser::make_GREATER_EQUAL(loc_); return parser::make_GREATER_EQUAL(loc_);
if (curr != '=') if (curr != '=')
return iw6::parser::make_RSHIFT(loc_); return parser::make_RSHIFT(loc_);
reader_.advance(); reader_.advance();
return iw6::parser::make_ASSIGN_RSHIFT(loc_); return parser::make_ASSIGN_RSHIFT(loc_);
default: default:
lex_name_or_number: lex_name_or_number:
if (last >= '0' && last <= '9') if (last >= '0' && last <= '9')
@ -496,9 +445,9 @@ lex_string:
} }
if (state_ == state::localize) if (state_ == state::localize)
return iw6::parser::make_ISTRING(std::string(buffer_.data, buffer_.length), loc_); return parser::make_ISTRING(std::string(buffer_.data, buffer_.length), loc_);
return iw6::parser::make_STRING(std::string(buffer_.data, buffer_.length), loc_); return parser::make_STRING(std::string(buffer_.data, buffer_.length), loc_);
lex_name: lex_name:
buffer_.push(last); buffer_.push(last);
@ -533,44 +482,55 @@ lex_name:
if (std::string_view(buffer_.data, buffer_.length) == "size") if (std::string_view(buffer_.data, buffer_.length) == "size")
{ {
return iw6::parser::make_SIZE(loc_); return parser::make_SIZE(loc_);
} }
return iw6::parser::make_FIELD(std::string(buffer_.data, buffer_.length), loc_); return parser::make_FIELD(std::string(buffer_.data, buffer_.length), loc_);
} }
else if (state_ == state::preprocessor) else if (state_ == state::preprocessor)
{ {
if (path) if (path)
throw comp_error(loc_, "invalid preprocessor directive"); throw comp_error(loc_, "invalid preprocessor directive");
auto key = get_keyword(std::string_view(buffer_.data, buffer_.length)); auto token = parser::token::IW6UNDEF;
if (key != keyword::KW_INVALID) if (buffer_.length < 16)
return keyword_token(key); {
const auto& itr = keyword_map.find(std::string_view(buffer_.data, buffer_.length));
// TODO: call preprocessor(key); if(itr != keyword_map.end())
{
if (itr->second > parser::token::HSENDIF)
return parser::symbol_type(itr->second, loc_);
token = itr->second;
}
}
// TODO: call preprocessor(token);
throw comp_error(loc_, "unknown preprocessor directive"); throw comp_error(loc_, "unknown preprocessor directive");
state_ = state::start; state_ = state::start;
continue; continue;
} }
else else
{ {
auto key = get_keyword(std::string_view(buffer_.data, buffer_.length)); if (buffer_.length < 17)
{
const auto& itr = keyword_map.find(std::string_view(buffer_.data, buffer_.length));
if (key != keyword::KW_INVALID) if(itr != keyword_map.end())
return keyword_token(key); return parser::symbol_type(itr->second, loc_);
}
if (path) if (path)
{ {
if (buffer_.data[buffer_.length - 1] == '/') if (buffer_.data[buffer_.length - 1] == '/')
throw comp_error(loc_, "invalid path end '\\'"); throw comp_error(loc_, "invalid path end '\\'");
//return iw6::parser::make_PATH(xsk::gsc::iw6::resolver::make_token(std::string_view(buffer_.data, buffer_.length)), loc_); return parser::make_PATH(resolver::make_token(std::string_view(buffer_.data, buffer_.length)), loc_);
return iw6::parser::make_PATH(std::string(buffer_.data, buffer_.length), loc_);
} }
//return iw6::parser::make_IDENTIFIER(xsk::gsc::iw6::resolver::make_token(std::string_view(buffer_.data, buffer_.length)), loc_); return parser::make_IDENTIFIER(resolver::make_token(std::string_view(buffer_.data, buffer_.length)), loc_);
return iw6::parser::make_IDENTIFIER(std::string(buffer_.data, buffer_.length), loc_);
} }
lex_number: lex_number:
@ -621,9 +581,9 @@ lex_number:
throw comp_error(loc_, "invalid number literal"); throw comp_error(loc_, "invalid number literal");
if (state_ == state::field || dot || flt) if (state_ == state::field || dot || flt)
return iw6::parser::make_FLOAT(std::string(buffer_.data, buffer_.length), loc_); return parser::make_FLOAT(std::string(buffer_.data, buffer_.length), loc_);
return iw6::parser::make_INTEGER(std::string(buffer_.data, buffer_.length), loc_); return parser::make_INTEGER(std::string(buffer_.data, buffer_.length), loc_);
} }
else if (curr == 'o') else if (curr == 'o')
{ {
@ -655,7 +615,7 @@ lex_number:
if (last == '\'' || buffer_.length <= 0) if (last == '\'' || buffer_.length <= 0)
throw comp_error(loc_, "invalid octal literal"); throw comp_error(loc_, "invalid octal literal");
return iw6::parser::make_INTEGER(xsk::utils::string::oct_to_dec(buffer_.data), loc_); return parser::make_INTEGER(xsk::utils::string::oct_to_dec(buffer_.data), loc_);
} }
else if (curr == 'b') else if (curr == 'b')
{ {
@ -689,7 +649,7 @@ lex_number:
if (last == '\'' || buffer_.length < 3) if (last == '\'' || buffer_.length < 3)
throw comp_error(loc_, "invalid binary literal"); throw comp_error(loc_, "invalid binary literal");
return iw6::parser::make_INTEGER(xsk::utils::string::bin_to_dec(buffer_.data), loc_); return parser::make_INTEGER(xsk::utils::string::bin_to_dec(buffer_.data), loc_);
} }
else if (curr == 'x') else if (curr == 'x')
{ {
@ -723,176 +683,59 @@ lex_number:
if (last == '\'' || buffer_.length < 3) if (last == '\'' || buffer_.length < 3)
throw comp_error(loc_, "invalid hexadecimal literal"); throw comp_error(loc_, "invalid hexadecimal literal");
return iw6::parser::make_INTEGER(xsk::utils::string::hex_to_dec(buffer_.data), loc_); return parser::make_INTEGER(xsk::utils::string::hex_to_dec(buffer_.data), loc_);
} }
// cant get here! // cant get here!
} }
} }
auto lexer::keyword_token(keyword k) -> xsk::gsc::iw6::parser::symbol_type const std::unordered_map<std::string_view, parser::token::token_kind_type> lexer::keyword_map
{
switch (k)
{
case keyword::KW_pre_inline:
return iw6::parser::make_INLINE(loc_);
case keyword::KW_pre_include:
return iw6::parser::make_INCLUDE(loc_);
case keyword::KW_pre_using_animtree:
return iw6::parser::make_USINGTREE(loc_);
case keyword::KW_pre_animtree:
return iw6::parser::make_ANIMTREE(loc_);
case keyword::KW_endon:
return iw6::parser::make_ENDON(loc_);
case keyword::KW_notify:
return iw6::parser::make_NOTIFY(loc_);
case keyword::KW_wait:
return iw6::parser::make_WAIT(loc_);
case keyword::KW_waittill:
return iw6::parser::make_WAITTILL(loc_);
case keyword::KW_waittillmatch:
return iw6::parser::make_WAITTILLMATCH(loc_);
case keyword::KW_waittillframeend:
return iw6::parser::make_WAITTILLFRAMEEND(loc_);
case keyword::KW_if:
return iw6::parser::make_IF(loc_);
case keyword::KW_else:
return iw6::parser::make_ELSE(loc_);
case keyword::KW_do:
return iw6::parser::make_DO(loc_);
case keyword::KW_while:
return iw6::parser::make_WHILE(loc_);
case keyword::KW_for:
return iw6::parser::make_FOR(loc_);
case keyword::KW_foreach:
return iw6::parser::make_FOREACH(loc_);
case keyword::KW_in:
return iw6::parser::make_IN(loc_);
case keyword::KW_switch:
return iw6::parser::make_SWITCH(loc_);
case keyword::KW_case:
return iw6::parser::make_CASE(loc_);
case keyword::KW_default:
return iw6::parser::make_DEFAULT(loc_);
case keyword::KW_break:
return iw6::parser::make_BREAK(loc_);
case keyword::KW_continue:
return iw6::parser::make_CONTINUE(loc_);
case keyword::KW_return:
return iw6::parser::make_RETURN(loc_);
case keyword::KW_breakpoint:
return iw6::parser::make_BREAKPOINT(loc_);
case keyword::KW_prof_begin:
return iw6::parser::make_PROFBEGIN(loc_);
case keyword::KW_prof_end:
return iw6::parser::make_PROFEND(loc_);
case keyword::KW_thread:
return iw6::parser::make_THREAD(loc_);
case keyword::KW_childthread:
return iw6::parser::make_CHILDTHREAD(loc_);
case keyword::KW_thisthread:
return iw6::parser::make_THISTHREAD(loc_);
case keyword::KW_call:
return iw6::parser::make_CALL(loc_);
case keyword::KW_true:
return iw6::parser::make_TRUE(loc_);
case keyword::KW_false:
return iw6::parser::make_FALSE(loc_);
case keyword::KW_undefined:
return iw6::parser::make_UNDEFINED(loc_);
case keyword::KW_dotsize:
return iw6::parser::make_SIZE(loc_);
case keyword::KW_game:
return iw6::parser::make_GAME(loc_);
case keyword::KW_self:
return iw6::parser::make_SELF(loc_);
case keyword::KW_anim:
return iw6::parser::make_ANIM(loc_);
case keyword::KW_level:
return iw6::parser::make_LEVEL(loc_);
default:
throw error("gsc lexer: INVALID KEYWORD TOKEN!");
}
}
auto lexer::keyword_is_token(keyword k) -> bool
{
switch (k)
{
/* case keyword::KW_pre_define:
case keyword::KW_pre_undef:
case keyword::KW_pre_ifdef:
case keyword::KW_pre_ifndef:
case keyword::KW_pre_if:
case keyword::KW_pre_elif:
case keyword::KW_pre_else:
case keyword::KW_pre_endif:*/
case keyword::KW_INVALID:
return false;
default:
return true;
}
}
auto lexer::get_keyword(std::string_view str) -> keyword
{
auto itr = keywords.find(str);
if(itr != keywords.end())
{
return itr->second;
}
return keyword::KW_INVALID;
}
std::unordered_map<std::string_view, keyword> lexer::keywords
{{ {{
/* { "#define", keyword::KW_pre_define }, { "#define", parser::token::HSDEFINE },
{ "#undef", keyword::KW_pre_undef }, { "#undef", parser::token::HSUNDEF },
{ "#ifdef", keyword::KW_pre_ifdef }, { "#ifdef", parser::token::HSIFDEF },
{ "#ifndef", keyword::KW_pre_ifndef }, { "#ifndef", parser::token::HSIFNDEF },
{ "#if", keyword::KW_pre_if }, { "#if", parser::token::HSIF },
{ "#elif", keyword::KW_pre_elif }, { "#elif", parser::token::HSELIF },
{ "#else", keyword::KW_pre_else }, { "#else", parser::token::HSELSE },
{ "#endif", keyword::KW_pre_endif },*/ { "#endif", parser::token::HSENDIF },
{ "#inline", keyword::KW_pre_inline }, { "#inline", parser::token::INLINE },
{ "#include", keyword::KW_pre_include }, { "#include", parser::token::INCLUDE },
{ "#using_animtree", keyword::KW_pre_using_animtree }, { "#using_animtree", parser::token::USINGTREE },
{ "#animtree", keyword::KW_pre_animtree }, { "#animtree", parser::token::ANIMTREE },
{ "endon", keyword::KW_endon }, { "endon", parser::token::ENDON },
{ "notify", keyword::KW_notify }, { "notify", parser::token::NOTIFY },
{ "wait", keyword::KW_wait }, { "wait", parser::token::WAIT },
{ "waittill", keyword::KW_waittill }, { "waittill", parser::token::WAITTILL },
{ "waittillmatch", keyword::KW_waittillmatch }, { "waittillmatch", parser::token::WAITTILLMATCH },
{ "waittillframeend", keyword::KW_waittillframeend }, { "waittillframeend", parser::token::WAITTILLFRAMEEND },
{ "if", keyword::KW_if }, { "if", parser::token::IF },
{ "else", keyword::KW_else }, { "else", parser::token::ELSE },
{ "do", keyword::KW_do }, { "do", parser::token::DO },
{ "while", keyword::KW_while }, { "while", parser::token::WHILE },
{ "for", keyword::KW_for }, { "for", parser::token::FOR },
{ "foreach", keyword::KW_foreach }, { "foreach", parser::token::FOREACH },
{ "in", keyword::KW_in }, { "in", parser::token::IN },
{ "switch", keyword::KW_switch }, { "switch", parser::token::SWITCH },
{ "case", keyword::KW_case }, { "case", parser::token::CASE },
{ "default", keyword::KW_default }, { "default", parser::token::DEFAULT },
{ "break", keyword::KW_break }, { "break", parser::token::BREAK },
{ "continue", keyword::KW_continue }, { "continue", parser::token::CONTINUE },
{ "return", keyword::KW_return }, { "return", parser::token::RETURN },
{ "breakpoint", keyword::KW_breakpoint }, { "breakpoint", parser::token::BREAKPOINT },
{ "prof_begin", keyword::KW_prof_begin }, { "prof_begin", parser::token::PROFBEGIN },
{ "prof_end", keyword::KW_prof_end }, { "prof_end", parser::token::PROFEND },
{ "thread", keyword::KW_thread }, { "thread", parser::token::THREAD },
{ "childthread", keyword::KW_childthread }, { "childthread", parser::token::CHILDTHREAD },
{ "thisthread", keyword::KW_thisthread }, { "thisthread", parser::token::THISTHREAD },
{ "call", keyword::KW_call }, { "call", parser::token::CALL },
{ "true", keyword::KW_true }, { "true", parser::token::TRUE },
{ "false", keyword::KW_false }, { "false", parser::token::FALSE },
{ "undefined", keyword::KW_undefined }, { "undefined", parser::token::UNDEFINED },
{ ".size", keyword::KW_dotsize }, { "game", parser::token::GAME },
{ "game", keyword::KW_game }, { "self", parser::token::SELF },
{ "self", keyword::KW_self }, { "anim", parser::token::ANIM },
{ "anim", keyword::KW_anim }, { "level", parser::token::LEVEL },
{ "level", keyword::KW_level },
}}; }};
} // namespace xsk::gsc::iw6 } // namespace xsk::gsc::iw6

View File

@ -10,8 +10,6 @@
namespace xsk::gsc::iw6 namespace xsk::gsc::iw6
{ {
enum class keyword;
constexpr size_t max_buf_size = 0x2000; constexpr size_t max_buf_size = 0x2000;
struct buffer struct buffer
@ -53,26 +51,22 @@ class lexer
reader reader_; reader reader_;
buffer buffer_; buffer buffer_;
location loc_; location loc_;
build mode_;
std::stack<location> locs_; std::stack<location> locs_;
std::stack<reader> readers_; std::stack<reader> readers_;
std::uint32_t header_top_; std::uint32_t header_top_;
state state_; state state_;
build mode_;
bool indev_; bool indev_;
public: public:
lexer(const std::string& name, const char* data, size_t size); lexer(const std::string& name, const char* data, size_t size);
auto lex() -> xsk::gsc::iw6::parser::symbol_type; auto lex() -> parser::symbol_type;
void push_header(const std::string& file); void push_header(const std::string& file);
void pop_header(); void pop_header();
void restrict_header(const xsk::gsc::location& loc); void ban_header(const location& loc);
private: private:
auto keyword_token(keyword k) -> xsk::gsc::iw6::parser::symbol_type; static const std::unordered_map<std::string_view, parser::token::token_kind_type> keyword_map;
static auto keyword_is_token(keyword k) -> bool;
static auto get_keyword(std::string_view str) -> keyword;
static std::unordered_map<std::string_view, keyword> keywords;
}; };
} // namespace xsk::gsc::iw6 } // namespace xsk::gsc::iw6

File diff suppressed because it is too large Load Diff

View File

@ -674,108 +674,116 @@ namespace xsk { namespace gsc { namespace iw6 {
IW6EOF = 0, // "end of file" IW6EOF = 0, // "end of file"
IW6error = 1, // error IW6error = 1, // error
IW6UNDEF = 2, // "invalid token" IW6UNDEF = 2, // "invalid token"
DEVBEGIN = 3, // "/#" HSDEFINE = 3, // "#define"
DEVEND = 4, // "#/" HSUNDEF = 4, // "#undef"
INLINE = 5, // "#inline" HSIFDEF = 5, // "#ifdef"
INCLUDE = 6, // "#include" HSIFNDEF = 6, // "#ifndef"
USINGTREE = 7, // "#using_animtree" HSIF = 7, // "#if"
ANIMTREE = 8, // "#animtree" HSELIF = 8, // "#elif"
ENDON = 9, // "endon" HSELSE = 9, // "#else"
NOTIFY = 10, // "notify" HSENDIF = 10, // "#endif"
WAIT = 11, // "wait" DEVBEGIN = 11, // "/#"
WAITTILL = 12, // "waittill" DEVEND = 12, // "#/"
WAITTILLMATCH = 13, // "waittillmatch" INLINE = 13, // "#inline"
WAITTILLFRAMEEND = 14, // "waittillframeend" INCLUDE = 14, // "#include"
IF = 15, // "if" USINGTREE = 15, // "#using_animtree"
ELSE = 16, // "else" ANIMTREE = 16, // "#animtree"
DO = 17, // "do" ENDON = 17, // "endon"
WHILE = 18, // "while" NOTIFY = 18, // "notify"
FOR = 19, // "for" WAIT = 19, // "wait"
FOREACH = 20, // "foreach" WAITTILL = 20, // "waittill"
IN = 21, // "in" WAITTILLMATCH = 21, // "waittillmatch"
SWITCH = 22, // "switch" WAITTILLFRAMEEND = 22, // "waittillframeend"
CASE = 23, // "case" IF = 23, // "if"
DEFAULT = 24, // "default" ELSE = 24, // "else"
BREAK = 25, // "break" DO = 25, // "do"
CONTINUE = 26, // "continue" WHILE = 26, // "while"
RETURN = 27, // "return" FOR = 27, // "for"
BREAKPOINT = 28, // "breakpoint" FOREACH = 28, // "foreach"
PROFBEGIN = 29, // "prof_begin" IN = 29, // "in"
PROFEND = 30, // "prof_end" SWITCH = 30, // "switch"
THREAD = 31, // "thread" CASE = 31, // "case"
CHILDTHREAD = 32, // "childthread" DEFAULT = 32, // "default"
THISTHREAD = 33, // "thisthread" BREAK = 33, // "break"
CALL = 34, // "call" CONTINUE = 34, // "continue"
TRUE = 35, // "true" RETURN = 35, // "return"
FALSE = 36, // "false" BREAKPOINT = 36, // "breakpoint"
UNDEFINED = 37, // "undefined" PROFBEGIN = 37, // "prof_begin"
SIZE = 38, // ".size" PROFEND = 38, // "prof_end"
GAME = 39, // "game" THREAD = 39, // "thread"
SELF = 40, // "self" CHILDTHREAD = 40, // "childthread"
ANIM = 41, // "anim" THISTHREAD = 41, // "thisthread"
LEVEL = 42, // "level" CALL = 42, // "call"
LPAREN = 43, // "(" TRUE = 43, // "true"
RPAREN = 44, // ")" FALSE = 44, // "false"
LBRACE = 45, // "{" UNDEFINED = 45, // "undefined"
RBRACE = 46, // "}" SIZE = 46, // ".size"
LBRACKET = 47, // "[" GAME = 47, // "game"
RBRACKET = 48, // "]" SELF = 48, // "self"
COMMA = 49, // "," ANIM = 49, // "anim"
DOT = 50, // "." LEVEL = 50, // "level"
DOUBLECOLON = 51, // "::" LPAREN = 51, // "("
COLON = 52, // ":" RPAREN = 52, // ")"
SEMICOLON = 53, // ";" LBRACE = 53, // "{"
QMARK = 54, // "?" RBRACE = 54, // "}"
INCREMENT = 55, // "++" LBRACKET = 55, // "["
DECREMENT = 56, // "--" RBRACKET = 56, // "]"
LSHIFT = 57, // "<<" COMMA = 57, // ","
RSHIFT = 58, // ">>" DOT = 58, // "."
OR = 59, // "||" DOUBLECOLON = 59, // "::"
AND = 60, // "&&" COLON = 60, // ":"
EQUALITY = 61, // "==" SEMICOLON = 61, // ";"
INEQUALITY = 62, // "!=" QMARK = 62, // "?"
LESS_EQUAL = 63, // "<=" INCREMENT = 63, // "++"
GREATER_EQUAL = 64, // ">=" DECREMENT = 64, // "--"
LESS = 65, // "<" LSHIFT = 65, // "<<"
GREATER = 66, // ">" RSHIFT = 66, // ">>"
NOT = 67, // "!" OR = 67, // "||"
COMPLEMENT = 68, // "~" AND = 68, // "&&"
ASSIGN = 69, // "=" EQUALITY = 69, // "=="
ASSIGN_ADD = 70, // "+=" INEQUALITY = 70, // "!="
ASSIGN_SUB = 71, // "-=" LESS_EQUAL = 71, // "<="
ASSIGN_MUL = 72, // "*=" GREATER_EQUAL = 72, // ">="
ASSIGN_DIV = 73, // "/=" LESS = 73, // "<"
ASSIGN_MOD = 74, // "%=" GREATER = 74, // ">"
ASSIGN_BW_OR = 75, // "|=" NOT = 75, // "!"
ASSIGN_BW_AND = 76, // "&=" COMPLEMENT = 76, // "~"
ASSIGN_BW_EXOR = 77, // "^=" ASSIGN = 77, // "="
ASSIGN_RSHIFT = 78, // ">>=" ASSIGN_ADD = 78, // "+="
ASSIGN_LSHIFT = 79, // "<<=" ASSIGN_SUB = 79, // "-="
BITWISE_OR = 80, // "|" ASSIGN_MUL = 80, // "*="
BITWISE_AND = 81, // "&" ASSIGN_DIV = 81, // "/="
BITWISE_EXOR = 82, // "^" ASSIGN_MOD = 82, // "%="
ADD = 83, // "+" ASSIGN_BW_OR = 83, // "|="
SUB = 84, // "-" ASSIGN_BW_AND = 84, // "&="
MUL = 85, // "*" ASSIGN_BW_EXOR = 85, // "^="
DIV = 86, // "/" ASSIGN_RSHIFT = 86, // ">>="
MOD = 87, // "%" ASSIGN_LSHIFT = 87, // "<<="
FIELD = 88, // "field" BITWISE_OR = 88, // "|"
PATH = 89, // "path" BITWISE_AND = 89, // "&"
IDENTIFIER = 90, // "identifier" BITWISE_EXOR = 90, // "^"
STRING = 91, // "string literal" ADD = 91, // "+"
ISTRING = 92, // "localized string" SUB = 92, // "-"
COLOR = 93, // "color" MUL = 93, // "*"
FLOAT = 94, // "float" DIV = 94, // "/"
INTEGER = 95, // "integer" MOD = 95, // "%"
ADD_ARRAY = 96, // ADD_ARRAY FIELD = 96, // "field"
THEN = 97, // THEN PATH = 97, // "path"
TERN = 98, // TERN IDENTIFIER = 98, // "identifier"
NEG = 99, // NEG STRING = 99, // "string literal"
ANIMREF = 100, // ANIMREF ISTRING = 100, // "localized string"
PREINC = 101, // PREINC COLOR = 101, // "color"
PREDEC = 102, // PREDEC FLOAT = 102, // "float"
POSTINC = 103, // POSTINC INTEGER = 103, // "integer"
POSTDEC = 104 // POSTDEC ADD_ARRAY = 104, // ADD_ARRAY
THEN = 105, // THEN
TERN = 106, // TERN
NEG = 107, // NEG
ANIMREF = 108, // ANIMREF
PREINC = 109, // PREINC
PREDEC = 110, // PREDEC
POSTINC = 111, // POSTINC
POSTDEC = 112 // POSTDEC
}; };
/// Backward compatibility alias (Bison 3.6). /// Backward compatibility alias (Bison 3.6).
typedef token_kind_type yytokentype; typedef token_kind_type yytokentype;
@ -792,193 +800,201 @@ namespace xsk { namespace gsc { namespace iw6 {
{ {
enum symbol_kind_type enum symbol_kind_type
{ {
YYNTOKENS = 105, ///< Number of tokens. YYNTOKENS = 113, ///< Number of tokens.
S_YYEMPTY = -2, S_YYEMPTY = -2,
S_YYEOF = 0, // "end of file" S_YYEOF = 0, // "end of file"
S_YYerror = 1, // error S_YYerror = 1, // error
S_YYUNDEF = 2, // "invalid token" S_YYUNDEF = 2, // "invalid token"
S_DEVBEGIN = 3, // "/#" S_HSDEFINE = 3, // "#define"
S_DEVEND = 4, // "#/" S_HSUNDEF = 4, // "#undef"
S_INLINE = 5, // "#inline" S_HSIFDEF = 5, // "#ifdef"
S_INCLUDE = 6, // "#include" S_HSIFNDEF = 6, // "#ifndef"
S_USINGTREE = 7, // "#using_animtree" S_HSIF = 7, // "#if"
S_ANIMTREE = 8, // "#animtree" S_HSELIF = 8, // "#elif"
S_ENDON = 9, // "endon" S_HSELSE = 9, // "#else"
S_NOTIFY = 10, // "notify" S_HSENDIF = 10, // "#endif"
S_WAIT = 11, // "wait" S_DEVBEGIN = 11, // "/#"
S_WAITTILL = 12, // "waittill" S_DEVEND = 12, // "#/"
S_WAITTILLMATCH = 13, // "waittillmatch" S_INLINE = 13, // "#inline"
S_WAITTILLFRAMEEND = 14, // "waittillframeend" S_INCLUDE = 14, // "#include"
S_IF = 15, // "if" S_USINGTREE = 15, // "#using_animtree"
S_ELSE = 16, // "else" S_ANIMTREE = 16, // "#animtree"
S_DO = 17, // "do" S_ENDON = 17, // "endon"
S_WHILE = 18, // "while" S_NOTIFY = 18, // "notify"
S_FOR = 19, // "for" S_WAIT = 19, // "wait"
S_FOREACH = 20, // "foreach" S_WAITTILL = 20, // "waittill"
S_IN = 21, // "in" S_WAITTILLMATCH = 21, // "waittillmatch"
S_SWITCH = 22, // "switch" S_WAITTILLFRAMEEND = 22, // "waittillframeend"
S_CASE = 23, // "case" S_IF = 23, // "if"
S_DEFAULT = 24, // "default" S_ELSE = 24, // "else"
S_BREAK = 25, // "break" S_DO = 25, // "do"
S_CONTINUE = 26, // "continue" S_WHILE = 26, // "while"
S_RETURN = 27, // "return" S_FOR = 27, // "for"
S_BREAKPOINT = 28, // "breakpoint" S_FOREACH = 28, // "foreach"
S_PROFBEGIN = 29, // "prof_begin" S_IN = 29, // "in"
S_PROFEND = 30, // "prof_end" S_SWITCH = 30, // "switch"
S_THREAD = 31, // "thread" S_CASE = 31, // "case"
S_CHILDTHREAD = 32, // "childthread" S_DEFAULT = 32, // "default"
S_THISTHREAD = 33, // "thisthread" S_BREAK = 33, // "break"
S_CALL = 34, // "call" S_CONTINUE = 34, // "continue"
S_TRUE = 35, // "true" S_RETURN = 35, // "return"
S_FALSE = 36, // "false" S_BREAKPOINT = 36, // "breakpoint"
S_UNDEFINED = 37, // "undefined" S_PROFBEGIN = 37, // "prof_begin"
S_SIZE = 38, // ".size" S_PROFEND = 38, // "prof_end"
S_GAME = 39, // "game" S_THREAD = 39, // "thread"
S_SELF = 40, // "self" S_CHILDTHREAD = 40, // "childthread"
S_ANIM = 41, // "anim" S_THISTHREAD = 41, // "thisthread"
S_LEVEL = 42, // "level" S_CALL = 42, // "call"
S_LPAREN = 43, // "(" S_TRUE = 43, // "true"
S_RPAREN = 44, // ")" S_FALSE = 44, // "false"
S_LBRACE = 45, // "{" S_UNDEFINED = 45, // "undefined"
S_RBRACE = 46, // "}" S_SIZE = 46, // ".size"
S_LBRACKET = 47, // "[" S_GAME = 47, // "game"
S_RBRACKET = 48, // "]" S_SELF = 48, // "self"
S_COMMA = 49, // "," S_ANIM = 49, // "anim"
S_DOT = 50, // "." S_LEVEL = 50, // "level"
S_DOUBLECOLON = 51, // "::" S_LPAREN = 51, // "("
S_COLON = 52, // ":" S_RPAREN = 52, // ")"
S_SEMICOLON = 53, // ";" S_LBRACE = 53, // "{"
S_QMARK = 54, // "?" S_RBRACE = 54, // "}"
S_INCREMENT = 55, // "++" S_LBRACKET = 55, // "["
S_DECREMENT = 56, // "--" S_RBRACKET = 56, // "]"
S_LSHIFT = 57, // "<<" S_COMMA = 57, // ","
S_RSHIFT = 58, // ">>" S_DOT = 58, // "."
S_OR = 59, // "||" S_DOUBLECOLON = 59, // "::"
S_AND = 60, // "&&" S_COLON = 60, // ":"
S_EQUALITY = 61, // "==" S_SEMICOLON = 61, // ";"
S_INEQUALITY = 62, // "!=" S_QMARK = 62, // "?"
S_LESS_EQUAL = 63, // "<=" S_INCREMENT = 63, // "++"
S_GREATER_EQUAL = 64, // ">=" S_DECREMENT = 64, // "--"
S_LESS = 65, // "<" S_LSHIFT = 65, // "<<"
S_GREATER = 66, // ">" S_RSHIFT = 66, // ">>"
S_NOT = 67, // "!" S_OR = 67, // "||"
S_COMPLEMENT = 68, // "~" S_AND = 68, // "&&"
S_ASSIGN = 69, // "=" S_EQUALITY = 69, // "=="
S_ASSIGN_ADD = 70, // "+=" S_INEQUALITY = 70, // "!="
S_ASSIGN_SUB = 71, // "-=" S_LESS_EQUAL = 71, // "<="
S_ASSIGN_MUL = 72, // "*=" S_GREATER_EQUAL = 72, // ">="
S_ASSIGN_DIV = 73, // "/=" S_LESS = 73, // "<"
S_ASSIGN_MOD = 74, // "%=" S_GREATER = 74, // ">"
S_ASSIGN_BW_OR = 75, // "|=" S_NOT = 75, // "!"
S_ASSIGN_BW_AND = 76, // "&=" S_COMPLEMENT = 76, // "~"
S_ASSIGN_BW_EXOR = 77, // "^=" S_ASSIGN = 77, // "="
S_ASSIGN_RSHIFT = 78, // ">>=" S_ASSIGN_ADD = 78, // "+="
S_ASSIGN_LSHIFT = 79, // "<<=" S_ASSIGN_SUB = 79, // "-="
S_BITWISE_OR = 80, // "|" S_ASSIGN_MUL = 80, // "*="
S_BITWISE_AND = 81, // "&" S_ASSIGN_DIV = 81, // "/="
S_BITWISE_EXOR = 82, // "^" S_ASSIGN_MOD = 82, // "%="
S_ADD = 83, // "+" S_ASSIGN_BW_OR = 83, // "|="
S_SUB = 84, // "-" S_ASSIGN_BW_AND = 84, // "&="
S_MUL = 85, // "*" S_ASSIGN_BW_EXOR = 85, // "^="
S_DIV = 86, // "/" S_ASSIGN_RSHIFT = 86, // ">>="
S_MOD = 87, // "%" S_ASSIGN_LSHIFT = 87, // "<<="
S_FIELD = 88, // "field" S_BITWISE_OR = 88, // "|"
S_PATH = 89, // "path" S_BITWISE_AND = 89, // "&"
S_IDENTIFIER = 90, // "identifier" S_BITWISE_EXOR = 90, // "^"
S_STRING = 91, // "string literal" S_ADD = 91, // "+"
S_ISTRING = 92, // "localized string" S_SUB = 92, // "-"
S_COLOR = 93, // "color" S_MUL = 93, // "*"
S_FLOAT = 94, // "float" S_DIV = 94, // "/"
S_INTEGER = 95, // "integer" S_MOD = 95, // "%"
S_ADD_ARRAY = 96, // ADD_ARRAY S_FIELD = 96, // "field"
S_THEN = 97, // THEN S_PATH = 97, // "path"
S_TERN = 98, // TERN S_IDENTIFIER = 98, // "identifier"
S_NEG = 99, // NEG S_STRING = 99, // "string literal"
S_ANIMREF = 100, // ANIMREF S_ISTRING = 100, // "localized string"
S_PREINC = 101, // PREINC S_COLOR = 101, // "color"
S_PREDEC = 102, // PREDEC S_FLOAT = 102, // "float"
S_POSTINC = 103, // POSTINC S_INTEGER = 103, // "integer"
S_POSTDEC = 104, // POSTDEC S_ADD_ARRAY = 104, // ADD_ARRAY
S_YYACCEPT = 105, // $accept S_THEN = 105, // THEN
S_root = 106, // root S_TERN = 106, // TERN
S_program = 107, // program S_NEG = 107, // NEG
S_inline = 108, // inline S_ANIMREF = 108, // ANIMREF
S_include = 109, // include S_PREINC = 109, // PREINC
S_declaration = 110, // declaration S_PREDEC = 110, // PREDEC
S_decl_usingtree = 111, // decl_usingtree S_POSTINC = 111, // POSTINC
S_decl_constant = 112, // decl_constant S_POSTDEC = 112, // POSTDEC
S_decl_thread = 113, // decl_thread S_YYACCEPT = 113, // $accept
S_stmt = 114, // stmt S_root = 114, // root
S_stmt_dev = 115, // stmt_dev S_program = 115, // program
S_stmt_block = 116, // stmt_block S_inline = 116, // inline
S_stmt_list = 117, // stmt_list S_include = 117, // include
S_stmt_expr = 118, // stmt_expr S_declaration = 118, // declaration
S_stmt_call = 119, // stmt_call S_decl_usingtree = 119, // decl_usingtree
S_stmt_assign = 120, // stmt_assign S_decl_constant = 120, // decl_constant
S_stmt_endon = 121, // stmt_endon S_decl_thread = 121, // decl_thread
S_stmt_notify = 122, // stmt_notify S_stmt = 122, // stmt
S_stmt_wait = 123, // stmt_wait S_stmt_dev = 123, // stmt_dev
S_stmt_waittill = 124, // stmt_waittill S_stmt_block = 124, // stmt_block
S_stmt_waittillmatch = 125, // stmt_waittillmatch S_stmt_list = 125, // stmt_list
S_stmt_waittillframeend = 126, // stmt_waittillframeend S_stmt_expr = 126, // stmt_expr
S_stmt_if = 127, // stmt_if S_stmt_call = 127, // stmt_call
S_stmt_ifelse = 128, // stmt_ifelse S_stmt_assign = 128, // stmt_assign
S_stmt_while = 129, // stmt_while S_stmt_endon = 129, // stmt_endon
S_stmt_dowhile = 130, // stmt_dowhile S_stmt_notify = 130, // stmt_notify
S_stmt_for = 131, // stmt_for S_stmt_wait = 131, // stmt_wait
S_stmt_foreach = 132, // stmt_foreach S_stmt_waittill = 132, // stmt_waittill
S_stmt_switch = 133, // stmt_switch S_stmt_waittillmatch = 133, // stmt_waittillmatch
S_stmt_case = 134, // stmt_case S_stmt_waittillframeend = 134, // stmt_waittillframeend
S_stmt_default = 135, // stmt_default S_stmt_if = 135, // stmt_if
S_stmt_break = 136, // stmt_break S_stmt_ifelse = 136, // stmt_ifelse
S_stmt_continue = 137, // stmt_continue S_stmt_while = 137, // stmt_while
S_stmt_return = 138, // stmt_return S_stmt_dowhile = 138, // stmt_dowhile
S_stmt_breakpoint = 139, // stmt_breakpoint S_stmt_for = 139, // stmt_for
S_stmt_prof_begin = 140, // stmt_prof_begin S_stmt_foreach = 140, // stmt_foreach
S_stmt_prof_end = 141, // stmt_prof_end S_stmt_switch = 141, // stmt_switch
S_expr = 142, // expr S_stmt_case = 142, // stmt_case
S_expr_or_empty = 143, // expr_or_empty S_stmt_default = 143, // stmt_default
S_expr_assign = 144, // expr_assign S_stmt_break = 144, // stmt_break
S_expr_increment = 145, // expr_increment S_stmt_continue = 145, // stmt_continue
S_expr_decrement = 146, // expr_decrement S_stmt_return = 146, // stmt_return
S_expr_ternary = 147, // expr_ternary S_stmt_breakpoint = 147, // stmt_breakpoint
S_expr_binary = 148, // expr_binary S_stmt_prof_begin = 148, // stmt_prof_begin
S_expr_primitive = 149, // expr_primitive S_stmt_prof_end = 149, // stmt_prof_end
S_expr_complement = 150, // expr_complement S_expr = 150, // expr
S_expr_not = 151, // expr_not S_expr_or_empty = 151, // expr_or_empty
S_expr_call = 152, // expr_call S_expr_assign = 152, // expr_assign
S_expr_method = 153, // expr_method S_expr_increment = 153, // expr_increment
S_expr_function = 154, // expr_function S_expr_decrement = 154, // expr_decrement
S_expr_pointer = 155, // expr_pointer S_expr_ternary = 155, // expr_ternary
S_expr_add_array = 156, // expr_add_array S_expr_binary = 156, // expr_binary
S_expr_parameters = 157, // expr_parameters S_expr_primitive = 157, // expr_primitive
S_expr_arguments = 158, // expr_arguments S_expr_complement = 158, // expr_complement
S_expr_arguments_no_empty = 159, // expr_arguments_no_empty S_expr_not = 159, // expr_not
S_expr_reference = 160, // expr_reference S_expr_call = 160, // expr_call
S_expr_array = 161, // expr_array S_expr_method = 161, // expr_method
S_expr_field = 162, // expr_field S_expr_function = 162, // expr_function
S_expr_size = 163, // expr_size S_expr_pointer = 163, // expr_pointer
S_expr_paren = 164, // expr_paren S_expr_add_array = 164, // expr_add_array
S_expr_object = 165, // expr_object S_expr_parameters = 165, // expr_parameters
S_expr_thisthread = 166, // expr_thisthread S_expr_arguments = 166, // expr_arguments
S_expr_empty_array = 167, // expr_empty_array S_expr_arguments_no_empty = 167, // expr_arguments_no_empty
S_expr_undefined = 168, // expr_undefined S_expr_reference = 168, // expr_reference
S_expr_game = 169, // expr_game S_expr_array = 169, // expr_array
S_expr_self = 170, // expr_self S_expr_field = 170, // expr_field
S_expr_anim = 171, // expr_anim S_expr_size = 171, // expr_size
S_expr_level = 172, // expr_level S_expr_paren = 172, // expr_paren
S_expr_animation = 173, // expr_animation S_expr_object = 173, // expr_object
S_expr_animtree = 174, // expr_animtree S_expr_thisthread = 174, // expr_thisthread
S_expr_identifier = 175, // expr_identifier S_expr_empty_array = 175, // expr_empty_array
S_expr_path = 176, // expr_path S_expr_undefined = 176, // expr_undefined
S_expr_istring = 177, // expr_istring S_expr_game = 177, // expr_game
S_expr_string = 178, // expr_string S_expr_self = 178, // expr_self
S_expr_color = 179, // expr_color S_expr_anim = 179, // expr_anim
S_expr_vector = 180, // expr_vector S_expr_level = 180, // expr_level
S_expr_float = 181, // expr_float S_expr_animation = 181, // expr_animation
S_expr_integer = 182, // expr_integer S_expr_animtree = 182, // expr_animtree
S_expr_false = 183, // expr_false S_expr_identifier = 183, // expr_identifier
S_expr_true = 184 // expr_true S_expr_path = 184, // expr_path
S_expr_istring = 185, // expr_istring
S_expr_string = 186, // expr_string
S_expr_color = 187, // expr_color
S_expr_vector = 188, // expr_vector
S_expr_float = 189, // expr_float
S_expr_integer = 190, // expr_integer
S_expr_false = 191, // expr_false
S_expr_true = 192 // expr_true
}; };
}; };
@ -2751,6 +2767,126 @@ switch (yykind)
return symbol_type (token::IW6UNDEF, l); return symbol_type (token::IW6UNDEF, l);
} }
#endif #endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_HSDEFINE (location_type l)
{
return symbol_type (token::HSDEFINE, std::move (l));
}
#else
static
symbol_type
make_HSDEFINE (const location_type& l)
{
return symbol_type (token::HSDEFINE, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_HSUNDEF (location_type l)
{
return symbol_type (token::HSUNDEF, std::move (l));
}
#else
static
symbol_type
make_HSUNDEF (const location_type& l)
{
return symbol_type (token::HSUNDEF, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_HSIFDEF (location_type l)
{
return symbol_type (token::HSIFDEF, std::move (l));
}
#else
static
symbol_type
make_HSIFDEF (const location_type& l)
{
return symbol_type (token::HSIFDEF, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_HSIFNDEF (location_type l)
{
return symbol_type (token::HSIFNDEF, std::move (l));
}
#else
static
symbol_type
make_HSIFNDEF (const location_type& l)
{
return symbol_type (token::HSIFNDEF, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_HSIF (location_type l)
{
return symbol_type (token::HSIF, std::move (l));
}
#else
static
symbol_type
make_HSIF (const location_type& l)
{
return symbol_type (token::HSIF, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_HSELIF (location_type l)
{
return symbol_type (token::HSELIF, std::move (l));
}
#else
static
symbol_type
make_HSELIF (const location_type& l)
{
return symbol_type (token::HSELIF, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_HSELSE (location_type l)
{
return symbol_type (token::HSELSE, std::move (l));
}
#else
static
symbol_type
make_HSELSE (const location_type& l)
{
return symbol_type (token::HSELSE, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_HSENDIF (location_type l)
{
return symbol_type (token::HSENDIF, std::move (l));
}
#else
static
symbol_type
make_HSENDIF (const location_type& l)
{
return symbol_type (token::HSENDIF, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS #if 201103L <= YY_CPLUSPLUS
static static
symbol_type symbol_type
@ -5311,7 +5447,7 @@ switch (yykind)
#line 13 "parser.ypp" #line 13 "parser.ypp"
} } } // xsk::gsc::iw6 } } } // xsk::gsc::iw6
#line 5315 "parser.hpp" #line 5451 "parser.hpp"

View File

@ -16,57 +16,6 @@ xsk::gsc::iw7::parser::symbol_type IW7lex(xsk::gsc::iw7::lexer& lexer)
namespace xsk::gsc::iw7 namespace xsk::gsc::iw7
{ {
enum class keyword
{
/* KW_pre_define,
KW_pre_undef,
KW_pre_ifdef,
KW_pre_ifndef,
KW_pre_if,
KW_pre_elif,
KW_pre_else,
KW_pre_endif,*/
KW_pre_inline,
KW_pre_include,
KW_pre_using_animtree,
KW_pre_animtree,
KW_endon,
KW_notify,
KW_wait,
KW_waittill,
KW_waittillmatch,
KW_waittillframeend,
KW_if,
KW_else,
KW_do,
KW_while,
KW_for,
KW_foreach,
KW_in,
KW_switch,
KW_case,
KW_default,
KW_break,
KW_continue,
KW_return,
KW_breakpoint,
KW_prof_begin,
KW_prof_end,
KW_thread,
KW_childthread,
KW_thisthread,
KW_call,
KW_true,
KW_false,
KW_undefined,
KW_dotsize,
KW_game,
KW_self,
KW_anim,
KW_level,
KW_INVALID,
};
buffer::buffer() : length(0) buffer::buffer() : length(0)
{ {
data = static_cast<char*>(std::malloc(max_buf_size)); data = static_cast<char*>(std::malloc(max_buf_size));
@ -129,7 +78,7 @@ void reader::advance()
} }
} }
lexer::lexer(const std::string& name, const char* data, size_t size) : indev_(false), loc_(xsk::gsc::location(&name)), lexer::lexer(const std::string& name, const char* data, size_t size) : indev_(false), loc_(location(&name)),
mode_(build::dev), header_top_(0), locs_(std::stack<location>()), readers_(std::stack<reader>()) mode_(build::dev), header_top_(0), locs_(std::stack<location>()), readers_(std::stack<reader>())
{ {
reader_.init(data, size); reader_.init(data, size);
@ -140,7 +89,7 @@ void lexer::push_header(const std::string& file)
try try
{ {
if (header_top_++ >= 10) if (header_top_++ >= 10)
throw xsk::gsc::error("maximum gsh depth exceeded '10'"); throw comp_error(loc_, "maximum gsh depth exceeded '10'");
auto data = resolver::file_data(file + ".gsh"); auto data = resolver::file_data(file + ".gsh");
@ -151,7 +100,7 @@ void lexer::push_header(const std::string& file)
} }
catch (const std::exception& e) catch (const std::exception& e)
{ {
throw xsk::gsc::error("parsing header file '" + file + "': " + e.what()); throw error("parsing header file '" + file + "': " + e.what());
} }
} }
@ -164,7 +113,7 @@ void lexer::pop_header()
readers_.pop(); readers_.pop();
} }
void lexer::restrict_header(const xsk::gsc::location& loc) void lexer::ban_header(const location& loc)
{ {
if (header_top_ > 0) if (header_top_ > 0)
{ {
@ -172,7 +121,7 @@ void lexer::restrict_header(const xsk::gsc::location& loc)
} }
} }
auto lexer::lex() -> xsk::gsc::iw7::parser::symbol_type auto lexer::lex() -> parser::symbol_type
{ {
buffer_.length = 0; buffer_.length = 0;
state_ = state::start; state_ = state::start;
@ -193,7 +142,7 @@ auto lexer::lex() -> xsk::gsc::iw7::parser::symbol_type
if (header_top_ > 0) if (header_top_ > 0)
pop_header(); pop_header();
else else
return iw7::parser::make_IW7EOF(loc_); return parser::make_IW7EOF(loc_);
} }
reader_.advance(); reader_.advance();
@ -211,22 +160,22 @@ auto lexer::lex() -> xsk::gsc::iw7::parser::symbol_type
continue; continue;
case '/': case '/':
if (curr != '/' && curr != '*' && curr != '#' && curr != '=') if (curr != '/' && curr != '*' && curr != '#' && curr != '=')
return iw7::parser::make_DIV(loc_); return parser::make_DIV(loc_);
reader_.advance(); reader_.advance();
if (last == '=') if (last == '=')
return iw7::parser::make_ASSIGN_DIV(loc_); return parser::make_ASSIGN_DIV(loc_);
if (last == '#') if (last == '#')
{ {
if (indev_) if (indev_)
throw comp_error(loc_, "cannot recurse devblock ('/#')"); throw comp_error(loc_, "cannot recurse devblock ('/#')");
if (mode_ == xsk::gsc::build::dev) if (mode_ == build::dev)
{ {
indev_ = true; indev_ = true;
return iw7::parser::make_DEVBEGIN(loc_); return parser::make_DEVBEGIN(loc_);
} }
else else
{ {
@ -290,7 +239,7 @@ auto lexer::lex() -> xsk::gsc::iw7::parser::symbol_type
indev_ = false; indev_ = false;
reader_.advance(); reader_.advance();
return iw7::parser::make_DEVEND(loc_); return parser::make_DEVEND(loc_);
} }
buffer_.push(last); buffer_.push(last);
@ -303,12 +252,12 @@ auto lexer::lex() -> xsk::gsc::iw7::parser::symbol_type
goto lex_name; goto lex_name;
case '*': case '*':
if (curr != '/' && curr != '=') if (curr != '/' && curr != '=')
return iw7::parser::make_MUL(loc_); return parser::make_MUL(loc_);
reader_.advance(); reader_.advance();
if (last == '=') if (last == '=')
return iw7::parser::make_ASSIGN_MUL(loc_); return parser::make_ASSIGN_MUL(loc_);
throw comp_error(loc_, "unmatched multiline comment end ('*/')"); throw comp_error(loc_, "unmatched multiline comment end ('*/')");
case '"': case '"':
@ -323,127 +272,127 @@ auto lexer::lex() -> xsk::gsc::iw7::parser::symbol_type
state_ = state::field; state_ = state::field;
goto lex_name_or_number; goto lex_name_or_number;
case '(': case '(':
return iw7::parser::make_LPAREN(loc_); return parser::make_LPAREN(loc_);
case ')': case ')':
return iw7::parser::make_RPAREN(loc_); return parser::make_RPAREN(loc_);
case '{': case '{':
return iw7::parser::make_LBRACE(loc_); return parser::make_LBRACE(loc_);
case '}': case '}':
return iw7::parser::make_RBRACE(loc_); return parser::make_RBRACE(loc_);
case '[': case '[':
return iw7::parser::make_LBRACKET(loc_); return parser::make_LBRACKET(loc_);
case ']': case ']':
return iw7::parser::make_RBRACKET(loc_); return parser::make_RBRACKET(loc_);
case ',': case ',':
return iw7::parser::make_COMMA(loc_); return parser::make_COMMA(loc_);
case ';': case ';':
return iw7::parser::make_SEMICOLON(loc_); return parser::make_SEMICOLON(loc_);
case ':': case ':':
if (curr != ':') if (curr != ':')
return iw7::parser::make_COLON(loc_); return parser::make_COLON(loc_);
reader_.advance(); reader_.advance();
return iw7::parser::make_DOUBLECOLON(loc_); return parser::make_DOUBLECOLON(loc_);
case '?': case '?':
return iw7::parser::make_QMARK(loc_); return parser::make_QMARK(loc_);
case '=': case '=':
if (curr != '=') if (curr != '=')
return iw7::parser::make_ASSIGN(loc_); return parser::make_ASSIGN(loc_);
reader_.advance(); reader_.advance();
return iw7::parser::make_EQUALITY(loc_); return parser::make_EQUALITY(loc_);
case '+': case '+':
if (curr != '+' && curr != '=') if (curr != '+' && curr != '=')
return iw7::parser::make_ADD(loc_); return parser::make_ADD(loc_);
reader_.advance(); reader_.advance();
if (last == '+') if (last == '+')
return iw7::parser::make_INCREMENT(loc_); return parser::make_INCREMENT(loc_);
return iw7::parser::make_ASSIGN_ADD(loc_); return parser::make_ASSIGN_ADD(loc_);
case '-': case '-':
if (curr != '-' && curr != '=') if (curr != '-' && curr != '=')
return iw7::parser::make_SUB(loc_); return parser::make_SUB(loc_);
reader_.advance(); reader_.advance();
if (last == '-') if (last == '-')
return iw7::parser::make_DECREMENT(loc_); return parser::make_DECREMENT(loc_);
return iw7::parser::make_ASSIGN_SUB(loc_); return parser::make_ASSIGN_SUB(loc_);
case '%': case '%':
if (curr != '=') if (curr != '=')
return iw7::parser::make_MOD(loc_); return parser::make_MOD(loc_);
reader_.advance(); reader_.advance();
return iw7::parser::make_ASSIGN_MOD(loc_); return parser::make_ASSIGN_MOD(loc_);
case '|': case '|':
if (curr != '|' && curr != '=') if (curr != '|' && curr != '=')
return iw7::parser::make_BITWISE_OR(loc_); return parser::make_BITWISE_OR(loc_);
reader_.advance(); reader_.advance();
if (last == '|') if (last == '|')
return iw7::parser::make_OR(loc_); return parser::make_OR(loc_);
return iw7::parser::make_ASSIGN_BW_OR(loc_); return parser::make_ASSIGN_BW_OR(loc_);
case '&': case '&':
if (curr != '&' && curr != '=' && curr != '"' && curr != '\'') if (curr != '&' && curr != '=' && curr != '"' && curr != '\'')
return iw7::parser::make_BITWISE_AND(loc_); return parser::make_BITWISE_AND(loc_);
reader_.advance(); reader_.advance();
if (last == '&') if (last == '&')
return iw7::parser::make_AND(loc_); return parser::make_AND(loc_);
if (last == '=') if (last == '=')
return iw7::parser::make_ASSIGN_BW_AND(loc_); return parser::make_ASSIGN_BW_AND(loc_);
state_ = state::localize; state_ = state::localize;
goto lex_string; goto lex_string;
case '^': case '^':
if (curr != '=') if (curr != '=')
return iw7::parser::make_BITWISE_EXOR(loc_); return parser::make_BITWISE_EXOR(loc_);
reader_.advance(); reader_.advance();
return iw7::parser::make_ASSIGN_BW_EXOR(loc_); return parser::make_ASSIGN_BW_EXOR(loc_);
case '!': case '!':
if (curr != '=') if (curr != '=')
return iw7::parser::make_NOT(loc_); return parser::make_NOT(loc_);
reader_.advance(); reader_.advance();
return iw7::parser::make_INEQUALITY(loc_); return parser::make_INEQUALITY(loc_);
case '~': case '~':
return iw7::parser::make_COMPLEMENT(loc_); return parser::make_COMPLEMENT(loc_);
case '<': case '<':
if (curr != '<' && curr != '=') if (curr != '<' && curr != '=')
return iw7::parser::make_LESS(loc_); return parser::make_LESS(loc_);
reader_.advance(); reader_.advance();
if (last == '=') if (last == '=')
return iw7::parser::make_LESS_EQUAL(loc_); return parser::make_LESS_EQUAL(loc_);
if (curr != '=') if (curr != '=')
return iw7::parser::make_LSHIFT(loc_); return parser::make_LSHIFT(loc_);
reader_.advance(); reader_.advance();
return iw7::parser::make_ASSIGN_LSHIFT(loc_); return parser::make_ASSIGN_LSHIFT(loc_);
case '>': case '>':
if (curr != '>' && curr != '=') if (curr != '>' && curr != '=')
return iw7::parser::make_GREATER(loc_); return parser::make_GREATER(loc_);
reader_.advance(); reader_.advance();
if (last == '=') if (last == '=')
return iw7::parser::make_GREATER_EQUAL(loc_); return parser::make_GREATER_EQUAL(loc_);
if (curr != '=') if (curr != '=')
return iw7::parser::make_RSHIFT(loc_); return parser::make_RSHIFT(loc_);
reader_.advance(); reader_.advance();
return iw7::parser::make_ASSIGN_RSHIFT(loc_); return parser::make_ASSIGN_RSHIFT(loc_);
default: default:
lex_name_or_number: lex_name_or_number:
if (last >= '0' && last <= '9') if (last >= '0' && last <= '9')
@ -496,9 +445,9 @@ lex_string:
} }
if (state_ == state::localize) if (state_ == state::localize)
return iw7::parser::make_ISTRING(std::string(buffer_.data, buffer_.length), loc_); return parser::make_ISTRING(std::string(buffer_.data, buffer_.length), loc_);
return iw7::parser::make_STRING(std::string(buffer_.data, buffer_.length), loc_); return parser::make_STRING(std::string(buffer_.data, buffer_.length), loc_);
lex_name: lex_name:
buffer_.push(last); buffer_.push(last);
@ -533,44 +482,55 @@ lex_name:
if (std::string_view(buffer_.data, buffer_.length) == "size") if (std::string_view(buffer_.data, buffer_.length) == "size")
{ {
return iw7::parser::make_SIZE(loc_); return parser::make_SIZE(loc_);
} }
return iw7::parser::make_FIELD(std::string(buffer_.data, buffer_.length), loc_); return parser::make_FIELD(std::string(buffer_.data, buffer_.length), loc_);
} }
else if (state_ == state::preprocessor) else if (state_ == state::preprocessor)
{ {
if (path) if (path)
throw comp_error(loc_, "invalid preprocessor directive"); throw comp_error(loc_, "invalid preprocessor directive");
auto key = get_keyword(std::string_view(buffer_.data, buffer_.length)); auto token = parser::token::IW7UNDEF;
if (key != keyword::KW_INVALID) if (buffer_.length < 16)
return keyword_token(key); {
const auto& itr = keyword_map.find(std::string_view(buffer_.data, buffer_.length));
// TODO: call preprocessor(key); if(itr != keyword_map.end())
{
if (itr->second > parser::token::HSENDIF)
return parser::symbol_type(itr->second, loc_);
token = itr->second;
}
}
// TODO: call preprocessor(token);
throw comp_error(loc_, "unknown preprocessor directive"); throw comp_error(loc_, "unknown preprocessor directive");
state_ = state::start; state_ = state::start;
continue; continue;
} }
else else
{ {
auto key = get_keyword(std::string_view(buffer_.data, buffer_.length)); if (buffer_.length < 17)
{
const auto& itr = keyword_map.find(std::string_view(buffer_.data, buffer_.length));
if (key != keyword::KW_INVALID) if(itr != keyword_map.end())
return keyword_token(key); return parser::symbol_type(itr->second, loc_);
}
if (path) if (path)
{ {
if (buffer_.data[buffer_.length - 1] == '/') if (buffer_.data[buffer_.length - 1] == '/')
throw comp_error(loc_, "invalid path end '\\'"); throw comp_error(loc_, "invalid path end '\\'");
//return iw7::parser::make_PATH(xsk::gsc::iw7::resolver::make_token(std::string_view(buffer_.data, buffer_.length)), loc_); return parser::make_PATH(resolver::make_token(std::string_view(buffer_.data, buffer_.length)), loc_);
return iw7::parser::make_PATH(std::string(buffer_.data, buffer_.length), loc_);
} }
//return iw7::parser::make_IDENTIFIER(xsk::gsc::iw7::resolver::make_token(std::string_view(buffer_.data, buffer_.length)), loc_); return parser::make_IDENTIFIER(resolver::make_token(std::string_view(buffer_.data, buffer_.length)), loc_);
return iw7::parser::make_IDENTIFIER(std::string(buffer_.data, buffer_.length), loc_);
} }
lex_number: lex_number:
@ -621,9 +581,9 @@ lex_number:
throw comp_error(loc_, "invalid number literal"); throw comp_error(loc_, "invalid number literal");
if (state_ == state::field || dot || flt) if (state_ == state::field || dot || flt)
return iw7::parser::make_FLOAT(std::string(buffer_.data, buffer_.length), loc_); return parser::make_FLOAT(std::string(buffer_.data, buffer_.length), loc_);
return iw7::parser::make_INTEGER(std::string(buffer_.data, buffer_.length), loc_); return parser::make_INTEGER(std::string(buffer_.data, buffer_.length), loc_);
} }
else if (curr == 'o') else if (curr == 'o')
{ {
@ -655,7 +615,7 @@ lex_number:
if (last == '\'' || buffer_.length <= 0) if (last == '\'' || buffer_.length <= 0)
throw comp_error(loc_, "invalid octal literal"); throw comp_error(loc_, "invalid octal literal");
return iw7::parser::make_INTEGER(xsk::utils::string::oct_to_dec(buffer_.data), loc_); return parser::make_INTEGER(xsk::utils::string::oct_to_dec(buffer_.data), loc_);
} }
else if (curr == 'b') else if (curr == 'b')
{ {
@ -689,7 +649,7 @@ lex_number:
if (last == '\'' || buffer_.length < 3) if (last == '\'' || buffer_.length < 3)
throw comp_error(loc_, "invalid binary literal"); throw comp_error(loc_, "invalid binary literal");
return iw7::parser::make_INTEGER(xsk::utils::string::bin_to_dec(buffer_.data), loc_); return parser::make_INTEGER(xsk::utils::string::bin_to_dec(buffer_.data), loc_);
} }
else if (curr == 'x') else if (curr == 'x')
{ {
@ -723,176 +683,59 @@ lex_number:
if (last == '\'' || buffer_.length < 3) if (last == '\'' || buffer_.length < 3)
throw comp_error(loc_, "invalid hexadecimal literal"); throw comp_error(loc_, "invalid hexadecimal literal");
return iw7::parser::make_INTEGER(xsk::utils::string::hex_to_dec(buffer_.data), loc_); return parser::make_INTEGER(xsk::utils::string::hex_to_dec(buffer_.data), loc_);
} }
// cant get here! // cant get here!
} }
} }
auto lexer::keyword_token(keyword k) -> xsk::gsc::iw7::parser::symbol_type const std::unordered_map<std::string_view, parser::token::token_kind_type> lexer::keyword_map
{
switch (k)
{
case keyword::KW_pre_inline:
return iw7::parser::make_INLINE(loc_);
case keyword::KW_pre_include:
return iw7::parser::make_INCLUDE(loc_);
case keyword::KW_pre_using_animtree:
return iw7::parser::make_USINGTREE(loc_);
case keyword::KW_pre_animtree:
return iw7::parser::make_ANIMTREE(loc_);
case keyword::KW_endon:
return iw7::parser::make_ENDON(loc_);
case keyword::KW_notify:
return iw7::parser::make_NOTIFY(loc_);
case keyword::KW_wait:
return iw7::parser::make_WAIT(loc_);
case keyword::KW_waittill:
return iw7::parser::make_WAITTILL(loc_);
case keyword::KW_waittillmatch:
return iw7::parser::make_WAITTILLMATCH(loc_);
case keyword::KW_waittillframeend:
return iw7::parser::make_WAITTILLFRAMEEND(loc_);
case keyword::KW_if:
return iw7::parser::make_IF(loc_);
case keyword::KW_else:
return iw7::parser::make_ELSE(loc_);
case keyword::KW_do:
return iw7::parser::make_DO(loc_);
case keyword::KW_while:
return iw7::parser::make_WHILE(loc_);
case keyword::KW_for:
return iw7::parser::make_FOR(loc_);
case keyword::KW_foreach:
return iw7::parser::make_FOREACH(loc_);
case keyword::KW_in:
return iw7::parser::make_IN(loc_);
case keyword::KW_switch:
return iw7::parser::make_SWITCH(loc_);
case keyword::KW_case:
return iw7::parser::make_CASE(loc_);
case keyword::KW_default:
return iw7::parser::make_DEFAULT(loc_);
case keyword::KW_break:
return iw7::parser::make_BREAK(loc_);
case keyword::KW_continue:
return iw7::parser::make_CONTINUE(loc_);
case keyword::KW_return:
return iw7::parser::make_RETURN(loc_);
case keyword::KW_breakpoint:
return iw7::parser::make_BREAKPOINT(loc_);
case keyword::KW_prof_begin:
return iw7::parser::make_PROFBEGIN(loc_);
case keyword::KW_prof_end:
return iw7::parser::make_PROFEND(loc_);
case keyword::KW_thread:
return iw7::parser::make_THREAD(loc_);
case keyword::KW_childthread:
return iw7::parser::make_CHILDTHREAD(loc_);
case keyword::KW_thisthread:
return iw7::parser::make_THISTHREAD(loc_);
case keyword::KW_call:
return iw7::parser::make_CALL(loc_);
case keyword::KW_true:
return iw7::parser::make_TRUE(loc_);
case keyword::KW_false:
return iw7::parser::make_FALSE(loc_);
case keyword::KW_undefined:
return iw7::parser::make_UNDEFINED(loc_);
case keyword::KW_dotsize:
return iw7::parser::make_SIZE(loc_);
case keyword::KW_game:
return iw7::parser::make_GAME(loc_);
case keyword::KW_self:
return iw7::parser::make_SELF(loc_);
case keyword::KW_anim:
return iw7::parser::make_ANIM(loc_);
case keyword::KW_level:
return iw7::parser::make_LEVEL(loc_);
default:
throw error("gsc lexer: INVALID KEYWORD TOKEN!");
}
}
auto lexer::keyword_is_token(keyword k) -> bool
{
switch (k)
{
/* case keyword::KW_pre_define:
case keyword::KW_pre_undef:
case keyword::KW_pre_ifdef:
case keyword::KW_pre_ifndef:
case keyword::KW_pre_if:
case keyword::KW_pre_elif:
case keyword::KW_pre_else:
case keyword::KW_pre_endif:*/
case keyword::KW_INVALID:
return false;
default:
return true;
}
}
auto lexer::get_keyword(std::string_view str) -> keyword
{
auto itr = keywords.find(str);
if(itr != keywords.end())
{
return itr->second;
}
return keyword::KW_INVALID;
}
std::unordered_map<std::string_view, keyword> lexer::keywords
{{ {{
/* { "#define", keyword::KW_pre_define }, { "#define", parser::token::HSDEFINE },
{ "#undef", keyword::KW_pre_undef }, { "#undef", parser::token::HSUNDEF },
{ "#ifdef", keyword::KW_pre_ifdef }, { "#ifdef", parser::token::HSIFDEF },
{ "#ifndef", keyword::KW_pre_ifndef }, { "#ifndef", parser::token::HSIFNDEF },
{ "#if", keyword::KW_pre_if }, { "#if", parser::token::HSIF },
{ "#elif", keyword::KW_pre_elif }, { "#elif", parser::token::HSELIF },
{ "#else", keyword::KW_pre_else }, { "#else", parser::token::HSELSE },
{ "#endif", keyword::KW_pre_endif },*/ { "#endif", parser::token::HSENDIF },
{ "#inline", keyword::KW_pre_inline }, { "#inline", parser::token::INLINE },
{ "#include", keyword::KW_pre_include }, { "#include", parser::token::INCLUDE },
{ "#using_animtree", keyword::KW_pre_using_animtree }, { "#using_animtree", parser::token::USINGTREE },
{ "#animtree", keyword::KW_pre_animtree }, { "#animtree", parser::token::ANIMTREE },
{ "endon", keyword::KW_endon }, { "endon", parser::token::ENDON },
{ "notify", keyword::KW_notify }, { "notify", parser::token::NOTIFY },
{ "wait", keyword::KW_wait }, { "wait", parser::token::WAIT },
{ "waittill", keyword::KW_waittill }, { "waittill", parser::token::WAITTILL },
{ "waittillmatch", keyword::KW_waittillmatch }, { "waittillmatch", parser::token::WAITTILLMATCH },
{ "waittillframeend", keyword::KW_waittillframeend }, { "waittillframeend", parser::token::WAITTILLFRAMEEND },
{ "if", keyword::KW_if }, { "if", parser::token::IF },
{ "else", keyword::KW_else }, { "else", parser::token::ELSE },
{ "do", keyword::KW_do }, { "do", parser::token::DO },
{ "while", keyword::KW_while }, { "while", parser::token::WHILE },
{ "for", keyword::KW_for }, { "for", parser::token::FOR },
{ "foreach", keyword::KW_foreach }, { "foreach", parser::token::FOREACH },
{ "in", keyword::KW_in }, { "in", parser::token::IN },
{ "switch", keyword::KW_switch }, { "switch", parser::token::SWITCH },
{ "case", keyword::KW_case }, { "case", parser::token::CASE },
{ "default", keyword::KW_default }, { "default", parser::token::DEFAULT },
{ "break", keyword::KW_break }, { "break", parser::token::BREAK },
{ "continue", keyword::KW_continue }, { "continue", parser::token::CONTINUE },
{ "return", keyword::KW_return }, { "return", parser::token::RETURN },
{ "breakpoint", keyword::KW_breakpoint }, { "breakpoint", parser::token::BREAKPOINT },
{ "prof_begin", keyword::KW_prof_begin }, { "prof_begin", parser::token::PROFBEGIN },
{ "prof_end", keyword::KW_prof_end }, { "prof_end", parser::token::PROFEND },
{ "thread", keyword::KW_thread }, { "thread", parser::token::THREAD },
{ "childthread", keyword::KW_childthread }, { "childthread", parser::token::CHILDTHREAD },
{ "thisthread", keyword::KW_thisthread }, { "thisthread", parser::token::THISTHREAD },
{ "call", keyword::KW_call }, { "call", parser::token::CALL },
{ "true", keyword::KW_true }, { "true", parser::token::TRUE },
{ "false", keyword::KW_false }, { "false", parser::token::FALSE },
{ "undefined", keyword::KW_undefined }, { "undefined", parser::token::UNDEFINED },
{ ".size", keyword::KW_dotsize }, { "game", parser::token::GAME },
{ "game", keyword::KW_game }, { "self", parser::token::SELF },
{ "self", keyword::KW_self }, { "anim", parser::token::ANIM },
{ "anim", keyword::KW_anim }, { "level", parser::token::LEVEL },
{ "level", keyword::KW_level },
}}; }};
} // namespace xsk::gsc::iw7 } // namespace xsk::gsc::iw7

View File

@ -10,8 +10,6 @@
namespace xsk::gsc::iw7 namespace xsk::gsc::iw7
{ {
enum class keyword;
constexpr size_t max_buf_size = 0x2000; constexpr size_t max_buf_size = 0x2000;
struct buffer struct buffer
@ -53,26 +51,22 @@ class lexer
reader reader_; reader reader_;
buffer buffer_; buffer buffer_;
location loc_; location loc_;
build mode_;
std::stack<location> locs_; std::stack<location> locs_;
std::stack<reader> readers_; std::stack<reader> readers_;
std::uint32_t header_top_; std::uint32_t header_top_;
state state_; state state_;
build mode_;
bool indev_; bool indev_;
public: public:
lexer(const std::string& name, const char* data, size_t size); lexer(const std::string& name, const char* data, size_t size);
auto lex() -> xsk::gsc::iw7::parser::symbol_type; auto lex() -> parser::symbol_type;
void push_header(const std::string& file); void push_header(const std::string& file);
void pop_header(); void pop_header();
void restrict_header(const xsk::gsc::location& loc); void ban_header(const location& loc);
private: private:
auto keyword_token(keyword k) -> xsk::gsc::iw7::parser::symbol_type; static const std::unordered_map<std::string_view, parser::token::token_kind_type> keyword_map;
static auto keyword_is_token(keyword k) -> bool;
static auto get_keyword(std::string_view str) -> keyword;
static std::unordered_map<std::string_view, keyword> keywords;
}; };
} // namespace xsk::gsc::iw7 } // namespace xsk::gsc::iw7

File diff suppressed because it is too large Load Diff

View File

@ -674,108 +674,116 @@ namespace xsk { namespace gsc { namespace iw7 {
IW7EOF = 0, // "end of file" IW7EOF = 0, // "end of file"
IW7error = 1, // error IW7error = 1, // error
IW7UNDEF = 2, // "invalid token" IW7UNDEF = 2, // "invalid token"
DEVBEGIN = 3, // "/#" HSDEFINE = 3, // "#define"
DEVEND = 4, // "#/" HSUNDEF = 4, // "#undef"
INLINE = 5, // "#inline" HSIFDEF = 5, // "#ifdef"
INCLUDE = 6, // "#include" HSIFNDEF = 6, // "#ifndef"
USINGTREE = 7, // "#using_animtree" HSIF = 7, // "#if"
ANIMTREE = 8, // "#animtree" HSELIF = 8, // "#elif"
ENDON = 9, // "endon" HSELSE = 9, // "#else"
NOTIFY = 10, // "notify" HSENDIF = 10, // "#endif"
WAIT = 11, // "wait" DEVBEGIN = 11, // "/#"
WAITTILL = 12, // "waittill" DEVEND = 12, // "#/"
WAITTILLMATCH = 13, // "waittillmatch" INLINE = 13, // "#inline"
WAITTILLFRAMEEND = 14, // "waittillframeend" INCLUDE = 14, // "#include"
IF = 15, // "if" USINGTREE = 15, // "#using_animtree"
ELSE = 16, // "else" ANIMTREE = 16, // "#animtree"
DO = 17, // "do" ENDON = 17, // "endon"
WHILE = 18, // "while" NOTIFY = 18, // "notify"
FOR = 19, // "for" WAIT = 19, // "wait"
FOREACH = 20, // "foreach" WAITTILL = 20, // "waittill"
IN = 21, // "in" WAITTILLMATCH = 21, // "waittillmatch"
SWITCH = 22, // "switch" WAITTILLFRAMEEND = 22, // "waittillframeend"
CASE = 23, // "case" IF = 23, // "if"
DEFAULT = 24, // "default" ELSE = 24, // "else"
BREAK = 25, // "break" DO = 25, // "do"
CONTINUE = 26, // "continue" WHILE = 26, // "while"
RETURN = 27, // "return" FOR = 27, // "for"
BREAKPOINT = 28, // "breakpoint" FOREACH = 28, // "foreach"
PROFBEGIN = 29, // "prof_begin" IN = 29, // "in"
PROFEND = 30, // "prof_end" SWITCH = 30, // "switch"
THREAD = 31, // "thread" CASE = 31, // "case"
CHILDTHREAD = 32, // "childthread" DEFAULT = 32, // "default"
THISTHREAD = 33, // "thisthread" BREAK = 33, // "break"
CALL = 34, // "call" CONTINUE = 34, // "continue"
TRUE = 35, // "true" RETURN = 35, // "return"
FALSE = 36, // "false" BREAKPOINT = 36, // "breakpoint"
UNDEFINED = 37, // "undefined" PROFBEGIN = 37, // "prof_begin"
SIZE = 38, // ".size" PROFEND = 38, // "prof_end"
GAME = 39, // "game" THREAD = 39, // "thread"
SELF = 40, // "self" CHILDTHREAD = 40, // "childthread"
ANIM = 41, // "anim" THISTHREAD = 41, // "thisthread"
LEVEL = 42, // "level" CALL = 42, // "call"
LPAREN = 43, // "(" TRUE = 43, // "true"
RPAREN = 44, // ")" FALSE = 44, // "false"
LBRACE = 45, // "{" UNDEFINED = 45, // "undefined"
RBRACE = 46, // "}" SIZE = 46, // ".size"
LBRACKET = 47, // "[" GAME = 47, // "game"
RBRACKET = 48, // "]" SELF = 48, // "self"
COMMA = 49, // "," ANIM = 49, // "anim"
DOT = 50, // "." LEVEL = 50, // "level"
DOUBLECOLON = 51, // "::" LPAREN = 51, // "("
COLON = 52, // ":" RPAREN = 52, // ")"
SEMICOLON = 53, // ";" LBRACE = 53, // "{"
QMARK = 54, // "?" RBRACE = 54, // "}"
INCREMENT = 55, // "++" LBRACKET = 55, // "["
DECREMENT = 56, // "--" RBRACKET = 56, // "]"
LSHIFT = 57, // "<<" COMMA = 57, // ","
RSHIFT = 58, // ">>" DOT = 58, // "."
OR = 59, // "||" DOUBLECOLON = 59, // "::"
AND = 60, // "&&" COLON = 60, // ":"
EQUALITY = 61, // "==" SEMICOLON = 61, // ";"
INEQUALITY = 62, // "!=" QMARK = 62, // "?"
LESS_EQUAL = 63, // "<=" INCREMENT = 63, // "++"
GREATER_EQUAL = 64, // ">=" DECREMENT = 64, // "--"
LESS = 65, // "<" LSHIFT = 65, // "<<"
GREATER = 66, // ">" RSHIFT = 66, // ">>"
NOT = 67, // "!" OR = 67, // "||"
COMPLEMENT = 68, // "~" AND = 68, // "&&"
ASSIGN = 69, // "=" EQUALITY = 69, // "=="
ASSIGN_ADD = 70, // "+=" INEQUALITY = 70, // "!="
ASSIGN_SUB = 71, // "-=" LESS_EQUAL = 71, // "<="
ASSIGN_MUL = 72, // "*=" GREATER_EQUAL = 72, // ">="
ASSIGN_DIV = 73, // "/=" LESS = 73, // "<"
ASSIGN_MOD = 74, // "%=" GREATER = 74, // ">"
ASSIGN_BW_OR = 75, // "|=" NOT = 75, // "!"
ASSIGN_BW_AND = 76, // "&=" COMPLEMENT = 76, // "~"
ASSIGN_BW_EXOR = 77, // "^=" ASSIGN = 77, // "="
ASSIGN_RSHIFT = 78, // ">>=" ASSIGN_ADD = 78, // "+="
ASSIGN_LSHIFT = 79, // "<<=" ASSIGN_SUB = 79, // "-="
BITWISE_OR = 80, // "|" ASSIGN_MUL = 80, // "*="
BITWISE_AND = 81, // "&" ASSIGN_DIV = 81, // "/="
BITWISE_EXOR = 82, // "^" ASSIGN_MOD = 82, // "%="
ADD = 83, // "+" ASSIGN_BW_OR = 83, // "|="
SUB = 84, // "-" ASSIGN_BW_AND = 84, // "&="
MUL = 85, // "*" ASSIGN_BW_EXOR = 85, // "^="
DIV = 86, // "/" ASSIGN_RSHIFT = 86, // ">>="
MOD = 87, // "%" ASSIGN_LSHIFT = 87, // "<<="
FIELD = 88, // "field" BITWISE_OR = 88, // "|"
PATH = 89, // "path" BITWISE_AND = 89, // "&"
IDENTIFIER = 90, // "identifier" BITWISE_EXOR = 90, // "^"
STRING = 91, // "string literal" ADD = 91, // "+"
ISTRING = 92, // "localized string" SUB = 92, // "-"
COLOR = 93, // "color" MUL = 93, // "*"
FLOAT = 94, // "float" DIV = 94, // "/"
INTEGER = 95, // "integer" MOD = 95, // "%"
ADD_ARRAY = 96, // ADD_ARRAY FIELD = 96, // "field"
THEN = 97, // THEN PATH = 97, // "path"
TERN = 98, // TERN IDENTIFIER = 98, // "identifier"
NEG = 99, // NEG STRING = 99, // "string literal"
ANIMREF = 100, // ANIMREF ISTRING = 100, // "localized string"
PREINC = 101, // PREINC COLOR = 101, // "color"
PREDEC = 102, // PREDEC FLOAT = 102, // "float"
POSTINC = 103, // POSTINC INTEGER = 103, // "integer"
POSTDEC = 104 // POSTDEC ADD_ARRAY = 104, // ADD_ARRAY
THEN = 105, // THEN
TERN = 106, // TERN
NEG = 107, // NEG
ANIMREF = 108, // ANIMREF
PREINC = 109, // PREINC
PREDEC = 110, // PREDEC
POSTINC = 111, // POSTINC
POSTDEC = 112 // POSTDEC
}; };
/// Backward compatibility alias (Bison 3.6). /// Backward compatibility alias (Bison 3.6).
typedef token_kind_type yytokentype; typedef token_kind_type yytokentype;
@ -792,193 +800,201 @@ namespace xsk { namespace gsc { namespace iw7 {
{ {
enum symbol_kind_type enum symbol_kind_type
{ {
YYNTOKENS = 105, ///< Number of tokens. YYNTOKENS = 113, ///< Number of tokens.
S_YYEMPTY = -2, S_YYEMPTY = -2,
S_YYEOF = 0, // "end of file" S_YYEOF = 0, // "end of file"
S_YYerror = 1, // error S_YYerror = 1, // error
S_YYUNDEF = 2, // "invalid token" S_YYUNDEF = 2, // "invalid token"
S_DEVBEGIN = 3, // "/#" S_HSDEFINE = 3, // "#define"
S_DEVEND = 4, // "#/" S_HSUNDEF = 4, // "#undef"
S_INLINE = 5, // "#inline" S_HSIFDEF = 5, // "#ifdef"
S_INCLUDE = 6, // "#include" S_HSIFNDEF = 6, // "#ifndef"
S_USINGTREE = 7, // "#using_animtree" S_HSIF = 7, // "#if"
S_ANIMTREE = 8, // "#animtree" S_HSELIF = 8, // "#elif"
S_ENDON = 9, // "endon" S_HSELSE = 9, // "#else"
S_NOTIFY = 10, // "notify" S_HSENDIF = 10, // "#endif"
S_WAIT = 11, // "wait" S_DEVBEGIN = 11, // "/#"
S_WAITTILL = 12, // "waittill" S_DEVEND = 12, // "#/"
S_WAITTILLMATCH = 13, // "waittillmatch" S_INLINE = 13, // "#inline"
S_WAITTILLFRAMEEND = 14, // "waittillframeend" S_INCLUDE = 14, // "#include"
S_IF = 15, // "if" S_USINGTREE = 15, // "#using_animtree"
S_ELSE = 16, // "else" S_ANIMTREE = 16, // "#animtree"
S_DO = 17, // "do" S_ENDON = 17, // "endon"
S_WHILE = 18, // "while" S_NOTIFY = 18, // "notify"
S_FOR = 19, // "for" S_WAIT = 19, // "wait"
S_FOREACH = 20, // "foreach" S_WAITTILL = 20, // "waittill"
S_IN = 21, // "in" S_WAITTILLMATCH = 21, // "waittillmatch"
S_SWITCH = 22, // "switch" S_WAITTILLFRAMEEND = 22, // "waittillframeend"
S_CASE = 23, // "case" S_IF = 23, // "if"
S_DEFAULT = 24, // "default" S_ELSE = 24, // "else"
S_BREAK = 25, // "break" S_DO = 25, // "do"
S_CONTINUE = 26, // "continue" S_WHILE = 26, // "while"
S_RETURN = 27, // "return" S_FOR = 27, // "for"
S_BREAKPOINT = 28, // "breakpoint" S_FOREACH = 28, // "foreach"
S_PROFBEGIN = 29, // "prof_begin" S_IN = 29, // "in"
S_PROFEND = 30, // "prof_end" S_SWITCH = 30, // "switch"
S_THREAD = 31, // "thread" S_CASE = 31, // "case"
S_CHILDTHREAD = 32, // "childthread" S_DEFAULT = 32, // "default"
S_THISTHREAD = 33, // "thisthread" S_BREAK = 33, // "break"
S_CALL = 34, // "call" S_CONTINUE = 34, // "continue"
S_TRUE = 35, // "true" S_RETURN = 35, // "return"
S_FALSE = 36, // "false" S_BREAKPOINT = 36, // "breakpoint"
S_UNDEFINED = 37, // "undefined" S_PROFBEGIN = 37, // "prof_begin"
S_SIZE = 38, // ".size" S_PROFEND = 38, // "prof_end"
S_GAME = 39, // "game" S_THREAD = 39, // "thread"
S_SELF = 40, // "self" S_CHILDTHREAD = 40, // "childthread"
S_ANIM = 41, // "anim" S_THISTHREAD = 41, // "thisthread"
S_LEVEL = 42, // "level" S_CALL = 42, // "call"
S_LPAREN = 43, // "(" S_TRUE = 43, // "true"
S_RPAREN = 44, // ")" S_FALSE = 44, // "false"
S_LBRACE = 45, // "{" S_UNDEFINED = 45, // "undefined"
S_RBRACE = 46, // "}" S_SIZE = 46, // ".size"
S_LBRACKET = 47, // "[" S_GAME = 47, // "game"
S_RBRACKET = 48, // "]" S_SELF = 48, // "self"
S_COMMA = 49, // "," S_ANIM = 49, // "anim"
S_DOT = 50, // "." S_LEVEL = 50, // "level"
S_DOUBLECOLON = 51, // "::" S_LPAREN = 51, // "("
S_COLON = 52, // ":" S_RPAREN = 52, // ")"
S_SEMICOLON = 53, // ";" S_LBRACE = 53, // "{"
S_QMARK = 54, // "?" S_RBRACE = 54, // "}"
S_INCREMENT = 55, // "++" S_LBRACKET = 55, // "["
S_DECREMENT = 56, // "--" S_RBRACKET = 56, // "]"
S_LSHIFT = 57, // "<<" S_COMMA = 57, // ","
S_RSHIFT = 58, // ">>" S_DOT = 58, // "."
S_OR = 59, // "||" S_DOUBLECOLON = 59, // "::"
S_AND = 60, // "&&" S_COLON = 60, // ":"
S_EQUALITY = 61, // "==" S_SEMICOLON = 61, // ";"
S_INEQUALITY = 62, // "!=" S_QMARK = 62, // "?"
S_LESS_EQUAL = 63, // "<=" S_INCREMENT = 63, // "++"
S_GREATER_EQUAL = 64, // ">=" S_DECREMENT = 64, // "--"
S_LESS = 65, // "<" S_LSHIFT = 65, // "<<"
S_GREATER = 66, // ">" S_RSHIFT = 66, // ">>"
S_NOT = 67, // "!" S_OR = 67, // "||"
S_COMPLEMENT = 68, // "~" S_AND = 68, // "&&"
S_ASSIGN = 69, // "=" S_EQUALITY = 69, // "=="
S_ASSIGN_ADD = 70, // "+=" S_INEQUALITY = 70, // "!="
S_ASSIGN_SUB = 71, // "-=" S_LESS_EQUAL = 71, // "<="
S_ASSIGN_MUL = 72, // "*=" S_GREATER_EQUAL = 72, // ">="
S_ASSIGN_DIV = 73, // "/=" S_LESS = 73, // "<"
S_ASSIGN_MOD = 74, // "%=" S_GREATER = 74, // ">"
S_ASSIGN_BW_OR = 75, // "|=" S_NOT = 75, // "!"
S_ASSIGN_BW_AND = 76, // "&=" S_COMPLEMENT = 76, // "~"
S_ASSIGN_BW_EXOR = 77, // "^=" S_ASSIGN = 77, // "="
S_ASSIGN_RSHIFT = 78, // ">>=" S_ASSIGN_ADD = 78, // "+="
S_ASSIGN_LSHIFT = 79, // "<<=" S_ASSIGN_SUB = 79, // "-="
S_BITWISE_OR = 80, // "|" S_ASSIGN_MUL = 80, // "*="
S_BITWISE_AND = 81, // "&" S_ASSIGN_DIV = 81, // "/="
S_BITWISE_EXOR = 82, // "^" S_ASSIGN_MOD = 82, // "%="
S_ADD = 83, // "+" S_ASSIGN_BW_OR = 83, // "|="
S_SUB = 84, // "-" S_ASSIGN_BW_AND = 84, // "&="
S_MUL = 85, // "*" S_ASSIGN_BW_EXOR = 85, // "^="
S_DIV = 86, // "/" S_ASSIGN_RSHIFT = 86, // ">>="
S_MOD = 87, // "%" S_ASSIGN_LSHIFT = 87, // "<<="
S_FIELD = 88, // "field" S_BITWISE_OR = 88, // "|"
S_PATH = 89, // "path" S_BITWISE_AND = 89, // "&"
S_IDENTIFIER = 90, // "identifier" S_BITWISE_EXOR = 90, // "^"
S_STRING = 91, // "string literal" S_ADD = 91, // "+"
S_ISTRING = 92, // "localized string" S_SUB = 92, // "-"
S_COLOR = 93, // "color" S_MUL = 93, // "*"
S_FLOAT = 94, // "float" S_DIV = 94, // "/"
S_INTEGER = 95, // "integer" S_MOD = 95, // "%"
S_ADD_ARRAY = 96, // ADD_ARRAY S_FIELD = 96, // "field"
S_THEN = 97, // THEN S_PATH = 97, // "path"
S_TERN = 98, // TERN S_IDENTIFIER = 98, // "identifier"
S_NEG = 99, // NEG S_STRING = 99, // "string literal"
S_ANIMREF = 100, // ANIMREF S_ISTRING = 100, // "localized string"
S_PREINC = 101, // PREINC S_COLOR = 101, // "color"
S_PREDEC = 102, // PREDEC S_FLOAT = 102, // "float"
S_POSTINC = 103, // POSTINC S_INTEGER = 103, // "integer"
S_POSTDEC = 104, // POSTDEC S_ADD_ARRAY = 104, // ADD_ARRAY
S_YYACCEPT = 105, // $accept S_THEN = 105, // THEN
S_root = 106, // root S_TERN = 106, // TERN
S_program = 107, // program S_NEG = 107, // NEG
S_inline = 108, // inline S_ANIMREF = 108, // ANIMREF
S_include = 109, // include S_PREINC = 109, // PREINC
S_declaration = 110, // declaration S_PREDEC = 110, // PREDEC
S_decl_usingtree = 111, // decl_usingtree S_POSTINC = 111, // POSTINC
S_decl_constant = 112, // decl_constant S_POSTDEC = 112, // POSTDEC
S_decl_thread = 113, // decl_thread S_YYACCEPT = 113, // $accept
S_stmt = 114, // stmt S_root = 114, // root
S_stmt_dev = 115, // stmt_dev S_program = 115, // program
S_stmt_block = 116, // stmt_block S_inline = 116, // inline
S_stmt_list = 117, // stmt_list S_include = 117, // include
S_stmt_expr = 118, // stmt_expr S_declaration = 118, // declaration
S_stmt_call = 119, // stmt_call S_decl_usingtree = 119, // decl_usingtree
S_stmt_assign = 120, // stmt_assign S_decl_constant = 120, // decl_constant
S_stmt_endon = 121, // stmt_endon S_decl_thread = 121, // decl_thread
S_stmt_notify = 122, // stmt_notify S_stmt = 122, // stmt
S_stmt_wait = 123, // stmt_wait S_stmt_dev = 123, // stmt_dev
S_stmt_waittill = 124, // stmt_waittill S_stmt_block = 124, // stmt_block
S_stmt_waittillmatch = 125, // stmt_waittillmatch S_stmt_list = 125, // stmt_list
S_stmt_waittillframeend = 126, // stmt_waittillframeend S_stmt_expr = 126, // stmt_expr
S_stmt_if = 127, // stmt_if S_stmt_call = 127, // stmt_call
S_stmt_ifelse = 128, // stmt_ifelse S_stmt_assign = 128, // stmt_assign
S_stmt_while = 129, // stmt_while S_stmt_endon = 129, // stmt_endon
S_stmt_dowhile = 130, // stmt_dowhile S_stmt_notify = 130, // stmt_notify
S_stmt_for = 131, // stmt_for S_stmt_wait = 131, // stmt_wait
S_stmt_foreach = 132, // stmt_foreach S_stmt_waittill = 132, // stmt_waittill
S_stmt_switch = 133, // stmt_switch S_stmt_waittillmatch = 133, // stmt_waittillmatch
S_stmt_case = 134, // stmt_case S_stmt_waittillframeend = 134, // stmt_waittillframeend
S_stmt_default = 135, // stmt_default S_stmt_if = 135, // stmt_if
S_stmt_break = 136, // stmt_break S_stmt_ifelse = 136, // stmt_ifelse
S_stmt_continue = 137, // stmt_continue S_stmt_while = 137, // stmt_while
S_stmt_return = 138, // stmt_return S_stmt_dowhile = 138, // stmt_dowhile
S_stmt_breakpoint = 139, // stmt_breakpoint S_stmt_for = 139, // stmt_for
S_stmt_prof_begin = 140, // stmt_prof_begin S_stmt_foreach = 140, // stmt_foreach
S_stmt_prof_end = 141, // stmt_prof_end S_stmt_switch = 141, // stmt_switch
S_expr = 142, // expr S_stmt_case = 142, // stmt_case
S_expr_or_empty = 143, // expr_or_empty S_stmt_default = 143, // stmt_default
S_expr_assign = 144, // expr_assign S_stmt_break = 144, // stmt_break
S_expr_increment = 145, // expr_increment S_stmt_continue = 145, // stmt_continue
S_expr_decrement = 146, // expr_decrement S_stmt_return = 146, // stmt_return
S_expr_ternary = 147, // expr_ternary S_stmt_breakpoint = 147, // stmt_breakpoint
S_expr_binary = 148, // expr_binary S_stmt_prof_begin = 148, // stmt_prof_begin
S_expr_primitive = 149, // expr_primitive S_stmt_prof_end = 149, // stmt_prof_end
S_expr_complement = 150, // expr_complement S_expr = 150, // expr
S_expr_not = 151, // expr_not S_expr_or_empty = 151, // expr_or_empty
S_expr_call = 152, // expr_call S_expr_assign = 152, // expr_assign
S_expr_method = 153, // expr_method S_expr_increment = 153, // expr_increment
S_expr_function = 154, // expr_function S_expr_decrement = 154, // expr_decrement
S_expr_pointer = 155, // expr_pointer S_expr_ternary = 155, // expr_ternary
S_expr_add_array = 156, // expr_add_array S_expr_binary = 156, // expr_binary
S_expr_parameters = 157, // expr_parameters S_expr_primitive = 157, // expr_primitive
S_expr_arguments = 158, // expr_arguments S_expr_complement = 158, // expr_complement
S_expr_arguments_no_empty = 159, // expr_arguments_no_empty S_expr_not = 159, // expr_not
S_expr_reference = 160, // expr_reference S_expr_call = 160, // expr_call
S_expr_array = 161, // expr_array S_expr_method = 161, // expr_method
S_expr_field = 162, // expr_field S_expr_function = 162, // expr_function
S_expr_size = 163, // expr_size S_expr_pointer = 163, // expr_pointer
S_expr_paren = 164, // expr_paren S_expr_add_array = 164, // expr_add_array
S_expr_object = 165, // expr_object S_expr_parameters = 165, // expr_parameters
S_expr_thisthread = 166, // expr_thisthread S_expr_arguments = 166, // expr_arguments
S_expr_empty_array = 167, // expr_empty_array S_expr_arguments_no_empty = 167, // expr_arguments_no_empty
S_expr_undefined = 168, // expr_undefined S_expr_reference = 168, // expr_reference
S_expr_game = 169, // expr_game S_expr_array = 169, // expr_array
S_expr_self = 170, // expr_self S_expr_field = 170, // expr_field
S_expr_anim = 171, // expr_anim S_expr_size = 171, // expr_size
S_expr_level = 172, // expr_level S_expr_paren = 172, // expr_paren
S_expr_animation = 173, // expr_animation S_expr_object = 173, // expr_object
S_expr_animtree = 174, // expr_animtree S_expr_thisthread = 174, // expr_thisthread
S_expr_identifier = 175, // expr_identifier S_expr_empty_array = 175, // expr_empty_array
S_expr_path = 176, // expr_path S_expr_undefined = 176, // expr_undefined
S_expr_istring = 177, // expr_istring S_expr_game = 177, // expr_game
S_expr_string = 178, // expr_string S_expr_self = 178, // expr_self
S_expr_color = 179, // expr_color S_expr_anim = 179, // expr_anim
S_expr_vector = 180, // expr_vector S_expr_level = 180, // expr_level
S_expr_float = 181, // expr_float S_expr_animation = 181, // expr_animation
S_expr_integer = 182, // expr_integer S_expr_animtree = 182, // expr_animtree
S_expr_false = 183, // expr_false S_expr_identifier = 183, // expr_identifier
S_expr_true = 184 // expr_true S_expr_path = 184, // expr_path
S_expr_istring = 185, // expr_istring
S_expr_string = 186, // expr_string
S_expr_color = 187, // expr_color
S_expr_vector = 188, // expr_vector
S_expr_float = 189, // expr_float
S_expr_integer = 190, // expr_integer
S_expr_false = 191, // expr_false
S_expr_true = 192 // expr_true
}; };
}; };
@ -2751,6 +2767,126 @@ switch (yykind)
return symbol_type (token::IW7UNDEF, l); return symbol_type (token::IW7UNDEF, l);
} }
#endif #endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_HSDEFINE (location_type l)
{
return symbol_type (token::HSDEFINE, std::move (l));
}
#else
static
symbol_type
make_HSDEFINE (const location_type& l)
{
return symbol_type (token::HSDEFINE, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_HSUNDEF (location_type l)
{
return symbol_type (token::HSUNDEF, std::move (l));
}
#else
static
symbol_type
make_HSUNDEF (const location_type& l)
{
return symbol_type (token::HSUNDEF, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_HSIFDEF (location_type l)
{
return symbol_type (token::HSIFDEF, std::move (l));
}
#else
static
symbol_type
make_HSIFDEF (const location_type& l)
{
return symbol_type (token::HSIFDEF, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_HSIFNDEF (location_type l)
{
return symbol_type (token::HSIFNDEF, std::move (l));
}
#else
static
symbol_type
make_HSIFNDEF (const location_type& l)
{
return symbol_type (token::HSIFNDEF, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_HSIF (location_type l)
{
return symbol_type (token::HSIF, std::move (l));
}
#else
static
symbol_type
make_HSIF (const location_type& l)
{
return symbol_type (token::HSIF, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_HSELIF (location_type l)
{
return symbol_type (token::HSELIF, std::move (l));
}
#else
static
symbol_type
make_HSELIF (const location_type& l)
{
return symbol_type (token::HSELIF, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_HSELSE (location_type l)
{
return symbol_type (token::HSELSE, std::move (l));
}
#else
static
symbol_type
make_HSELSE (const location_type& l)
{
return symbol_type (token::HSELSE, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_HSENDIF (location_type l)
{
return symbol_type (token::HSENDIF, std::move (l));
}
#else
static
symbol_type
make_HSENDIF (const location_type& l)
{
return symbol_type (token::HSENDIF, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS #if 201103L <= YY_CPLUSPLUS
static static
symbol_type symbol_type
@ -5311,7 +5447,7 @@ switch (yykind)
#line 13 "parser.ypp" #line 13 "parser.ypp"
} } } // xsk::gsc::iw7 } } } // xsk::gsc::iw7
#line 5315 "parser.hpp" #line 5451 "parser.hpp"

View File

@ -16,60 +16,6 @@ xsk::gsc::iw8::parser::symbol_type IW8lex(xsk::gsc::iw8::lexer& lexer)
namespace xsk::gsc::iw8 namespace xsk::gsc::iw8
{ {
enum class keyword
{
/* KW_pre_define,
KW_pre_undef,
KW_pre_ifdef,
KW_pre_ifndef,
KW_pre_if,
KW_pre_elif,
KW_pre_else,
KW_pre_endif,*/
KW_pre_inline,
KW_pre_include,
KW_pre_using_animtree,
KW_pre_animtree,
KW_endon,
KW_notify,
KW_wait,
KW_waittill,
KW_waittillmatch,
KW_waittillframeend,
KW_waitframe,
KW_if,
KW_else,
KW_do,
KW_while,
KW_for,
KW_foreach,
KW_in,
KW_switch,
KW_case,
KW_default,
KW_break,
KW_continue,
KW_return,
KW_breakpoint,
KW_prof_begin,
KW_prof_end,
KW_thread,
KW_childthread,
KW_thisthread,
KW_call,
KW_true,
KW_false,
KW_undefined,
KW_dotsize,
KW_game,
KW_self,
KW_anim,
KW_level,
KW_isdefined,
KW_istrue,
KW_INVALID,
};
buffer::buffer() : length(0) buffer::buffer() : length(0)
{ {
data = static_cast<char*>(std::malloc(max_buf_size)); data = static_cast<char*>(std::malloc(max_buf_size));
@ -132,7 +78,7 @@ void reader::advance()
} }
} }
lexer::lexer(const std::string& name, const char* data, size_t size) : indev_(false), loc_(xsk::gsc::location(&name)), lexer::lexer(const std::string& name, const char* data, size_t size) : indev_(false), loc_(location(&name)),
mode_(build::dev), header_top_(0), locs_(std::stack<location>()), readers_(std::stack<reader>()) mode_(build::dev), header_top_(0), locs_(std::stack<location>()), readers_(std::stack<reader>())
{ {
reader_.init(data, size); reader_.init(data, size);
@ -143,7 +89,7 @@ void lexer::push_header(const std::string& file)
try try
{ {
if (header_top_++ >= 10) if (header_top_++ >= 10)
throw xsk::gsc::error("maximum gsh depth exceeded '10'"); throw comp_error(loc_, "maximum gsh depth exceeded '10'");
auto data = resolver::file_data(file + ".gsh"); auto data = resolver::file_data(file + ".gsh");
@ -154,7 +100,7 @@ void lexer::push_header(const std::string& file)
} }
catch (const std::exception& e) catch (const std::exception& e)
{ {
throw xsk::gsc::error("parsing header file '" + file + "': " + e.what()); throw error("parsing header file '" + file + "': " + e.what());
} }
} }
@ -167,7 +113,7 @@ void lexer::pop_header()
readers_.pop(); readers_.pop();
} }
void lexer::restrict_header(const xsk::gsc::location& loc) void lexer::ban_header(const location& loc)
{ {
if (header_top_ > 0) if (header_top_ > 0)
{ {
@ -175,7 +121,7 @@ void lexer::restrict_header(const xsk::gsc::location& loc)
} }
} }
auto lexer::lex() -> xsk::gsc::iw8::parser::symbol_type auto lexer::lex() -> parser::symbol_type
{ {
buffer_.length = 0; buffer_.length = 0;
state_ = state::start; state_ = state::start;
@ -196,7 +142,7 @@ auto lexer::lex() -> xsk::gsc::iw8::parser::symbol_type
if (header_top_ > 0) if (header_top_ > 0)
pop_header(); pop_header();
else else
return iw8::parser::make_IW8EOF(loc_); return parser::make_IW8EOF(loc_);
} }
reader_.advance(); reader_.advance();
@ -214,22 +160,22 @@ auto lexer::lex() -> xsk::gsc::iw8::parser::symbol_type
continue; continue;
case '/': case '/':
if (curr != '/' && curr != '*' && curr != '#' && curr != '=') if (curr != '/' && curr != '*' && curr != '#' && curr != '=')
return iw8::parser::make_DIV(loc_); return parser::make_DIV(loc_);
reader_.advance(); reader_.advance();
if (last == '=') if (last == '=')
return iw8::parser::make_ASSIGN_DIV(loc_); return parser::make_ASSIGN_DIV(loc_);
if (last == '#') if (last == '#')
{ {
if (indev_) if (indev_)
throw comp_error(loc_, "cannot recurse devblock ('/#')"); throw comp_error(loc_, "cannot recurse devblock ('/#')");
if (mode_ == xsk::gsc::build::dev) if (mode_ == build::dev)
{ {
indev_ = true; indev_ = true;
return iw8::parser::make_DEVBEGIN(loc_); return parser::make_DEVBEGIN(loc_);
} }
else else
{ {
@ -293,7 +239,7 @@ auto lexer::lex() -> xsk::gsc::iw8::parser::symbol_type
indev_ = false; indev_ = false;
reader_.advance(); reader_.advance();
return iw8::parser::make_DEVEND(loc_); return parser::make_DEVEND(loc_);
} }
buffer_.push(last); buffer_.push(last);
@ -306,12 +252,12 @@ auto lexer::lex() -> xsk::gsc::iw8::parser::symbol_type
goto lex_name; goto lex_name;
case '*': case '*':
if (curr != '/' && curr != '=') if (curr != '/' && curr != '=')
return iw8::parser::make_MUL(loc_); return parser::make_MUL(loc_);
reader_.advance(); reader_.advance();
if (last == '=') if (last == '=')
return iw8::parser::make_ASSIGN_MUL(loc_); return parser::make_ASSIGN_MUL(loc_);
throw comp_error(loc_, "unmatched multiline comment end ('*/')"); throw comp_error(loc_, "unmatched multiline comment end ('*/')");
case '"': case '"':
@ -326,127 +272,127 @@ auto lexer::lex() -> xsk::gsc::iw8::parser::symbol_type
state_ = state::field; state_ = state::field;
goto lex_name_or_number; goto lex_name_or_number;
case '(': case '(':
return iw8::parser::make_LPAREN(loc_); return parser::make_LPAREN(loc_);
case ')': case ')':
return iw8::parser::make_RPAREN(loc_); return parser::make_RPAREN(loc_);
case '{': case '{':
return iw8::parser::make_LBRACE(loc_); return parser::make_LBRACE(loc_);
case '}': case '}':
return iw8::parser::make_RBRACE(loc_); return parser::make_RBRACE(loc_);
case '[': case '[':
return iw8::parser::make_LBRACKET(loc_); return parser::make_LBRACKET(loc_);
case ']': case ']':
return iw8::parser::make_RBRACKET(loc_); return parser::make_RBRACKET(loc_);
case ',': case ',':
return iw8::parser::make_COMMA(loc_); return parser::make_COMMA(loc_);
case ';': case ';':
return iw8::parser::make_SEMICOLON(loc_); return parser::make_SEMICOLON(loc_);
case ':': case ':':
if (curr != ':') if (curr != ':')
return iw8::parser::make_COLON(loc_); return parser::make_COLON(loc_);
reader_.advance(); reader_.advance();
return iw8::parser::make_DOUBLECOLON(loc_); return parser::make_DOUBLECOLON(loc_);
case '?': case '?':
return iw8::parser::make_QMARK(loc_); return parser::make_QMARK(loc_);
case '=': case '=':
if (curr != '=') if (curr != '=')
return iw8::parser::make_ASSIGN(loc_); return parser::make_ASSIGN(loc_);
reader_.advance(); reader_.advance();
return iw8::parser::make_EQUALITY(loc_); return parser::make_EQUALITY(loc_);
case '+': case '+':
if (curr != '+' && curr != '=') if (curr != '+' && curr != '=')
return iw8::parser::make_ADD(loc_); return parser::make_ADD(loc_);
reader_.advance(); reader_.advance();
if (last == '+') if (last == '+')
return iw8::parser::make_INCREMENT(loc_); return parser::make_INCREMENT(loc_);
return iw8::parser::make_ASSIGN_ADD(loc_); return parser::make_ASSIGN_ADD(loc_);
case '-': case '-':
if (curr != '-' && curr != '=') if (curr != '-' && curr != '=')
return iw8::parser::make_SUB(loc_); return parser::make_SUB(loc_);
reader_.advance(); reader_.advance();
if (last == '-') if (last == '-')
return iw8::parser::make_DECREMENT(loc_); return parser::make_DECREMENT(loc_);
return iw8::parser::make_ASSIGN_SUB(loc_); return parser::make_ASSIGN_SUB(loc_);
case '%': case '%':
if (curr != '=') if (curr != '=')
return iw8::parser::make_MOD(loc_); return parser::make_MOD(loc_);
reader_.advance(); reader_.advance();
return iw8::parser::make_ASSIGN_MOD(loc_); return parser::make_ASSIGN_MOD(loc_);
case '|': case '|':
if (curr != '|' && curr != '=') if (curr != '|' && curr != '=')
return iw8::parser::make_BITWISE_OR(loc_); return parser::make_BITWISE_OR(loc_);
reader_.advance(); reader_.advance();
if (last == '|') if (last == '|')
return iw8::parser::make_OR(loc_); return parser::make_OR(loc_);
return iw8::parser::make_ASSIGN_BW_OR(loc_); return parser::make_ASSIGN_BW_OR(loc_);
case '&': case '&':
if (curr != '&' && curr != '=' && curr != '"' && curr != '\'') if (curr != '&' && curr != '=' && curr != '"' && curr != '\'')
return iw8::parser::make_BITWISE_AND(loc_); return parser::make_BITWISE_AND(loc_);
reader_.advance(); reader_.advance();
if (last == '&') if (last == '&')
return iw8::parser::make_AND(loc_); return parser::make_AND(loc_);
if (last == '=') if (last == '=')
return iw8::parser::make_ASSIGN_BW_AND(loc_); return parser::make_ASSIGN_BW_AND(loc_);
state_ = state::localize; state_ = state::localize;
goto lex_string; goto lex_string;
case '^': case '^':
if (curr != '=') if (curr != '=')
return iw8::parser::make_BITWISE_EXOR(loc_); return parser::make_BITWISE_EXOR(loc_);
reader_.advance(); reader_.advance();
return iw8::parser::make_ASSIGN_BW_EXOR(loc_); return parser::make_ASSIGN_BW_EXOR(loc_);
case '!': case '!':
if (curr != '=') if (curr != '=')
return iw8::parser::make_NOT(loc_); return parser::make_NOT(loc_);
reader_.advance(); reader_.advance();
return iw8::parser::make_INEQUALITY(loc_); return parser::make_INEQUALITY(loc_);
case '~': case '~':
return iw8::parser::make_COMPLEMENT(loc_); return parser::make_COMPLEMENT(loc_);
case '<': case '<':
if (curr != '<' && curr != '=') if (curr != '<' && curr != '=')
return iw8::parser::make_LESS(loc_); return parser::make_LESS(loc_);
reader_.advance(); reader_.advance();
if (last == '=') if (last == '=')
return iw8::parser::make_LESS_EQUAL(loc_); return parser::make_LESS_EQUAL(loc_);
if (curr != '=') if (curr != '=')
return iw8::parser::make_LSHIFT(loc_); return parser::make_LSHIFT(loc_);
reader_.advance(); reader_.advance();
return iw8::parser::make_ASSIGN_LSHIFT(loc_); return parser::make_ASSIGN_LSHIFT(loc_);
case '>': case '>':
if (curr != '>' && curr != '=') if (curr != '>' && curr != '=')
return iw8::parser::make_GREATER(loc_); return parser::make_GREATER(loc_);
reader_.advance(); reader_.advance();
if (last == '=') if (last == '=')
return iw8::parser::make_GREATER_EQUAL(loc_); return parser::make_GREATER_EQUAL(loc_);
if (curr != '=') if (curr != '=')
return iw8::parser::make_RSHIFT(loc_); return parser::make_RSHIFT(loc_);
reader_.advance(); reader_.advance();
return iw8::parser::make_ASSIGN_RSHIFT(loc_); return parser::make_ASSIGN_RSHIFT(loc_);
default: default:
lex_name_or_number: lex_name_or_number:
if (last >= '0' && last <= '9') if (last >= '0' && last <= '9')
@ -499,9 +445,9 @@ lex_string:
} }
if (state_ == state::localize) if (state_ == state::localize)
return iw8::parser::make_ISTRING(std::string(buffer_.data, buffer_.length), loc_); return parser::make_ISTRING(std::string(buffer_.data, buffer_.length), loc_);
return iw8::parser::make_STRING(std::string(buffer_.data, buffer_.length), loc_); return parser::make_STRING(std::string(buffer_.data, buffer_.length), loc_);
lex_name: lex_name:
buffer_.push(last); buffer_.push(last);
@ -536,22 +482,32 @@ lex_name:
if (std::string_view(buffer_.data, buffer_.length) == "size") if (std::string_view(buffer_.data, buffer_.length) == "size")
{ {
return iw8::parser::make_SIZE(loc_); return parser::make_SIZE(loc_);
} }
return iw8::parser::make_FIELD(std::string(buffer_.data, buffer_.length), loc_); return parser::make_FIELD(std::string(buffer_.data, buffer_.length), loc_);
} }
else if (state_ == state::preprocessor) else if (state_ == state::preprocessor)
{ {
if (path) if (path)
throw comp_error(loc_, "invalid preprocessor directive"); throw comp_error(loc_, "invalid preprocessor directive");
auto key = get_keyword(std::string_view(buffer_.data, buffer_.length)); auto token = parser::token::IW8UNDEF;
if (key != keyword::KW_INVALID) if (buffer_.length < 16)
return keyword_token(key); {
const auto& itr = keyword_map.find(std::string_view(buffer_.data, buffer_.length));
// TODO: call preprocessor(key); if(itr != keyword_map.end())
{
if (itr->second > parser::token::HSENDIF)
return parser::symbol_type(itr->second, loc_);
token = itr->second;
}
}
// TODO: call preprocessor(token);
throw comp_error(loc_, "unknown preprocessor directive"); throw comp_error(loc_, "unknown preprocessor directive");
state_ = state::start; state_ = state::start;
continue; continue;
@ -569,22 +525,23 @@ lex_name:
} }
} }
auto key = get_keyword(std::string_view(buffer_.data, buffer_.length)); if (buffer_.length < 17)
{
const auto& itr = keyword_map.find(std::string_view(buffer_.data, buffer_.length));
if (key != keyword::KW_INVALID) if(itr != keyword_map.end())
return keyword_token(key); return parser::symbol_type(itr->second, loc_);
}
if (path) if (path)
{ {
if (buffer_.data[buffer_.length - 1] == '/') if (buffer_.data[buffer_.length - 1] == '/')
throw comp_error(loc_, "invalid path end '\\'"); throw comp_error(loc_, "invalid path end '\\'");
//return iw8::parser::make_PATH(xsk::gsc::iw8::resolver::make_token(std::string_view(buffer_.data, buffer_.length)), loc_); return parser::make_PATH(resolver::make_token(std::string_view(buffer_.data, buffer_.length)), loc_);
return iw8::parser::make_PATH(std::string(buffer_.data, buffer_.length), loc_);
} }
//return iw8::parser::make_IDENTIFIER(xsk::gsc::iw8::resolver::make_token(std::string_view(buffer_.data, buffer_.length)), loc_); return parser::make_IDENTIFIER(resolver::make_token(std::string_view(buffer_.data, buffer_.length)), loc_);
return iw8::parser::make_IDENTIFIER(std::string(buffer_.data, buffer_.length), loc_);
} }
lex_number: lex_number:
@ -635,9 +592,9 @@ lex_number:
throw comp_error(loc_, "invalid number literal"); throw comp_error(loc_, "invalid number literal");
if (state_ == state::field || dot || flt) if (state_ == state::field || dot || flt)
return iw8::parser::make_FLOAT(std::string(buffer_.data, buffer_.length), loc_); return parser::make_FLOAT(std::string(buffer_.data, buffer_.length), loc_);
return iw8::parser::make_INTEGER(std::string(buffer_.data, buffer_.length), loc_); return parser::make_INTEGER(std::string(buffer_.data, buffer_.length), loc_);
} }
else if (curr == 'o') else if (curr == 'o')
{ {
@ -669,7 +626,7 @@ lex_number:
if (last == '\'' || buffer_.length <= 0) if (last == '\'' || buffer_.length <= 0)
throw comp_error(loc_, "invalid octal literal"); throw comp_error(loc_, "invalid octal literal");
return iw8::parser::make_INTEGER(xsk::utils::string::oct_to_dec(buffer_.data), loc_); return parser::make_INTEGER(xsk::utils::string::oct_to_dec(buffer_.data), loc_);
} }
else if (curr == 'b') else if (curr == 'b')
{ {
@ -703,7 +660,7 @@ lex_number:
if (last == '\'' || buffer_.length < 3) if (last == '\'' || buffer_.length < 3)
throw comp_error(loc_, "invalid binary literal"); throw comp_error(loc_, "invalid binary literal");
return iw8::parser::make_INTEGER(xsk::utils::string::bin_to_dec(buffer_.data), loc_); return parser::make_INTEGER(xsk::utils::string::bin_to_dec(buffer_.data), loc_);
} }
else if (curr == 'x') else if (curr == 'x')
{ {
@ -737,185 +694,62 @@ lex_number:
if (last == '\'' || buffer_.length < 3) if (last == '\'' || buffer_.length < 3)
throw comp_error(loc_, "invalid hexadecimal literal"); throw comp_error(loc_, "invalid hexadecimal literal");
return iw8::parser::make_INTEGER(xsk::utils::string::hex_to_dec(buffer_.data), loc_); return parser::make_INTEGER(xsk::utils::string::hex_to_dec(buffer_.data), loc_);
} }
// cant get here! // cant get here!
} }
} }
auto lexer::keyword_token(keyword k) -> xsk::gsc::iw8::parser::symbol_type const std::unordered_map<std::string_view, parser::token::token_kind_type> lexer::keyword_map
{
switch (k)
{
case keyword::KW_pre_inline:
return iw8::parser::make_INLINE(loc_);
case keyword::KW_pre_include:
return iw8::parser::make_INCLUDE(loc_);
case keyword::KW_pre_using_animtree:
return iw8::parser::make_USINGTREE(loc_);
case keyword::KW_pre_animtree:
return iw8::parser::make_ANIMTREE(loc_);
case keyword::KW_endon:
return iw8::parser::make_ENDON(loc_);
case keyword::KW_notify:
return iw8::parser::make_NOTIFY(loc_);
case keyword::KW_wait:
return iw8::parser::make_WAIT(loc_);
case keyword::KW_waittill:
return iw8::parser::make_WAITTILL(loc_);
case keyword::KW_waittillmatch:
return iw8::parser::make_WAITTILLMATCH(loc_);
case keyword::KW_waittillframeend:
return iw8::parser::make_WAITTILLFRAMEEND(loc_);
case keyword::KW_waitframe:
return iw8::parser::make_WAITFRAME(loc_);
case keyword::KW_if:
return iw8::parser::make_IF(loc_);
case keyword::KW_else:
return iw8::parser::make_ELSE(loc_);
case keyword::KW_do:
return iw8::parser::make_DO(loc_);
case keyword::KW_while:
return iw8::parser::make_WHILE(loc_);
case keyword::KW_for:
return iw8::parser::make_FOR(loc_);
case keyword::KW_foreach:
return iw8::parser::make_FOREACH(loc_);
case keyword::KW_in:
return iw8::parser::make_IN(loc_);
case keyword::KW_switch:
return iw8::parser::make_SWITCH(loc_);
case keyword::KW_case:
return iw8::parser::make_CASE(loc_);
case keyword::KW_default:
return iw8::parser::make_DEFAULT(loc_);
case keyword::KW_break:
return iw8::parser::make_BREAK(loc_);
case keyword::KW_continue:
return iw8::parser::make_CONTINUE(loc_);
case keyword::KW_return:
return iw8::parser::make_RETURN(loc_);
case keyword::KW_breakpoint:
return iw8::parser::make_BREAKPOINT(loc_);
case keyword::KW_prof_begin:
return iw8::parser::make_PROFBEGIN(loc_);
case keyword::KW_prof_end:
return iw8::parser::make_PROFEND(loc_);
case keyword::KW_thread:
return iw8::parser::make_THREAD(loc_);
case keyword::KW_childthread:
return iw8::parser::make_CHILDTHREAD(loc_);
case keyword::KW_thisthread:
return iw8::parser::make_THISTHREAD(loc_);
case keyword::KW_call:
return iw8::parser::make_CALL(loc_);
case keyword::KW_true:
return iw8::parser::make_TRUE(loc_);
case keyword::KW_false:
return iw8::parser::make_FALSE(loc_);
case keyword::KW_undefined:
return iw8::parser::make_UNDEFINED(loc_);
case keyword::KW_dotsize:
return iw8::parser::make_SIZE(loc_);
case keyword::KW_game:
return iw8::parser::make_GAME(loc_);
case keyword::KW_self:
return iw8::parser::make_SELF(loc_);
case keyword::KW_anim:
return iw8::parser::make_ANIM(loc_);
case keyword::KW_level:
return iw8::parser::make_LEVEL(loc_);
case keyword::KW_isdefined:
return iw8::parser::make_ISDEFINED(loc_);
case keyword::KW_istrue:
return iw8::parser::make_ISTRUE(loc_);
default:
throw error("gsc lexer: INVALID KEYWORD TOKEN!");
}
}
auto lexer::keyword_is_token(keyword k) -> bool
{
switch (k)
{
/* case keyword::KW_pre_define:
case keyword::KW_pre_undef:
case keyword::KW_pre_ifdef:
case keyword::KW_pre_ifndef:
case keyword::KW_pre_if:
case keyword::KW_pre_elif:
case keyword::KW_pre_else:
case keyword::KW_pre_endif:*/
case keyword::KW_INVALID:
return false;
default:
return true;
}
}
auto lexer::get_keyword(std::string_view str) -> keyword
{
auto itr = keywords.find(str);
if(itr != keywords.end())
{
return itr->second;
}
return keyword::KW_INVALID;
}
std::unordered_map<std::string_view, keyword> lexer::keywords
{{ {{
/* { "#define", keyword::KW_pre_define }, { "#define", parser::token::HSDEFINE },
{ "#undef", keyword::KW_pre_undef }, { "#undef", parser::token::HSUNDEF },
{ "#ifdef", keyword::KW_pre_ifdef }, { "#ifdef", parser::token::HSIFDEF },
{ "#ifndef", keyword::KW_pre_ifndef }, { "#ifndef", parser::token::HSIFNDEF },
{ "#if", keyword::KW_pre_if }, { "#if", parser::token::HSIF },
{ "#elif", keyword::KW_pre_elif }, { "#elif", parser::token::HSELIF },
{ "#else", keyword::KW_pre_else }, { "#else", parser::token::HSELSE },
{ "#endif", keyword::KW_pre_endif },*/ { "#endif", parser::token::HSENDIF },
{ "#inline", keyword::KW_pre_inline }, { "#inline", parser::token::INLINE },
{ "#include", keyword::KW_pre_include }, { "#include", parser::token::INCLUDE },
{ "#using_animtree", keyword::KW_pre_using_animtree }, { "#using_animtree", parser::token::USINGTREE },
{ "#animtree", keyword::KW_pre_animtree }, { "#animtree", parser::token::ANIMTREE },
{ "endon", keyword::KW_endon }, { "endon", parser::token::ENDON },
{ "notify", keyword::KW_notify }, { "notify", parser::token::NOTIFY },
{ "wait", keyword::KW_wait }, { "wait", parser::token::WAIT },
{ "waittill", keyword::KW_waittill }, { "waittill", parser::token::WAITTILL },
{ "waittillmatch", keyword::KW_waittillmatch }, { "waittillmatch", parser::token::WAITTILLMATCH },
{ "waittillframeend", keyword::KW_waittillframeend }, { "waittillframeend", parser::token::WAITTILLFRAMEEND },
{ "waitframe", keyword::KW_waitframe }, { "waitframe", parser::token::WAITFRAME },
{ "if", keyword::KW_if }, { "if", parser::token::IF },
{ "else", keyword::KW_else }, { "else", parser::token::ELSE },
{ "do", keyword::KW_do }, { "do", parser::token::DO },
{ "while", keyword::KW_while }, { "while", parser::token::WHILE },
{ "for", keyword::KW_for }, { "for", parser::token::FOR },
{ "foreach", keyword::KW_foreach }, { "foreach", parser::token::FOREACH },
{ "in", keyword::KW_in }, { "in", parser::token::IN },
{ "switch", keyword::KW_switch }, { "switch", parser::token::SWITCH },
{ "case", keyword::KW_case }, { "case", parser::token::CASE },
{ "default", keyword::KW_default }, { "default", parser::token::DEFAULT },
{ "break", keyword::KW_break }, { "break", parser::token::BREAK },
{ "continue", keyword::KW_continue }, { "continue", parser::token::CONTINUE },
{ "return", keyword::KW_return }, { "return", parser::token::RETURN },
{ "breakpoint", keyword::KW_breakpoint }, { "breakpoint", parser::token::BREAKPOINT },
{ "prof_begin", keyword::KW_prof_begin }, { "prof_begin", parser::token::PROFBEGIN },
{ "prof_end", keyword::KW_prof_end }, { "prof_end", parser::token::PROFEND },
{ "thread", keyword::KW_thread }, { "thread", parser::token::THREAD },
{ "childthread", keyword::KW_childthread }, { "childthread", parser::token::CHILDTHREAD },
{ "thisthread", keyword::KW_thisthread }, { "thisthread", parser::token::THISTHREAD },
{ "call", keyword::KW_call }, { "call", parser::token::CALL },
{ "true", keyword::KW_true }, { "true", parser::token::TRUE },
{ "false", keyword::KW_false }, { "false", parser::token::FALSE },
{ "undefined", keyword::KW_undefined }, { "undefined", parser::token::UNDEFINED },
{ ".size", keyword::KW_dotsize }, { "game", parser::token::GAME },
{ "game", keyword::KW_game }, { "self", parser::token::SELF },
{ "self", keyword::KW_self }, { "anim", parser::token::ANIM },
{ "anim", keyword::KW_anim }, { "level", parser::token::LEVEL },
{ "level", keyword::KW_level }, { "isdefined", parser::token::ISDEFINED },
{ "isdefined", keyword::KW_isdefined }, { "istrue", parser::token::ISTRUE },
{ "istrue", keyword::KW_istrue },
}}; }};
} // namespace xsk::gsc::iw8 } // namespace xsk::gsc::iw8

View File

@ -10,8 +10,6 @@
namespace xsk::gsc::iw8 namespace xsk::gsc::iw8
{ {
enum class keyword;
constexpr size_t max_buf_size = 0x2000; constexpr size_t max_buf_size = 0x2000;
struct buffer struct buffer
@ -53,26 +51,22 @@ class lexer
reader reader_; reader reader_;
buffer buffer_; buffer buffer_;
location loc_; location loc_;
build mode_;
std::stack<location> locs_; std::stack<location> locs_;
std::stack<reader> readers_; std::stack<reader> readers_;
std::uint32_t header_top_; std::uint32_t header_top_;
state state_; state state_;
build mode_;
bool indev_; bool indev_;
public: public:
lexer(const std::string& name, const char* data, size_t size); lexer(const std::string& name, const char* data, size_t size);
auto lex() -> xsk::gsc::iw8::parser::symbol_type; auto lex() -> parser::symbol_type;
void push_header(const std::string& file); void push_header(const std::string& file);
void pop_header(); void pop_header();
void restrict_header(const xsk::gsc::location& loc); void ban_header(const location& loc);
private: private:
auto keyword_token(keyword k) -> xsk::gsc::iw8::parser::symbol_type; static const std::unordered_map<std::string_view, parser::token::token_kind_type> keyword_map;
static auto keyword_is_token(keyword k) -> bool;
static auto get_keyword(std::string_view str) -> keyword;
static std::unordered_map<std::string_view, keyword> keywords;
}; };
} // namespace xsk::gsc::iw8 } // namespace xsk::gsc::iw8

File diff suppressed because it is too large Load Diff

View File

@ -683,111 +683,119 @@ namespace xsk { namespace gsc { namespace iw8 {
IW8EOF = 0, // "end of file" IW8EOF = 0, // "end of file"
IW8error = 1, // error IW8error = 1, // error
IW8UNDEF = 2, // "invalid token" IW8UNDEF = 2, // "invalid token"
DEVBEGIN = 3, // "/#" HSDEFINE = 3, // "#define"
DEVEND = 4, // "#/" HSUNDEF = 4, // "#undef"
INLINE = 5, // "#inline" HSIFDEF = 5, // "#ifdef"
INCLUDE = 6, // "#include" HSIFNDEF = 6, // "#ifndef"
USINGTREE = 7, // "#using_animtree" HSIF = 7, // "#if"
ANIMTREE = 8, // "#animtree" HSELIF = 8, // "#elif"
ENDON = 9, // "endon" HSELSE = 9, // "#else"
NOTIFY = 10, // "notify" HSENDIF = 10, // "#endif"
WAIT = 11, // "wait" DEVBEGIN = 11, // "/#"
WAITTILL = 12, // "waittill" DEVEND = 12, // "#/"
WAITTILLMATCH = 13, // "waittillmatch" INLINE = 13, // "#inline"
WAITTILLFRAMEEND = 14, // "waittillframeend" INCLUDE = 14, // "#include"
WAITFRAME = 15, // "waitframe" USINGTREE = 15, // "#using_animtree"
IF = 16, // "if" ANIMTREE = 16, // "#animtree"
ELSE = 17, // "else" ENDON = 17, // "endon"
DO = 18, // "do" NOTIFY = 18, // "notify"
WHILE = 19, // "while" WAIT = 19, // "wait"
FOR = 20, // "for" WAITTILL = 20, // "waittill"
FOREACH = 21, // "foreach" WAITTILLMATCH = 21, // "waittillmatch"
IN = 22, // "in" WAITTILLFRAMEEND = 22, // "waittillframeend"
SWITCH = 23, // "switch" WAITFRAME = 23, // "waitframe"
CASE = 24, // "case" IF = 24, // "if"
DEFAULT = 25, // "default" ELSE = 25, // "else"
BREAK = 26, // "break" DO = 26, // "do"
CONTINUE = 27, // "continue" WHILE = 27, // "while"
RETURN = 28, // "return" FOR = 28, // "for"
BREAKPOINT = 29, // "breakpoint" FOREACH = 29, // "foreach"
PROFBEGIN = 30, // "prof_begin" IN = 30, // "in"
PROFEND = 31, // "prof_end" SWITCH = 31, // "switch"
THREAD = 32, // "thread" CASE = 32, // "case"
CHILDTHREAD = 33, // "childthread" DEFAULT = 33, // "default"
THISTHREAD = 34, // "thisthread" BREAK = 34, // "break"
CALL = 35, // "call" CONTINUE = 35, // "continue"
TRUE = 36, // "true" RETURN = 36, // "return"
FALSE = 37, // "false" BREAKPOINT = 37, // "breakpoint"
UNDEFINED = 38, // "undefined" PROFBEGIN = 38, // "prof_begin"
SIZE = 39, // ".size" PROFEND = 39, // "prof_end"
GAME = 40, // "game" THREAD = 40, // "thread"
SELF = 41, // "self" CHILDTHREAD = 41, // "childthread"
ANIM = 42, // "anim" THISTHREAD = 42, // "thisthread"
LEVEL = 43, // "level" CALL = 43, // "call"
ISDEFINED = 44, // "isdefined" TRUE = 44, // "true"
ISTRUE = 45, // "istrue" FALSE = 45, // "false"
LPAREN = 46, // "(" UNDEFINED = 46, // "undefined"
RPAREN = 47, // ")" SIZE = 47, // ".size"
LBRACE = 48, // "{" GAME = 48, // "game"
RBRACE = 49, // "}" SELF = 49, // "self"
LBRACKET = 50, // "[" ANIM = 50, // "anim"
RBRACKET = 51, // "]" LEVEL = 51, // "level"
COMMA = 52, // "," ISDEFINED = 52, // "isdefined"
DOT = 53, // "." ISTRUE = 53, // "istrue"
DOUBLECOLON = 54, // "::" LPAREN = 54, // "("
COLON = 55, // ":" RPAREN = 55, // ")"
SEMICOLON = 56, // ";" LBRACE = 56, // "{"
QMARK = 57, // "?" RBRACE = 57, // "}"
INCREMENT = 58, // "++" LBRACKET = 58, // "["
DECREMENT = 59, // "--" RBRACKET = 59, // "]"
LSHIFT = 60, // "<<" COMMA = 60, // ","
RSHIFT = 61, // ">>" DOT = 61, // "."
OR = 62, // "||" DOUBLECOLON = 62, // "::"
AND = 63, // "&&" COLON = 63, // ":"
EQUALITY = 64, // "==" SEMICOLON = 64, // ";"
INEQUALITY = 65, // "!=" QMARK = 65, // "?"
LESS_EQUAL = 66, // "<=" INCREMENT = 66, // "++"
GREATER_EQUAL = 67, // ">=" DECREMENT = 67, // "--"
LESS = 68, // "<" LSHIFT = 68, // "<<"
GREATER = 69, // ">" RSHIFT = 69, // ">>"
NOT = 70, // "!" OR = 70, // "||"
COMPLEMENT = 71, // "~" AND = 71, // "&&"
ASSIGN = 72, // "=" EQUALITY = 72, // "=="
ASSIGN_ADD = 73, // "+=" INEQUALITY = 73, // "!="
ASSIGN_SUB = 74, // "-=" LESS_EQUAL = 74, // "<="
ASSIGN_MUL = 75, // "*=" GREATER_EQUAL = 75, // ">="
ASSIGN_DIV = 76, // "/=" LESS = 76, // "<"
ASSIGN_MOD = 77, // "%=" GREATER = 77, // ">"
ASSIGN_BW_OR = 78, // "|=" NOT = 78, // "!"
ASSIGN_BW_AND = 79, // "&=" COMPLEMENT = 79, // "~"
ASSIGN_BW_EXOR = 80, // "^=" ASSIGN = 80, // "="
ASSIGN_RSHIFT = 81, // ">>=" ASSIGN_ADD = 81, // "+="
ASSIGN_LSHIFT = 82, // "<<=" ASSIGN_SUB = 82, // "-="
BITWISE_OR = 83, // "|" ASSIGN_MUL = 83, // "*="
BITWISE_AND = 84, // "&" ASSIGN_DIV = 84, // "/="
BITWISE_EXOR = 85, // "^" ASSIGN_MOD = 85, // "%="
ADD = 86, // "+" ASSIGN_BW_OR = 86, // "|="
SUB = 87, // "-" ASSIGN_BW_AND = 87, // "&="
MUL = 88, // "*" ASSIGN_BW_EXOR = 88, // "^="
DIV = 89, // "/" ASSIGN_RSHIFT = 89, // ">>="
MOD = 90, // "%" ASSIGN_LSHIFT = 90, // "<<="
FIELD = 91, // "field" BITWISE_OR = 91, // "|"
PATH = 92, // "path" BITWISE_AND = 92, // "&"
IDENTIFIER = 93, // "identifier" BITWISE_EXOR = 93, // "^"
STRING = 94, // "string literal" ADD = 94, // "+"
ISTRING = 95, // "localized string" SUB = 95, // "-"
COLOR = 96, // "color" MUL = 96, // "*"
FLOAT = 97, // "float" DIV = 97, // "/"
INTEGER = 98, // "integer" MOD = 98, // "%"
ADD_ARRAY = 99, // ADD_ARRAY FIELD = 99, // "field"
THEN = 100, // THEN PATH = 100, // "path"
TERN = 101, // TERN IDENTIFIER = 101, // "identifier"
NEG = 102, // NEG STRING = 102, // "string literal"
ANIMREF = 103, // ANIMREF ISTRING = 103, // "localized string"
PREINC = 104, // PREINC COLOR = 104, // "color"
PREDEC = 105, // PREDEC FLOAT = 105, // "float"
POSTINC = 106, // POSTINC INTEGER = 106, // "integer"
POSTDEC = 107 // POSTDEC ADD_ARRAY = 107, // ADD_ARRAY
THEN = 108, // THEN
TERN = 109, // TERN
NEG = 110, // NEG
ANIMREF = 111, // ANIMREF
PREINC = 112, // PREINC
PREDEC = 113, // PREDEC
POSTINC = 114, // POSTINC
POSTDEC = 115 // POSTDEC
}; };
/// Backward compatibility alias (Bison 3.6). /// Backward compatibility alias (Bison 3.6).
typedef token_kind_type yytokentype; typedef token_kind_type yytokentype;
@ -804,199 +812,207 @@ namespace xsk { namespace gsc { namespace iw8 {
{ {
enum symbol_kind_type enum symbol_kind_type
{ {
YYNTOKENS = 108, ///< Number of tokens. YYNTOKENS = 116, ///< Number of tokens.
S_YYEMPTY = -2, S_YYEMPTY = -2,
S_YYEOF = 0, // "end of file" S_YYEOF = 0, // "end of file"
S_YYerror = 1, // error S_YYerror = 1, // error
S_YYUNDEF = 2, // "invalid token" S_YYUNDEF = 2, // "invalid token"
S_DEVBEGIN = 3, // "/#" S_HSDEFINE = 3, // "#define"
S_DEVEND = 4, // "#/" S_HSUNDEF = 4, // "#undef"
S_INLINE = 5, // "#inline" S_HSIFDEF = 5, // "#ifdef"
S_INCLUDE = 6, // "#include" S_HSIFNDEF = 6, // "#ifndef"
S_USINGTREE = 7, // "#using_animtree" S_HSIF = 7, // "#if"
S_ANIMTREE = 8, // "#animtree" S_HSELIF = 8, // "#elif"
S_ENDON = 9, // "endon" S_HSELSE = 9, // "#else"
S_NOTIFY = 10, // "notify" S_HSENDIF = 10, // "#endif"
S_WAIT = 11, // "wait" S_DEVBEGIN = 11, // "/#"
S_WAITTILL = 12, // "waittill" S_DEVEND = 12, // "#/"
S_WAITTILLMATCH = 13, // "waittillmatch" S_INLINE = 13, // "#inline"
S_WAITTILLFRAMEEND = 14, // "waittillframeend" S_INCLUDE = 14, // "#include"
S_WAITFRAME = 15, // "waitframe" S_USINGTREE = 15, // "#using_animtree"
S_IF = 16, // "if" S_ANIMTREE = 16, // "#animtree"
S_ELSE = 17, // "else" S_ENDON = 17, // "endon"
S_DO = 18, // "do" S_NOTIFY = 18, // "notify"
S_WHILE = 19, // "while" S_WAIT = 19, // "wait"
S_FOR = 20, // "for" S_WAITTILL = 20, // "waittill"
S_FOREACH = 21, // "foreach" S_WAITTILLMATCH = 21, // "waittillmatch"
S_IN = 22, // "in" S_WAITTILLFRAMEEND = 22, // "waittillframeend"
S_SWITCH = 23, // "switch" S_WAITFRAME = 23, // "waitframe"
S_CASE = 24, // "case" S_IF = 24, // "if"
S_DEFAULT = 25, // "default" S_ELSE = 25, // "else"
S_BREAK = 26, // "break" S_DO = 26, // "do"
S_CONTINUE = 27, // "continue" S_WHILE = 27, // "while"
S_RETURN = 28, // "return" S_FOR = 28, // "for"
S_BREAKPOINT = 29, // "breakpoint" S_FOREACH = 29, // "foreach"
S_PROFBEGIN = 30, // "prof_begin" S_IN = 30, // "in"
S_PROFEND = 31, // "prof_end" S_SWITCH = 31, // "switch"
S_THREAD = 32, // "thread" S_CASE = 32, // "case"
S_CHILDTHREAD = 33, // "childthread" S_DEFAULT = 33, // "default"
S_THISTHREAD = 34, // "thisthread" S_BREAK = 34, // "break"
S_CALL = 35, // "call" S_CONTINUE = 35, // "continue"
S_TRUE = 36, // "true" S_RETURN = 36, // "return"
S_FALSE = 37, // "false" S_BREAKPOINT = 37, // "breakpoint"
S_UNDEFINED = 38, // "undefined" S_PROFBEGIN = 38, // "prof_begin"
S_SIZE = 39, // ".size" S_PROFEND = 39, // "prof_end"
S_GAME = 40, // "game" S_THREAD = 40, // "thread"
S_SELF = 41, // "self" S_CHILDTHREAD = 41, // "childthread"
S_ANIM = 42, // "anim" S_THISTHREAD = 42, // "thisthread"
S_LEVEL = 43, // "level" S_CALL = 43, // "call"
S_ISDEFINED = 44, // "isdefined" S_TRUE = 44, // "true"
S_ISTRUE = 45, // "istrue" S_FALSE = 45, // "false"
S_LPAREN = 46, // "(" S_UNDEFINED = 46, // "undefined"
S_RPAREN = 47, // ")" S_SIZE = 47, // ".size"
S_LBRACE = 48, // "{" S_GAME = 48, // "game"
S_RBRACE = 49, // "}" S_SELF = 49, // "self"
S_LBRACKET = 50, // "[" S_ANIM = 50, // "anim"
S_RBRACKET = 51, // "]" S_LEVEL = 51, // "level"
S_COMMA = 52, // "," S_ISDEFINED = 52, // "isdefined"
S_DOT = 53, // "." S_ISTRUE = 53, // "istrue"
S_DOUBLECOLON = 54, // "::" S_LPAREN = 54, // "("
S_COLON = 55, // ":" S_RPAREN = 55, // ")"
S_SEMICOLON = 56, // ";" S_LBRACE = 56, // "{"
S_QMARK = 57, // "?" S_RBRACE = 57, // "}"
S_INCREMENT = 58, // "++" S_LBRACKET = 58, // "["
S_DECREMENT = 59, // "--" S_RBRACKET = 59, // "]"
S_LSHIFT = 60, // "<<" S_COMMA = 60, // ","
S_RSHIFT = 61, // ">>" S_DOT = 61, // "."
S_OR = 62, // "||" S_DOUBLECOLON = 62, // "::"
S_AND = 63, // "&&" S_COLON = 63, // ":"
S_EQUALITY = 64, // "==" S_SEMICOLON = 64, // ";"
S_INEQUALITY = 65, // "!=" S_QMARK = 65, // "?"
S_LESS_EQUAL = 66, // "<=" S_INCREMENT = 66, // "++"
S_GREATER_EQUAL = 67, // ">=" S_DECREMENT = 67, // "--"
S_LESS = 68, // "<" S_LSHIFT = 68, // "<<"
S_GREATER = 69, // ">" S_RSHIFT = 69, // ">>"
S_NOT = 70, // "!" S_OR = 70, // "||"
S_COMPLEMENT = 71, // "~" S_AND = 71, // "&&"
S_ASSIGN = 72, // "=" S_EQUALITY = 72, // "=="
S_ASSIGN_ADD = 73, // "+=" S_INEQUALITY = 73, // "!="
S_ASSIGN_SUB = 74, // "-=" S_LESS_EQUAL = 74, // "<="
S_ASSIGN_MUL = 75, // "*=" S_GREATER_EQUAL = 75, // ">="
S_ASSIGN_DIV = 76, // "/=" S_LESS = 76, // "<"
S_ASSIGN_MOD = 77, // "%=" S_GREATER = 77, // ">"
S_ASSIGN_BW_OR = 78, // "|=" S_NOT = 78, // "!"
S_ASSIGN_BW_AND = 79, // "&=" S_COMPLEMENT = 79, // "~"
S_ASSIGN_BW_EXOR = 80, // "^=" S_ASSIGN = 80, // "="
S_ASSIGN_RSHIFT = 81, // ">>=" S_ASSIGN_ADD = 81, // "+="
S_ASSIGN_LSHIFT = 82, // "<<=" S_ASSIGN_SUB = 82, // "-="
S_BITWISE_OR = 83, // "|" S_ASSIGN_MUL = 83, // "*="
S_BITWISE_AND = 84, // "&" S_ASSIGN_DIV = 84, // "/="
S_BITWISE_EXOR = 85, // "^" S_ASSIGN_MOD = 85, // "%="
S_ADD = 86, // "+" S_ASSIGN_BW_OR = 86, // "|="
S_SUB = 87, // "-" S_ASSIGN_BW_AND = 87, // "&="
S_MUL = 88, // "*" S_ASSIGN_BW_EXOR = 88, // "^="
S_DIV = 89, // "/" S_ASSIGN_RSHIFT = 89, // ">>="
S_MOD = 90, // "%" S_ASSIGN_LSHIFT = 90, // "<<="
S_FIELD = 91, // "field" S_BITWISE_OR = 91, // "|"
S_PATH = 92, // "path" S_BITWISE_AND = 92, // "&"
S_IDENTIFIER = 93, // "identifier" S_BITWISE_EXOR = 93, // "^"
S_STRING = 94, // "string literal" S_ADD = 94, // "+"
S_ISTRING = 95, // "localized string" S_SUB = 95, // "-"
S_COLOR = 96, // "color" S_MUL = 96, // "*"
S_FLOAT = 97, // "float" S_DIV = 97, // "/"
S_INTEGER = 98, // "integer" S_MOD = 98, // "%"
S_ADD_ARRAY = 99, // ADD_ARRAY S_FIELD = 99, // "field"
S_THEN = 100, // THEN S_PATH = 100, // "path"
S_TERN = 101, // TERN S_IDENTIFIER = 101, // "identifier"
S_NEG = 102, // NEG S_STRING = 102, // "string literal"
S_ANIMREF = 103, // ANIMREF S_ISTRING = 103, // "localized string"
S_PREINC = 104, // PREINC S_COLOR = 104, // "color"
S_PREDEC = 105, // PREDEC S_FLOAT = 105, // "float"
S_POSTINC = 106, // POSTINC S_INTEGER = 106, // "integer"
S_POSTDEC = 107, // POSTDEC S_ADD_ARRAY = 107, // ADD_ARRAY
S_YYACCEPT = 108, // $accept S_THEN = 108, // THEN
S_root = 109, // root S_TERN = 109, // TERN
S_program = 110, // program S_NEG = 110, // NEG
S_inline = 111, // inline S_ANIMREF = 111, // ANIMREF
S_include = 112, // include S_PREINC = 112, // PREINC
S_declaration = 113, // declaration S_PREDEC = 113, // PREDEC
S_decl_usingtree = 114, // decl_usingtree S_POSTINC = 114, // POSTINC
S_decl_constant = 115, // decl_constant S_POSTDEC = 115, // POSTDEC
S_decl_thread = 116, // decl_thread S_YYACCEPT = 116, // $accept
S_stmt = 117, // stmt S_root = 117, // root
S_stmt_dev = 118, // stmt_dev S_program = 118, // program
S_stmt_block = 119, // stmt_block S_inline = 119, // inline
S_stmt_list = 120, // stmt_list S_include = 120, // include
S_stmt_expr = 121, // stmt_expr S_declaration = 121, // declaration
S_stmt_call = 122, // stmt_call S_decl_usingtree = 122, // decl_usingtree
S_stmt_assign = 123, // stmt_assign S_decl_constant = 123, // decl_constant
S_stmt_endon = 124, // stmt_endon S_decl_thread = 124, // decl_thread
S_stmt_notify = 125, // stmt_notify S_stmt = 125, // stmt
S_stmt_wait = 126, // stmt_wait S_stmt_dev = 126, // stmt_dev
S_stmt_waittill = 127, // stmt_waittill S_stmt_block = 127, // stmt_block
S_stmt_waittillmatch = 128, // stmt_waittillmatch S_stmt_list = 128, // stmt_list
S_stmt_waittillframeend = 129, // stmt_waittillframeend S_stmt_expr = 129, // stmt_expr
S_stmt_waitframe = 130, // stmt_waitframe S_stmt_call = 130, // stmt_call
S_stmt_if = 131, // stmt_if S_stmt_assign = 131, // stmt_assign
S_stmt_ifelse = 132, // stmt_ifelse S_stmt_endon = 132, // stmt_endon
S_stmt_while = 133, // stmt_while S_stmt_notify = 133, // stmt_notify
S_stmt_dowhile = 134, // stmt_dowhile S_stmt_wait = 134, // stmt_wait
S_stmt_for = 135, // stmt_for S_stmt_waittill = 135, // stmt_waittill
S_stmt_foreach = 136, // stmt_foreach S_stmt_waittillmatch = 136, // stmt_waittillmatch
S_stmt_switch = 137, // stmt_switch S_stmt_waittillframeend = 137, // stmt_waittillframeend
S_stmt_case = 138, // stmt_case S_stmt_waitframe = 138, // stmt_waitframe
S_stmt_default = 139, // stmt_default S_stmt_if = 139, // stmt_if
S_stmt_break = 140, // stmt_break S_stmt_ifelse = 140, // stmt_ifelse
S_stmt_continue = 141, // stmt_continue S_stmt_while = 141, // stmt_while
S_stmt_return = 142, // stmt_return S_stmt_dowhile = 142, // stmt_dowhile
S_stmt_breakpoint = 143, // stmt_breakpoint S_stmt_for = 143, // stmt_for
S_stmt_prof_begin = 144, // stmt_prof_begin S_stmt_foreach = 144, // stmt_foreach
S_stmt_prof_end = 145, // stmt_prof_end S_stmt_switch = 145, // stmt_switch
S_expr = 146, // expr S_stmt_case = 146, // stmt_case
S_expr_or_empty = 147, // expr_or_empty S_stmt_default = 147, // stmt_default
S_expr_assign = 148, // expr_assign S_stmt_break = 148, // stmt_break
S_expr_increment = 149, // expr_increment S_stmt_continue = 149, // stmt_continue
S_expr_decrement = 150, // expr_decrement S_stmt_return = 150, // stmt_return
S_expr_ternary = 151, // expr_ternary S_stmt_breakpoint = 151, // stmt_breakpoint
S_expr_binary = 152, // expr_binary S_stmt_prof_begin = 152, // stmt_prof_begin
S_expr_primitive = 153, // expr_primitive S_stmt_prof_end = 153, // stmt_prof_end
S_expr_complement = 154, // expr_complement S_expr = 154, // expr
S_expr_not = 155, // expr_not S_expr_or_empty = 155, // expr_or_empty
S_expr_call = 156, // expr_call S_expr_assign = 156, // expr_assign
S_expr_method = 157, // expr_method S_expr_increment = 157, // expr_increment
S_expr_function = 158, // expr_function S_expr_decrement = 158, // expr_decrement
S_expr_pointer = 159, // expr_pointer S_expr_ternary = 159, // expr_ternary
S_expr_add_array = 160, // expr_add_array S_expr_binary = 160, // expr_binary
S_expr_parameters = 161, // expr_parameters S_expr_primitive = 161, // expr_primitive
S_expr_arguments = 162, // expr_arguments S_expr_complement = 162, // expr_complement
S_expr_arguments_no_empty = 163, // expr_arguments_no_empty S_expr_not = 163, // expr_not
S_expr_isdefined = 164, // expr_isdefined S_expr_call = 164, // expr_call
S_expr_istrue = 165, // expr_istrue S_expr_method = 165, // expr_method
S_expr_reference = 166, // expr_reference S_expr_function = 166, // expr_function
S_expr_array = 167, // expr_array S_expr_pointer = 167, // expr_pointer
S_expr_field = 168, // expr_field S_expr_add_array = 168, // expr_add_array
S_expr_size = 169, // expr_size S_expr_parameters = 169, // expr_parameters
S_expr_paren = 170, // expr_paren S_expr_arguments = 170, // expr_arguments
S_expr_object = 171, // expr_object S_expr_arguments_no_empty = 171, // expr_arguments_no_empty
S_expr_thisthread = 172, // expr_thisthread S_expr_isdefined = 172, // expr_isdefined
S_expr_empty_array = 173, // expr_empty_array S_expr_istrue = 173, // expr_istrue
S_expr_undefined = 174, // expr_undefined S_expr_reference = 174, // expr_reference
S_expr_game = 175, // expr_game S_expr_array = 175, // expr_array
S_expr_self = 176, // expr_self S_expr_field = 176, // expr_field
S_expr_anim = 177, // expr_anim S_expr_size = 177, // expr_size
S_expr_level = 178, // expr_level S_expr_paren = 178, // expr_paren
S_expr_animation = 179, // expr_animation S_expr_object = 179, // expr_object
S_expr_animtree = 180, // expr_animtree S_expr_thisthread = 180, // expr_thisthread
S_expr_identifier = 181, // expr_identifier S_expr_empty_array = 181, // expr_empty_array
S_expr_path = 182, // expr_path S_expr_undefined = 182, // expr_undefined
S_expr_istring = 183, // expr_istring S_expr_game = 183, // expr_game
S_expr_string = 184, // expr_string S_expr_self = 184, // expr_self
S_expr_color = 185, // expr_color S_expr_anim = 185, // expr_anim
S_expr_vector = 186, // expr_vector S_expr_level = 186, // expr_level
S_expr_float = 187, // expr_float S_expr_animation = 187, // expr_animation
S_expr_integer = 188, // expr_integer S_expr_animtree = 188, // expr_animtree
S_expr_false = 189, // expr_false S_expr_identifier = 189, // expr_identifier
S_expr_true = 190 // expr_true S_expr_path = 190, // expr_path
S_expr_istring = 191, // expr_istring
S_expr_string = 192, // expr_string
S_expr_color = 193, // expr_color
S_expr_vector = 194, // expr_vector
S_expr_float = 195, // expr_float
S_expr_integer = 196, // expr_integer
S_expr_false = 197, // expr_false
S_expr_true = 198 // expr_true
}; };
}; };
@ -2835,6 +2851,126 @@ switch (yykind)
return symbol_type (token::IW8UNDEF, l); return symbol_type (token::IW8UNDEF, l);
} }
#endif #endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_HSDEFINE (location_type l)
{
return symbol_type (token::HSDEFINE, std::move (l));
}
#else
static
symbol_type
make_HSDEFINE (const location_type& l)
{
return symbol_type (token::HSDEFINE, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_HSUNDEF (location_type l)
{
return symbol_type (token::HSUNDEF, std::move (l));
}
#else
static
symbol_type
make_HSUNDEF (const location_type& l)
{
return symbol_type (token::HSUNDEF, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_HSIFDEF (location_type l)
{
return symbol_type (token::HSIFDEF, std::move (l));
}
#else
static
symbol_type
make_HSIFDEF (const location_type& l)
{
return symbol_type (token::HSIFDEF, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_HSIFNDEF (location_type l)
{
return symbol_type (token::HSIFNDEF, std::move (l));
}
#else
static
symbol_type
make_HSIFNDEF (const location_type& l)
{
return symbol_type (token::HSIFNDEF, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_HSIF (location_type l)
{
return symbol_type (token::HSIF, std::move (l));
}
#else
static
symbol_type
make_HSIF (const location_type& l)
{
return symbol_type (token::HSIF, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_HSELIF (location_type l)
{
return symbol_type (token::HSELIF, std::move (l));
}
#else
static
symbol_type
make_HSELIF (const location_type& l)
{
return symbol_type (token::HSELIF, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_HSELSE (location_type l)
{
return symbol_type (token::HSELSE, std::move (l));
}
#else
static
symbol_type
make_HSELSE (const location_type& l)
{
return symbol_type (token::HSELSE, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_HSENDIF (location_type l)
{
return symbol_type (token::HSENDIF, std::move (l));
}
#else
static
symbol_type
make_HSENDIF (const location_type& l)
{
return symbol_type (token::HSENDIF, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS #if 201103L <= YY_CPLUSPLUS
static static
symbol_type symbol_type
@ -5464,7 +5600,7 @@ switch (yykind)
#line 13 "parser.ypp" #line 13 "parser.ypp"
} } } // xsk::gsc::iw8 } } } // xsk::gsc::iw8
#line 5468 "parser.hpp" #line 5604 "parser.hpp"

View File

@ -16,58 +16,6 @@ xsk::gsc::s1::parser::symbol_type S1lex(xsk::gsc::s1::lexer& lexer)
namespace xsk::gsc::s1 namespace xsk::gsc::s1
{ {
enum class keyword
{
/* KW_pre_define,
KW_pre_undef,
KW_pre_ifdef,
KW_pre_ifndef,
KW_pre_if,
KW_pre_elif,
KW_pre_else,
KW_pre_endif,*/
KW_pre_inline,
KW_pre_include,
KW_pre_using_animtree,
KW_pre_animtree,
KW_endon,
KW_notify,
KW_wait,
KW_waittill,
KW_waittillmatch,
KW_waittillframeend,
KW_waitframe,
KW_if,
KW_else,
KW_do,
KW_while,
KW_for,
KW_foreach,
KW_in,
KW_switch,
KW_case,
KW_default,
KW_break,
KW_continue,
KW_return,
KW_breakpoint,
KW_prof_begin,
KW_prof_end,
KW_thread,
KW_childthread,
KW_thisthread,
KW_call,
KW_true,
KW_false,
KW_undefined,
KW_dotsize,
KW_game,
KW_self,
KW_anim,
KW_level,
KW_INVALID,
};
buffer::buffer() : length(0) buffer::buffer() : length(0)
{ {
data = static_cast<char*>(std::malloc(max_buf_size)); data = static_cast<char*>(std::malloc(max_buf_size));
@ -130,7 +78,7 @@ void reader::advance()
} }
} }
lexer::lexer(const std::string& name, const char* data, size_t size) : indev_(false), loc_(xsk::gsc::location(&name)), lexer::lexer(const std::string& name, const char* data, size_t size) : indev_(false), loc_(location(&name)),
mode_(build::dev), header_top_(0), locs_(std::stack<location>()), readers_(std::stack<reader>()) mode_(build::dev), header_top_(0), locs_(std::stack<location>()), readers_(std::stack<reader>())
{ {
reader_.init(data, size); reader_.init(data, size);
@ -141,7 +89,7 @@ void lexer::push_header(const std::string& file)
try try
{ {
if (header_top_++ >= 10) if (header_top_++ >= 10)
throw xsk::gsc::error("maximum gsh depth exceeded '10'"); throw comp_error(loc_, "maximum gsh depth exceeded '10'");
auto data = resolver::file_data(file + ".gsh"); auto data = resolver::file_data(file + ".gsh");
@ -152,7 +100,7 @@ void lexer::push_header(const std::string& file)
} }
catch (const std::exception& e) catch (const std::exception& e)
{ {
throw xsk::gsc::error("parsing header file '" + file + "': " + e.what()); throw error("parsing header file '" + file + "': " + e.what());
} }
} }
@ -165,7 +113,7 @@ void lexer::pop_header()
readers_.pop(); readers_.pop();
} }
void lexer::restrict_header(const xsk::gsc::location& loc) void lexer::ban_header(const location& loc)
{ {
if (header_top_ > 0) if (header_top_ > 0)
{ {
@ -173,7 +121,7 @@ void lexer::restrict_header(const xsk::gsc::location& loc)
} }
} }
auto lexer::lex() -> xsk::gsc::s1::parser::symbol_type auto lexer::lex() -> parser::symbol_type
{ {
buffer_.length = 0; buffer_.length = 0;
state_ = state::start; state_ = state::start;
@ -194,7 +142,7 @@ auto lexer::lex() -> xsk::gsc::s1::parser::symbol_type
if (header_top_ > 0) if (header_top_ > 0)
pop_header(); pop_header();
else else
return s1::parser::make_S1EOF(loc_); return parser::make_S1EOF(loc_);
} }
reader_.advance(); reader_.advance();
@ -212,22 +160,22 @@ auto lexer::lex() -> xsk::gsc::s1::parser::symbol_type
continue; continue;
case '/': case '/':
if (curr != '/' && curr != '*' && curr != '#' && curr != '=') if (curr != '/' && curr != '*' && curr != '#' && curr != '=')
return s1::parser::make_DIV(loc_); return parser::make_DIV(loc_);
reader_.advance(); reader_.advance();
if (last == '=') if (last == '=')
return s1::parser::make_ASSIGN_DIV(loc_); return parser::make_ASSIGN_DIV(loc_);
if (last == '#') if (last == '#')
{ {
if (indev_) if (indev_)
throw comp_error(loc_, "cannot recurse devblock ('/#')"); throw comp_error(loc_, "cannot recurse devblock ('/#')");
if (mode_ == xsk::gsc::build::dev) if (mode_ == build::dev)
{ {
indev_ = true; indev_ = true;
return s1::parser::make_DEVBEGIN(loc_); return parser::make_DEVBEGIN(loc_);
} }
else else
{ {
@ -291,7 +239,7 @@ auto lexer::lex() -> xsk::gsc::s1::parser::symbol_type
indev_ = false; indev_ = false;
reader_.advance(); reader_.advance();
return s1::parser::make_DEVEND(loc_); return parser::make_DEVEND(loc_);
} }
buffer_.push(last); buffer_.push(last);
@ -304,12 +252,12 @@ auto lexer::lex() -> xsk::gsc::s1::parser::symbol_type
goto lex_name; goto lex_name;
case '*': case '*':
if (curr != '/' && curr != '=') if (curr != '/' && curr != '=')
return s1::parser::make_MUL(loc_); return parser::make_MUL(loc_);
reader_.advance(); reader_.advance();
if (last == '=') if (last == '=')
return s1::parser::make_ASSIGN_MUL(loc_); return parser::make_ASSIGN_MUL(loc_);
throw comp_error(loc_, "unmatched multiline comment end ('*/')"); throw comp_error(loc_, "unmatched multiline comment end ('*/')");
case '"': case '"':
@ -324,127 +272,127 @@ auto lexer::lex() -> xsk::gsc::s1::parser::symbol_type
state_ = state::field; state_ = state::field;
goto lex_name_or_number; goto lex_name_or_number;
case '(': case '(':
return s1::parser::make_LPAREN(loc_); return parser::make_LPAREN(loc_);
case ')': case ')':
return s1::parser::make_RPAREN(loc_); return parser::make_RPAREN(loc_);
case '{': case '{':
return s1::parser::make_LBRACE(loc_); return parser::make_LBRACE(loc_);
case '}': case '}':
return s1::parser::make_RBRACE(loc_); return parser::make_RBRACE(loc_);
case '[': case '[':
return s1::parser::make_LBRACKET(loc_); return parser::make_LBRACKET(loc_);
case ']': case ']':
return s1::parser::make_RBRACKET(loc_); return parser::make_RBRACKET(loc_);
case ',': case ',':
return s1::parser::make_COMMA(loc_); return parser::make_COMMA(loc_);
case ';': case ';':
return s1::parser::make_SEMICOLON(loc_); return parser::make_SEMICOLON(loc_);
case ':': case ':':
if (curr != ':') if (curr != ':')
return s1::parser::make_COLON(loc_); return parser::make_COLON(loc_);
reader_.advance(); reader_.advance();
return s1::parser::make_DOUBLECOLON(loc_); return parser::make_DOUBLECOLON(loc_);
case '?': case '?':
return s1::parser::make_QMARK(loc_); return parser::make_QMARK(loc_);
case '=': case '=':
if (curr != '=') if (curr != '=')
return s1::parser::make_ASSIGN(loc_); return parser::make_ASSIGN(loc_);
reader_.advance(); reader_.advance();
return s1::parser::make_EQUALITY(loc_); return parser::make_EQUALITY(loc_);
case '+': case '+':
if (curr != '+' && curr != '=') if (curr != '+' && curr != '=')
return s1::parser::make_ADD(loc_); return parser::make_ADD(loc_);
reader_.advance(); reader_.advance();
if (last == '+') if (last == '+')
return s1::parser::make_INCREMENT(loc_); return parser::make_INCREMENT(loc_);
return s1::parser::make_ASSIGN_ADD(loc_); return parser::make_ASSIGN_ADD(loc_);
case '-': case '-':
if (curr != '-' && curr != '=') if (curr != '-' && curr != '=')
return s1::parser::make_SUB(loc_); return parser::make_SUB(loc_);
reader_.advance(); reader_.advance();
if (last == '-') if (last == '-')
return s1::parser::make_DECREMENT(loc_); return parser::make_DECREMENT(loc_);
return s1::parser::make_ASSIGN_SUB(loc_); return parser::make_ASSIGN_SUB(loc_);
case '%': case '%':
if (curr != '=') if (curr != '=')
return s1::parser::make_MOD(loc_); return parser::make_MOD(loc_);
reader_.advance(); reader_.advance();
return s1::parser::make_ASSIGN_MOD(loc_); return parser::make_ASSIGN_MOD(loc_);
case '|': case '|':
if (curr != '|' && curr != '=') if (curr != '|' && curr != '=')
return s1::parser::make_BITWISE_OR(loc_); return parser::make_BITWISE_OR(loc_);
reader_.advance(); reader_.advance();
if (last == '|') if (last == '|')
return s1::parser::make_OR(loc_); return parser::make_OR(loc_);
return s1::parser::make_ASSIGN_BW_OR(loc_); return parser::make_ASSIGN_BW_OR(loc_);
case '&': case '&':
if (curr != '&' && curr != '=' && curr != '"' && curr != '\'') if (curr != '&' && curr != '=' && curr != '"' && curr != '\'')
return s1::parser::make_BITWISE_AND(loc_); return parser::make_BITWISE_AND(loc_);
reader_.advance(); reader_.advance();
if (last == '&') if (last == '&')
return s1::parser::make_AND(loc_); return parser::make_AND(loc_);
if (last == '=') if (last == '=')
return s1::parser::make_ASSIGN_BW_AND(loc_); return parser::make_ASSIGN_BW_AND(loc_);
state_ = state::localize; state_ = state::localize;
goto lex_string; goto lex_string;
case '^': case '^':
if (curr != '=') if (curr != '=')
return s1::parser::make_BITWISE_EXOR(loc_); return parser::make_BITWISE_EXOR(loc_);
reader_.advance(); reader_.advance();
return s1::parser::make_ASSIGN_BW_EXOR(loc_); return parser::make_ASSIGN_BW_EXOR(loc_);
case '!': case '!':
if (curr != '=') if (curr != '=')
return s1::parser::make_NOT(loc_); return parser::make_NOT(loc_);
reader_.advance(); reader_.advance();
return s1::parser::make_INEQUALITY(loc_); return parser::make_INEQUALITY(loc_);
case '~': case '~':
return s1::parser::make_COMPLEMENT(loc_); return parser::make_COMPLEMENT(loc_);
case '<': case '<':
if (curr != '<' && curr != '=') if (curr != '<' && curr != '=')
return s1::parser::make_LESS(loc_); return parser::make_LESS(loc_);
reader_.advance(); reader_.advance();
if (last == '=') if (last == '=')
return s1::parser::make_LESS_EQUAL(loc_); return parser::make_LESS_EQUAL(loc_);
if (curr != '=') if (curr != '=')
return s1::parser::make_LSHIFT(loc_); return parser::make_LSHIFT(loc_);
reader_.advance(); reader_.advance();
return s1::parser::make_ASSIGN_LSHIFT(loc_); return parser::make_ASSIGN_LSHIFT(loc_);
case '>': case '>':
if (curr != '>' && curr != '=') if (curr != '>' && curr != '=')
return s1::parser::make_GREATER(loc_); return parser::make_GREATER(loc_);
reader_.advance(); reader_.advance();
if (last == '=') if (last == '=')
return s1::parser::make_GREATER_EQUAL(loc_); return parser::make_GREATER_EQUAL(loc_);
if (curr != '=') if (curr != '=')
return s1::parser::make_RSHIFT(loc_); return parser::make_RSHIFT(loc_);
reader_.advance(); reader_.advance();
return s1::parser::make_ASSIGN_RSHIFT(loc_); return parser::make_ASSIGN_RSHIFT(loc_);
default: default:
lex_name_or_number: lex_name_or_number:
if (last >= '0' && last <= '9') if (last >= '0' && last <= '9')
@ -497,9 +445,9 @@ lex_string:
} }
if (state_ == state::localize) if (state_ == state::localize)
return s1::parser::make_ISTRING(std::string(buffer_.data, buffer_.length), loc_); return parser::make_ISTRING(std::string(buffer_.data, buffer_.length), loc_);
return s1::parser::make_STRING(std::string(buffer_.data, buffer_.length), loc_); return parser::make_STRING(std::string(buffer_.data, buffer_.length), loc_);
lex_name: lex_name:
buffer_.push(last); buffer_.push(last);
@ -534,44 +482,55 @@ lex_name:
if (std::string_view(buffer_.data, buffer_.length) == "size") if (std::string_view(buffer_.data, buffer_.length) == "size")
{ {
return s1::parser::make_SIZE(loc_); return parser::make_SIZE(loc_);
} }
return s1::parser::make_FIELD(std::string(buffer_.data, buffer_.length), loc_); return parser::make_FIELD(std::string(buffer_.data, buffer_.length), loc_);
} }
else if (state_ == state::preprocessor) else if (state_ == state::preprocessor)
{ {
if (path) if (path)
throw comp_error(loc_, "invalid preprocessor directive"); throw comp_error(loc_, "invalid preprocessor directive");
auto key = get_keyword(std::string_view(buffer_.data, buffer_.length)); auto token = parser::token::S1UNDEF;
if (key != keyword::KW_INVALID) if (buffer_.length < 16)
return keyword_token(key); {
const auto& itr = keyword_map.find(std::string_view(buffer_.data, buffer_.length));
// TODO: call preprocessor(key); if(itr != keyword_map.end())
{
if (itr->second > parser::token::HSENDIF)
return parser::symbol_type(itr->second, loc_);
token = itr->second;
}
}
// TODO: call preprocessor(token);
throw comp_error(loc_, "unknown preprocessor directive"); throw comp_error(loc_, "unknown preprocessor directive");
state_ = state::start; state_ = state::start;
continue; continue;
} }
else else
{ {
auto key = get_keyword(std::string_view(buffer_.data, buffer_.length)); if (buffer_.length < 17)
{
const auto& itr = keyword_map.find(std::string_view(buffer_.data, buffer_.length));
if (key != keyword::KW_INVALID) if(itr != keyword_map.end())
return keyword_token(key); return parser::symbol_type(itr->second, loc_);
}
if (path) if (path)
{ {
if (buffer_.data[buffer_.length - 1] == '/') if (buffer_.data[buffer_.length - 1] == '/')
throw comp_error(loc_, "invalid path end '\\'"); throw comp_error(loc_, "invalid path end '\\'");
//return s1::parser::make_PATH(xsk::gsc::s1::resolver::make_token(std::string_view(buffer_.data, buffer_.length)), loc_); return parser::make_PATH(resolver::make_token(std::string_view(buffer_.data, buffer_.length)), loc_);
return s1::parser::make_PATH(std::string(buffer_.data, buffer_.length), loc_);
} }
//return s1::parser::make_IDENTIFIER(xsk::gsc::s1::resolver::make_token(std::string_view(buffer_.data, buffer_.length)), loc_); return parser::make_IDENTIFIER(resolver::make_token(std::string_view(buffer_.data, buffer_.length)), loc_);
return s1::parser::make_IDENTIFIER(std::string(buffer_.data, buffer_.length), loc_);
} }
lex_number: lex_number:
@ -622,9 +581,9 @@ lex_number:
throw comp_error(loc_, "invalid number literal"); throw comp_error(loc_, "invalid number literal");
if (state_ == state::field || dot || flt) if (state_ == state::field || dot || flt)
return s1::parser::make_FLOAT(std::string(buffer_.data, buffer_.length), loc_); return parser::make_FLOAT(std::string(buffer_.data, buffer_.length), loc_);
return s1::parser::make_INTEGER(std::string(buffer_.data, buffer_.length), loc_); return parser::make_INTEGER(std::string(buffer_.data, buffer_.length), loc_);
} }
else if (curr == 'o') else if (curr == 'o')
{ {
@ -656,7 +615,7 @@ lex_number:
if (last == '\'' || buffer_.length <= 0) if (last == '\'' || buffer_.length <= 0)
throw comp_error(loc_, "invalid octal literal"); throw comp_error(loc_, "invalid octal literal");
return s1::parser::make_INTEGER(xsk::utils::string::oct_to_dec(buffer_.data), loc_); return parser::make_INTEGER(xsk::utils::string::oct_to_dec(buffer_.data), loc_);
} }
else if (curr == 'b') else if (curr == 'b')
{ {
@ -690,7 +649,7 @@ lex_number:
if (last == '\'' || buffer_.length < 3) if (last == '\'' || buffer_.length < 3)
throw comp_error(loc_, "invalid binary literal"); throw comp_error(loc_, "invalid binary literal");
return s1::parser::make_INTEGER(xsk::utils::string::bin_to_dec(buffer_.data), loc_); return parser::make_INTEGER(xsk::utils::string::bin_to_dec(buffer_.data), loc_);
} }
else if (curr == 'x') else if (curr == 'x')
{ {
@ -724,179 +683,60 @@ lex_number:
if (last == '\'' || buffer_.length < 3) if (last == '\'' || buffer_.length < 3)
throw comp_error(loc_, "invalid hexadecimal literal"); throw comp_error(loc_, "invalid hexadecimal literal");
return s1::parser::make_INTEGER(xsk::utils::string::hex_to_dec(buffer_.data), loc_); return parser::make_INTEGER(xsk::utils::string::hex_to_dec(buffer_.data), loc_);
} }
// cant get here! // cant get here!
} }
} }
auto lexer::keyword_token(keyword k) -> xsk::gsc::s1::parser::symbol_type const std::unordered_map<std::string_view, parser::token::token_kind_type> lexer::keyword_map
{
switch (k)
{
case keyword::KW_pre_inline:
return s1::parser::make_INLINE(loc_);
case keyword::KW_pre_include:
return s1::parser::make_INCLUDE(loc_);
case keyword::KW_pre_using_animtree:
return s1::parser::make_USINGTREE(loc_);
case keyword::KW_pre_animtree:
return s1::parser::make_ANIMTREE(loc_);
case keyword::KW_endon:
return s1::parser::make_ENDON(loc_);
case keyword::KW_notify:
return s1::parser::make_NOTIFY(loc_);
case keyword::KW_wait:
return s1::parser::make_WAIT(loc_);
case keyword::KW_waittill:
return s1::parser::make_WAITTILL(loc_);
case keyword::KW_waittillmatch:
return s1::parser::make_WAITTILLMATCH(loc_);
case keyword::KW_waittillframeend:
return s1::parser::make_WAITTILLFRAMEEND(loc_);
case keyword::KW_waitframe:
return s1::parser::make_WAITFRAME(loc_);
case keyword::KW_if:
return s1::parser::make_IF(loc_);
case keyword::KW_else:
return s1::parser::make_ELSE(loc_);
case keyword::KW_do:
return s1::parser::make_DO(loc_);
case keyword::KW_while:
return s1::parser::make_WHILE(loc_);
case keyword::KW_for:
return s1::parser::make_FOR(loc_);
case keyword::KW_foreach:
return s1::parser::make_FOREACH(loc_);
case keyword::KW_in:
return s1::parser::make_IN(loc_);
case keyword::KW_switch:
return s1::parser::make_SWITCH(loc_);
case keyword::KW_case:
return s1::parser::make_CASE(loc_);
case keyword::KW_default:
return s1::parser::make_DEFAULT(loc_);
case keyword::KW_break:
return s1::parser::make_BREAK(loc_);
case keyword::KW_continue:
return s1::parser::make_CONTINUE(loc_);
case keyword::KW_return:
return s1::parser::make_RETURN(loc_);
case keyword::KW_breakpoint:
return s1::parser::make_BREAKPOINT(loc_);
case keyword::KW_prof_begin:
return s1::parser::make_PROFBEGIN(loc_);
case keyword::KW_prof_end:
return s1::parser::make_PROFEND(loc_);
case keyword::KW_thread:
return s1::parser::make_THREAD(loc_);
case keyword::KW_childthread:
return s1::parser::make_CHILDTHREAD(loc_);
case keyword::KW_thisthread:
return s1::parser::make_THISTHREAD(loc_);
case keyword::KW_call:
return s1::parser::make_CALL(loc_);
case keyword::KW_true:
return s1::parser::make_TRUE(loc_);
case keyword::KW_false:
return s1::parser::make_FALSE(loc_);
case keyword::KW_undefined:
return s1::parser::make_UNDEFINED(loc_);
case keyword::KW_dotsize:
return s1::parser::make_SIZE(loc_);
case keyword::KW_game:
return s1::parser::make_GAME(loc_);
case keyword::KW_self:
return s1::parser::make_SELF(loc_);
case keyword::KW_anim:
return s1::parser::make_ANIM(loc_);
case keyword::KW_level:
return s1::parser::make_LEVEL(loc_);
default:
throw error("gsc lexer: INVALID KEYWORD TOKEN!");
}
}
auto lexer::keyword_is_token(keyword k) -> bool
{
switch (k)
{
/* case keyword::KW_pre_define:
case keyword::KW_pre_undef:
case keyword::KW_pre_ifdef:
case keyword::KW_pre_ifndef:
case keyword::KW_pre_if:
case keyword::KW_pre_elif:
case keyword::KW_pre_else:
case keyword::KW_pre_endif:*/
case keyword::KW_INVALID:
return false;
default:
return true;
}
}
auto lexer::get_keyword(std::string_view str) -> keyword
{
auto itr = keywords.find(str);
if(itr != keywords.end())
{
return itr->second;
}
return keyword::KW_INVALID;
}
std::unordered_map<std::string_view, keyword> lexer::keywords
{{ {{
/* { "#define", keyword::KW_pre_define }, { "#define", parser::token::HSDEFINE },
{ "#undef", keyword::KW_pre_undef }, { "#undef", parser::token::HSUNDEF },
{ "#ifdef", keyword::KW_pre_ifdef }, { "#ifdef", parser::token::HSIFDEF },
{ "#ifndef", keyword::KW_pre_ifndef }, { "#ifndef", parser::token::HSIFNDEF },
{ "#if", keyword::KW_pre_if }, { "#if", parser::token::HSIF },
{ "#elif", keyword::KW_pre_elif }, { "#elif", parser::token::HSELIF },
{ "#else", keyword::KW_pre_else }, { "#else", parser::token::HSELSE },
{ "#endif", keyword::KW_pre_endif },*/ { "#endif", parser::token::HSENDIF },
{ "#inline", keyword::KW_pre_inline }, { "#inline", parser::token::INLINE },
{ "#include", keyword::KW_pre_include }, { "#include", parser::token::INCLUDE },
{ "#using_animtree", keyword::KW_pre_using_animtree }, { "#using_animtree", parser::token::USINGTREE },
{ "#animtree", keyword::KW_pre_animtree }, { "#animtree", parser::token::ANIMTREE },
{ "endon", keyword::KW_endon }, { "endon", parser::token::ENDON },
{ "notify", keyword::KW_notify }, { "notify", parser::token::NOTIFY },
{ "wait", keyword::KW_wait }, { "wait", parser::token::WAIT },
{ "waittill", keyword::KW_waittill }, { "waittill", parser::token::WAITTILL },
{ "waittillmatch", keyword::KW_waittillmatch }, { "waittillmatch", parser::token::WAITTILLMATCH },
{ "waittillframeend", keyword::KW_waittillframeend }, { "waittillframeend", parser::token::WAITTILLFRAMEEND },
{ "waitframe", keyword::KW_waitframe }, { "waitframe", parser::token::WAITFRAME },
{ "if", keyword::KW_if }, { "if", parser::token::IF },
{ "else", keyword::KW_else }, { "else", parser::token::ELSE },
{ "do", keyword::KW_do }, { "do", parser::token::DO },
{ "while", keyword::KW_while }, { "while", parser::token::WHILE },
{ "for", keyword::KW_for }, { "for", parser::token::FOR },
{ "foreach", keyword::KW_foreach }, { "foreach", parser::token::FOREACH },
{ "in", keyword::KW_in }, { "in", parser::token::IN },
{ "switch", keyword::KW_switch }, { "switch", parser::token::SWITCH },
{ "case", keyword::KW_case }, { "case", parser::token::CASE },
{ "default", keyword::KW_default }, { "default", parser::token::DEFAULT },
{ "break", keyword::KW_break }, { "break", parser::token::BREAK },
{ "continue", keyword::KW_continue }, { "continue", parser::token::CONTINUE },
{ "return", keyword::KW_return }, { "return", parser::token::RETURN },
{ "breakpoint", keyword::KW_breakpoint }, { "breakpoint", parser::token::BREAKPOINT },
{ "prof_begin", keyword::KW_prof_begin }, { "prof_begin", parser::token::PROFBEGIN },
{ "prof_end", keyword::KW_prof_end }, { "prof_end", parser::token::PROFEND },
{ "thread", keyword::KW_thread }, { "thread", parser::token::THREAD },
{ "childthread", keyword::KW_childthread }, { "childthread", parser::token::CHILDTHREAD },
{ "thisthread", keyword::KW_thisthread }, { "thisthread", parser::token::THISTHREAD },
{ "call", keyword::KW_call }, { "call", parser::token::CALL },
{ "true", keyword::KW_true }, { "true", parser::token::TRUE },
{ "false", keyword::KW_false }, { "false", parser::token::FALSE },
{ "undefined", keyword::KW_undefined }, { "undefined", parser::token::UNDEFINED },
{ ".size", keyword::KW_dotsize }, { "game", parser::token::GAME },
{ "game", keyword::KW_game }, { "self", parser::token::SELF },
{ "self", keyword::KW_self }, { "anim", parser::token::ANIM },
{ "anim", keyword::KW_anim }, { "level", parser::token::LEVEL },
{ "level", keyword::KW_level },
}}; }};
} // namespace xsk::gsc::s1 } // namespace xsk::gsc::s1

View File

@ -10,8 +10,6 @@
namespace xsk::gsc::s1 namespace xsk::gsc::s1
{ {
enum class keyword;
constexpr size_t max_buf_size = 0x2000; constexpr size_t max_buf_size = 0x2000;
struct buffer struct buffer
@ -53,26 +51,22 @@ class lexer
reader reader_; reader reader_;
buffer buffer_; buffer buffer_;
location loc_; location loc_;
build mode_;
std::stack<location> locs_; std::stack<location> locs_;
std::stack<reader> readers_; std::stack<reader> readers_;
std::uint32_t header_top_; std::uint32_t header_top_;
state state_; state state_;
build mode_;
bool indev_; bool indev_;
public: public:
lexer(const std::string& name, const char* data, size_t size); lexer(const std::string& name, const char* data, size_t size);
auto lex() -> xsk::gsc::s1::parser::symbol_type; auto lex() -> parser::symbol_type;
void push_header(const std::string& file); void push_header(const std::string& file);
void pop_header(); void pop_header();
void restrict_header(const xsk::gsc::location& loc); void ban_header(const location& loc);
private: private:
auto keyword_token(keyword k) -> xsk::gsc::s1::parser::symbol_type; static const std::unordered_map<std::string_view, parser::token::token_kind_type> keyword_map;
static auto keyword_is_token(keyword k) -> bool;
static auto get_keyword(std::string_view str) -> keyword;
static std::unordered_map<std::string_view, keyword> keywords;
}; };
} // namespace xsk::gsc::s1 } // namespace xsk::gsc::s1

File diff suppressed because it is too large Load Diff

View File

@ -677,109 +677,117 @@ namespace xsk { namespace gsc { namespace s1 {
S1EOF = 0, // "end of file" S1EOF = 0, // "end of file"
S1error = 1, // error S1error = 1, // error
S1UNDEF = 2, // "invalid token" S1UNDEF = 2, // "invalid token"
DEVBEGIN = 3, // "/#" HSDEFINE = 3, // "#define"
DEVEND = 4, // "#/" HSUNDEF = 4, // "#undef"
INLINE = 5, // "#inline" HSIFDEF = 5, // "#ifdef"
INCLUDE = 6, // "#include" HSIFNDEF = 6, // "#ifndef"
USINGTREE = 7, // "#using_animtree" HSIF = 7, // "#if"
ANIMTREE = 8, // "#animtree" HSELIF = 8, // "#elif"
ENDON = 9, // "endon" HSELSE = 9, // "#else"
NOTIFY = 10, // "notify" HSENDIF = 10, // "#endif"
WAIT = 11, // "wait" DEVBEGIN = 11, // "/#"
WAITTILL = 12, // "waittill" DEVEND = 12, // "#/"
WAITTILLMATCH = 13, // "waittillmatch" INLINE = 13, // "#inline"
WAITTILLFRAMEEND = 14, // "waittillframeend" INCLUDE = 14, // "#include"
WAITFRAME = 15, // "waitframe" USINGTREE = 15, // "#using_animtree"
IF = 16, // "if" ANIMTREE = 16, // "#animtree"
ELSE = 17, // "else" ENDON = 17, // "endon"
DO = 18, // "do" NOTIFY = 18, // "notify"
WHILE = 19, // "while" WAIT = 19, // "wait"
FOR = 20, // "for" WAITTILL = 20, // "waittill"
FOREACH = 21, // "foreach" WAITTILLMATCH = 21, // "waittillmatch"
IN = 22, // "in" WAITTILLFRAMEEND = 22, // "waittillframeend"
SWITCH = 23, // "switch" WAITFRAME = 23, // "waitframe"
CASE = 24, // "case" IF = 24, // "if"
DEFAULT = 25, // "default" ELSE = 25, // "else"
BREAK = 26, // "break" DO = 26, // "do"
CONTINUE = 27, // "continue" WHILE = 27, // "while"
RETURN = 28, // "return" FOR = 28, // "for"
BREAKPOINT = 29, // "breakpoint" FOREACH = 29, // "foreach"
PROFBEGIN = 30, // "prof_begin" IN = 30, // "in"
PROFEND = 31, // "prof_end" SWITCH = 31, // "switch"
THREAD = 32, // "thread" CASE = 32, // "case"
CHILDTHREAD = 33, // "childthread" DEFAULT = 33, // "default"
THISTHREAD = 34, // "thisthread" BREAK = 34, // "break"
CALL = 35, // "call" CONTINUE = 35, // "continue"
TRUE = 36, // "true" RETURN = 36, // "return"
FALSE = 37, // "false" BREAKPOINT = 37, // "breakpoint"
UNDEFINED = 38, // "undefined" PROFBEGIN = 38, // "prof_begin"
SIZE = 39, // ".size" PROFEND = 39, // "prof_end"
GAME = 40, // "game" THREAD = 40, // "thread"
SELF = 41, // "self" CHILDTHREAD = 41, // "childthread"
ANIM = 42, // "anim" THISTHREAD = 42, // "thisthread"
LEVEL = 43, // "level" CALL = 43, // "call"
LPAREN = 44, // "(" TRUE = 44, // "true"
RPAREN = 45, // ")" FALSE = 45, // "false"
LBRACE = 46, // "{" UNDEFINED = 46, // "undefined"
RBRACE = 47, // "}" SIZE = 47, // ".size"
LBRACKET = 48, // "[" GAME = 48, // "game"
RBRACKET = 49, // "]" SELF = 49, // "self"
COMMA = 50, // "," ANIM = 50, // "anim"
DOT = 51, // "." LEVEL = 51, // "level"
DOUBLECOLON = 52, // "::" LPAREN = 52, // "("
COLON = 53, // ":" RPAREN = 53, // ")"
SEMICOLON = 54, // ";" LBRACE = 54, // "{"
QMARK = 55, // "?" RBRACE = 55, // "}"
INCREMENT = 56, // "++" LBRACKET = 56, // "["
DECREMENT = 57, // "--" RBRACKET = 57, // "]"
LSHIFT = 58, // "<<" COMMA = 58, // ","
RSHIFT = 59, // ">>" DOT = 59, // "."
OR = 60, // "||" DOUBLECOLON = 60, // "::"
AND = 61, // "&&" COLON = 61, // ":"
EQUALITY = 62, // "==" SEMICOLON = 62, // ";"
INEQUALITY = 63, // "!=" QMARK = 63, // "?"
LESS_EQUAL = 64, // "<=" INCREMENT = 64, // "++"
GREATER_EQUAL = 65, // ">=" DECREMENT = 65, // "--"
LESS = 66, // "<" LSHIFT = 66, // "<<"
GREATER = 67, // ">" RSHIFT = 67, // ">>"
NOT = 68, // "!" OR = 68, // "||"
COMPLEMENT = 69, // "~" AND = 69, // "&&"
ASSIGN = 70, // "=" EQUALITY = 70, // "=="
ASSIGN_ADD = 71, // "+=" INEQUALITY = 71, // "!="
ASSIGN_SUB = 72, // "-=" LESS_EQUAL = 72, // "<="
ASSIGN_MUL = 73, // "*=" GREATER_EQUAL = 73, // ">="
ASSIGN_DIV = 74, // "/=" LESS = 74, // "<"
ASSIGN_MOD = 75, // "%=" GREATER = 75, // ">"
ASSIGN_BW_OR = 76, // "|=" NOT = 76, // "!"
ASSIGN_BW_AND = 77, // "&=" COMPLEMENT = 77, // "~"
ASSIGN_BW_EXOR = 78, // "^=" ASSIGN = 78, // "="
ASSIGN_RSHIFT = 79, // ">>=" ASSIGN_ADD = 79, // "+="
ASSIGN_LSHIFT = 80, // "<<=" ASSIGN_SUB = 80, // "-="
BITWISE_OR = 81, // "|" ASSIGN_MUL = 81, // "*="
BITWISE_AND = 82, // "&" ASSIGN_DIV = 82, // "/="
BITWISE_EXOR = 83, // "^" ASSIGN_MOD = 83, // "%="
ADD = 84, // "+" ASSIGN_BW_OR = 84, // "|="
SUB = 85, // "-" ASSIGN_BW_AND = 85, // "&="
MUL = 86, // "*" ASSIGN_BW_EXOR = 86, // "^="
DIV = 87, // "/" ASSIGN_RSHIFT = 87, // ">>="
MOD = 88, // "%" ASSIGN_LSHIFT = 88, // "<<="
FIELD = 89, // "field" BITWISE_OR = 89, // "|"
PATH = 90, // "path" BITWISE_AND = 90, // "&"
IDENTIFIER = 91, // "identifier" BITWISE_EXOR = 91, // "^"
STRING = 92, // "string literal" ADD = 92, // "+"
ISTRING = 93, // "localized string" SUB = 93, // "-"
COLOR = 94, // "color" MUL = 94, // "*"
FLOAT = 95, // "float" DIV = 95, // "/"
INTEGER = 96, // "integer" MOD = 96, // "%"
ADD_ARRAY = 97, // ADD_ARRAY FIELD = 97, // "field"
THEN = 98, // THEN PATH = 98, // "path"
TERN = 99, // TERN IDENTIFIER = 99, // "identifier"
NEG = 100, // NEG STRING = 100, // "string literal"
ANIMREF = 101, // ANIMREF ISTRING = 101, // "localized string"
PREINC = 102, // PREINC COLOR = 102, // "color"
PREDEC = 103, // PREDEC FLOAT = 103, // "float"
POSTINC = 104, // POSTINC INTEGER = 104, // "integer"
POSTDEC = 105 // POSTDEC ADD_ARRAY = 105, // ADD_ARRAY
THEN = 106, // THEN
TERN = 107, // TERN
NEG = 108, // NEG
ANIMREF = 109, // ANIMREF
PREINC = 110, // PREINC
PREDEC = 111, // PREDEC
POSTINC = 112, // POSTINC
POSTDEC = 113 // POSTDEC
}; };
/// Backward compatibility alias (Bison 3.6). /// Backward compatibility alias (Bison 3.6).
typedef token_kind_type yytokentype; typedef token_kind_type yytokentype;
@ -796,195 +804,203 @@ namespace xsk { namespace gsc { namespace s1 {
{ {
enum symbol_kind_type enum symbol_kind_type
{ {
YYNTOKENS = 106, ///< Number of tokens. YYNTOKENS = 114, ///< Number of tokens.
S_YYEMPTY = -2, S_YYEMPTY = -2,
S_YYEOF = 0, // "end of file" S_YYEOF = 0, // "end of file"
S_YYerror = 1, // error S_YYerror = 1, // error
S_YYUNDEF = 2, // "invalid token" S_YYUNDEF = 2, // "invalid token"
S_DEVBEGIN = 3, // "/#" S_HSDEFINE = 3, // "#define"
S_DEVEND = 4, // "#/" S_HSUNDEF = 4, // "#undef"
S_INLINE = 5, // "#inline" S_HSIFDEF = 5, // "#ifdef"
S_INCLUDE = 6, // "#include" S_HSIFNDEF = 6, // "#ifndef"
S_USINGTREE = 7, // "#using_animtree" S_HSIF = 7, // "#if"
S_ANIMTREE = 8, // "#animtree" S_HSELIF = 8, // "#elif"
S_ENDON = 9, // "endon" S_HSELSE = 9, // "#else"
S_NOTIFY = 10, // "notify" S_HSENDIF = 10, // "#endif"
S_WAIT = 11, // "wait" S_DEVBEGIN = 11, // "/#"
S_WAITTILL = 12, // "waittill" S_DEVEND = 12, // "#/"
S_WAITTILLMATCH = 13, // "waittillmatch" S_INLINE = 13, // "#inline"
S_WAITTILLFRAMEEND = 14, // "waittillframeend" S_INCLUDE = 14, // "#include"
S_WAITFRAME = 15, // "waitframe" S_USINGTREE = 15, // "#using_animtree"
S_IF = 16, // "if" S_ANIMTREE = 16, // "#animtree"
S_ELSE = 17, // "else" S_ENDON = 17, // "endon"
S_DO = 18, // "do" S_NOTIFY = 18, // "notify"
S_WHILE = 19, // "while" S_WAIT = 19, // "wait"
S_FOR = 20, // "for" S_WAITTILL = 20, // "waittill"
S_FOREACH = 21, // "foreach" S_WAITTILLMATCH = 21, // "waittillmatch"
S_IN = 22, // "in" S_WAITTILLFRAMEEND = 22, // "waittillframeend"
S_SWITCH = 23, // "switch" S_WAITFRAME = 23, // "waitframe"
S_CASE = 24, // "case" S_IF = 24, // "if"
S_DEFAULT = 25, // "default" S_ELSE = 25, // "else"
S_BREAK = 26, // "break" S_DO = 26, // "do"
S_CONTINUE = 27, // "continue" S_WHILE = 27, // "while"
S_RETURN = 28, // "return" S_FOR = 28, // "for"
S_BREAKPOINT = 29, // "breakpoint" S_FOREACH = 29, // "foreach"
S_PROFBEGIN = 30, // "prof_begin" S_IN = 30, // "in"
S_PROFEND = 31, // "prof_end" S_SWITCH = 31, // "switch"
S_THREAD = 32, // "thread" S_CASE = 32, // "case"
S_CHILDTHREAD = 33, // "childthread" S_DEFAULT = 33, // "default"
S_THISTHREAD = 34, // "thisthread" S_BREAK = 34, // "break"
S_CALL = 35, // "call" S_CONTINUE = 35, // "continue"
S_TRUE = 36, // "true" S_RETURN = 36, // "return"
S_FALSE = 37, // "false" S_BREAKPOINT = 37, // "breakpoint"
S_UNDEFINED = 38, // "undefined" S_PROFBEGIN = 38, // "prof_begin"
S_SIZE = 39, // ".size" S_PROFEND = 39, // "prof_end"
S_GAME = 40, // "game" S_THREAD = 40, // "thread"
S_SELF = 41, // "self" S_CHILDTHREAD = 41, // "childthread"
S_ANIM = 42, // "anim" S_THISTHREAD = 42, // "thisthread"
S_LEVEL = 43, // "level" S_CALL = 43, // "call"
S_LPAREN = 44, // "(" S_TRUE = 44, // "true"
S_RPAREN = 45, // ")" S_FALSE = 45, // "false"
S_LBRACE = 46, // "{" S_UNDEFINED = 46, // "undefined"
S_RBRACE = 47, // "}" S_SIZE = 47, // ".size"
S_LBRACKET = 48, // "[" S_GAME = 48, // "game"
S_RBRACKET = 49, // "]" S_SELF = 49, // "self"
S_COMMA = 50, // "," S_ANIM = 50, // "anim"
S_DOT = 51, // "." S_LEVEL = 51, // "level"
S_DOUBLECOLON = 52, // "::" S_LPAREN = 52, // "("
S_COLON = 53, // ":" S_RPAREN = 53, // ")"
S_SEMICOLON = 54, // ";" S_LBRACE = 54, // "{"
S_QMARK = 55, // "?" S_RBRACE = 55, // "}"
S_INCREMENT = 56, // "++" S_LBRACKET = 56, // "["
S_DECREMENT = 57, // "--" S_RBRACKET = 57, // "]"
S_LSHIFT = 58, // "<<" S_COMMA = 58, // ","
S_RSHIFT = 59, // ">>" S_DOT = 59, // "."
S_OR = 60, // "||" S_DOUBLECOLON = 60, // "::"
S_AND = 61, // "&&" S_COLON = 61, // ":"
S_EQUALITY = 62, // "==" S_SEMICOLON = 62, // ";"
S_INEQUALITY = 63, // "!=" S_QMARK = 63, // "?"
S_LESS_EQUAL = 64, // "<=" S_INCREMENT = 64, // "++"
S_GREATER_EQUAL = 65, // ">=" S_DECREMENT = 65, // "--"
S_LESS = 66, // "<" S_LSHIFT = 66, // "<<"
S_GREATER = 67, // ">" S_RSHIFT = 67, // ">>"
S_NOT = 68, // "!" S_OR = 68, // "||"
S_COMPLEMENT = 69, // "~" S_AND = 69, // "&&"
S_ASSIGN = 70, // "=" S_EQUALITY = 70, // "=="
S_ASSIGN_ADD = 71, // "+=" S_INEQUALITY = 71, // "!="
S_ASSIGN_SUB = 72, // "-=" S_LESS_EQUAL = 72, // "<="
S_ASSIGN_MUL = 73, // "*=" S_GREATER_EQUAL = 73, // ">="
S_ASSIGN_DIV = 74, // "/=" S_LESS = 74, // "<"
S_ASSIGN_MOD = 75, // "%=" S_GREATER = 75, // ">"
S_ASSIGN_BW_OR = 76, // "|=" S_NOT = 76, // "!"
S_ASSIGN_BW_AND = 77, // "&=" S_COMPLEMENT = 77, // "~"
S_ASSIGN_BW_EXOR = 78, // "^=" S_ASSIGN = 78, // "="
S_ASSIGN_RSHIFT = 79, // ">>=" S_ASSIGN_ADD = 79, // "+="
S_ASSIGN_LSHIFT = 80, // "<<=" S_ASSIGN_SUB = 80, // "-="
S_BITWISE_OR = 81, // "|" S_ASSIGN_MUL = 81, // "*="
S_BITWISE_AND = 82, // "&" S_ASSIGN_DIV = 82, // "/="
S_BITWISE_EXOR = 83, // "^" S_ASSIGN_MOD = 83, // "%="
S_ADD = 84, // "+" S_ASSIGN_BW_OR = 84, // "|="
S_SUB = 85, // "-" S_ASSIGN_BW_AND = 85, // "&="
S_MUL = 86, // "*" S_ASSIGN_BW_EXOR = 86, // "^="
S_DIV = 87, // "/" S_ASSIGN_RSHIFT = 87, // ">>="
S_MOD = 88, // "%" S_ASSIGN_LSHIFT = 88, // "<<="
S_FIELD = 89, // "field" S_BITWISE_OR = 89, // "|"
S_PATH = 90, // "path" S_BITWISE_AND = 90, // "&"
S_IDENTIFIER = 91, // "identifier" S_BITWISE_EXOR = 91, // "^"
S_STRING = 92, // "string literal" S_ADD = 92, // "+"
S_ISTRING = 93, // "localized string" S_SUB = 93, // "-"
S_COLOR = 94, // "color" S_MUL = 94, // "*"
S_FLOAT = 95, // "float" S_DIV = 95, // "/"
S_INTEGER = 96, // "integer" S_MOD = 96, // "%"
S_ADD_ARRAY = 97, // ADD_ARRAY S_FIELD = 97, // "field"
S_THEN = 98, // THEN S_PATH = 98, // "path"
S_TERN = 99, // TERN S_IDENTIFIER = 99, // "identifier"
S_NEG = 100, // NEG S_STRING = 100, // "string literal"
S_ANIMREF = 101, // ANIMREF S_ISTRING = 101, // "localized string"
S_PREINC = 102, // PREINC S_COLOR = 102, // "color"
S_PREDEC = 103, // PREDEC S_FLOAT = 103, // "float"
S_POSTINC = 104, // POSTINC S_INTEGER = 104, // "integer"
S_POSTDEC = 105, // POSTDEC S_ADD_ARRAY = 105, // ADD_ARRAY
S_YYACCEPT = 106, // $accept S_THEN = 106, // THEN
S_root = 107, // root S_TERN = 107, // TERN
S_program = 108, // program S_NEG = 108, // NEG
S_inline = 109, // inline S_ANIMREF = 109, // ANIMREF
S_include = 110, // include S_PREINC = 110, // PREINC
S_declaration = 111, // declaration S_PREDEC = 111, // PREDEC
S_decl_usingtree = 112, // decl_usingtree S_POSTINC = 112, // POSTINC
S_decl_constant = 113, // decl_constant S_POSTDEC = 113, // POSTDEC
S_decl_thread = 114, // decl_thread S_YYACCEPT = 114, // $accept
S_stmt = 115, // stmt S_root = 115, // root
S_stmt_dev = 116, // stmt_dev S_program = 116, // program
S_stmt_block = 117, // stmt_block S_inline = 117, // inline
S_stmt_list = 118, // stmt_list S_include = 118, // include
S_stmt_expr = 119, // stmt_expr S_declaration = 119, // declaration
S_stmt_call = 120, // stmt_call S_decl_usingtree = 120, // decl_usingtree
S_stmt_assign = 121, // stmt_assign S_decl_constant = 121, // decl_constant
S_stmt_endon = 122, // stmt_endon S_decl_thread = 122, // decl_thread
S_stmt_notify = 123, // stmt_notify S_stmt = 123, // stmt
S_stmt_wait = 124, // stmt_wait S_stmt_dev = 124, // stmt_dev
S_stmt_waittill = 125, // stmt_waittill S_stmt_block = 125, // stmt_block
S_stmt_waittillmatch = 126, // stmt_waittillmatch S_stmt_list = 126, // stmt_list
S_stmt_waittillframeend = 127, // stmt_waittillframeend S_stmt_expr = 127, // stmt_expr
S_stmt_waitframe = 128, // stmt_waitframe S_stmt_call = 128, // stmt_call
S_stmt_if = 129, // stmt_if S_stmt_assign = 129, // stmt_assign
S_stmt_ifelse = 130, // stmt_ifelse S_stmt_endon = 130, // stmt_endon
S_stmt_while = 131, // stmt_while S_stmt_notify = 131, // stmt_notify
S_stmt_dowhile = 132, // stmt_dowhile S_stmt_wait = 132, // stmt_wait
S_stmt_for = 133, // stmt_for S_stmt_waittill = 133, // stmt_waittill
S_stmt_foreach = 134, // stmt_foreach S_stmt_waittillmatch = 134, // stmt_waittillmatch
S_stmt_switch = 135, // stmt_switch S_stmt_waittillframeend = 135, // stmt_waittillframeend
S_stmt_case = 136, // stmt_case S_stmt_waitframe = 136, // stmt_waitframe
S_stmt_default = 137, // stmt_default S_stmt_if = 137, // stmt_if
S_stmt_break = 138, // stmt_break S_stmt_ifelse = 138, // stmt_ifelse
S_stmt_continue = 139, // stmt_continue S_stmt_while = 139, // stmt_while
S_stmt_return = 140, // stmt_return S_stmt_dowhile = 140, // stmt_dowhile
S_stmt_breakpoint = 141, // stmt_breakpoint S_stmt_for = 141, // stmt_for
S_stmt_prof_begin = 142, // stmt_prof_begin S_stmt_foreach = 142, // stmt_foreach
S_stmt_prof_end = 143, // stmt_prof_end S_stmt_switch = 143, // stmt_switch
S_expr = 144, // expr S_stmt_case = 144, // stmt_case
S_expr_or_empty = 145, // expr_or_empty S_stmt_default = 145, // stmt_default
S_expr_assign = 146, // expr_assign S_stmt_break = 146, // stmt_break
S_expr_increment = 147, // expr_increment S_stmt_continue = 147, // stmt_continue
S_expr_decrement = 148, // expr_decrement S_stmt_return = 148, // stmt_return
S_expr_ternary = 149, // expr_ternary S_stmt_breakpoint = 149, // stmt_breakpoint
S_expr_binary = 150, // expr_binary S_stmt_prof_begin = 150, // stmt_prof_begin
S_expr_primitive = 151, // expr_primitive S_stmt_prof_end = 151, // stmt_prof_end
S_expr_complement = 152, // expr_complement S_expr = 152, // expr
S_expr_not = 153, // expr_not S_expr_or_empty = 153, // expr_or_empty
S_expr_call = 154, // expr_call S_expr_assign = 154, // expr_assign
S_expr_method = 155, // expr_method S_expr_increment = 155, // expr_increment
S_expr_function = 156, // expr_function S_expr_decrement = 156, // expr_decrement
S_expr_pointer = 157, // expr_pointer S_expr_ternary = 157, // expr_ternary
S_expr_add_array = 158, // expr_add_array S_expr_binary = 158, // expr_binary
S_expr_parameters = 159, // expr_parameters S_expr_primitive = 159, // expr_primitive
S_expr_arguments = 160, // expr_arguments S_expr_complement = 160, // expr_complement
S_expr_arguments_no_empty = 161, // expr_arguments_no_empty S_expr_not = 161, // expr_not
S_expr_reference = 162, // expr_reference S_expr_call = 162, // expr_call
S_expr_array = 163, // expr_array S_expr_method = 163, // expr_method
S_expr_field = 164, // expr_field S_expr_function = 164, // expr_function
S_expr_size = 165, // expr_size S_expr_pointer = 165, // expr_pointer
S_expr_paren = 166, // expr_paren S_expr_add_array = 166, // expr_add_array
S_expr_object = 167, // expr_object S_expr_parameters = 167, // expr_parameters
S_expr_thisthread = 168, // expr_thisthread S_expr_arguments = 168, // expr_arguments
S_expr_empty_array = 169, // expr_empty_array S_expr_arguments_no_empty = 169, // expr_arguments_no_empty
S_expr_undefined = 170, // expr_undefined S_expr_reference = 170, // expr_reference
S_expr_game = 171, // expr_game S_expr_array = 171, // expr_array
S_expr_self = 172, // expr_self S_expr_field = 172, // expr_field
S_expr_anim = 173, // expr_anim S_expr_size = 173, // expr_size
S_expr_level = 174, // expr_level S_expr_paren = 174, // expr_paren
S_expr_animation = 175, // expr_animation S_expr_object = 175, // expr_object
S_expr_animtree = 176, // expr_animtree S_expr_thisthread = 176, // expr_thisthread
S_expr_identifier = 177, // expr_identifier S_expr_empty_array = 177, // expr_empty_array
S_expr_path = 178, // expr_path S_expr_undefined = 178, // expr_undefined
S_expr_istring = 179, // expr_istring S_expr_game = 179, // expr_game
S_expr_string = 180, // expr_string S_expr_self = 180, // expr_self
S_expr_color = 181, // expr_color S_expr_anim = 181, // expr_anim
S_expr_vector = 182, // expr_vector S_expr_level = 182, // expr_level
S_expr_float = 183, // expr_float S_expr_animation = 183, // expr_animation
S_expr_integer = 184, // expr_integer S_expr_animtree = 184, // expr_animtree
S_expr_false = 185, // expr_false S_expr_identifier = 185, // expr_identifier
S_expr_true = 186 // expr_true S_expr_path = 186, // expr_path
S_expr_istring = 187, // expr_istring
S_expr_string = 188, // expr_string
S_expr_color = 189, // expr_color
S_expr_vector = 190, // expr_vector
S_expr_float = 191, // expr_float
S_expr_integer = 192, // expr_integer
S_expr_false = 193, // expr_false
S_expr_true = 194 // expr_true
}; };
}; };
@ -2779,6 +2795,126 @@ switch (yykind)
return symbol_type (token::S1UNDEF, l); return symbol_type (token::S1UNDEF, l);
} }
#endif #endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_HSDEFINE (location_type l)
{
return symbol_type (token::HSDEFINE, std::move (l));
}
#else
static
symbol_type
make_HSDEFINE (const location_type& l)
{
return symbol_type (token::HSDEFINE, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_HSUNDEF (location_type l)
{
return symbol_type (token::HSUNDEF, std::move (l));
}
#else
static
symbol_type
make_HSUNDEF (const location_type& l)
{
return symbol_type (token::HSUNDEF, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_HSIFDEF (location_type l)
{
return symbol_type (token::HSIFDEF, std::move (l));
}
#else
static
symbol_type
make_HSIFDEF (const location_type& l)
{
return symbol_type (token::HSIFDEF, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_HSIFNDEF (location_type l)
{
return symbol_type (token::HSIFNDEF, std::move (l));
}
#else
static
symbol_type
make_HSIFNDEF (const location_type& l)
{
return symbol_type (token::HSIFNDEF, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_HSIF (location_type l)
{
return symbol_type (token::HSIF, std::move (l));
}
#else
static
symbol_type
make_HSIF (const location_type& l)
{
return symbol_type (token::HSIF, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_HSELIF (location_type l)
{
return symbol_type (token::HSELIF, std::move (l));
}
#else
static
symbol_type
make_HSELIF (const location_type& l)
{
return symbol_type (token::HSELIF, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_HSELSE (location_type l)
{
return symbol_type (token::HSELSE, std::move (l));
}
#else
static
symbol_type
make_HSELSE (const location_type& l)
{
return symbol_type (token::HSELSE, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_HSENDIF (location_type l)
{
return symbol_type (token::HSENDIF, std::move (l));
}
#else
static
symbol_type
make_HSENDIF (const location_type& l)
{
return symbol_type (token::HSENDIF, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS #if 201103L <= YY_CPLUSPLUS
static static
symbol_type symbol_type
@ -5362,7 +5498,7 @@ switch (yykind)
#line 13 "parser.ypp" #line 13 "parser.ypp"
} } } // xsk::gsc::s1 } } } // xsk::gsc::s1
#line 5366 "parser.hpp" #line 5502 "parser.hpp"

View File

@ -16,58 +16,6 @@ xsk::gsc::s2::parser::symbol_type S2lex(xsk::gsc::s2::lexer& lexer)
namespace xsk::gsc::s2 namespace xsk::gsc::s2
{ {
enum class keyword
{
/* KW_pre_define,
KW_pre_undef,
KW_pre_ifdef,
KW_pre_ifndef,
KW_pre_if,
KW_pre_elif,
KW_pre_else,
KW_pre_endif,*/
KW_pre_inline,
KW_pre_include,
KW_pre_using_animtree,
KW_pre_animtree,
KW_endon,
KW_notify,
KW_wait,
KW_waittill,
KW_waittillmatch,
KW_waittillframeend,
KW_waitframe,
KW_if,
KW_else,
KW_do,
KW_while,
KW_for,
KW_foreach,
KW_in,
KW_switch,
KW_case,
KW_default,
KW_break,
KW_continue,
KW_return,
KW_breakpoint,
KW_prof_begin,
KW_prof_end,
KW_thread,
KW_childthread,
KW_thisthread,
KW_call,
KW_true,
KW_false,
KW_undefined,
KW_dotsize,
KW_game,
KW_self,
KW_anim,
KW_level,
KW_INVALID,
};
buffer::buffer() : length(0) buffer::buffer() : length(0)
{ {
data = static_cast<char*>(std::malloc(max_buf_size)); data = static_cast<char*>(std::malloc(max_buf_size));
@ -130,7 +78,7 @@ void reader::advance()
} }
} }
lexer::lexer(const std::string& name, const char* data, size_t size) : indev_(false), loc_(xsk::gsc::location(&name)), lexer::lexer(const std::string& name, const char* data, size_t size) : indev_(false), loc_(location(&name)),
mode_(build::dev), header_top_(0), locs_(std::stack<location>()), readers_(std::stack<reader>()) mode_(build::dev), header_top_(0), locs_(std::stack<location>()), readers_(std::stack<reader>())
{ {
reader_.init(data, size); reader_.init(data, size);
@ -141,7 +89,7 @@ void lexer::push_header(const std::string& file)
try try
{ {
if (header_top_++ >= 10) if (header_top_++ >= 10)
throw xsk::gsc::error("maximum gsh depth exceeded '10'"); throw comp_error(loc_, "maximum gsh depth exceeded '10'");
auto data = resolver::file_data(file + ".gsh"); auto data = resolver::file_data(file + ".gsh");
@ -152,7 +100,7 @@ void lexer::push_header(const std::string& file)
} }
catch (const std::exception& e) catch (const std::exception& e)
{ {
throw xsk::gsc::error("parsing header file '" + file + "': " + e.what()); throw error("parsing header file '" + file + "': " + e.what());
} }
} }
@ -165,7 +113,7 @@ void lexer::pop_header()
readers_.pop(); readers_.pop();
} }
void lexer::restrict_header(const xsk::gsc::location& loc) void lexer::ban_header(const location& loc)
{ {
if (header_top_ > 0) if (header_top_ > 0)
{ {
@ -173,7 +121,7 @@ void lexer::restrict_header(const xsk::gsc::location& loc)
} }
} }
auto lexer::lex() -> xsk::gsc::s2::parser::symbol_type auto lexer::lex() -> parser::symbol_type
{ {
buffer_.length = 0; buffer_.length = 0;
state_ = state::start; state_ = state::start;
@ -194,7 +142,7 @@ auto lexer::lex() -> xsk::gsc::s2::parser::symbol_type
if (header_top_ > 0) if (header_top_ > 0)
pop_header(); pop_header();
else else
return s2::parser::make_S2EOF(loc_); return parser::make_S2EOF(loc_);
} }
reader_.advance(); reader_.advance();
@ -212,22 +160,22 @@ auto lexer::lex() -> xsk::gsc::s2::parser::symbol_type
continue; continue;
case '/': case '/':
if (curr != '/' && curr != '*' && curr != '#' && curr != '=') if (curr != '/' && curr != '*' && curr != '#' && curr != '=')
return s2::parser::make_DIV(loc_); return parser::make_DIV(loc_);
reader_.advance(); reader_.advance();
if (last == '=') if (last == '=')
return s2::parser::make_ASSIGN_DIV(loc_); return parser::make_ASSIGN_DIV(loc_);
if (last == '#') if (last == '#')
{ {
if (indev_) if (indev_)
throw comp_error(loc_, "cannot recurse devblock ('/#')"); throw comp_error(loc_, "cannot recurse devblock ('/#')");
if (mode_ == xsk::gsc::build::dev) if (mode_ == build::dev)
{ {
indev_ = true; indev_ = true;
return s2::parser::make_DEVBEGIN(loc_); return parser::make_DEVBEGIN(loc_);
} }
else else
{ {
@ -291,7 +239,7 @@ auto lexer::lex() -> xsk::gsc::s2::parser::symbol_type
indev_ = false; indev_ = false;
reader_.advance(); reader_.advance();
return s2::parser::make_DEVEND(loc_); return parser::make_DEVEND(loc_);
} }
buffer_.push(last); buffer_.push(last);
@ -304,12 +252,12 @@ auto lexer::lex() -> xsk::gsc::s2::parser::symbol_type
goto lex_name; goto lex_name;
case '*': case '*':
if (curr != '/' && curr != '=') if (curr != '/' && curr != '=')
return s2::parser::make_MUL(loc_); return parser::make_MUL(loc_);
reader_.advance(); reader_.advance();
if (last == '=') if (last == '=')
return s2::parser::make_ASSIGN_MUL(loc_); return parser::make_ASSIGN_MUL(loc_);
throw comp_error(loc_, "unmatched multiline comment end ('*/')"); throw comp_error(loc_, "unmatched multiline comment end ('*/')");
case '"': case '"':
@ -324,127 +272,127 @@ auto lexer::lex() -> xsk::gsc::s2::parser::symbol_type
state_ = state::field; state_ = state::field;
goto lex_name_or_number; goto lex_name_or_number;
case '(': case '(':
return s2::parser::make_LPAREN(loc_); return parser::make_LPAREN(loc_);
case ')': case ')':
return s2::parser::make_RPAREN(loc_); return parser::make_RPAREN(loc_);
case '{': case '{':
return s2::parser::make_LBRACE(loc_); return parser::make_LBRACE(loc_);
case '}': case '}':
return s2::parser::make_RBRACE(loc_); return parser::make_RBRACE(loc_);
case '[': case '[':
return s2::parser::make_LBRACKET(loc_); return parser::make_LBRACKET(loc_);
case ']': case ']':
return s2::parser::make_RBRACKET(loc_); return parser::make_RBRACKET(loc_);
case ',': case ',':
return s2::parser::make_COMMA(loc_); return parser::make_COMMA(loc_);
case ';': case ';':
return s2::parser::make_SEMICOLON(loc_); return parser::make_SEMICOLON(loc_);
case ':': case ':':
if (curr != ':') if (curr != ':')
return s2::parser::make_COLON(loc_); return parser::make_COLON(loc_);
reader_.advance(); reader_.advance();
return s2::parser::make_DOUBLECOLON(loc_); return parser::make_DOUBLECOLON(loc_);
case '?': case '?':
return s2::parser::make_QMARK(loc_); return parser::make_QMARK(loc_);
case '=': case '=':
if (curr != '=') if (curr != '=')
return s2::parser::make_ASSIGN(loc_); return parser::make_ASSIGN(loc_);
reader_.advance(); reader_.advance();
return s2::parser::make_EQUALITY(loc_); return parser::make_EQUALITY(loc_);
case '+': case '+':
if (curr != '+' && curr != '=') if (curr != '+' && curr != '=')
return s2::parser::make_ADD(loc_); return parser::make_ADD(loc_);
reader_.advance(); reader_.advance();
if (last == '+') if (last == '+')
return s2::parser::make_INCREMENT(loc_); return parser::make_INCREMENT(loc_);
return s2::parser::make_ASSIGN_ADD(loc_); return parser::make_ASSIGN_ADD(loc_);
case '-': case '-':
if (curr != '-' && curr != '=') if (curr != '-' && curr != '=')
return s2::parser::make_SUB(loc_); return parser::make_SUB(loc_);
reader_.advance(); reader_.advance();
if (last == '-') if (last == '-')
return s2::parser::make_DECREMENT(loc_); return parser::make_DECREMENT(loc_);
return s2::parser::make_ASSIGN_SUB(loc_); return parser::make_ASSIGN_SUB(loc_);
case '%': case '%':
if (curr != '=') if (curr != '=')
return s2::parser::make_MOD(loc_); return parser::make_MOD(loc_);
reader_.advance(); reader_.advance();
return s2::parser::make_ASSIGN_MOD(loc_); return parser::make_ASSIGN_MOD(loc_);
case '|': case '|':
if (curr != '|' && curr != '=') if (curr != '|' && curr != '=')
return s2::parser::make_BITWISE_OR(loc_); return parser::make_BITWISE_OR(loc_);
reader_.advance(); reader_.advance();
if (last == '|') if (last == '|')
return s2::parser::make_OR(loc_); return parser::make_OR(loc_);
return s2::parser::make_ASSIGN_BW_OR(loc_); return parser::make_ASSIGN_BW_OR(loc_);
case '&': case '&':
if (curr != '&' && curr != '=' && curr != '"' && curr != '\'') if (curr != '&' && curr != '=' && curr != '"' && curr != '\'')
return s2::parser::make_BITWISE_AND(loc_); return parser::make_BITWISE_AND(loc_);
reader_.advance(); reader_.advance();
if (last == '&') if (last == '&')
return s2::parser::make_AND(loc_); return parser::make_AND(loc_);
if (last == '=') if (last == '=')
return s2::parser::make_ASSIGN_BW_AND(loc_); return parser::make_ASSIGN_BW_AND(loc_);
state_ = state::localize; state_ = state::localize;
goto lex_string; goto lex_string;
case '^': case '^':
if (curr != '=') if (curr != '=')
return s2::parser::make_BITWISE_EXOR(loc_); return parser::make_BITWISE_EXOR(loc_);
reader_.advance(); reader_.advance();
return s2::parser::make_ASSIGN_BW_EXOR(loc_); return parser::make_ASSIGN_BW_EXOR(loc_);
case '!': case '!':
if (curr != '=') if (curr != '=')
return s2::parser::make_NOT(loc_); return parser::make_NOT(loc_);
reader_.advance(); reader_.advance();
return s2::parser::make_INEQUALITY(loc_); return parser::make_INEQUALITY(loc_);
case '~': case '~':
return s2::parser::make_COMPLEMENT(loc_); return parser::make_COMPLEMENT(loc_);
case '<': case '<':
if (curr != '<' && curr != '=') if (curr != '<' && curr != '=')
return s2::parser::make_LESS(loc_); return parser::make_LESS(loc_);
reader_.advance(); reader_.advance();
if (last == '=') if (last == '=')
return s2::parser::make_LESS_EQUAL(loc_); return parser::make_LESS_EQUAL(loc_);
if (curr != '=') if (curr != '=')
return s2::parser::make_LSHIFT(loc_); return parser::make_LSHIFT(loc_);
reader_.advance(); reader_.advance();
return s2::parser::make_ASSIGN_LSHIFT(loc_); return parser::make_ASSIGN_LSHIFT(loc_);
case '>': case '>':
if (curr != '>' && curr != '=') if (curr != '>' && curr != '=')
return s2::parser::make_GREATER(loc_); return parser::make_GREATER(loc_);
reader_.advance(); reader_.advance();
if (last == '=') if (last == '=')
return s2::parser::make_GREATER_EQUAL(loc_); return parser::make_GREATER_EQUAL(loc_);
if (curr != '=') if (curr != '=')
return s2::parser::make_RSHIFT(loc_); return parser::make_RSHIFT(loc_);
reader_.advance(); reader_.advance();
return s2::parser::make_ASSIGN_RSHIFT(loc_); return parser::make_ASSIGN_RSHIFT(loc_);
default: default:
lex_name_or_number: lex_name_or_number:
if (last >= '0' && last <= '9') if (last >= '0' && last <= '9')
@ -497,9 +445,9 @@ lex_string:
} }
if (state_ == state::localize) if (state_ == state::localize)
return s2::parser::make_ISTRING(std::string(buffer_.data, buffer_.length), loc_); return parser::make_ISTRING(std::string(buffer_.data, buffer_.length), loc_);
return s2::parser::make_STRING(std::string(buffer_.data, buffer_.length), loc_); return parser::make_STRING(std::string(buffer_.data, buffer_.length), loc_);
lex_name: lex_name:
buffer_.push(last); buffer_.push(last);
@ -534,44 +482,55 @@ lex_name:
if (std::string_view(buffer_.data, buffer_.length) == "size") if (std::string_view(buffer_.data, buffer_.length) == "size")
{ {
return s2::parser::make_SIZE(loc_); return parser::make_SIZE(loc_);
} }
return s2::parser::make_FIELD(std::string(buffer_.data, buffer_.length), loc_); return parser::make_FIELD(std::string(buffer_.data, buffer_.length), loc_);
} }
else if (state_ == state::preprocessor) else if (state_ == state::preprocessor)
{ {
if (path) if (path)
throw comp_error(loc_, "invalid preprocessor directive"); throw comp_error(loc_, "invalid preprocessor directive");
auto key = get_keyword(std::string_view(buffer_.data, buffer_.length)); auto token = parser::token::S2UNDEF;
if (key != keyword::KW_INVALID) if (buffer_.length < 16)
return keyword_token(key); {
const auto& itr = keyword_map.find(std::string_view(buffer_.data, buffer_.length));
// TODO: call preprocessor(key); if(itr != keyword_map.end())
{
if (itr->second > parser::token::HSENDIF)
return parser::symbol_type(itr->second, loc_);
token = itr->second;
}
}
// TODO: call preprocessor(token);
throw comp_error(loc_, "unknown preprocessor directive"); throw comp_error(loc_, "unknown preprocessor directive");
state_ = state::start; state_ = state::start;
continue; continue;
} }
else else
{ {
auto key = get_keyword(std::string_view(buffer_.data, buffer_.length)); if (buffer_.length < 17)
{
const auto& itr = keyword_map.find(std::string_view(buffer_.data, buffer_.length));
if (key != keyword::KW_INVALID) if(itr != keyword_map.end())
return keyword_token(key); return parser::symbol_type(itr->second, loc_);
}
if (path) if (path)
{ {
if (buffer_.data[buffer_.length - 1] == '/') if (buffer_.data[buffer_.length - 1] == '/')
throw comp_error(loc_, "invalid path end '\\'"); throw comp_error(loc_, "invalid path end '\\'");
//return s2::parser::make_PATH(xsk::gsc::s2::resolver::make_token(std::string_view(buffer_.data, buffer_.length)), loc_); return parser::make_PATH(resolver::make_token(std::string_view(buffer_.data, buffer_.length)), loc_);
return s2::parser::make_PATH(std::string(buffer_.data, buffer_.length), loc_);
} }
//return s2::parser::make_IDENTIFIER(xsk::gsc::s2::resolver::make_token(std::string_view(buffer_.data, buffer_.length)), loc_); return parser::make_IDENTIFIER(resolver::make_token(std::string_view(buffer_.data, buffer_.length)), loc_);
return s2::parser::make_IDENTIFIER(std::string(buffer_.data, buffer_.length), loc_);
} }
lex_number: lex_number:
@ -622,9 +581,9 @@ lex_number:
throw comp_error(loc_, "invalid number literal"); throw comp_error(loc_, "invalid number literal");
if (state_ == state::field || dot || flt) if (state_ == state::field || dot || flt)
return s2::parser::make_FLOAT(std::string(buffer_.data, buffer_.length), loc_); return parser::make_FLOAT(std::string(buffer_.data, buffer_.length), loc_);
return s2::parser::make_INTEGER(std::string(buffer_.data, buffer_.length), loc_); return parser::make_INTEGER(std::string(buffer_.data, buffer_.length), loc_);
} }
else if (curr == 'o') else if (curr == 'o')
{ {
@ -656,7 +615,7 @@ lex_number:
if (last == '\'' || buffer_.length <= 0) if (last == '\'' || buffer_.length <= 0)
throw comp_error(loc_, "invalid octal literal"); throw comp_error(loc_, "invalid octal literal");
return s2::parser::make_INTEGER(xsk::utils::string::oct_to_dec(buffer_.data), loc_); return parser::make_INTEGER(xsk::utils::string::oct_to_dec(buffer_.data), loc_);
} }
else if (curr == 'b') else if (curr == 'b')
{ {
@ -690,7 +649,7 @@ lex_number:
if (last == '\'' || buffer_.length < 3) if (last == '\'' || buffer_.length < 3)
throw comp_error(loc_, "invalid binary literal"); throw comp_error(loc_, "invalid binary literal");
return s2::parser::make_INTEGER(xsk::utils::string::bin_to_dec(buffer_.data), loc_); return parser::make_INTEGER(xsk::utils::string::bin_to_dec(buffer_.data), loc_);
} }
else if (curr == 'x') else if (curr == 'x')
{ {
@ -724,179 +683,60 @@ lex_number:
if (last == '\'' || buffer_.length < 3) if (last == '\'' || buffer_.length < 3)
throw comp_error(loc_, "invalid hexadecimal literal"); throw comp_error(loc_, "invalid hexadecimal literal");
return s2::parser::make_INTEGER(xsk::utils::string::hex_to_dec(buffer_.data), loc_); return parser::make_INTEGER(xsk::utils::string::hex_to_dec(buffer_.data), loc_);
} }
// cant get here! // cant get here!
} }
} }
auto lexer::keyword_token(keyword k) -> xsk::gsc::s2::parser::symbol_type const std::unordered_map<std::string_view, parser::token::token_kind_type> lexer::keyword_map
{
switch (k)
{
case keyword::KW_pre_inline:
return s2::parser::make_INLINE(loc_);
case keyword::KW_pre_include:
return s2::parser::make_INCLUDE(loc_);
case keyword::KW_pre_using_animtree:
return s2::parser::make_USINGTREE(loc_);
case keyword::KW_pre_animtree:
return s2::parser::make_ANIMTREE(loc_);
case keyword::KW_endon:
return s2::parser::make_ENDON(loc_);
case keyword::KW_notify:
return s2::parser::make_NOTIFY(loc_);
case keyword::KW_wait:
return s2::parser::make_WAIT(loc_);
case keyword::KW_waittill:
return s2::parser::make_WAITTILL(loc_);
case keyword::KW_waittillmatch:
return s2::parser::make_WAITTILLMATCH(loc_);
case keyword::KW_waittillframeend:
return s2::parser::make_WAITTILLFRAMEEND(loc_);
case keyword::KW_waitframe:
return s2::parser::make_WAITFRAME(loc_);
case keyword::KW_if:
return s2::parser::make_IF(loc_);
case keyword::KW_else:
return s2::parser::make_ELSE(loc_);
case keyword::KW_do:
return s2::parser::make_DO(loc_);
case keyword::KW_while:
return s2::parser::make_WHILE(loc_);
case keyword::KW_for:
return s2::parser::make_FOR(loc_);
case keyword::KW_foreach:
return s2::parser::make_FOREACH(loc_);
case keyword::KW_in:
return s2::parser::make_IN(loc_);
case keyword::KW_switch:
return s2::parser::make_SWITCH(loc_);
case keyword::KW_case:
return s2::parser::make_CASE(loc_);
case keyword::KW_default:
return s2::parser::make_DEFAULT(loc_);
case keyword::KW_break:
return s2::parser::make_BREAK(loc_);
case keyword::KW_continue:
return s2::parser::make_CONTINUE(loc_);
case keyword::KW_return:
return s2::parser::make_RETURN(loc_);
case keyword::KW_breakpoint:
return s2::parser::make_BREAKPOINT(loc_);
case keyword::KW_prof_begin:
return s2::parser::make_PROFBEGIN(loc_);
case keyword::KW_prof_end:
return s2::parser::make_PROFEND(loc_);
case keyword::KW_thread:
return s2::parser::make_THREAD(loc_);
case keyword::KW_childthread:
return s2::parser::make_CHILDTHREAD(loc_);
case keyword::KW_thisthread:
return s2::parser::make_THISTHREAD(loc_);
case keyword::KW_call:
return s2::parser::make_CALL(loc_);
case keyword::KW_true:
return s2::parser::make_TRUE(loc_);
case keyword::KW_false:
return s2::parser::make_FALSE(loc_);
case keyword::KW_undefined:
return s2::parser::make_UNDEFINED(loc_);
case keyword::KW_dotsize:
return s2::parser::make_SIZE(loc_);
case keyword::KW_game:
return s2::parser::make_GAME(loc_);
case keyword::KW_self:
return s2::parser::make_SELF(loc_);
case keyword::KW_anim:
return s2::parser::make_ANIM(loc_);
case keyword::KW_level:
return s2::parser::make_LEVEL(loc_);
default:
throw error("gsc lexer: INVALID KEYWORD TOKEN!");
}
}
auto lexer::keyword_is_token(keyword k) -> bool
{
switch (k)
{
/* case keyword::KW_pre_define:
case keyword::KW_pre_undef:
case keyword::KW_pre_ifdef:
case keyword::KW_pre_ifndef:
case keyword::KW_pre_if:
case keyword::KW_pre_elif:
case keyword::KW_pre_else:
case keyword::KW_pre_endif:*/
case keyword::KW_INVALID:
return false;
default:
return true;
}
}
auto lexer::get_keyword(std::string_view str) -> keyword
{
auto itr = keywords.find(str);
if(itr != keywords.end())
{
return itr->second;
}
return keyword::KW_INVALID;
}
std::unordered_map<std::string_view, keyword> lexer::keywords
{{ {{
/* { "#define", keyword::KW_pre_define }, { "#define", parser::token::HSDEFINE },
{ "#undef", keyword::KW_pre_undef }, { "#undef", parser::token::HSUNDEF },
{ "#ifdef", keyword::KW_pre_ifdef }, { "#ifdef", parser::token::HSIFDEF },
{ "#ifndef", keyword::KW_pre_ifndef }, { "#ifndef", parser::token::HSIFNDEF },
{ "#if", keyword::KW_pre_if }, { "#if", parser::token::HSIF },
{ "#elif", keyword::KW_pre_elif }, { "#elif", parser::token::HSELIF },
{ "#else", keyword::KW_pre_else }, { "#else", parser::token::HSELSE },
{ "#endif", keyword::KW_pre_endif },*/ { "#endif", parser::token::HSENDIF },
{ "#inline", keyword::KW_pre_inline }, { "#inline", parser::token::INLINE },
{ "#include", keyword::KW_pre_include }, { "#include", parser::token::INCLUDE },
{ "#using_animtree", keyword::KW_pre_using_animtree }, { "#using_animtree", parser::token::USINGTREE },
{ "#animtree", keyword::KW_pre_animtree }, { "#animtree", parser::token::ANIMTREE },
{ "endon", keyword::KW_endon }, { "endon", parser::token::ENDON },
{ "notify", keyword::KW_notify }, { "notify", parser::token::NOTIFY },
{ "wait", keyword::KW_wait }, { "wait", parser::token::WAIT },
{ "waittill", keyword::KW_waittill }, { "waittill", parser::token::WAITTILL },
{ "waittillmatch", keyword::KW_waittillmatch }, { "waittillmatch", parser::token::WAITTILLMATCH },
{ "waittillframeend", keyword::KW_waittillframeend }, { "waittillframeend", parser::token::WAITTILLFRAMEEND },
{ "waitframe", keyword::KW_waitframe }, { "waitframe", parser::token::WAITFRAME },
{ "if", keyword::KW_if }, { "if", parser::token::IF },
{ "else", keyword::KW_else }, { "else", parser::token::ELSE },
{ "do", keyword::KW_do }, { "do", parser::token::DO },
{ "while", keyword::KW_while }, { "while", parser::token::WHILE },
{ "for", keyword::KW_for }, { "for", parser::token::FOR },
{ "foreach", keyword::KW_foreach }, { "foreach", parser::token::FOREACH },
{ "in", keyword::KW_in }, { "in", parser::token::IN },
{ "switch", keyword::KW_switch }, { "switch", parser::token::SWITCH },
{ "case", keyword::KW_case }, { "case", parser::token::CASE },
{ "default", keyword::KW_default }, { "default", parser::token::DEFAULT },
{ "break", keyword::KW_break }, { "break", parser::token::BREAK },
{ "continue", keyword::KW_continue }, { "continue", parser::token::CONTINUE },
{ "return", keyword::KW_return }, { "return", parser::token::RETURN },
{ "breakpoint", keyword::KW_breakpoint }, { "breakpoint", parser::token::BREAKPOINT },
{ "prof_begin", keyword::KW_prof_begin }, { "prof_begin", parser::token::PROFBEGIN },
{ "prof_end", keyword::KW_prof_end }, { "prof_end", parser::token::PROFEND },
{ "thread", keyword::KW_thread }, { "thread", parser::token::THREAD },
{ "childthread", keyword::KW_childthread }, { "childthread", parser::token::CHILDTHREAD },
{ "thisthread", keyword::KW_thisthread }, { "thisthread", parser::token::THISTHREAD },
{ "call", keyword::KW_call }, { "call", parser::token::CALL },
{ "true", keyword::KW_true }, { "true", parser::token::TRUE },
{ "false", keyword::KW_false }, { "false", parser::token::FALSE },
{ "undefined", keyword::KW_undefined }, { "undefined", parser::token::UNDEFINED },
{ ".size", keyword::KW_dotsize }, { "game", parser::token::GAME },
{ "game", keyword::KW_game }, { "self", parser::token::SELF },
{ "self", keyword::KW_self }, { "anim", parser::token::ANIM },
{ "anim", keyword::KW_anim }, { "level", parser::token::LEVEL },
{ "level", keyword::KW_level },
}}; }};
} // namespace xsk::gsc::s2 } // namespace xsk::gsc::s2

View File

@ -10,8 +10,6 @@
namespace xsk::gsc::s2 namespace xsk::gsc::s2
{ {
enum class keyword;
constexpr size_t max_buf_size = 0x2000; constexpr size_t max_buf_size = 0x2000;
struct buffer struct buffer
@ -53,26 +51,22 @@ class lexer
reader reader_; reader reader_;
buffer buffer_; buffer buffer_;
location loc_; location loc_;
build mode_;
std::stack<location> locs_; std::stack<location> locs_;
std::stack<reader> readers_; std::stack<reader> readers_;
std::uint32_t header_top_; std::uint32_t header_top_;
state state_; state state_;
build mode_;
bool indev_; bool indev_;
public: public:
lexer(const std::string& name, const char* data, size_t size); lexer(const std::string& name, const char* data, size_t size);
auto lex() -> xsk::gsc::s2::parser::symbol_type; auto lex() -> parser::symbol_type;
void push_header(const std::string& file); void push_header(const std::string& file);
void pop_header(); void pop_header();
void restrict_header(const xsk::gsc::location& loc); void ban_header(const location& loc);
private: private:
auto keyword_token(keyword k) -> xsk::gsc::s2::parser::symbol_type; static const std::unordered_map<std::string_view, parser::token::token_kind_type> keyword_map;
static auto keyword_is_token(keyword k) -> bool;
static auto get_keyword(std::string_view str) -> keyword;
static std::unordered_map<std::string_view, keyword> keywords;
}; };
} // namespace xsk::gsc::s2 } // namespace xsk::gsc::s2

File diff suppressed because it is too large Load Diff

View File

@ -677,109 +677,117 @@ namespace xsk { namespace gsc { namespace s2 {
S2EOF = 0, // "end of file" S2EOF = 0, // "end of file"
S2error = 1, // error S2error = 1, // error
S2UNDEF = 2, // "invalid token" S2UNDEF = 2, // "invalid token"
DEVBEGIN = 3, // "/#" HSDEFINE = 3, // "#define"
DEVEND = 4, // "#/" HSUNDEF = 4, // "#undef"
INLINE = 5, // "#inline" HSIFDEF = 5, // "#ifdef"
INCLUDE = 6, // "#include" HSIFNDEF = 6, // "#ifndef"
USINGTREE = 7, // "#using_animtree" HSIF = 7, // "#if"
ANIMTREE = 8, // "#animtree" HSELIF = 8, // "#elif"
ENDON = 9, // "endon" HSELSE = 9, // "#else"
NOTIFY = 10, // "notify" HSENDIF = 10, // "#endif"
WAIT = 11, // "wait" DEVBEGIN = 11, // "/#"
WAITTILL = 12, // "waittill" DEVEND = 12, // "#/"
WAITTILLMATCH = 13, // "waittillmatch" INLINE = 13, // "#inline"
WAITTILLFRAMEEND = 14, // "waittillframeend" INCLUDE = 14, // "#include"
WAITFRAME = 15, // "waitframe" USINGTREE = 15, // "#using_animtree"
IF = 16, // "if" ANIMTREE = 16, // "#animtree"
ELSE = 17, // "else" ENDON = 17, // "endon"
DO = 18, // "do" NOTIFY = 18, // "notify"
WHILE = 19, // "while" WAIT = 19, // "wait"
FOR = 20, // "for" WAITTILL = 20, // "waittill"
FOREACH = 21, // "foreach" WAITTILLMATCH = 21, // "waittillmatch"
IN = 22, // "in" WAITTILLFRAMEEND = 22, // "waittillframeend"
SWITCH = 23, // "switch" WAITFRAME = 23, // "waitframe"
CASE = 24, // "case" IF = 24, // "if"
DEFAULT = 25, // "default" ELSE = 25, // "else"
BREAK = 26, // "break" DO = 26, // "do"
CONTINUE = 27, // "continue" WHILE = 27, // "while"
RETURN = 28, // "return" FOR = 28, // "for"
BREAKPOINT = 29, // "breakpoint" FOREACH = 29, // "foreach"
PROFBEGIN = 30, // "prof_begin" IN = 30, // "in"
PROFEND = 31, // "prof_end" SWITCH = 31, // "switch"
THREAD = 32, // "thread" CASE = 32, // "case"
CHILDTHREAD = 33, // "childthread" DEFAULT = 33, // "default"
THISTHREAD = 34, // "thisthread" BREAK = 34, // "break"
CALL = 35, // "call" CONTINUE = 35, // "continue"
TRUE = 36, // "true" RETURN = 36, // "return"
FALSE = 37, // "false" BREAKPOINT = 37, // "breakpoint"
UNDEFINED = 38, // "undefined" PROFBEGIN = 38, // "prof_begin"
SIZE = 39, // ".size" PROFEND = 39, // "prof_end"
GAME = 40, // "game" THREAD = 40, // "thread"
SELF = 41, // "self" CHILDTHREAD = 41, // "childthread"
ANIM = 42, // "anim" THISTHREAD = 42, // "thisthread"
LEVEL = 43, // "level" CALL = 43, // "call"
LPAREN = 44, // "(" TRUE = 44, // "true"
RPAREN = 45, // ")" FALSE = 45, // "false"
LBRACE = 46, // "{" UNDEFINED = 46, // "undefined"
RBRACE = 47, // "}" SIZE = 47, // ".size"
LBRACKET = 48, // "[" GAME = 48, // "game"
RBRACKET = 49, // "]" SELF = 49, // "self"
COMMA = 50, // "," ANIM = 50, // "anim"
DOT = 51, // "." LEVEL = 51, // "level"
DOUBLECOLON = 52, // "::" LPAREN = 52, // "("
COLON = 53, // ":" RPAREN = 53, // ")"
SEMICOLON = 54, // ";" LBRACE = 54, // "{"
QMARK = 55, // "?" RBRACE = 55, // "}"
INCREMENT = 56, // "++" LBRACKET = 56, // "["
DECREMENT = 57, // "--" RBRACKET = 57, // "]"
LSHIFT = 58, // "<<" COMMA = 58, // ","
RSHIFT = 59, // ">>" DOT = 59, // "."
OR = 60, // "||" DOUBLECOLON = 60, // "::"
AND = 61, // "&&" COLON = 61, // ":"
EQUALITY = 62, // "==" SEMICOLON = 62, // ";"
INEQUALITY = 63, // "!=" QMARK = 63, // "?"
LESS_EQUAL = 64, // "<=" INCREMENT = 64, // "++"
GREATER_EQUAL = 65, // ">=" DECREMENT = 65, // "--"
LESS = 66, // "<" LSHIFT = 66, // "<<"
GREATER = 67, // ">" RSHIFT = 67, // ">>"
NOT = 68, // "!" OR = 68, // "||"
COMPLEMENT = 69, // "~" AND = 69, // "&&"
ASSIGN = 70, // "=" EQUALITY = 70, // "=="
ASSIGN_ADD = 71, // "+=" INEQUALITY = 71, // "!="
ASSIGN_SUB = 72, // "-=" LESS_EQUAL = 72, // "<="
ASSIGN_MUL = 73, // "*=" GREATER_EQUAL = 73, // ">="
ASSIGN_DIV = 74, // "/=" LESS = 74, // "<"
ASSIGN_MOD = 75, // "%=" GREATER = 75, // ">"
ASSIGN_BW_OR = 76, // "|=" NOT = 76, // "!"
ASSIGN_BW_AND = 77, // "&=" COMPLEMENT = 77, // "~"
ASSIGN_BW_EXOR = 78, // "^=" ASSIGN = 78, // "="
ASSIGN_RSHIFT = 79, // ">>=" ASSIGN_ADD = 79, // "+="
ASSIGN_LSHIFT = 80, // "<<=" ASSIGN_SUB = 80, // "-="
BITWISE_OR = 81, // "|" ASSIGN_MUL = 81, // "*="
BITWISE_AND = 82, // "&" ASSIGN_DIV = 82, // "/="
BITWISE_EXOR = 83, // "^" ASSIGN_MOD = 83, // "%="
ADD = 84, // "+" ASSIGN_BW_OR = 84, // "|="
SUB = 85, // "-" ASSIGN_BW_AND = 85, // "&="
MUL = 86, // "*" ASSIGN_BW_EXOR = 86, // "^="
DIV = 87, // "/" ASSIGN_RSHIFT = 87, // ">>="
MOD = 88, // "%" ASSIGN_LSHIFT = 88, // "<<="
FIELD = 89, // "field" BITWISE_OR = 89, // "|"
PATH = 90, // "path" BITWISE_AND = 90, // "&"
IDENTIFIER = 91, // "identifier" BITWISE_EXOR = 91, // "^"
STRING = 92, // "string literal" ADD = 92, // "+"
ISTRING = 93, // "localized string" SUB = 93, // "-"
COLOR = 94, // "color" MUL = 94, // "*"
FLOAT = 95, // "float" DIV = 95, // "/"
INTEGER = 96, // "integer" MOD = 96, // "%"
ADD_ARRAY = 97, // ADD_ARRAY FIELD = 97, // "field"
THEN = 98, // THEN PATH = 98, // "path"
TERN = 99, // TERN IDENTIFIER = 99, // "identifier"
NEG = 100, // NEG STRING = 100, // "string literal"
ANIMREF = 101, // ANIMREF ISTRING = 101, // "localized string"
PREINC = 102, // PREINC COLOR = 102, // "color"
PREDEC = 103, // PREDEC FLOAT = 103, // "float"
POSTINC = 104, // POSTINC INTEGER = 104, // "integer"
POSTDEC = 105 // POSTDEC ADD_ARRAY = 105, // ADD_ARRAY
THEN = 106, // THEN
TERN = 107, // TERN
NEG = 108, // NEG
ANIMREF = 109, // ANIMREF
PREINC = 110, // PREINC
PREDEC = 111, // PREDEC
POSTINC = 112, // POSTINC
POSTDEC = 113 // POSTDEC
}; };
/// Backward compatibility alias (Bison 3.6). /// Backward compatibility alias (Bison 3.6).
typedef token_kind_type yytokentype; typedef token_kind_type yytokentype;
@ -796,195 +804,203 @@ namespace xsk { namespace gsc { namespace s2 {
{ {
enum symbol_kind_type enum symbol_kind_type
{ {
YYNTOKENS = 106, ///< Number of tokens. YYNTOKENS = 114, ///< Number of tokens.
S_YYEMPTY = -2, S_YYEMPTY = -2,
S_YYEOF = 0, // "end of file" S_YYEOF = 0, // "end of file"
S_YYerror = 1, // error S_YYerror = 1, // error
S_YYUNDEF = 2, // "invalid token" S_YYUNDEF = 2, // "invalid token"
S_DEVBEGIN = 3, // "/#" S_HSDEFINE = 3, // "#define"
S_DEVEND = 4, // "#/" S_HSUNDEF = 4, // "#undef"
S_INLINE = 5, // "#inline" S_HSIFDEF = 5, // "#ifdef"
S_INCLUDE = 6, // "#include" S_HSIFNDEF = 6, // "#ifndef"
S_USINGTREE = 7, // "#using_animtree" S_HSIF = 7, // "#if"
S_ANIMTREE = 8, // "#animtree" S_HSELIF = 8, // "#elif"
S_ENDON = 9, // "endon" S_HSELSE = 9, // "#else"
S_NOTIFY = 10, // "notify" S_HSENDIF = 10, // "#endif"
S_WAIT = 11, // "wait" S_DEVBEGIN = 11, // "/#"
S_WAITTILL = 12, // "waittill" S_DEVEND = 12, // "#/"
S_WAITTILLMATCH = 13, // "waittillmatch" S_INLINE = 13, // "#inline"
S_WAITTILLFRAMEEND = 14, // "waittillframeend" S_INCLUDE = 14, // "#include"
S_WAITFRAME = 15, // "waitframe" S_USINGTREE = 15, // "#using_animtree"
S_IF = 16, // "if" S_ANIMTREE = 16, // "#animtree"
S_ELSE = 17, // "else" S_ENDON = 17, // "endon"
S_DO = 18, // "do" S_NOTIFY = 18, // "notify"
S_WHILE = 19, // "while" S_WAIT = 19, // "wait"
S_FOR = 20, // "for" S_WAITTILL = 20, // "waittill"
S_FOREACH = 21, // "foreach" S_WAITTILLMATCH = 21, // "waittillmatch"
S_IN = 22, // "in" S_WAITTILLFRAMEEND = 22, // "waittillframeend"
S_SWITCH = 23, // "switch" S_WAITFRAME = 23, // "waitframe"
S_CASE = 24, // "case" S_IF = 24, // "if"
S_DEFAULT = 25, // "default" S_ELSE = 25, // "else"
S_BREAK = 26, // "break" S_DO = 26, // "do"
S_CONTINUE = 27, // "continue" S_WHILE = 27, // "while"
S_RETURN = 28, // "return" S_FOR = 28, // "for"
S_BREAKPOINT = 29, // "breakpoint" S_FOREACH = 29, // "foreach"
S_PROFBEGIN = 30, // "prof_begin" S_IN = 30, // "in"
S_PROFEND = 31, // "prof_end" S_SWITCH = 31, // "switch"
S_THREAD = 32, // "thread" S_CASE = 32, // "case"
S_CHILDTHREAD = 33, // "childthread" S_DEFAULT = 33, // "default"
S_THISTHREAD = 34, // "thisthread" S_BREAK = 34, // "break"
S_CALL = 35, // "call" S_CONTINUE = 35, // "continue"
S_TRUE = 36, // "true" S_RETURN = 36, // "return"
S_FALSE = 37, // "false" S_BREAKPOINT = 37, // "breakpoint"
S_UNDEFINED = 38, // "undefined" S_PROFBEGIN = 38, // "prof_begin"
S_SIZE = 39, // ".size" S_PROFEND = 39, // "prof_end"
S_GAME = 40, // "game" S_THREAD = 40, // "thread"
S_SELF = 41, // "self" S_CHILDTHREAD = 41, // "childthread"
S_ANIM = 42, // "anim" S_THISTHREAD = 42, // "thisthread"
S_LEVEL = 43, // "level" S_CALL = 43, // "call"
S_LPAREN = 44, // "(" S_TRUE = 44, // "true"
S_RPAREN = 45, // ")" S_FALSE = 45, // "false"
S_LBRACE = 46, // "{" S_UNDEFINED = 46, // "undefined"
S_RBRACE = 47, // "}" S_SIZE = 47, // ".size"
S_LBRACKET = 48, // "[" S_GAME = 48, // "game"
S_RBRACKET = 49, // "]" S_SELF = 49, // "self"
S_COMMA = 50, // "," S_ANIM = 50, // "anim"
S_DOT = 51, // "." S_LEVEL = 51, // "level"
S_DOUBLECOLON = 52, // "::" S_LPAREN = 52, // "("
S_COLON = 53, // ":" S_RPAREN = 53, // ")"
S_SEMICOLON = 54, // ";" S_LBRACE = 54, // "{"
S_QMARK = 55, // "?" S_RBRACE = 55, // "}"
S_INCREMENT = 56, // "++" S_LBRACKET = 56, // "["
S_DECREMENT = 57, // "--" S_RBRACKET = 57, // "]"
S_LSHIFT = 58, // "<<" S_COMMA = 58, // ","
S_RSHIFT = 59, // ">>" S_DOT = 59, // "."
S_OR = 60, // "||" S_DOUBLECOLON = 60, // "::"
S_AND = 61, // "&&" S_COLON = 61, // ":"
S_EQUALITY = 62, // "==" S_SEMICOLON = 62, // ";"
S_INEQUALITY = 63, // "!=" S_QMARK = 63, // "?"
S_LESS_EQUAL = 64, // "<=" S_INCREMENT = 64, // "++"
S_GREATER_EQUAL = 65, // ">=" S_DECREMENT = 65, // "--"
S_LESS = 66, // "<" S_LSHIFT = 66, // "<<"
S_GREATER = 67, // ">" S_RSHIFT = 67, // ">>"
S_NOT = 68, // "!" S_OR = 68, // "||"
S_COMPLEMENT = 69, // "~" S_AND = 69, // "&&"
S_ASSIGN = 70, // "=" S_EQUALITY = 70, // "=="
S_ASSIGN_ADD = 71, // "+=" S_INEQUALITY = 71, // "!="
S_ASSIGN_SUB = 72, // "-=" S_LESS_EQUAL = 72, // "<="
S_ASSIGN_MUL = 73, // "*=" S_GREATER_EQUAL = 73, // ">="
S_ASSIGN_DIV = 74, // "/=" S_LESS = 74, // "<"
S_ASSIGN_MOD = 75, // "%=" S_GREATER = 75, // ">"
S_ASSIGN_BW_OR = 76, // "|=" S_NOT = 76, // "!"
S_ASSIGN_BW_AND = 77, // "&=" S_COMPLEMENT = 77, // "~"
S_ASSIGN_BW_EXOR = 78, // "^=" S_ASSIGN = 78, // "="
S_ASSIGN_RSHIFT = 79, // ">>=" S_ASSIGN_ADD = 79, // "+="
S_ASSIGN_LSHIFT = 80, // "<<=" S_ASSIGN_SUB = 80, // "-="
S_BITWISE_OR = 81, // "|" S_ASSIGN_MUL = 81, // "*="
S_BITWISE_AND = 82, // "&" S_ASSIGN_DIV = 82, // "/="
S_BITWISE_EXOR = 83, // "^" S_ASSIGN_MOD = 83, // "%="
S_ADD = 84, // "+" S_ASSIGN_BW_OR = 84, // "|="
S_SUB = 85, // "-" S_ASSIGN_BW_AND = 85, // "&="
S_MUL = 86, // "*" S_ASSIGN_BW_EXOR = 86, // "^="
S_DIV = 87, // "/" S_ASSIGN_RSHIFT = 87, // ">>="
S_MOD = 88, // "%" S_ASSIGN_LSHIFT = 88, // "<<="
S_FIELD = 89, // "field" S_BITWISE_OR = 89, // "|"
S_PATH = 90, // "path" S_BITWISE_AND = 90, // "&"
S_IDENTIFIER = 91, // "identifier" S_BITWISE_EXOR = 91, // "^"
S_STRING = 92, // "string literal" S_ADD = 92, // "+"
S_ISTRING = 93, // "localized string" S_SUB = 93, // "-"
S_COLOR = 94, // "color" S_MUL = 94, // "*"
S_FLOAT = 95, // "float" S_DIV = 95, // "/"
S_INTEGER = 96, // "integer" S_MOD = 96, // "%"
S_ADD_ARRAY = 97, // ADD_ARRAY S_FIELD = 97, // "field"
S_THEN = 98, // THEN S_PATH = 98, // "path"
S_TERN = 99, // TERN S_IDENTIFIER = 99, // "identifier"
S_NEG = 100, // NEG S_STRING = 100, // "string literal"
S_ANIMREF = 101, // ANIMREF S_ISTRING = 101, // "localized string"
S_PREINC = 102, // PREINC S_COLOR = 102, // "color"
S_PREDEC = 103, // PREDEC S_FLOAT = 103, // "float"
S_POSTINC = 104, // POSTINC S_INTEGER = 104, // "integer"
S_POSTDEC = 105, // POSTDEC S_ADD_ARRAY = 105, // ADD_ARRAY
S_YYACCEPT = 106, // $accept S_THEN = 106, // THEN
S_root = 107, // root S_TERN = 107, // TERN
S_program = 108, // program S_NEG = 108, // NEG
S_inline = 109, // inline S_ANIMREF = 109, // ANIMREF
S_include = 110, // include S_PREINC = 110, // PREINC
S_declaration = 111, // declaration S_PREDEC = 111, // PREDEC
S_decl_usingtree = 112, // decl_usingtree S_POSTINC = 112, // POSTINC
S_decl_constant = 113, // decl_constant S_POSTDEC = 113, // POSTDEC
S_decl_thread = 114, // decl_thread S_YYACCEPT = 114, // $accept
S_stmt = 115, // stmt S_root = 115, // root
S_stmt_dev = 116, // stmt_dev S_program = 116, // program
S_stmt_block = 117, // stmt_block S_inline = 117, // inline
S_stmt_list = 118, // stmt_list S_include = 118, // include
S_stmt_expr = 119, // stmt_expr S_declaration = 119, // declaration
S_stmt_call = 120, // stmt_call S_decl_usingtree = 120, // decl_usingtree
S_stmt_assign = 121, // stmt_assign S_decl_constant = 121, // decl_constant
S_stmt_endon = 122, // stmt_endon S_decl_thread = 122, // decl_thread
S_stmt_notify = 123, // stmt_notify S_stmt = 123, // stmt
S_stmt_wait = 124, // stmt_wait S_stmt_dev = 124, // stmt_dev
S_stmt_waittill = 125, // stmt_waittill S_stmt_block = 125, // stmt_block
S_stmt_waittillmatch = 126, // stmt_waittillmatch S_stmt_list = 126, // stmt_list
S_stmt_waittillframeend = 127, // stmt_waittillframeend S_stmt_expr = 127, // stmt_expr
S_stmt_waitframe = 128, // stmt_waitframe S_stmt_call = 128, // stmt_call
S_stmt_if = 129, // stmt_if S_stmt_assign = 129, // stmt_assign
S_stmt_ifelse = 130, // stmt_ifelse S_stmt_endon = 130, // stmt_endon
S_stmt_while = 131, // stmt_while S_stmt_notify = 131, // stmt_notify
S_stmt_dowhile = 132, // stmt_dowhile S_stmt_wait = 132, // stmt_wait
S_stmt_for = 133, // stmt_for S_stmt_waittill = 133, // stmt_waittill
S_stmt_foreach = 134, // stmt_foreach S_stmt_waittillmatch = 134, // stmt_waittillmatch
S_stmt_switch = 135, // stmt_switch S_stmt_waittillframeend = 135, // stmt_waittillframeend
S_stmt_case = 136, // stmt_case S_stmt_waitframe = 136, // stmt_waitframe
S_stmt_default = 137, // stmt_default S_stmt_if = 137, // stmt_if
S_stmt_break = 138, // stmt_break S_stmt_ifelse = 138, // stmt_ifelse
S_stmt_continue = 139, // stmt_continue S_stmt_while = 139, // stmt_while
S_stmt_return = 140, // stmt_return S_stmt_dowhile = 140, // stmt_dowhile
S_stmt_breakpoint = 141, // stmt_breakpoint S_stmt_for = 141, // stmt_for
S_stmt_prof_begin = 142, // stmt_prof_begin S_stmt_foreach = 142, // stmt_foreach
S_stmt_prof_end = 143, // stmt_prof_end S_stmt_switch = 143, // stmt_switch
S_expr = 144, // expr S_stmt_case = 144, // stmt_case
S_expr_or_empty = 145, // expr_or_empty S_stmt_default = 145, // stmt_default
S_expr_assign = 146, // expr_assign S_stmt_break = 146, // stmt_break
S_expr_increment = 147, // expr_increment S_stmt_continue = 147, // stmt_continue
S_expr_decrement = 148, // expr_decrement S_stmt_return = 148, // stmt_return
S_expr_ternary = 149, // expr_ternary S_stmt_breakpoint = 149, // stmt_breakpoint
S_expr_binary = 150, // expr_binary S_stmt_prof_begin = 150, // stmt_prof_begin
S_expr_primitive = 151, // expr_primitive S_stmt_prof_end = 151, // stmt_prof_end
S_expr_complement = 152, // expr_complement S_expr = 152, // expr
S_expr_not = 153, // expr_not S_expr_or_empty = 153, // expr_or_empty
S_expr_call = 154, // expr_call S_expr_assign = 154, // expr_assign
S_expr_method = 155, // expr_method S_expr_increment = 155, // expr_increment
S_expr_function = 156, // expr_function S_expr_decrement = 156, // expr_decrement
S_expr_pointer = 157, // expr_pointer S_expr_ternary = 157, // expr_ternary
S_expr_add_array = 158, // expr_add_array S_expr_binary = 158, // expr_binary
S_expr_parameters = 159, // expr_parameters S_expr_primitive = 159, // expr_primitive
S_expr_arguments = 160, // expr_arguments S_expr_complement = 160, // expr_complement
S_expr_arguments_no_empty = 161, // expr_arguments_no_empty S_expr_not = 161, // expr_not
S_expr_reference = 162, // expr_reference S_expr_call = 162, // expr_call
S_expr_array = 163, // expr_array S_expr_method = 163, // expr_method
S_expr_field = 164, // expr_field S_expr_function = 164, // expr_function
S_expr_size = 165, // expr_size S_expr_pointer = 165, // expr_pointer
S_expr_paren = 166, // expr_paren S_expr_add_array = 166, // expr_add_array
S_expr_object = 167, // expr_object S_expr_parameters = 167, // expr_parameters
S_expr_thisthread = 168, // expr_thisthread S_expr_arguments = 168, // expr_arguments
S_expr_empty_array = 169, // expr_empty_array S_expr_arguments_no_empty = 169, // expr_arguments_no_empty
S_expr_undefined = 170, // expr_undefined S_expr_reference = 170, // expr_reference
S_expr_game = 171, // expr_game S_expr_array = 171, // expr_array
S_expr_self = 172, // expr_self S_expr_field = 172, // expr_field
S_expr_anim = 173, // expr_anim S_expr_size = 173, // expr_size
S_expr_level = 174, // expr_level S_expr_paren = 174, // expr_paren
S_expr_animation = 175, // expr_animation S_expr_object = 175, // expr_object
S_expr_animtree = 176, // expr_animtree S_expr_thisthread = 176, // expr_thisthread
S_expr_identifier = 177, // expr_identifier S_expr_empty_array = 177, // expr_empty_array
S_expr_path = 178, // expr_path S_expr_undefined = 178, // expr_undefined
S_expr_istring = 179, // expr_istring S_expr_game = 179, // expr_game
S_expr_string = 180, // expr_string S_expr_self = 180, // expr_self
S_expr_color = 181, // expr_color S_expr_anim = 181, // expr_anim
S_expr_vector = 182, // expr_vector S_expr_level = 182, // expr_level
S_expr_float = 183, // expr_float S_expr_animation = 183, // expr_animation
S_expr_integer = 184, // expr_integer S_expr_animtree = 184, // expr_animtree
S_expr_false = 185, // expr_false S_expr_identifier = 185, // expr_identifier
S_expr_true = 186 // expr_true S_expr_path = 186, // expr_path
S_expr_istring = 187, // expr_istring
S_expr_string = 188, // expr_string
S_expr_color = 189, // expr_color
S_expr_vector = 190, // expr_vector
S_expr_float = 191, // expr_float
S_expr_integer = 192, // expr_integer
S_expr_false = 193, // expr_false
S_expr_true = 194 // expr_true
}; };
}; };
@ -2779,6 +2795,126 @@ switch (yykind)
return symbol_type (token::S2UNDEF, l); return symbol_type (token::S2UNDEF, l);
} }
#endif #endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_HSDEFINE (location_type l)
{
return symbol_type (token::HSDEFINE, std::move (l));
}
#else
static
symbol_type
make_HSDEFINE (const location_type& l)
{
return symbol_type (token::HSDEFINE, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_HSUNDEF (location_type l)
{
return symbol_type (token::HSUNDEF, std::move (l));
}
#else
static
symbol_type
make_HSUNDEF (const location_type& l)
{
return symbol_type (token::HSUNDEF, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_HSIFDEF (location_type l)
{
return symbol_type (token::HSIFDEF, std::move (l));
}
#else
static
symbol_type
make_HSIFDEF (const location_type& l)
{
return symbol_type (token::HSIFDEF, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_HSIFNDEF (location_type l)
{
return symbol_type (token::HSIFNDEF, std::move (l));
}
#else
static
symbol_type
make_HSIFNDEF (const location_type& l)
{
return symbol_type (token::HSIFNDEF, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_HSIF (location_type l)
{
return symbol_type (token::HSIF, std::move (l));
}
#else
static
symbol_type
make_HSIF (const location_type& l)
{
return symbol_type (token::HSIF, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_HSELIF (location_type l)
{
return symbol_type (token::HSELIF, std::move (l));
}
#else
static
symbol_type
make_HSELIF (const location_type& l)
{
return symbol_type (token::HSELIF, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_HSELSE (location_type l)
{
return symbol_type (token::HSELSE, std::move (l));
}
#else
static
symbol_type
make_HSELSE (const location_type& l)
{
return symbol_type (token::HSELSE, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_HSENDIF (location_type l)
{
return symbol_type (token::HSENDIF, std::move (l));
}
#else
static
symbol_type
make_HSENDIF (const location_type& l)
{
return symbol_type (token::HSENDIF, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS #if 201103L <= YY_CPLUSPLUS
static static
symbol_type symbol_type
@ -5362,7 +5498,7 @@ switch (yykind)
#line 13 "parser.ypp" #line 13 "parser.ypp"
} } } // xsk::gsc::s2 } } } // xsk::gsc::s2
#line 5366 "parser.hpp" #line 5502 "parser.hpp"

View File

@ -16,60 +16,6 @@ xsk::gsc::s4::parser::symbol_type S4lex(xsk::gsc::s4::lexer& lexer)
namespace xsk::gsc::s4 namespace xsk::gsc::s4
{ {
enum class keyword
{
/* KW_pre_define,
KW_pre_undef,
KW_pre_ifdef,
KW_pre_ifndef,
KW_pre_if,
KW_pre_elif,
KW_pre_else,
KW_pre_endif,*/
KW_pre_inline,
KW_pre_include,
KW_pre_using_animtree,
KW_pre_animtree,
KW_endon,
KW_notify,
KW_wait,
KW_waittill,
KW_waittillmatch,
KW_waittillframeend,
KW_waitframe,
KW_if,
KW_else,
KW_do,
KW_while,
KW_for,
KW_foreach,
KW_in,
KW_switch,
KW_case,
KW_default,
KW_break,
KW_continue,
KW_return,
KW_breakpoint,
KW_prof_begin,
KW_prof_end,
KW_thread,
KW_childthread,
KW_thisthread,
KW_call,
KW_true,
KW_false,
KW_undefined,
KW_dotsize,
KW_game,
KW_self,
KW_anim,
KW_level,
KW_isdefined,
KW_istrue,
KW_INVALID,
};
buffer::buffer() : length(0) buffer::buffer() : length(0)
{ {
data = static_cast<char*>(std::malloc(max_buf_size)); data = static_cast<char*>(std::malloc(max_buf_size));
@ -132,7 +78,7 @@ void reader::advance()
} }
} }
lexer::lexer(const std::string& name, const char* data, size_t size) : indev_(false), loc_(xsk::gsc::location(&name)), lexer::lexer(const std::string& name, const char* data, size_t size) : indev_(false), loc_(location(&name)),
mode_(build::dev), header_top_(0), locs_(std::stack<location>()), readers_(std::stack<reader>()) mode_(build::dev), header_top_(0), locs_(std::stack<location>()), readers_(std::stack<reader>())
{ {
reader_.init(data, size); reader_.init(data, size);
@ -143,7 +89,7 @@ void lexer::push_header(const std::string& file)
try try
{ {
if (header_top_++ >= 10) if (header_top_++ >= 10)
throw xsk::gsc::error("maximum gsh depth exceeded '10'"); throw comp_error(loc_, "maximum gsh depth exceeded '10'");
auto data = resolver::file_data(file + ".gsh"); auto data = resolver::file_data(file + ".gsh");
@ -154,7 +100,7 @@ void lexer::push_header(const std::string& file)
} }
catch (const std::exception& e) catch (const std::exception& e)
{ {
throw xsk::gsc::error("parsing header file '" + file + "': " + e.what()); throw error("parsing header file '" + file + "': " + e.what());
} }
} }
@ -167,7 +113,7 @@ void lexer::pop_header()
readers_.pop(); readers_.pop();
} }
void lexer::restrict_header(const xsk::gsc::location& loc) void lexer::ban_header(const location& loc)
{ {
if (header_top_ > 0) if (header_top_ > 0)
{ {
@ -175,7 +121,7 @@ void lexer::restrict_header(const xsk::gsc::location& loc)
} }
} }
auto lexer::lex() -> xsk::gsc::s4::parser::symbol_type auto lexer::lex() -> parser::symbol_type
{ {
buffer_.length = 0; buffer_.length = 0;
state_ = state::start; state_ = state::start;
@ -196,7 +142,7 @@ auto lexer::lex() -> xsk::gsc::s4::parser::symbol_type
if (header_top_ > 0) if (header_top_ > 0)
pop_header(); pop_header();
else else
return s4::parser::make_S4EOF(loc_); return parser::make_S4EOF(loc_);
} }
reader_.advance(); reader_.advance();
@ -214,22 +160,22 @@ auto lexer::lex() -> xsk::gsc::s4::parser::symbol_type
continue; continue;
case '/': case '/':
if (curr != '/' && curr != '*' && curr != '#' && curr != '=') if (curr != '/' && curr != '*' && curr != '#' && curr != '=')
return s4::parser::make_DIV(loc_); return parser::make_DIV(loc_);
reader_.advance(); reader_.advance();
if (last == '=') if (last == '=')
return s4::parser::make_ASSIGN_DIV(loc_); return parser::make_ASSIGN_DIV(loc_);
if (last == '#') if (last == '#')
{ {
if (indev_) if (indev_)
throw comp_error(loc_, "cannot recurse devblock ('/#')"); throw comp_error(loc_, "cannot recurse devblock ('/#')");
if (mode_ == xsk::gsc::build::dev) if (mode_ == build::dev)
{ {
indev_ = true; indev_ = true;
return s4::parser::make_DEVBEGIN(loc_); return parser::make_DEVBEGIN(loc_);
} }
else else
{ {
@ -293,7 +239,7 @@ auto lexer::lex() -> xsk::gsc::s4::parser::symbol_type
indev_ = false; indev_ = false;
reader_.advance(); reader_.advance();
return s4::parser::make_DEVEND(loc_); return parser::make_DEVEND(loc_);
} }
buffer_.push(last); buffer_.push(last);
@ -306,12 +252,12 @@ auto lexer::lex() -> xsk::gsc::s4::parser::symbol_type
goto lex_name; goto lex_name;
case '*': case '*':
if (curr != '/' && curr != '=') if (curr != '/' && curr != '=')
return s4::parser::make_MUL(loc_); return parser::make_MUL(loc_);
reader_.advance(); reader_.advance();
if (last == '=') if (last == '=')
return s4::parser::make_ASSIGN_MUL(loc_); return parser::make_ASSIGN_MUL(loc_);
throw comp_error(loc_, "unmatched multiline comment end ('*/')"); throw comp_error(loc_, "unmatched multiline comment end ('*/')");
case '"': case '"':
@ -326,127 +272,127 @@ auto lexer::lex() -> xsk::gsc::s4::parser::symbol_type
state_ = state::field; state_ = state::field;
goto lex_name_or_number; goto lex_name_or_number;
case '(': case '(':
return s4::parser::make_LPAREN(loc_); return parser::make_LPAREN(loc_);
case ')': case ')':
return s4::parser::make_RPAREN(loc_); return parser::make_RPAREN(loc_);
case '{': case '{':
return s4::parser::make_LBRACE(loc_); return parser::make_LBRACE(loc_);
case '}': case '}':
return s4::parser::make_RBRACE(loc_); return parser::make_RBRACE(loc_);
case '[': case '[':
return s4::parser::make_LBRACKET(loc_); return parser::make_LBRACKET(loc_);
case ']': case ']':
return s4::parser::make_RBRACKET(loc_); return parser::make_RBRACKET(loc_);
case ',': case ',':
return s4::parser::make_COMMA(loc_); return parser::make_COMMA(loc_);
case ';': case ';':
return s4::parser::make_SEMICOLON(loc_); return parser::make_SEMICOLON(loc_);
case ':': case ':':
if (curr != ':') if (curr != ':')
return s4::parser::make_COLON(loc_); return parser::make_COLON(loc_);
reader_.advance(); reader_.advance();
return s4::parser::make_DOUBLECOLON(loc_); return parser::make_DOUBLECOLON(loc_);
case '?': case '?':
return s4::parser::make_QMARK(loc_); return parser::make_QMARK(loc_);
case '=': case '=':
if (curr != '=') if (curr != '=')
return s4::parser::make_ASSIGN(loc_); return parser::make_ASSIGN(loc_);
reader_.advance(); reader_.advance();
return s4::parser::make_EQUALITY(loc_); return parser::make_EQUALITY(loc_);
case '+': case '+':
if (curr != '+' && curr != '=') if (curr != '+' && curr != '=')
return s4::parser::make_ADD(loc_); return parser::make_ADD(loc_);
reader_.advance(); reader_.advance();
if (last == '+') if (last == '+')
return s4::parser::make_INCREMENT(loc_); return parser::make_INCREMENT(loc_);
return s4::parser::make_ASSIGN_ADD(loc_); return parser::make_ASSIGN_ADD(loc_);
case '-': case '-':
if (curr != '-' && curr != '=') if (curr != '-' && curr != '=')
return s4::parser::make_SUB(loc_); return parser::make_SUB(loc_);
reader_.advance(); reader_.advance();
if (last == '-') if (last == '-')
return s4::parser::make_DECREMENT(loc_); return parser::make_DECREMENT(loc_);
return s4::parser::make_ASSIGN_SUB(loc_); return parser::make_ASSIGN_SUB(loc_);
case '%': case '%':
if (curr != '=') if (curr != '=')
return s4::parser::make_MOD(loc_); return parser::make_MOD(loc_);
reader_.advance(); reader_.advance();
return s4::parser::make_ASSIGN_MOD(loc_); return parser::make_ASSIGN_MOD(loc_);
case '|': case '|':
if (curr != '|' && curr != '=') if (curr != '|' && curr != '=')
return s4::parser::make_BITWISE_OR(loc_); return parser::make_BITWISE_OR(loc_);
reader_.advance(); reader_.advance();
if (last == '|') if (last == '|')
return s4::parser::make_OR(loc_); return parser::make_OR(loc_);
return s4::parser::make_ASSIGN_BW_OR(loc_); return parser::make_ASSIGN_BW_OR(loc_);
case '&': case '&':
if (curr != '&' && curr != '=' && curr != '"' && curr != '\'') if (curr != '&' && curr != '=' && curr != '"' && curr != '\'')
return s4::parser::make_BITWISE_AND(loc_); return parser::make_BITWISE_AND(loc_);
reader_.advance(); reader_.advance();
if (last == '&') if (last == '&')
return s4::parser::make_AND(loc_); return parser::make_AND(loc_);
if (last == '=') if (last == '=')
return s4::parser::make_ASSIGN_BW_AND(loc_); return parser::make_ASSIGN_BW_AND(loc_);
state_ = state::localize; state_ = state::localize;
goto lex_string; goto lex_string;
case '^': case '^':
if (curr != '=') if (curr != '=')
return s4::parser::make_BITWISE_EXOR(loc_); return parser::make_BITWISE_EXOR(loc_);
reader_.advance(); reader_.advance();
return s4::parser::make_ASSIGN_BW_EXOR(loc_); return parser::make_ASSIGN_BW_EXOR(loc_);
case '!': case '!':
if (curr != '=') if (curr != '=')
return s4::parser::make_NOT(loc_); return parser::make_NOT(loc_);
reader_.advance(); reader_.advance();
return s4::parser::make_INEQUALITY(loc_); return parser::make_INEQUALITY(loc_);
case '~': case '~':
return s4::parser::make_COMPLEMENT(loc_); return parser::make_COMPLEMENT(loc_);
case '<': case '<':
if (curr != '<' && curr != '=') if (curr != '<' && curr != '=')
return s4::parser::make_LESS(loc_); return parser::make_LESS(loc_);
reader_.advance(); reader_.advance();
if (last == '=') if (last == '=')
return s4::parser::make_LESS_EQUAL(loc_); return parser::make_LESS_EQUAL(loc_);
if (curr != '=') if (curr != '=')
return s4::parser::make_LSHIFT(loc_); return parser::make_LSHIFT(loc_);
reader_.advance(); reader_.advance();
return s4::parser::make_ASSIGN_LSHIFT(loc_); return parser::make_ASSIGN_LSHIFT(loc_);
case '>': case '>':
if (curr != '>' && curr != '=') if (curr != '>' && curr != '=')
return s4::parser::make_GREATER(loc_); return parser::make_GREATER(loc_);
reader_.advance(); reader_.advance();
if (last == '=') if (last == '=')
return s4::parser::make_GREATER_EQUAL(loc_); return parser::make_GREATER_EQUAL(loc_);
if (curr != '=') if (curr != '=')
return s4::parser::make_RSHIFT(loc_); return parser::make_RSHIFT(loc_);
reader_.advance(); reader_.advance();
return s4::parser::make_ASSIGN_RSHIFT(loc_); return parser::make_ASSIGN_RSHIFT(loc_);
default: default:
lex_name_or_number: lex_name_or_number:
if (last >= '0' && last <= '9') if (last >= '0' && last <= '9')
@ -499,9 +445,9 @@ lex_string:
} }
if (state_ == state::localize) if (state_ == state::localize)
return s4::parser::make_ISTRING(std::string(buffer_.data, buffer_.length), loc_); return parser::make_ISTRING(std::string(buffer_.data, buffer_.length), loc_);
return s4::parser::make_STRING(std::string(buffer_.data, buffer_.length), loc_); return parser::make_STRING(std::string(buffer_.data, buffer_.length), loc_);
lex_name: lex_name:
buffer_.push(last); buffer_.push(last);
@ -536,22 +482,32 @@ lex_name:
if (std::string_view(buffer_.data, buffer_.length) == "size") if (std::string_view(buffer_.data, buffer_.length) == "size")
{ {
return s4::parser::make_SIZE(loc_); return parser::make_SIZE(loc_);
} }
return s4::parser::make_FIELD(std::string(buffer_.data, buffer_.length), loc_); return parser::make_FIELD(std::string(buffer_.data, buffer_.length), loc_);
} }
else if (state_ == state::preprocessor) else if (state_ == state::preprocessor)
{ {
if (path) if (path)
throw comp_error(loc_, "invalid preprocessor directive"); throw comp_error(loc_, "invalid preprocessor directive");
auto key = get_keyword(std::string_view(buffer_.data, buffer_.length)); auto token = parser::token::S4UNDEF;
if (key != keyword::KW_INVALID) if (buffer_.length < 16)
return keyword_token(key); {
const auto& itr = keyword_map.find(std::string_view(buffer_.data, buffer_.length));
// TODO: call preprocessor(key); if(itr != keyword_map.end())
{
if (itr->second > parser::token::HSENDIF)
return parser::symbol_type(itr->second, loc_);
token = itr->second;
}
}
// TODO: call preprocessor(token);
throw comp_error(loc_, "unknown preprocessor directive"); throw comp_error(loc_, "unknown preprocessor directive");
state_ = state::start; state_ = state::start;
continue; continue;
@ -569,22 +525,23 @@ lex_name:
} }
} }
auto key = get_keyword(std::string_view(buffer_.data, buffer_.length)); if (buffer_.length < 17)
{
const auto& itr = keyword_map.find(std::string_view(buffer_.data, buffer_.length));
if (key != keyword::KW_INVALID) if(itr != keyword_map.end())
return keyword_token(key); return parser::symbol_type(itr->second, loc_);
}
if (path) if (path)
{ {
if (buffer_.data[buffer_.length - 1] == '/') if (buffer_.data[buffer_.length - 1] == '/')
throw comp_error(loc_, "invalid path end '\\'"); throw comp_error(loc_, "invalid path end '\\'");
//return s4::parser::make_PATH(xsk::gsc::s4::resolver::make_token(std::string_view(buffer_.data, buffer_.length)), loc_); return parser::make_PATH(resolver::make_token(std::string_view(buffer_.data, buffer_.length)), loc_);
return s4::parser::make_PATH(std::string(buffer_.data, buffer_.length), loc_);
} }
//return s4::parser::make_IDENTIFIER(xsk::gsc::s4::resolver::make_token(std::string_view(buffer_.data, buffer_.length)), loc_); return parser::make_IDENTIFIER(resolver::make_token(std::string_view(buffer_.data, buffer_.length)), loc_);
return s4::parser::make_IDENTIFIER(std::string(buffer_.data, buffer_.length), loc_);
} }
lex_number: lex_number:
@ -635,9 +592,9 @@ lex_number:
throw comp_error(loc_, "invalid number literal"); throw comp_error(loc_, "invalid number literal");
if (state_ == state::field || dot || flt) if (state_ == state::field || dot || flt)
return s4::parser::make_FLOAT(std::string(buffer_.data, buffer_.length), loc_); return parser::make_FLOAT(std::string(buffer_.data, buffer_.length), loc_);
return s4::parser::make_INTEGER(std::string(buffer_.data, buffer_.length), loc_); return parser::make_INTEGER(std::string(buffer_.data, buffer_.length), loc_);
} }
else if (curr == 'o') else if (curr == 'o')
{ {
@ -669,7 +626,7 @@ lex_number:
if (last == '\'' || buffer_.length <= 0) if (last == '\'' || buffer_.length <= 0)
throw comp_error(loc_, "invalid octal literal"); throw comp_error(loc_, "invalid octal literal");
return s4::parser::make_INTEGER(xsk::utils::string::oct_to_dec(buffer_.data), loc_); return parser::make_INTEGER(xsk::utils::string::oct_to_dec(buffer_.data), loc_);
} }
else if (curr == 'b') else if (curr == 'b')
{ {
@ -703,7 +660,7 @@ lex_number:
if (last == '\'' || buffer_.length < 3) if (last == '\'' || buffer_.length < 3)
throw comp_error(loc_, "invalid binary literal"); throw comp_error(loc_, "invalid binary literal");
return s4::parser::make_INTEGER(xsk::utils::string::bin_to_dec(buffer_.data), loc_); return parser::make_INTEGER(xsk::utils::string::bin_to_dec(buffer_.data), loc_);
} }
else if (curr == 'x') else if (curr == 'x')
{ {
@ -737,185 +694,62 @@ lex_number:
if (last == '\'' || buffer_.length < 3) if (last == '\'' || buffer_.length < 3)
throw comp_error(loc_, "invalid hexadecimal literal"); throw comp_error(loc_, "invalid hexadecimal literal");
return s4::parser::make_INTEGER(xsk::utils::string::hex_to_dec(buffer_.data), loc_); return parser::make_INTEGER(xsk::utils::string::hex_to_dec(buffer_.data), loc_);
} }
// cant get here! // cant get here!
} }
} }
auto lexer::keyword_token(keyword k) -> xsk::gsc::s4::parser::symbol_type const std::unordered_map<std::string_view, parser::token::token_kind_type> lexer::keyword_map
{
switch (k)
{
case keyword::KW_pre_inline:
return s4::parser::make_INLINE(loc_);
case keyword::KW_pre_include:
return s4::parser::make_INCLUDE(loc_);
case keyword::KW_pre_using_animtree:
return s4::parser::make_USINGTREE(loc_);
case keyword::KW_pre_animtree:
return s4::parser::make_ANIMTREE(loc_);
case keyword::KW_endon:
return s4::parser::make_ENDON(loc_);
case keyword::KW_notify:
return s4::parser::make_NOTIFY(loc_);
case keyword::KW_wait:
return s4::parser::make_WAIT(loc_);
case keyword::KW_waittill:
return s4::parser::make_WAITTILL(loc_);
case keyword::KW_waittillmatch:
return s4::parser::make_WAITTILLMATCH(loc_);
case keyword::KW_waittillframeend:
return s4::parser::make_WAITTILLFRAMEEND(loc_);
case keyword::KW_waitframe:
return s4::parser::make_WAITFRAME(loc_);
case keyword::KW_if:
return s4::parser::make_IF(loc_);
case keyword::KW_else:
return s4::parser::make_ELSE(loc_);
case keyword::KW_do:
return s4::parser::make_DO(loc_);
case keyword::KW_while:
return s4::parser::make_WHILE(loc_);
case keyword::KW_for:
return s4::parser::make_FOR(loc_);
case keyword::KW_foreach:
return s4::parser::make_FOREACH(loc_);
case keyword::KW_in:
return s4::parser::make_IN(loc_);
case keyword::KW_switch:
return s4::parser::make_SWITCH(loc_);
case keyword::KW_case:
return s4::parser::make_CASE(loc_);
case keyword::KW_default:
return s4::parser::make_DEFAULT(loc_);
case keyword::KW_break:
return s4::parser::make_BREAK(loc_);
case keyword::KW_continue:
return s4::parser::make_CONTINUE(loc_);
case keyword::KW_return:
return s4::parser::make_RETURN(loc_);
case keyword::KW_breakpoint:
return s4::parser::make_BREAKPOINT(loc_);
case keyword::KW_prof_begin:
return s4::parser::make_PROFBEGIN(loc_);
case keyword::KW_prof_end:
return s4::parser::make_PROFEND(loc_);
case keyword::KW_thread:
return s4::parser::make_THREAD(loc_);
case keyword::KW_childthread:
return s4::parser::make_CHILDTHREAD(loc_);
case keyword::KW_thisthread:
return s4::parser::make_THISTHREAD(loc_);
case keyword::KW_call:
return s4::parser::make_CALL(loc_);
case keyword::KW_true:
return s4::parser::make_TRUE(loc_);
case keyword::KW_false:
return s4::parser::make_FALSE(loc_);
case keyword::KW_undefined:
return s4::parser::make_UNDEFINED(loc_);
case keyword::KW_dotsize:
return s4::parser::make_SIZE(loc_);
case keyword::KW_game:
return s4::parser::make_GAME(loc_);
case keyword::KW_self:
return s4::parser::make_SELF(loc_);
case keyword::KW_anim:
return s4::parser::make_ANIM(loc_);
case keyword::KW_level:
return s4::parser::make_LEVEL(loc_);
case keyword::KW_isdefined:
return s4::parser::make_ISDEFINED(loc_);
case keyword::KW_istrue:
return s4::parser::make_ISTRUE(loc_);
default:
throw error("gsc lexer: INVALID KEYWORD TOKEN!");
}
}
auto lexer::keyword_is_token(keyword k) -> bool
{
switch (k)
{
/* case keyword::KW_pre_define:
case keyword::KW_pre_undef:
case keyword::KW_pre_ifdef:
case keyword::KW_pre_ifndef:
case keyword::KW_pre_if:
case keyword::KW_pre_elif:
case keyword::KW_pre_else:
case keyword::KW_pre_endif:*/
case keyword::KW_INVALID:
return false;
default:
return true;
}
}
auto lexer::get_keyword(std::string_view str) -> keyword
{
auto itr = keywords.find(str);
if(itr != keywords.end())
{
return itr->second;
}
return keyword::KW_INVALID;
}
std::unordered_map<std::string_view, keyword> lexer::keywords
{{ {{
/* { "#define", keyword::KW_pre_define }, { "#define", parser::token::HSDEFINE },
{ "#undef", keyword::KW_pre_undef }, { "#undef", parser::token::HSUNDEF },
{ "#ifdef", keyword::KW_pre_ifdef }, { "#ifdef", parser::token::HSIFDEF },
{ "#ifndef", keyword::KW_pre_ifndef }, { "#ifndef", parser::token::HSIFNDEF },
{ "#if", keyword::KW_pre_if }, { "#if", parser::token::HSIF },
{ "#elif", keyword::KW_pre_elif }, { "#elif", parser::token::HSELIF },
{ "#else", keyword::KW_pre_else }, { "#else", parser::token::HSELSE },
{ "#endif", keyword::KW_pre_endif },*/ { "#endif", parser::token::HSENDIF },
{ "#inline", keyword::KW_pre_inline }, { "#inline", parser::token::INLINE },
{ "#include", keyword::KW_pre_include }, { "#include", parser::token::INCLUDE },
{ "#using_animtree", keyword::KW_pre_using_animtree }, { "#using_animtree", parser::token::USINGTREE },
{ "#animtree", keyword::KW_pre_animtree }, { "#animtree", parser::token::ANIMTREE },
{ "endon", keyword::KW_endon }, { "endon", parser::token::ENDON },
{ "notify", keyword::KW_notify }, { "notify", parser::token::NOTIFY },
{ "wait", keyword::KW_wait }, { "wait", parser::token::WAIT },
{ "waittill", keyword::KW_waittill }, { "waittill", parser::token::WAITTILL },
{ "waittillmatch", keyword::KW_waittillmatch }, { "waittillmatch", parser::token::WAITTILLMATCH },
{ "waittillframeend", keyword::KW_waittillframeend }, { "waittillframeend", parser::token::WAITTILLFRAMEEND },
{ "waitframe", keyword::KW_waitframe }, { "waitframe", parser::token::WAITFRAME },
{ "if", keyword::KW_if }, { "if", parser::token::IF },
{ "else", keyword::KW_else }, { "else", parser::token::ELSE },
{ "do", keyword::KW_do }, { "do", parser::token::DO },
{ "while", keyword::KW_while }, { "while", parser::token::WHILE },
{ "for", keyword::KW_for }, { "for", parser::token::FOR },
{ "foreach", keyword::KW_foreach }, { "foreach", parser::token::FOREACH },
{ "in", keyword::KW_in }, { "in", parser::token::IN },
{ "switch", keyword::KW_switch }, { "switch", parser::token::SWITCH },
{ "case", keyword::KW_case }, { "case", parser::token::CASE },
{ "default", keyword::KW_default }, { "default", parser::token::DEFAULT },
{ "break", keyword::KW_break }, { "break", parser::token::BREAK },
{ "continue", keyword::KW_continue }, { "continue", parser::token::CONTINUE },
{ "return", keyword::KW_return }, { "return", parser::token::RETURN },
{ "breakpoint", keyword::KW_breakpoint }, { "breakpoint", parser::token::BREAKPOINT },
{ "prof_begin", keyword::KW_prof_begin }, { "prof_begin", parser::token::PROFBEGIN },
{ "prof_end", keyword::KW_prof_end }, { "prof_end", parser::token::PROFEND },
{ "thread", keyword::KW_thread }, { "thread", parser::token::THREAD },
{ "childthread", keyword::KW_childthread }, { "childthread", parser::token::CHILDTHREAD },
{ "thisthread", keyword::KW_thisthread }, { "thisthread", parser::token::THISTHREAD },
{ "call", keyword::KW_call }, { "call", parser::token::CALL },
{ "true", keyword::KW_true }, { "true", parser::token::TRUE },
{ "false", keyword::KW_false }, { "false", parser::token::FALSE },
{ "undefined", keyword::KW_undefined }, { "undefined", parser::token::UNDEFINED },
{ ".size", keyword::KW_dotsize }, { "game", parser::token::GAME },
{ "game", keyword::KW_game }, { "self", parser::token::SELF },
{ "self", keyword::KW_self }, { "anim", parser::token::ANIM },
{ "anim", keyword::KW_anim }, { "level", parser::token::LEVEL },
{ "level", keyword::KW_level }, { "isdefined", parser::token::ISDEFINED },
{ "isdefined", keyword::KW_isdefined }, { "istrue", parser::token::ISTRUE },
{ "istrue", keyword::KW_istrue },
}}; }};
} // namespace xsk::gsc::s4 } // namespace xsk::gsc::s4

View File

@ -10,8 +10,6 @@
namespace xsk::gsc::s4 namespace xsk::gsc::s4
{ {
enum class keyword;
constexpr size_t max_buf_size = 0x2000; constexpr size_t max_buf_size = 0x2000;
struct buffer struct buffer
@ -53,26 +51,22 @@ class lexer
reader reader_; reader reader_;
buffer buffer_; buffer buffer_;
location loc_; location loc_;
build mode_;
std::stack<location> locs_; std::stack<location> locs_;
std::stack<reader> readers_; std::stack<reader> readers_;
std::uint32_t header_top_; std::uint32_t header_top_;
state state_; state state_;
build mode_;
bool indev_; bool indev_;
public: public:
lexer(const std::string& name, const char* data, size_t size); lexer(const std::string& name, const char* data, size_t size);
auto lex() -> xsk::gsc::s4::parser::symbol_type; auto lex() -> parser::symbol_type;
void push_header(const std::string& file); void push_header(const std::string& file);
void pop_header(); void pop_header();
void restrict_header(const xsk::gsc::location& loc); void ban_header(const location& loc);
private: private:
auto keyword_token(keyword k) -> xsk::gsc::s4::parser::symbol_type; static const std::unordered_map<std::string_view, parser::token::token_kind_type> keyword_map;
static auto keyword_is_token(keyword k) -> bool;
static auto get_keyword(std::string_view str) -> keyword;
static std::unordered_map<std::string_view, keyword> keywords;
}; };
} // namespace xsk::gsc::s4 } // namespace xsk::gsc::s4

File diff suppressed because it is too large Load Diff

View File

@ -683,111 +683,119 @@ namespace xsk { namespace gsc { namespace s4 {
S4EOF = 0, // "end of file" S4EOF = 0, // "end of file"
S4error = 1, // error S4error = 1, // error
S4UNDEF = 2, // "invalid token" S4UNDEF = 2, // "invalid token"
DEVBEGIN = 3, // "/#" HSDEFINE = 3, // "#define"
DEVEND = 4, // "#/" HSUNDEF = 4, // "#undef"
INLINE = 5, // "#inline" HSIFDEF = 5, // "#ifdef"
INCLUDE = 6, // "#include" HSIFNDEF = 6, // "#ifndef"
USINGTREE = 7, // "#using_animtree" HSIF = 7, // "#if"
ANIMTREE = 8, // "#animtree" HSELIF = 8, // "#elif"
ENDON = 9, // "endon" HSELSE = 9, // "#else"
NOTIFY = 10, // "notify" HSENDIF = 10, // "#endif"
WAIT = 11, // "wait" DEVBEGIN = 11, // "/#"
WAITTILL = 12, // "waittill" DEVEND = 12, // "#/"
WAITTILLMATCH = 13, // "waittillmatch" INLINE = 13, // "#inline"
WAITTILLFRAMEEND = 14, // "waittillframeend" INCLUDE = 14, // "#include"
WAITFRAME = 15, // "waitframe" USINGTREE = 15, // "#using_animtree"
IF = 16, // "if" ANIMTREE = 16, // "#animtree"
ELSE = 17, // "else" ENDON = 17, // "endon"
DO = 18, // "do" NOTIFY = 18, // "notify"
WHILE = 19, // "while" WAIT = 19, // "wait"
FOR = 20, // "for" WAITTILL = 20, // "waittill"
FOREACH = 21, // "foreach" WAITTILLMATCH = 21, // "waittillmatch"
IN = 22, // "in" WAITTILLFRAMEEND = 22, // "waittillframeend"
SWITCH = 23, // "switch" WAITFRAME = 23, // "waitframe"
CASE = 24, // "case" IF = 24, // "if"
DEFAULT = 25, // "default" ELSE = 25, // "else"
BREAK = 26, // "break" DO = 26, // "do"
CONTINUE = 27, // "continue" WHILE = 27, // "while"
RETURN = 28, // "return" FOR = 28, // "for"
BREAKPOINT = 29, // "breakpoint" FOREACH = 29, // "foreach"
PROFBEGIN = 30, // "prof_begin" IN = 30, // "in"
PROFEND = 31, // "prof_end" SWITCH = 31, // "switch"
THREAD = 32, // "thread" CASE = 32, // "case"
CHILDTHREAD = 33, // "childthread" DEFAULT = 33, // "default"
THISTHREAD = 34, // "thisthread" BREAK = 34, // "break"
CALL = 35, // "call" CONTINUE = 35, // "continue"
TRUE = 36, // "true" RETURN = 36, // "return"
FALSE = 37, // "false" BREAKPOINT = 37, // "breakpoint"
UNDEFINED = 38, // "undefined" PROFBEGIN = 38, // "prof_begin"
SIZE = 39, // ".size" PROFEND = 39, // "prof_end"
GAME = 40, // "game" THREAD = 40, // "thread"
SELF = 41, // "self" CHILDTHREAD = 41, // "childthread"
ANIM = 42, // "anim" THISTHREAD = 42, // "thisthread"
LEVEL = 43, // "level" CALL = 43, // "call"
ISDEFINED = 44, // "isdefined" TRUE = 44, // "true"
ISTRUE = 45, // "istrue" FALSE = 45, // "false"
LPAREN = 46, // "(" UNDEFINED = 46, // "undefined"
RPAREN = 47, // ")" SIZE = 47, // ".size"
LBRACE = 48, // "{" GAME = 48, // "game"
RBRACE = 49, // "}" SELF = 49, // "self"
LBRACKET = 50, // "[" ANIM = 50, // "anim"
RBRACKET = 51, // "]" LEVEL = 51, // "level"
COMMA = 52, // "," ISDEFINED = 52, // "isdefined"
DOT = 53, // "." ISTRUE = 53, // "istrue"
DOUBLECOLON = 54, // "::" LPAREN = 54, // "("
COLON = 55, // ":" RPAREN = 55, // ")"
SEMICOLON = 56, // ";" LBRACE = 56, // "{"
QMARK = 57, // "?" RBRACE = 57, // "}"
INCREMENT = 58, // "++" LBRACKET = 58, // "["
DECREMENT = 59, // "--" RBRACKET = 59, // "]"
LSHIFT = 60, // "<<" COMMA = 60, // ","
RSHIFT = 61, // ">>" DOT = 61, // "."
OR = 62, // "||" DOUBLECOLON = 62, // "::"
AND = 63, // "&&" COLON = 63, // ":"
EQUALITY = 64, // "==" SEMICOLON = 64, // ";"
INEQUALITY = 65, // "!=" QMARK = 65, // "?"
LESS_EQUAL = 66, // "<=" INCREMENT = 66, // "++"
GREATER_EQUAL = 67, // ">=" DECREMENT = 67, // "--"
LESS = 68, // "<" LSHIFT = 68, // "<<"
GREATER = 69, // ">" RSHIFT = 69, // ">>"
NOT = 70, // "!" OR = 70, // "||"
COMPLEMENT = 71, // "~" AND = 71, // "&&"
ASSIGN = 72, // "=" EQUALITY = 72, // "=="
ASSIGN_ADD = 73, // "+=" INEQUALITY = 73, // "!="
ASSIGN_SUB = 74, // "-=" LESS_EQUAL = 74, // "<="
ASSIGN_MUL = 75, // "*=" GREATER_EQUAL = 75, // ">="
ASSIGN_DIV = 76, // "/=" LESS = 76, // "<"
ASSIGN_MOD = 77, // "%=" GREATER = 77, // ">"
ASSIGN_BW_OR = 78, // "|=" NOT = 78, // "!"
ASSIGN_BW_AND = 79, // "&=" COMPLEMENT = 79, // "~"
ASSIGN_BW_EXOR = 80, // "^=" ASSIGN = 80, // "="
ASSIGN_RSHIFT = 81, // ">>=" ASSIGN_ADD = 81, // "+="
ASSIGN_LSHIFT = 82, // "<<=" ASSIGN_SUB = 82, // "-="
BITWISE_OR = 83, // "|" ASSIGN_MUL = 83, // "*="
BITWISE_AND = 84, // "&" ASSIGN_DIV = 84, // "/="
BITWISE_EXOR = 85, // "^" ASSIGN_MOD = 85, // "%="
ADD = 86, // "+" ASSIGN_BW_OR = 86, // "|="
SUB = 87, // "-" ASSIGN_BW_AND = 87, // "&="
MUL = 88, // "*" ASSIGN_BW_EXOR = 88, // "^="
DIV = 89, // "/" ASSIGN_RSHIFT = 89, // ">>="
MOD = 90, // "%" ASSIGN_LSHIFT = 90, // "<<="
FIELD = 91, // "field" BITWISE_OR = 91, // "|"
PATH = 92, // "path" BITWISE_AND = 92, // "&"
IDENTIFIER = 93, // "identifier" BITWISE_EXOR = 93, // "^"
STRING = 94, // "string literal" ADD = 94, // "+"
ISTRING = 95, // "localized string" SUB = 95, // "-"
COLOR = 96, // "color" MUL = 96, // "*"
FLOAT = 97, // "float" DIV = 97, // "/"
INTEGER = 98, // "integer" MOD = 98, // "%"
ADD_ARRAY = 99, // ADD_ARRAY FIELD = 99, // "field"
THEN = 100, // THEN PATH = 100, // "path"
TERN = 101, // TERN IDENTIFIER = 101, // "identifier"
NEG = 102, // NEG STRING = 102, // "string literal"
ANIMREF = 103, // ANIMREF ISTRING = 103, // "localized string"
PREINC = 104, // PREINC COLOR = 104, // "color"
PREDEC = 105, // PREDEC FLOAT = 105, // "float"
POSTINC = 106, // POSTINC INTEGER = 106, // "integer"
POSTDEC = 107 // POSTDEC ADD_ARRAY = 107, // ADD_ARRAY
THEN = 108, // THEN
TERN = 109, // TERN
NEG = 110, // NEG
ANIMREF = 111, // ANIMREF
PREINC = 112, // PREINC
PREDEC = 113, // PREDEC
POSTINC = 114, // POSTINC
POSTDEC = 115 // POSTDEC
}; };
/// Backward compatibility alias (Bison 3.6). /// Backward compatibility alias (Bison 3.6).
typedef token_kind_type yytokentype; typedef token_kind_type yytokentype;
@ -804,199 +812,207 @@ namespace xsk { namespace gsc { namespace s4 {
{ {
enum symbol_kind_type enum symbol_kind_type
{ {
YYNTOKENS = 108, ///< Number of tokens. YYNTOKENS = 116, ///< Number of tokens.
S_YYEMPTY = -2, S_YYEMPTY = -2,
S_YYEOF = 0, // "end of file" S_YYEOF = 0, // "end of file"
S_YYerror = 1, // error S_YYerror = 1, // error
S_YYUNDEF = 2, // "invalid token" S_YYUNDEF = 2, // "invalid token"
S_DEVBEGIN = 3, // "/#" S_HSDEFINE = 3, // "#define"
S_DEVEND = 4, // "#/" S_HSUNDEF = 4, // "#undef"
S_INLINE = 5, // "#inline" S_HSIFDEF = 5, // "#ifdef"
S_INCLUDE = 6, // "#include" S_HSIFNDEF = 6, // "#ifndef"
S_USINGTREE = 7, // "#using_animtree" S_HSIF = 7, // "#if"
S_ANIMTREE = 8, // "#animtree" S_HSELIF = 8, // "#elif"
S_ENDON = 9, // "endon" S_HSELSE = 9, // "#else"
S_NOTIFY = 10, // "notify" S_HSENDIF = 10, // "#endif"
S_WAIT = 11, // "wait" S_DEVBEGIN = 11, // "/#"
S_WAITTILL = 12, // "waittill" S_DEVEND = 12, // "#/"
S_WAITTILLMATCH = 13, // "waittillmatch" S_INLINE = 13, // "#inline"
S_WAITTILLFRAMEEND = 14, // "waittillframeend" S_INCLUDE = 14, // "#include"
S_WAITFRAME = 15, // "waitframe" S_USINGTREE = 15, // "#using_animtree"
S_IF = 16, // "if" S_ANIMTREE = 16, // "#animtree"
S_ELSE = 17, // "else" S_ENDON = 17, // "endon"
S_DO = 18, // "do" S_NOTIFY = 18, // "notify"
S_WHILE = 19, // "while" S_WAIT = 19, // "wait"
S_FOR = 20, // "for" S_WAITTILL = 20, // "waittill"
S_FOREACH = 21, // "foreach" S_WAITTILLMATCH = 21, // "waittillmatch"
S_IN = 22, // "in" S_WAITTILLFRAMEEND = 22, // "waittillframeend"
S_SWITCH = 23, // "switch" S_WAITFRAME = 23, // "waitframe"
S_CASE = 24, // "case" S_IF = 24, // "if"
S_DEFAULT = 25, // "default" S_ELSE = 25, // "else"
S_BREAK = 26, // "break" S_DO = 26, // "do"
S_CONTINUE = 27, // "continue" S_WHILE = 27, // "while"
S_RETURN = 28, // "return" S_FOR = 28, // "for"
S_BREAKPOINT = 29, // "breakpoint" S_FOREACH = 29, // "foreach"
S_PROFBEGIN = 30, // "prof_begin" S_IN = 30, // "in"
S_PROFEND = 31, // "prof_end" S_SWITCH = 31, // "switch"
S_THREAD = 32, // "thread" S_CASE = 32, // "case"
S_CHILDTHREAD = 33, // "childthread" S_DEFAULT = 33, // "default"
S_THISTHREAD = 34, // "thisthread" S_BREAK = 34, // "break"
S_CALL = 35, // "call" S_CONTINUE = 35, // "continue"
S_TRUE = 36, // "true" S_RETURN = 36, // "return"
S_FALSE = 37, // "false" S_BREAKPOINT = 37, // "breakpoint"
S_UNDEFINED = 38, // "undefined" S_PROFBEGIN = 38, // "prof_begin"
S_SIZE = 39, // ".size" S_PROFEND = 39, // "prof_end"
S_GAME = 40, // "game" S_THREAD = 40, // "thread"
S_SELF = 41, // "self" S_CHILDTHREAD = 41, // "childthread"
S_ANIM = 42, // "anim" S_THISTHREAD = 42, // "thisthread"
S_LEVEL = 43, // "level" S_CALL = 43, // "call"
S_ISDEFINED = 44, // "isdefined" S_TRUE = 44, // "true"
S_ISTRUE = 45, // "istrue" S_FALSE = 45, // "false"
S_LPAREN = 46, // "(" S_UNDEFINED = 46, // "undefined"
S_RPAREN = 47, // ")" S_SIZE = 47, // ".size"
S_LBRACE = 48, // "{" S_GAME = 48, // "game"
S_RBRACE = 49, // "}" S_SELF = 49, // "self"
S_LBRACKET = 50, // "[" S_ANIM = 50, // "anim"
S_RBRACKET = 51, // "]" S_LEVEL = 51, // "level"
S_COMMA = 52, // "," S_ISDEFINED = 52, // "isdefined"
S_DOT = 53, // "." S_ISTRUE = 53, // "istrue"
S_DOUBLECOLON = 54, // "::" S_LPAREN = 54, // "("
S_COLON = 55, // ":" S_RPAREN = 55, // ")"
S_SEMICOLON = 56, // ";" S_LBRACE = 56, // "{"
S_QMARK = 57, // "?" S_RBRACE = 57, // "}"
S_INCREMENT = 58, // "++" S_LBRACKET = 58, // "["
S_DECREMENT = 59, // "--" S_RBRACKET = 59, // "]"
S_LSHIFT = 60, // "<<" S_COMMA = 60, // ","
S_RSHIFT = 61, // ">>" S_DOT = 61, // "."
S_OR = 62, // "||" S_DOUBLECOLON = 62, // "::"
S_AND = 63, // "&&" S_COLON = 63, // ":"
S_EQUALITY = 64, // "==" S_SEMICOLON = 64, // ";"
S_INEQUALITY = 65, // "!=" S_QMARK = 65, // "?"
S_LESS_EQUAL = 66, // "<=" S_INCREMENT = 66, // "++"
S_GREATER_EQUAL = 67, // ">=" S_DECREMENT = 67, // "--"
S_LESS = 68, // "<" S_LSHIFT = 68, // "<<"
S_GREATER = 69, // ">" S_RSHIFT = 69, // ">>"
S_NOT = 70, // "!" S_OR = 70, // "||"
S_COMPLEMENT = 71, // "~" S_AND = 71, // "&&"
S_ASSIGN = 72, // "=" S_EQUALITY = 72, // "=="
S_ASSIGN_ADD = 73, // "+=" S_INEQUALITY = 73, // "!="
S_ASSIGN_SUB = 74, // "-=" S_LESS_EQUAL = 74, // "<="
S_ASSIGN_MUL = 75, // "*=" S_GREATER_EQUAL = 75, // ">="
S_ASSIGN_DIV = 76, // "/=" S_LESS = 76, // "<"
S_ASSIGN_MOD = 77, // "%=" S_GREATER = 77, // ">"
S_ASSIGN_BW_OR = 78, // "|=" S_NOT = 78, // "!"
S_ASSIGN_BW_AND = 79, // "&=" S_COMPLEMENT = 79, // "~"
S_ASSIGN_BW_EXOR = 80, // "^=" S_ASSIGN = 80, // "="
S_ASSIGN_RSHIFT = 81, // ">>=" S_ASSIGN_ADD = 81, // "+="
S_ASSIGN_LSHIFT = 82, // "<<=" S_ASSIGN_SUB = 82, // "-="
S_BITWISE_OR = 83, // "|" S_ASSIGN_MUL = 83, // "*="
S_BITWISE_AND = 84, // "&" S_ASSIGN_DIV = 84, // "/="
S_BITWISE_EXOR = 85, // "^" S_ASSIGN_MOD = 85, // "%="
S_ADD = 86, // "+" S_ASSIGN_BW_OR = 86, // "|="
S_SUB = 87, // "-" S_ASSIGN_BW_AND = 87, // "&="
S_MUL = 88, // "*" S_ASSIGN_BW_EXOR = 88, // "^="
S_DIV = 89, // "/" S_ASSIGN_RSHIFT = 89, // ">>="
S_MOD = 90, // "%" S_ASSIGN_LSHIFT = 90, // "<<="
S_FIELD = 91, // "field" S_BITWISE_OR = 91, // "|"
S_PATH = 92, // "path" S_BITWISE_AND = 92, // "&"
S_IDENTIFIER = 93, // "identifier" S_BITWISE_EXOR = 93, // "^"
S_STRING = 94, // "string literal" S_ADD = 94, // "+"
S_ISTRING = 95, // "localized string" S_SUB = 95, // "-"
S_COLOR = 96, // "color" S_MUL = 96, // "*"
S_FLOAT = 97, // "float" S_DIV = 97, // "/"
S_INTEGER = 98, // "integer" S_MOD = 98, // "%"
S_ADD_ARRAY = 99, // ADD_ARRAY S_FIELD = 99, // "field"
S_THEN = 100, // THEN S_PATH = 100, // "path"
S_TERN = 101, // TERN S_IDENTIFIER = 101, // "identifier"
S_NEG = 102, // NEG S_STRING = 102, // "string literal"
S_ANIMREF = 103, // ANIMREF S_ISTRING = 103, // "localized string"
S_PREINC = 104, // PREINC S_COLOR = 104, // "color"
S_PREDEC = 105, // PREDEC S_FLOAT = 105, // "float"
S_POSTINC = 106, // POSTINC S_INTEGER = 106, // "integer"
S_POSTDEC = 107, // POSTDEC S_ADD_ARRAY = 107, // ADD_ARRAY
S_YYACCEPT = 108, // $accept S_THEN = 108, // THEN
S_root = 109, // root S_TERN = 109, // TERN
S_program = 110, // program S_NEG = 110, // NEG
S_inline = 111, // inline S_ANIMREF = 111, // ANIMREF
S_include = 112, // include S_PREINC = 112, // PREINC
S_declaration = 113, // declaration S_PREDEC = 113, // PREDEC
S_decl_usingtree = 114, // decl_usingtree S_POSTINC = 114, // POSTINC
S_decl_constant = 115, // decl_constant S_POSTDEC = 115, // POSTDEC
S_decl_thread = 116, // decl_thread S_YYACCEPT = 116, // $accept
S_stmt = 117, // stmt S_root = 117, // root
S_stmt_dev = 118, // stmt_dev S_program = 118, // program
S_stmt_block = 119, // stmt_block S_inline = 119, // inline
S_stmt_list = 120, // stmt_list S_include = 120, // include
S_stmt_expr = 121, // stmt_expr S_declaration = 121, // declaration
S_stmt_call = 122, // stmt_call S_decl_usingtree = 122, // decl_usingtree
S_stmt_assign = 123, // stmt_assign S_decl_constant = 123, // decl_constant
S_stmt_endon = 124, // stmt_endon S_decl_thread = 124, // decl_thread
S_stmt_notify = 125, // stmt_notify S_stmt = 125, // stmt
S_stmt_wait = 126, // stmt_wait S_stmt_dev = 126, // stmt_dev
S_stmt_waittill = 127, // stmt_waittill S_stmt_block = 127, // stmt_block
S_stmt_waittillmatch = 128, // stmt_waittillmatch S_stmt_list = 128, // stmt_list
S_stmt_waittillframeend = 129, // stmt_waittillframeend S_stmt_expr = 129, // stmt_expr
S_stmt_waitframe = 130, // stmt_waitframe S_stmt_call = 130, // stmt_call
S_stmt_if = 131, // stmt_if S_stmt_assign = 131, // stmt_assign
S_stmt_ifelse = 132, // stmt_ifelse S_stmt_endon = 132, // stmt_endon
S_stmt_while = 133, // stmt_while S_stmt_notify = 133, // stmt_notify
S_stmt_dowhile = 134, // stmt_dowhile S_stmt_wait = 134, // stmt_wait
S_stmt_for = 135, // stmt_for S_stmt_waittill = 135, // stmt_waittill
S_stmt_foreach = 136, // stmt_foreach S_stmt_waittillmatch = 136, // stmt_waittillmatch
S_stmt_switch = 137, // stmt_switch S_stmt_waittillframeend = 137, // stmt_waittillframeend
S_stmt_case = 138, // stmt_case S_stmt_waitframe = 138, // stmt_waitframe
S_stmt_default = 139, // stmt_default S_stmt_if = 139, // stmt_if
S_stmt_break = 140, // stmt_break S_stmt_ifelse = 140, // stmt_ifelse
S_stmt_continue = 141, // stmt_continue S_stmt_while = 141, // stmt_while
S_stmt_return = 142, // stmt_return S_stmt_dowhile = 142, // stmt_dowhile
S_stmt_breakpoint = 143, // stmt_breakpoint S_stmt_for = 143, // stmt_for
S_stmt_prof_begin = 144, // stmt_prof_begin S_stmt_foreach = 144, // stmt_foreach
S_stmt_prof_end = 145, // stmt_prof_end S_stmt_switch = 145, // stmt_switch
S_expr = 146, // expr S_stmt_case = 146, // stmt_case
S_expr_or_empty = 147, // expr_or_empty S_stmt_default = 147, // stmt_default
S_expr_assign = 148, // expr_assign S_stmt_break = 148, // stmt_break
S_expr_increment = 149, // expr_increment S_stmt_continue = 149, // stmt_continue
S_expr_decrement = 150, // expr_decrement S_stmt_return = 150, // stmt_return
S_expr_ternary = 151, // expr_ternary S_stmt_breakpoint = 151, // stmt_breakpoint
S_expr_binary = 152, // expr_binary S_stmt_prof_begin = 152, // stmt_prof_begin
S_expr_primitive = 153, // expr_primitive S_stmt_prof_end = 153, // stmt_prof_end
S_expr_complement = 154, // expr_complement S_expr = 154, // expr
S_expr_not = 155, // expr_not S_expr_or_empty = 155, // expr_or_empty
S_expr_call = 156, // expr_call S_expr_assign = 156, // expr_assign
S_expr_method = 157, // expr_method S_expr_increment = 157, // expr_increment
S_expr_function = 158, // expr_function S_expr_decrement = 158, // expr_decrement
S_expr_pointer = 159, // expr_pointer S_expr_ternary = 159, // expr_ternary
S_expr_add_array = 160, // expr_add_array S_expr_binary = 160, // expr_binary
S_expr_parameters = 161, // expr_parameters S_expr_primitive = 161, // expr_primitive
S_expr_arguments = 162, // expr_arguments S_expr_complement = 162, // expr_complement
S_expr_arguments_no_empty = 163, // expr_arguments_no_empty S_expr_not = 163, // expr_not
S_expr_isdefined = 164, // expr_isdefined S_expr_call = 164, // expr_call
S_expr_istrue = 165, // expr_istrue S_expr_method = 165, // expr_method
S_expr_reference = 166, // expr_reference S_expr_function = 166, // expr_function
S_expr_array = 167, // expr_array S_expr_pointer = 167, // expr_pointer
S_expr_field = 168, // expr_field S_expr_add_array = 168, // expr_add_array
S_expr_size = 169, // expr_size S_expr_parameters = 169, // expr_parameters
S_expr_paren = 170, // expr_paren S_expr_arguments = 170, // expr_arguments
S_expr_object = 171, // expr_object S_expr_arguments_no_empty = 171, // expr_arguments_no_empty
S_expr_thisthread = 172, // expr_thisthread S_expr_isdefined = 172, // expr_isdefined
S_expr_empty_array = 173, // expr_empty_array S_expr_istrue = 173, // expr_istrue
S_expr_undefined = 174, // expr_undefined S_expr_reference = 174, // expr_reference
S_expr_game = 175, // expr_game S_expr_array = 175, // expr_array
S_expr_self = 176, // expr_self S_expr_field = 176, // expr_field
S_expr_anim = 177, // expr_anim S_expr_size = 177, // expr_size
S_expr_level = 178, // expr_level S_expr_paren = 178, // expr_paren
S_expr_animation = 179, // expr_animation S_expr_object = 179, // expr_object
S_expr_animtree = 180, // expr_animtree S_expr_thisthread = 180, // expr_thisthread
S_expr_identifier = 181, // expr_identifier S_expr_empty_array = 181, // expr_empty_array
S_expr_path = 182, // expr_path S_expr_undefined = 182, // expr_undefined
S_expr_istring = 183, // expr_istring S_expr_game = 183, // expr_game
S_expr_string = 184, // expr_string S_expr_self = 184, // expr_self
S_expr_color = 185, // expr_color S_expr_anim = 185, // expr_anim
S_expr_vector = 186, // expr_vector S_expr_level = 186, // expr_level
S_expr_float = 187, // expr_float S_expr_animation = 187, // expr_animation
S_expr_integer = 188, // expr_integer S_expr_animtree = 188, // expr_animtree
S_expr_false = 189, // expr_false S_expr_identifier = 189, // expr_identifier
S_expr_true = 190 // expr_true S_expr_path = 190, // expr_path
S_expr_istring = 191, // expr_istring
S_expr_string = 192, // expr_string
S_expr_color = 193, // expr_color
S_expr_vector = 194, // expr_vector
S_expr_float = 195, // expr_float
S_expr_integer = 196, // expr_integer
S_expr_false = 197, // expr_false
S_expr_true = 198 // expr_true
}; };
}; };
@ -2835,6 +2851,126 @@ switch (yykind)
return symbol_type (token::S4UNDEF, l); return symbol_type (token::S4UNDEF, l);
} }
#endif #endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_HSDEFINE (location_type l)
{
return symbol_type (token::HSDEFINE, std::move (l));
}
#else
static
symbol_type
make_HSDEFINE (const location_type& l)
{
return symbol_type (token::HSDEFINE, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_HSUNDEF (location_type l)
{
return symbol_type (token::HSUNDEF, std::move (l));
}
#else
static
symbol_type
make_HSUNDEF (const location_type& l)
{
return symbol_type (token::HSUNDEF, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_HSIFDEF (location_type l)
{
return symbol_type (token::HSIFDEF, std::move (l));
}
#else
static
symbol_type
make_HSIFDEF (const location_type& l)
{
return symbol_type (token::HSIFDEF, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_HSIFNDEF (location_type l)
{
return symbol_type (token::HSIFNDEF, std::move (l));
}
#else
static
symbol_type
make_HSIFNDEF (const location_type& l)
{
return symbol_type (token::HSIFNDEF, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_HSIF (location_type l)
{
return symbol_type (token::HSIF, std::move (l));
}
#else
static
symbol_type
make_HSIF (const location_type& l)
{
return symbol_type (token::HSIF, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_HSELIF (location_type l)
{
return symbol_type (token::HSELIF, std::move (l));
}
#else
static
symbol_type
make_HSELIF (const location_type& l)
{
return symbol_type (token::HSELIF, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_HSELSE (location_type l)
{
return symbol_type (token::HSELSE, std::move (l));
}
#else
static
symbol_type
make_HSELSE (const location_type& l)
{
return symbol_type (token::HSELSE, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS
static
symbol_type
make_HSENDIF (location_type l)
{
return symbol_type (token::HSENDIF, std::move (l));
}
#else
static
symbol_type
make_HSENDIF (const location_type& l)
{
return symbol_type (token::HSENDIF, l);
}
#endif
#if 201103L <= YY_CPLUSPLUS #if 201103L <= YY_CPLUSPLUS
static static
symbol_type symbol_type
@ -5464,7 +5600,7 @@ switch (yykind)
#line 13 "parser.ypp" #line 13 "parser.ypp"
} } } // xsk::gsc::s4 } } } // xsk::gsc::s4
#line 5468 "parser.hpp" #line 5604 "parser.hpp"