2023-01-23 17:31:08 -05:00
|
|
|
/* Copyright 2023 xensik. All rights reserved.
|
|
|
|
//
|
|
|
|
// Use of this source code is governed by a GNU GPLv3 license
|
|
|
|
// that can be found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
%require "3.7"
|
|
|
|
%skeleton "lalr1.cc"
|
|
|
|
%language "c++"
|
|
|
|
%output "parser.cpp"
|
|
|
|
%defines "parser.hpp"
|
|
|
|
%define api.prefix {GSC}
|
|
|
|
%define api.namespace {xsk::gsc}
|
|
|
|
%define api.location.type {xsk::gsc::location}
|
|
|
|
%define api.value.type variant
|
|
|
|
%define api.token.constructor
|
|
|
|
%define api.token.raw
|
|
|
|
%define parse.assert
|
|
|
|
%define parse.trace
|
|
|
|
%define parse.error detailed
|
|
|
|
%define parse.lac full
|
|
|
|
%locations
|
2023-01-30 07:48:27 -05:00
|
|
|
%lex-param { xsk::gsc::context const* ctx_ }
|
|
|
|
%lex-param { xsk::gsc::preprocessor& ppr }
|
2023-01-23 17:31:08 -05:00
|
|
|
%parse-param { xsk::gsc::context const* ctx_ }
|
2023-01-30 07:48:27 -05:00
|
|
|
%parse-param { xsk::gsc::preprocessor& ppr }
|
2023-01-23 17:31:08 -05:00
|
|
|
%parse-param { xsk::gsc::program::ptr& ast }
|
|
|
|
%parse-param { std::uint32_t index }
|
|
|
|
|
|
|
|
%code requires
|
|
|
|
{
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
#pragma warning(disable:4065)
|
|
|
|
#pragma warning(disable:4127)
|
|
|
|
#endif
|
|
|
|
#include "context.hpp"
|
2023-01-30 07:48:27 -05:00
|
|
|
namespace xsk::gsc { class preprocessor; }
|
2023-01-23 17:31:08 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
%code top
|
|
|
|
{
|
2023-03-02 10:41:32 -05:00
|
|
|
#include "xsk/stdinc.hpp"
|
|
|
|
#include "xsk/gsc/parser.hpp"
|
|
|
|
#include "xsk/gsc/preprocessor.hpp"
|
2023-01-23 17:31:08 -05:00
|
|
|
using namespace xsk::gsc;
|
|
|
|
namespace xsk::gsc
|
|
|
|
{
|
2023-01-30 07:48:27 -05:00
|
|
|
auto GSClex(context const* ctx_, preprocessor& ppr) -> parser::symbol_type;
|
2023-01-23 17:31:08 -05:00
|
|
|
auto parse_switch(stmt_switch& stm) -> void;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-30 07:48:27 -05:00
|
|
|
%token HASH "#"
|
2023-01-23 17:31:08 -05:00
|
|
|
%token DEVBEGIN "/#"
|
|
|
|
%token DEVEND "#/"
|
|
|
|
%token INLINE "#inline"
|
|
|
|
%token INCLUDE "#include"
|
|
|
|
%token USINGTREE "#using_animtree"
|
|
|
|
%token ANIMTREE "#animtree"
|
|
|
|
%token ENDON "endon"
|
|
|
|
%token NOTIFY "notify"
|
|
|
|
%token WAIT "wait"
|
|
|
|
%token WAITTILL "waittill"
|
|
|
|
%token WAITTILLMATCH "waittillmatch"
|
|
|
|
%token WAITTILLFRAMEEND "waittillframeend"
|
|
|
|
%token WAITFRAME "waitframe"
|
|
|
|
%token IF "if"
|
|
|
|
%token ELSE "else"
|
|
|
|
%token DO "do"
|
|
|
|
%token WHILE "while"
|
|
|
|
%token FOR "for"
|
|
|
|
%token FOREACH "foreach"
|
|
|
|
%token IN "in"
|
|
|
|
%token SWITCH "switch"
|
|
|
|
%token CASE "case"
|
|
|
|
%token DEFAULT "default"
|
|
|
|
%token BREAK "break"
|
|
|
|
%token CONTINUE "continue"
|
|
|
|
%token RETURN "return"
|
|
|
|
%token BREAKPOINT "breakpoint"
|
|
|
|
%token PROFBEGIN "prof_begin"
|
|
|
|
%token PROFEND "prof_end"
|
2023-02-01 10:39:46 -05:00
|
|
|
%token ASSERT "assert"
|
|
|
|
%token ASSERTEX "assertex"
|
|
|
|
%token ASSERTMSG "assertmsg"
|
2023-01-23 17:31:08 -05:00
|
|
|
%token THREAD "thread"
|
|
|
|
%token CHILDTHREAD "childthread"
|
|
|
|
%token THISTHREAD "thisthread"
|
|
|
|
%token CALL "call"
|
|
|
|
%token TRUE "true"
|
|
|
|
%token FALSE "false"
|
|
|
|
%token UNDEFINED "undefined"
|
|
|
|
%token SIZE "size"
|
|
|
|
%token GAME "game"
|
|
|
|
%token SELF "self"
|
|
|
|
%token ANIM "anim"
|
|
|
|
%token LEVEL "level"
|
|
|
|
%token ISDEFINED "isdefined"
|
|
|
|
%token ISTRUE "istrue"
|
|
|
|
%token LPAREN "("
|
|
|
|
%token RPAREN ")"
|
|
|
|
%token LBRACE "{"
|
|
|
|
%token RBRACE "}"
|
|
|
|
%token LBRACKET "["
|
|
|
|
%token RBRACKET "]"
|
|
|
|
%token COMMA ","
|
|
|
|
%token DOT "."
|
2023-02-17 10:44:38 -05:00
|
|
|
%token DOUBLEDOT ".."
|
2023-01-30 07:48:27 -05:00
|
|
|
%token ELLIPSIS "..."
|
2023-01-23 17:31:08 -05:00
|
|
|
%token DOUBLECOLON "::"
|
|
|
|
%token COLON ":"
|
|
|
|
%token SEMICOLON ";"
|
|
|
|
%token QMARK "?"
|
|
|
|
%token INCREMENT "++"
|
|
|
|
%token DECREMENT "--"
|
|
|
|
%token LSHIFT "<<"
|
|
|
|
%token RSHIFT ">>"
|
|
|
|
%token OR "||"
|
|
|
|
%token AND "&&"
|
|
|
|
%token EQUALITY "=="
|
|
|
|
%token INEQUALITY "!="
|
|
|
|
%token LESS_EQUAL "<="
|
|
|
|
%token GREATER_EQUAL ">="
|
|
|
|
%token LESS "<"
|
|
|
|
%token GREATER ">"
|
|
|
|
%token NOT "!"
|
|
|
|
%token COMPLEMENT "~"
|
|
|
|
%token ASSIGN "="
|
|
|
|
%token ASSIGN_ADD "+="
|
|
|
|
%token ASSIGN_SUB "-="
|
|
|
|
%token ASSIGN_MUL "*="
|
|
|
|
%token ASSIGN_DIV "/="
|
|
|
|
%token ASSIGN_MOD "%="
|
|
|
|
%token ASSIGN_BW_OR "|="
|
|
|
|
%token ASSIGN_BW_AND "&="
|
|
|
|
%token ASSIGN_BW_EXOR "^="
|
|
|
|
%token ASSIGN_RSHIFT ">>="
|
|
|
|
%token ASSIGN_LSHIFT "<<="
|
|
|
|
%token BITWISE_OR "|"
|
|
|
|
%token BITWISE_AND "&"
|
|
|
|
%token BITWISE_EXOR "^"
|
|
|
|
%token ADD "+"
|
|
|
|
%token SUB "-"
|
|
|
|
%token MUL "*"
|
|
|
|
%token DIV "/"
|
|
|
|
%token MOD "%"
|
|
|
|
%token <std::string> PATH "path"
|
|
|
|
%token <std::string> IDENTIFIER "identifier"
|
|
|
|
%token <std::string> STRING "string literal"
|
|
|
|
%token <std::string> ISTRING "localized string"
|
|
|
|
%token <std::string> FLOAT "float"
|
|
|
|
%token <std::string> INTEGER "integer"
|
|
|
|
|
|
|
|
%type <program::ptr> program
|
|
|
|
%type <include::ptr> include
|
2023-04-05 11:09:21 -04:00
|
|
|
%type <decl::ptr> declaration
|
2023-01-23 17:31:08 -05:00
|
|
|
%type <decl_usingtree::ptr> decl_usingtree
|
2023-02-01 10:39:46 -05:00
|
|
|
%type <decl_constant::ptr> decl_constant
|
2023-01-23 17:31:08 -05:00
|
|
|
%type <decl_function::ptr> decl_function
|
2023-04-05 11:09:21 -04:00
|
|
|
%type <stmt::ptr> stmt
|
|
|
|
%type <stmt::ptr> stmt_or_dev
|
2023-01-23 17:31:08 -05:00
|
|
|
%type <stmt_list::ptr> stmt_list
|
|
|
|
%type <stmt_list::ptr> stmt_or_dev_list
|
|
|
|
%type <stmt_dev::ptr> stmt_dev
|
2023-01-24 06:53:39 -05:00
|
|
|
%type <stmt_comp::ptr> stmt_comp
|
2023-01-23 17:31:08 -05:00
|
|
|
%type <stmt_expr::ptr> stmt_expr
|
2023-04-05 11:09:21 -04:00
|
|
|
%type <stmt_expr::ptr> stmt_call
|
|
|
|
%type <stmt_expr::ptr> stmt_assign
|
2023-01-23 17:31:08 -05:00
|
|
|
%type <stmt_endon::ptr> stmt_endon
|
|
|
|
%type <stmt_notify::ptr> stmt_notify
|
|
|
|
%type <stmt_wait::ptr> stmt_wait
|
|
|
|
%type <stmt_waittill::ptr> stmt_waittill
|
|
|
|
%type <stmt_waittillmatch::ptr> stmt_waittillmatch
|
|
|
|
%type <stmt_waittillframeend::ptr> stmt_waittillframeend
|
|
|
|
%type <stmt_waitframe::ptr> stmt_waitframe
|
|
|
|
%type <stmt_if::ptr> stmt_if
|
|
|
|
%type <stmt_ifelse::ptr> stmt_ifelse
|
|
|
|
%type <stmt_while::ptr> stmt_while
|
|
|
|
%type <stmt_dowhile::ptr> stmt_dowhile
|
|
|
|
%type <stmt_for::ptr> stmt_for
|
|
|
|
%type <stmt_foreach::ptr> stmt_foreach
|
|
|
|
%type <stmt_switch::ptr> stmt_switch
|
|
|
|
%type <stmt_case::ptr> stmt_case
|
|
|
|
%type <stmt_default::ptr> stmt_default
|
|
|
|
%type <stmt_break::ptr> stmt_break
|
|
|
|
%type <stmt_continue::ptr> stmt_continue
|
|
|
|
%type <stmt_return::ptr> stmt_return
|
|
|
|
%type <stmt_breakpoint::ptr> stmt_breakpoint
|
|
|
|
%type <stmt_prof_begin::ptr> stmt_prof_begin
|
|
|
|
%type <stmt_prof_end::ptr> stmt_prof_end
|
2023-02-01 10:39:46 -05:00
|
|
|
%type <stmt_assert::ptr> stmt_assert
|
|
|
|
%type <stmt_assertex::ptr> stmt_assertex
|
|
|
|
%type <stmt_assertmsg::ptr> stmt_assertmsg
|
2023-04-05 11:09:21 -04:00
|
|
|
%type <expr::ptr> expr
|
|
|
|
%type <expr::ptr> expr_or_empty
|
|
|
|
%type <expr::ptr> expr_increment
|
|
|
|
%type <expr::ptr> expr_decrement
|
|
|
|
%type <expr::ptr> expr_assign
|
|
|
|
%type <expr::ptr> expr_ternary
|
|
|
|
%type <expr::ptr> expr_binary
|
|
|
|
%type <expr::ptr> expr_primitive
|
2023-01-23 17:31:08 -05:00
|
|
|
%type <expr_complement::ptr> expr_complement
|
|
|
|
%type <expr_negate::ptr> expr_negate
|
|
|
|
%type <expr_not::ptr> expr_not
|
|
|
|
%type <expr_call::ptr> expr_call
|
|
|
|
%type <expr_method::ptr> expr_method
|
2023-04-05 11:09:21 -04:00
|
|
|
%type <call::ptr> expr_function
|
|
|
|
%type <call::ptr> expr_pointer
|
2023-01-23 17:31:08 -05:00
|
|
|
%type <expr_add_array::ptr> expr_add_array
|
|
|
|
%type <expr_parameters::ptr> expr_parameters
|
|
|
|
%type <expr_arguments::ptr> expr_arguments
|
|
|
|
%type <expr_arguments::ptr> expr_arguments_no_empty
|
|
|
|
%type <expr_isdefined::ptr> expr_isdefined
|
|
|
|
%type <expr_istrue::ptr> expr_istrue
|
|
|
|
%type <expr_reference::ptr> expr_reference
|
2023-04-05 11:09:21 -04:00
|
|
|
%type <expr::ptr> expr_tuple
|
2023-01-23 17:31:08 -05:00
|
|
|
%type <expr_tuple::ptr> expr_tuple_arguments
|
2023-04-05 11:09:21 -04:00
|
|
|
%type <expr::ptr> expr_tuple_types
|
2023-01-23 17:31:08 -05:00
|
|
|
%type <expr_array::ptr> expr_array
|
|
|
|
%type <expr_field::ptr> expr_field
|
|
|
|
%type <expr_size::ptr> expr_size
|
|
|
|
%type <expr_paren::ptr> expr_paren
|
2023-04-05 11:09:21 -04:00
|
|
|
%type <expr::ptr> expr_object
|
2023-01-23 17:31:08 -05:00
|
|
|
%type <expr_thisthread::ptr> expr_thisthread
|
|
|
|
%type <expr_empty_array::ptr> expr_empty_array
|
|
|
|
%type <expr_undefined::ptr> expr_undefined
|
|
|
|
%type <expr_game::ptr> expr_game
|
|
|
|
%type <expr_self::ptr> expr_self
|
|
|
|
%type <expr_anim::ptr> expr_anim
|
|
|
|
%type <expr_level::ptr> expr_level
|
|
|
|
%type <expr_animation::ptr> expr_animation
|
|
|
|
%type <expr_animtree::ptr> expr_animtree
|
|
|
|
%type <expr_identifier::ptr> expr_identifier_nosize
|
|
|
|
%type <expr_identifier::ptr> expr_identifier
|
|
|
|
%type <expr_path::ptr> expr_path
|
|
|
|
%type <expr_istring::ptr> expr_istring
|
|
|
|
%type <expr_string::ptr> expr_string
|
|
|
|
%type <expr_vector::ptr> expr_vector
|
|
|
|
%type <expr_float::ptr> expr_float
|
|
|
|
%type <expr_integer::ptr> expr_integer
|
|
|
|
%type <expr_false::ptr> expr_false
|
|
|
|
%type <expr_true::ptr> expr_true
|
|
|
|
|
|
|
|
%nonassoc SIZEOF
|
|
|
|
%nonassoc ADD_ARRAY
|
|
|
|
%nonassoc RBRACKET
|
|
|
|
%nonassoc THEN
|
|
|
|
%nonassoc ELSE
|
|
|
|
%nonassoc INCREMENT DECREMENT
|
|
|
|
|
|
|
|
%precedence TERN
|
|
|
|
%right QMARK
|
|
|
|
%left OR
|
|
|
|
%left AND
|
|
|
|
%left BITWISE_OR
|
|
|
|
%left BITWISE_EXOR
|
|
|
|
%left BITWISE_AND
|
|
|
|
%left EQUALITY INEQUALITY
|
|
|
|
%left LESS GREATER LESS_EQUAL GREATER_EQUAL
|
|
|
|
%left LSHIFT RSHIFT
|
|
|
|
%left ADD SUB
|
|
|
|
%left MUL DIV MOD
|
|
|
|
%right NOT COMPLEMENT
|
|
|
|
|
|
|
|
%precedence NEG
|
|
|
|
%precedence ANIMREF
|
|
|
|
%precedence PREINC PREDEC
|
|
|
|
%precedence POSTINC POSTDEC
|
|
|
|
|
|
|
|
%start root
|
|
|
|
|
|
|
|
%%
|
|
|
|
|
|
|
|
root
|
|
|
|
: program { ast = std::move($1); }
|
2023-04-05 11:09:21 -04:00
|
|
|
| { ast = program::make(@$); }
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
program
|
2023-02-14 14:53:53 -05:00
|
|
|
: program SEMICOLON
|
|
|
|
{ $$ = std::move($1); }
|
|
|
|
| program inline
|
2023-01-23 17:31:08 -05:00
|
|
|
{ $$ = std::move($1); }
|
|
|
|
| program include
|
|
|
|
{ $$ = std::move($1); $$->includes.push_back(std::move($2)); }
|
|
|
|
| program declaration
|
|
|
|
{ $$ = std::move($1); $$->declarations.push_back(std::move($2)); }
|
2023-02-14 14:53:53 -05:00
|
|
|
| SEMICOLON
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = program::make(@$); }
|
2023-01-23 17:31:08 -05:00
|
|
|
| inline
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = program::make(@$); }
|
2023-01-23 17:31:08 -05:00
|
|
|
| include
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = program::make(@$); $$->includes.push_back(std::move($1)); }
|
2023-01-23 17:31:08 -05:00
|
|
|
| declaration
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = program::make(@$); $$->declarations.push_back(std::move($1)); }
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
inline
|
2023-01-30 07:48:27 -05:00
|
|
|
: INLINE expr_path SEMICOLON { ppr.push_header($2->value); }
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
include
|
|
|
|
: INCLUDE expr_path SEMICOLON
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = include::make(@$, std::move($2)); }
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
declaration
|
2023-04-05 11:09:21 -04:00
|
|
|
: DEVBEGIN { $$ = decl_dev_begin::make(@$); }
|
|
|
|
| DEVEND { $$ = decl_dev_end::make(@$); }
|
|
|
|
| decl_usingtree { $$ = std::move($1); }
|
|
|
|
| decl_constant { $$ = std::move($1); }
|
|
|
|
| decl_function { $$ = std::move($1); }
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
decl_usingtree
|
|
|
|
: USINGTREE LPAREN expr_string RPAREN SEMICOLON
|
2023-04-05 11:09:21 -04:00
|
|
|
{ ppr.ban_header(@$); $$ = decl_usingtree::make(@$, std::move($3)); }
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
2023-02-01 10:39:46 -05:00
|
|
|
decl_constant
|
|
|
|
: expr_identifier ASSIGN expr SEMICOLON
|
|
|
|
{
|
2023-04-05 11:09:21 -04:00
|
|
|
ppr.ban_header(@$); $$ = decl_constant::make(@$, std::move($1), std::move($3));
|
2023-02-01 10:39:46 -05:00
|
|
|
printf("%s" , fmt::format("{}: constants deprecated, use #define instead\n", @$.print()).data());
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2023-01-23 17:31:08 -05:00
|
|
|
decl_function
|
2023-01-24 06:53:39 -05:00
|
|
|
: expr_identifier LPAREN expr_parameters RPAREN stmt_comp
|
2023-04-05 11:09:21 -04:00
|
|
|
{ ppr.ban_header(@$); $$ = decl_function::make(@$, std::move($1), std::move($3), std::move($5)); }
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
stmt
|
2023-04-05 11:09:21 -04:00
|
|
|
: stmt_comp { $$ = std::move($1); }
|
|
|
|
| stmt_call { $$ = std::move($1); }
|
|
|
|
| stmt_assign { $$ = std::move($1); }
|
|
|
|
| stmt_endon { $$ = std::move($1); }
|
|
|
|
| stmt_notify { $$ = std::move($1); }
|
|
|
|
| stmt_wait { $$ = std::move($1); }
|
|
|
|
| stmt_waittill { $$ = std::move($1); }
|
|
|
|
| stmt_waittillmatch { $$ = std::move($1); }
|
|
|
|
| stmt_waittillframeend { $$ = std::move($1); }
|
|
|
|
| stmt_waitframe { $$ = std::move($1); }
|
|
|
|
| stmt_if { $$ = std::move($1); }
|
|
|
|
| stmt_ifelse { $$ = std::move($1); }
|
|
|
|
| stmt_while { $$ = std::move($1); }
|
|
|
|
| stmt_dowhile { $$ = std::move($1); }
|
|
|
|
| stmt_for { $$ = std::move($1); }
|
|
|
|
| stmt_foreach { $$ = std::move($1); }
|
|
|
|
| stmt_switch { $$ = std::move($1); }
|
|
|
|
| stmt_case { $$ = std::move($1); }
|
|
|
|
| stmt_default { $$ = std::move($1); }
|
|
|
|
| stmt_break { $$ = std::move($1); }
|
|
|
|
| stmt_continue { $$ = std::move($1); }
|
|
|
|
| stmt_return { $$ = std::move($1); }
|
|
|
|
| stmt_breakpoint { $$ = std::move($1); }
|
|
|
|
| stmt_prof_begin { $$ = std::move($1); }
|
|
|
|
| stmt_prof_end { $$ = std::move($1); }
|
|
|
|
| stmt_assert { $$ = std::move($1); }
|
|
|
|
| stmt_assertex { $$ = std::move($1); }
|
|
|
|
| stmt_assertmsg { $$ = std::move($1); }
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
stmt_or_dev
|
|
|
|
: stmt { $$ = std::move($1); }
|
2023-04-05 11:09:21 -04:00
|
|
|
| stmt_dev { $$ = std::move($1); }
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
stmt_list
|
|
|
|
: stmt_list stmt
|
|
|
|
{ $$ = std::move($1); $$->list.push_back(std::move($2)); }
|
|
|
|
| stmt
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = stmt_list::make(@$); $$->list.push_back(std::move($1)); }
|
2023-01-30 07:48:27 -05:00
|
|
|
| stmt_list SEMICOLON
|
|
|
|
{ $$ = std::move($1); }
|
|
|
|
| SEMICOLON
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = stmt_list::make(@$); }
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
stmt_or_dev_list
|
|
|
|
: stmt_or_dev_list stmt_or_dev
|
|
|
|
{ $$ = std::move($1); $$->list.push_back(std::move($2)); }
|
|
|
|
| stmt_or_dev
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = stmt_list::make(@$); $$->list.push_back(std::move($1)); }
|
2023-01-30 07:48:27 -05:00
|
|
|
| stmt_or_dev_list SEMICOLON
|
|
|
|
{ $$ = std::move($1); }
|
|
|
|
| SEMICOLON
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = stmt_list::make(@$); }
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
stmt_dev
|
2023-04-05 11:09:21 -04:00
|
|
|
: DEVBEGIN stmt_list DEVEND { $$ = stmt_dev::make(@$, std::move($2)); }
|
|
|
|
| DEVBEGIN DEVEND { $$ = stmt_dev::make(@$, stmt_list::make(@$)); }
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
2023-01-24 06:53:39 -05:00
|
|
|
stmt_comp
|
2023-04-05 11:09:21 -04:00
|
|
|
: LBRACE stmt_or_dev_list RBRACE { $$ = stmt_comp::make(@$, std::move($2)); }
|
|
|
|
| LBRACE RBRACE { $$ = stmt_comp::make(@$, stmt_list::make(@$)); }
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
stmt_expr
|
|
|
|
: expr_assign
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = stmt_expr::make(@$, std::move($1)); }
|
2023-01-23 17:31:08 -05:00
|
|
|
| expr_increment
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = stmt_expr::make(@$, std::move($1)); }
|
2023-01-23 17:31:08 -05:00
|
|
|
| expr_decrement
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = stmt_expr::make(@$, std::move($1)); }
|
2023-01-23 17:31:08 -05:00
|
|
|
|
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = stmt_expr::make(@$, expr_empty::make(@$)); }
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
stmt_call
|
|
|
|
: expr_call SEMICOLON
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = stmt_expr::make(@$, std::move($1)); }
|
2023-01-23 17:31:08 -05:00
|
|
|
| expr_method SEMICOLON
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = stmt_expr::make(@$, std::move($1)); }
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
stmt_assign
|
|
|
|
: expr_assign SEMICOLON
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = stmt_expr::make(@$, std::move($1)); }
|
2023-01-23 17:31:08 -05:00
|
|
|
| expr_increment SEMICOLON
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = stmt_expr::make(@$, std::move($1)); }
|
2023-01-23 17:31:08 -05:00
|
|
|
| expr_decrement SEMICOLON
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = stmt_expr::make(@$, std::move($1)); }
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
stmt_endon
|
|
|
|
: expr_object ENDON LPAREN expr RPAREN SEMICOLON
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = stmt_endon::make(@$, std::move($1), std::move($4)); }
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
stmt_notify
|
|
|
|
: expr_object NOTIFY LPAREN expr COMMA expr_arguments_no_empty RPAREN SEMICOLON
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = stmt_notify::make(@$, std::move($1), std::move($4), std::move($6)); }
|
2023-01-23 17:31:08 -05:00
|
|
|
| expr_object NOTIFY LPAREN expr RPAREN SEMICOLON
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = stmt_notify::make(@$, std::move($1), std::move($4), expr_arguments::make(@$)); }
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
stmt_wait
|
|
|
|
: WAIT expr SEMICOLON
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = stmt_wait::make(@$, std::move($2)); }
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
stmt_waittill
|
|
|
|
: expr_object WAITTILL LPAREN expr COMMA expr_arguments_no_empty RPAREN SEMICOLON
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = stmt_waittill::make(@$, std::move($1), std::move($4), std::move($6)); }
|
2023-01-23 17:31:08 -05:00
|
|
|
| expr_object WAITTILL LPAREN expr RPAREN SEMICOLON
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = stmt_waittill::make(@$, std::move($1), std::move($4), expr_arguments::make(@$)); }
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
stmt_waittillmatch
|
|
|
|
: expr_object WAITTILLMATCH LPAREN expr COMMA expr_arguments_no_empty RPAREN SEMICOLON
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = stmt_waittillmatch::make(@$, std::move($1), std::move($4), std::move($6)); }
|
2023-01-23 17:31:08 -05:00
|
|
|
| expr_object WAITTILLMATCH LPAREN expr RPAREN SEMICOLON
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = stmt_waittillmatch::make(@$, std::move($1), std::move($4), expr_arguments::make(@$)); }
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
stmt_waittillframeend
|
|
|
|
: WAITTILLFRAMEEND SEMICOLON
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = stmt_waittillframeend::make(@$); }
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
stmt_waitframe
|
|
|
|
: WAITFRAME SEMICOLON
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = stmt_waitframe::make(@$); }
|
2023-01-23 17:31:08 -05:00
|
|
|
| WAITFRAME LPAREN RPAREN SEMICOLON
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = stmt_waitframe::make(@$); }
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
stmt_if
|
|
|
|
: IF LPAREN expr RPAREN stmt %prec THEN
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = stmt_if::make(@$, std::move($3), std::move($5)); }
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
stmt_ifelse
|
|
|
|
: IF LPAREN expr RPAREN stmt ELSE stmt
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = stmt_ifelse::make(@$, std::move($3), std::move($5), std::move($7)); }
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
stmt_while
|
|
|
|
: WHILE LPAREN expr RPAREN stmt
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = stmt_while::make(@$, std::move($3), std::move($5)); }
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
stmt_dowhile
|
|
|
|
: DO stmt WHILE LPAREN expr RPAREN SEMICOLON
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = stmt_dowhile::make(@$, std::move($5), std::move($2)); }
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
stmt_for
|
|
|
|
: FOR LPAREN stmt_expr SEMICOLON expr_or_empty SEMICOLON stmt_expr RPAREN stmt
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = stmt_for::make(@$, std::move($3), std::move($5), std::move($7), std::move($9)); }
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
stmt_foreach
|
|
|
|
: FOREACH LPAREN expr_identifier IN expr RPAREN stmt
|
|
|
|
{
|
2023-04-05 11:09:21 -04:00
|
|
|
auto array = expr_identifier::make(@$, fmt::format("_temp_{}", ++index));
|
|
|
|
auto key = expr_identifier::make(@$, fmt::format("_temp_{}", ++index));
|
|
|
|
$$ = stmt_foreach::make(@$, std::move($5), std::move($3), expr_empty::make(@$), std::move(array), std::move(key), std::move($7), false);
|
|
|
|
}
|
2023-01-23 17:31:08 -05:00
|
|
|
| FOREACH LPAREN expr_identifier COMMA expr_identifier IN expr RPAREN stmt
|
|
|
|
{
|
2023-04-05 11:09:21 -04:00
|
|
|
auto array = expr_identifier::make(@$, fmt::format("_temp_{}", ++index));
|
|
|
|
expr::ptr key = (ctx_->props() & props::foreach) ? expr_identifier::make(@$, fmt::format("_temp_{}", ++index)) : std::move($3);
|
|
|
|
$$ = stmt_foreach::make(@$, std::move($7), std::move($5), (ctx_->props() & props::foreach) ? std::move($3) : (expr::ptr)expr_empty::make(@$), std::move(array), std::move(key), std::move($9), true);
|
2023-01-23 17:31:08 -05:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
stmt_switch
|
2023-01-24 06:53:39 -05:00
|
|
|
: SWITCH LPAREN expr RPAREN stmt_comp
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = stmt_switch::make(@$, std::move($3), std::move($5));
|
2023-01-23 17:31:08 -05:00
|
|
|
parse_switch(*$$);
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
stmt_case
|
|
|
|
: CASE expr_integer COLON
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = stmt_case::make(@$, std::move($2), stmt_list::make(@$)); }
|
2023-01-23 17:31:08 -05:00
|
|
|
| CASE expr_string COLON
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = stmt_case::make(@$, std::move($2), stmt_list::make(@$)); }
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
stmt_default
|
|
|
|
: DEFAULT COLON
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = stmt_default::make(@$, stmt_list::make(@$)); }
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
stmt_break
|
|
|
|
: BREAK SEMICOLON
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = stmt_break::make(@$); }
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
stmt_continue
|
|
|
|
: CONTINUE SEMICOLON
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = stmt_continue::make(@$); }
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
stmt_return
|
|
|
|
: RETURN expr SEMICOLON
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = stmt_return::make(@$, std::move($2)); }
|
2023-01-23 17:31:08 -05:00
|
|
|
| RETURN SEMICOLON
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = stmt_return::make(@$, expr_empty::make(@$)); }
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
stmt_breakpoint
|
|
|
|
: BREAKPOINT SEMICOLON
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = stmt_breakpoint::make(@$); }
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
stmt_prof_begin
|
|
|
|
: PROFBEGIN LPAREN expr_arguments RPAREN SEMICOLON
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = stmt_prof_begin::make(@$, std::move($3)); }
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
stmt_prof_end
|
|
|
|
: PROFEND LPAREN expr_arguments RPAREN SEMICOLON
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = stmt_prof_end::make(@$, std::move($3)); }
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
2023-02-01 10:39:46 -05:00
|
|
|
stmt_assert
|
|
|
|
: ASSERT LPAREN expr_arguments RPAREN SEMICOLON
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = stmt_assert::make(@$, std::move($3)); }
|
2023-02-01 10:39:46 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
stmt_assertex
|
|
|
|
: ASSERTEX LPAREN expr_arguments RPAREN SEMICOLON
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = stmt_assertex::make(@$, std::move($3)); }
|
2023-02-01 10:39:46 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
stmt_assertmsg
|
|
|
|
: ASSERTMSG LPAREN expr_arguments RPAREN SEMICOLON
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = stmt_assertmsg::make(@$, std::move($3)); }
|
2023-02-01 10:39:46 -05:00
|
|
|
;
|
|
|
|
|
2023-01-23 17:31:08 -05:00
|
|
|
expr
|
|
|
|
: expr_ternary { $$ = std::move($1); }
|
|
|
|
| expr_binary { $$ = std::move($1); }
|
|
|
|
| expr_primitive { $$ = std::move($1); }
|
|
|
|
;
|
|
|
|
|
|
|
|
expr_or_empty
|
|
|
|
: expr { $$ = std::move($1); }
|
2023-04-05 11:09:21 -04:00
|
|
|
| { $$ = expr_empty::make(@$); }
|
|
|
|
;
|
|
|
|
|
|
|
|
expr_increment
|
|
|
|
: INCREMENT expr_object %prec PREINC
|
|
|
|
{ $$ = expr_increment::make(@$, std::move($2), true); }
|
|
|
|
| expr_object INCREMENT %prec POSTINC
|
|
|
|
{ $$ = expr_increment::make(@$, std::move($1), false); }
|
|
|
|
;
|
|
|
|
|
|
|
|
expr_decrement
|
|
|
|
: DECREMENT expr_object %prec PREDEC
|
|
|
|
{ $$ = expr_decrement::make(@$, std::move($2), true); }
|
|
|
|
| expr_object DECREMENT %prec POSTDEC
|
|
|
|
{ $$ = expr_decrement::make(@$, std::move($1), false); }
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
expr_assign
|
|
|
|
: expr_tuple ASSIGN expr
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_assign::make(@$, std::move($1), std::move($3), expr_assign::op::eq); }
|
2023-01-23 17:31:08 -05:00
|
|
|
| expr_object ASSIGN expr
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_assign::make(@$, std::move($1), std::move($3), expr_assign::op::eq); }
|
2023-01-23 17:31:08 -05:00
|
|
|
| expr_object ASSIGN_BW_OR expr
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_assign::make(@$, std::move($1), std::move($3), expr_assign::op::bwor); }
|
2023-01-23 17:31:08 -05:00
|
|
|
| expr_object ASSIGN_BW_AND expr
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_assign::make(@$, std::move($1), std::move($3), expr_assign::op::bwand); }
|
2023-01-23 17:31:08 -05:00
|
|
|
| expr_object ASSIGN_BW_EXOR expr
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_assign::make(@$, std::move($1), std::move($3), expr_assign::op::bwexor); }
|
2023-01-23 17:31:08 -05:00
|
|
|
| expr_object ASSIGN_LSHIFT expr
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_assign::make(@$, std::move($1), std::move($3), expr_assign::op::shl); }
|
2023-01-23 17:31:08 -05:00
|
|
|
| expr_object ASSIGN_RSHIFT expr
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_assign::make(@$, std::move($1), std::move($3), expr_assign::op::shr); }
|
2023-01-23 17:31:08 -05:00
|
|
|
| expr_object ASSIGN_ADD expr
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_assign::make(@$, std::move($1), std::move($3), expr_assign::op::add); }
|
2023-01-23 17:31:08 -05:00
|
|
|
| expr_object ASSIGN_SUB expr
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_assign::make(@$, std::move($1), std::move($3), expr_assign::op::sub); }
|
2023-01-23 17:31:08 -05:00
|
|
|
| expr_object ASSIGN_MUL expr
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_assign::make(@$, std::move($1), std::move($3), expr_assign::op::mul); }
|
2023-01-23 17:31:08 -05:00
|
|
|
| expr_object ASSIGN_DIV expr
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_assign::make(@$, std::move($1), std::move($3), expr_assign::op::div); }
|
2023-01-23 17:31:08 -05:00
|
|
|
| expr_object ASSIGN_MOD expr
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_assign::make(@$, std::move($1), std::move($3), expr_assign::op::mod); }
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
expr_ternary
|
|
|
|
: expr QMARK expr COLON expr %prec TERN
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_ternary::make(@$, std::move($1), std::move($3), std::move($5)); }
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
expr_binary
|
|
|
|
: expr OR expr
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_binary::make(@$, std::move($1), std::move($3), expr_binary::op::bool_or); }
|
2023-01-23 17:31:08 -05:00
|
|
|
| expr AND expr
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_binary::make(@$, std::move($1), std::move($3), expr_binary::op::bool_and); }
|
2023-01-23 17:31:08 -05:00
|
|
|
| expr EQUALITY expr
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_binary::make(@$, std::move($1), std::move($3), expr_binary::op::eq); }
|
2023-01-23 17:31:08 -05:00
|
|
|
| expr INEQUALITY expr
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_binary::make(@$, std::move($1), std::move($3), expr_binary::op::ne); }
|
2023-01-23 17:31:08 -05:00
|
|
|
| expr LESS_EQUAL expr
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_binary::make(@$, std::move($1), std::move($3), expr_binary::op::le); }
|
2023-01-23 17:31:08 -05:00
|
|
|
| expr GREATER_EQUAL expr
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_binary::make(@$, std::move($1), std::move($3), expr_binary::op::ge); }
|
2023-01-23 17:31:08 -05:00
|
|
|
| expr LESS expr
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_binary::make(@$, std::move($1), std::move($3), expr_binary::op::lt); }
|
2023-01-23 17:31:08 -05:00
|
|
|
| expr GREATER expr
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_binary::make(@$, std::move($1), std::move($3), expr_binary::op::gt); }
|
2023-01-23 17:31:08 -05:00
|
|
|
| expr BITWISE_OR expr
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_binary::make(@$, std::move($1), std::move($3), expr_binary::op::bwor); }
|
2023-01-23 17:31:08 -05:00
|
|
|
| expr BITWISE_AND expr
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_binary::make(@$, std::move($1), std::move($3), expr_binary::op::bwand); }
|
2023-01-23 17:31:08 -05:00
|
|
|
| expr BITWISE_EXOR expr
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_binary::make(@$, std::move($1), std::move($3), expr_binary::op::bwexor); }
|
2023-01-23 17:31:08 -05:00
|
|
|
| expr LSHIFT expr
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_binary::make(@$, std::move($1), std::move($3), expr_binary::op::shl); }
|
2023-01-23 17:31:08 -05:00
|
|
|
| expr RSHIFT expr
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_binary::make(@$, std::move($1), std::move($3), expr_binary::op::shr); }
|
2023-01-23 17:31:08 -05:00
|
|
|
| expr ADD expr
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_binary::make(@$, std::move($1), std::move($3), expr_binary::op::add); }
|
2023-01-23 17:31:08 -05:00
|
|
|
| expr SUB expr
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_binary::make(@$, std::move($1), std::move($3), expr_binary::op::sub); }
|
2023-01-23 17:31:08 -05:00
|
|
|
| expr MUL expr
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_binary::make(@$, std::move($1), std::move($3), expr_binary::op::mul); }
|
2023-01-23 17:31:08 -05:00
|
|
|
| expr DIV expr
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_binary::make(@$, std::move($1), std::move($3), expr_binary::op::div); }
|
2023-01-23 17:31:08 -05:00
|
|
|
| expr MOD expr
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_binary::make(@$, std::move($1), std::move($3), expr_binary::op::mod); }
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
expr_primitive
|
2023-04-05 11:09:21 -04:00
|
|
|
: expr_complement { $$ = std::move($1); }
|
|
|
|
| expr_negate { $$ = std::move($1); }
|
|
|
|
| expr_not { $$ = std::move($1); }
|
|
|
|
| expr_call { $$ = std::move($1); }
|
|
|
|
| expr_method { $$ = std::move($1); }
|
|
|
|
| expr_add_array { $$ = std::move($1); }
|
|
|
|
| expr_isdefined { $$ = std::move($1); }
|
|
|
|
| expr_istrue { $$ = std::move($1); }
|
|
|
|
| expr_reference { $$ = std::move($1); }
|
|
|
|
| expr_array { $$ = std::move($1); }
|
|
|
|
| expr_field { $$ = std::move($1); }
|
|
|
|
| expr_size { $$ = std::move($1); }
|
|
|
|
| expr_paren { $$ = std::move($1); }
|
|
|
|
| expr_thisthread { $$ = std::move($1); }
|
|
|
|
| expr_empty_array { $$ = std::move($1); }
|
|
|
|
| expr_undefined { $$ = std::move($1); }
|
|
|
|
| expr_game { $$ = std::move($1); }
|
|
|
|
| expr_self { $$ = std::move($1); }
|
|
|
|
| expr_anim { $$ = std::move($1); }
|
|
|
|
| expr_level { $$ = std::move($1); }
|
|
|
|
| expr_animation { $$ = std::move($1); }
|
|
|
|
| expr_animtree { $$ = std::move($1); }
|
|
|
|
| expr_identifier { $$ = std::move($1); }
|
|
|
|
| expr_istring { $$ = std::move($1); }
|
|
|
|
| expr_string { $$ = std::move($1); }
|
|
|
|
| expr_vector { $$ = std::move($1); }
|
|
|
|
| expr_float { $$ = std::move($1); }
|
|
|
|
| expr_integer { $$ = std::move($1); }
|
|
|
|
| expr_false { $$ = std::move($1); }
|
|
|
|
| expr_true { $$ = std::move($1); }
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
expr_complement
|
|
|
|
: COMPLEMENT expr
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_complement::make(@$, std::move($2)); }
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
expr_negate
|
|
|
|
: SUB expr_identifier %prec NEG
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_negate::make(@$, std::move($2)); }
|
2023-01-23 17:31:08 -05:00
|
|
|
| SUB expr_paren %prec NEG
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_negate::make(@$, std::move($2)); }
|
2023-01-23 17:31:08 -05:00
|
|
|
| SUB expr_array %prec NEG
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_negate::make(@$, std::move($2)); }
|
2023-01-23 17:31:08 -05:00
|
|
|
| SUB expr_field %prec NEG
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_negate::make(@$, std::move($2)); }
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
expr_not
|
|
|
|
: NOT expr
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_not::make(@$, std::move($2)); }
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
expr_call
|
2023-04-05 11:09:21 -04:00
|
|
|
: expr_function { $$ = expr_call::make(@$, std::move($1)); }
|
|
|
|
| expr_pointer { $$ = expr_call::make(@$, std::move($1)); }
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
2023-05-15 11:33:52 -04:00
|
|
|
|
2023-01-23 17:31:08 -05:00
|
|
|
expr_method
|
2023-05-15 11:33:52 -04:00
|
|
|
: expr_object expr_function
|
|
|
|
{
|
|
|
|
if ($1->loc().begin.line != $2->loc().begin.line)
|
|
|
|
error($2->loc(), "missing ';' ?");
|
|
|
|
|
|
|
|
$$ = expr_method::make(@$, std::move($1), std::move($2));
|
|
|
|
}
|
|
|
|
| expr_object expr_pointer
|
|
|
|
{
|
|
|
|
if ($1->loc().begin.line != $2->loc().begin.line)
|
|
|
|
error($2->loc(), "missing ';' ?");
|
|
|
|
|
|
|
|
$$ = expr_method::make(@$, std::move($1), std::move($2));
|
|
|
|
}
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
expr_function
|
|
|
|
: expr_identifier LPAREN expr_arguments RPAREN
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_function::make(@$, expr_path::make(@$), std::move($1), std::move($3), call::mode::normal); }
|
2023-01-23 17:31:08 -05:00
|
|
|
| expr_path DOUBLECOLON expr_identifier LPAREN expr_arguments RPAREN
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_function::make(@$, std::move($1), std::move($3), std::move($5), call::mode::normal); }
|
2023-01-23 17:31:08 -05:00
|
|
|
| THREAD expr_identifier LPAREN expr_arguments RPAREN
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_function::make(@$, expr_path::make(@$), std::move($2), std::move($4), call::mode::thread); }
|
2023-01-23 17:31:08 -05:00
|
|
|
| THREAD expr_path DOUBLECOLON expr_identifier LPAREN expr_arguments RPAREN
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_function::make(@$, std::move($2), std::move($4), std::move($6), call::mode::thread); }
|
2023-01-23 17:31:08 -05:00
|
|
|
| CHILDTHREAD expr_identifier LPAREN expr_arguments RPAREN
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_function::make(@$, expr_path::make(@$), std::move($2), std::move($4), call::mode::childthread); }
|
2023-01-23 17:31:08 -05:00
|
|
|
| CHILDTHREAD expr_path DOUBLECOLON expr_identifier LPAREN expr_arguments RPAREN
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_function::make(@$, std::move($2), std::move($4), std::move($6), call::mode::childthread); }
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
expr_pointer
|
|
|
|
: LBRACKET LBRACKET expr RBRACKET RBRACKET LPAREN expr_arguments RPAREN
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_pointer::make(@$, std::move($3), std::move($7), call::mode::normal); }
|
2023-01-23 17:31:08 -05:00
|
|
|
| THREAD LBRACKET LBRACKET expr RBRACKET RBRACKET LPAREN expr_arguments RPAREN
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_pointer::make(@$, std::move($4), std::move($8), call::mode::thread); }
|
2023-01-23 17:31:08 -05:00
|
|
|
| CHILDTHREAD LBRACKET LBRACKET expr RBRACKET RBRACKET LPAREN expr_arguments RPAREN
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_pointer::make(@$, std::move($4), std::move($8), call::mode::childthread); }
|
2023-01-23 17:31:08 -05:00
|
|
|
| CALL LBRACKET LBRACKET expr RBRACKET RBRACKET LPAREN expr_arguments RPAREN
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_pointer::make(@$, std::move($4), std::move($8), call::mode::builtin); }
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
expr_add_array
|
|
|
|
: LBRACKET expr_arguments_no_empty RBRACKET
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_add_array::make(@$, std::move($2)); }
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
expr_parameters
|
|
|
|
: expr_parameters COMMA expr_identifier
|
|
|
|
{ $$ = std::move($1); $$->list.push_back(std::move($3)); }
|
|
|
|
| expr_identifier
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_parameters::make(@$); $$->list.push_back(std::move($1)); }
|
2023-01-23 17:31:08 -05:00
|
|
|
|
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_parameters::make(@$); }
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
expr_arguments
|
|
|
|
: expr_arguments_no_empty
|
|
|
|
{ $$ = std::move($1); }
|
|
|
|
|
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_arguments::make(@$); }
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
expr_arguments_no_empty
|
|
|
|
: expr_arguments COMMA expr
|
|
|
|
{ $$ = std::move($1); $$->list.push_back(std::move($3)); }
|
|
|
|
| expr %prec ADD_ARRAY
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_arguments::make(@$); $$->list.push_back(std::move($1)); }
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
expr_isdefined
|
|
|
|
: ISDEFINED LPAREN expr RPAREN
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_isdefined::make(@$, std::move($3)); }
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
expr_istrue
|
|
|
|
: ISTRUE LPAREN expr RPAREN
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_istrue::make(@$, std::move($3)); }
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
expr_reference
|
|
|
|
: DOUBLECOLON expr_identifier
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_reference::make(@$, expr_path::make(@$), std::move($2)); }
|
2023-01-23 17:31:08 -05:00
|
|
|
| expr_path DOUBLECOLON expr_identifier
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_reference::make(@$, std::move($1), std::move($3)); }
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
expr_tuple
|
|
|
|
: LBRACKET expr_tuple_arguments RBRACKET
|
2023-04-05 11:09:21 -04:00
|
|
|
{
|
|
|
|
$$ = std::move($2);
|
|
|
|
$$->as<expr_tuple>().temp = expr_identifier::make($$->loc(), fmt::format("_temp_{}", ++index));
|
2023-01-23 17:31:08 -05:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
expr_tuple_arguments
|
|
|
|
: expr_tuple_arguments COMMA expr_tuple_types
|
|
|
|
{ $$ = std::move($1); $$->list.push_back(std::move($3)); }
|
|
|
|
| expr_tuple_types
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_tuple::make(@$); $$->list.push_back(std::move($1)); }
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
expr_tuple_types
|
2023-04-05 11:09:21 -04:00
|
|
|
: expr_array { $$ = std::move($1); }
|
|
|
|
| expr_field { $$ = std::move($1); }
|
|
|
|
| expr_identifier { $$ = std::move($1); }
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
expr_array
|
|
|
|
: expr_object LBRACKET expr RBRACKET
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_array::make(@$, std::move($1), std::move($3)); }
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
expr_field
|
|
|
|
: expr_object DOT expr_identifier_nosize
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_field::make(@$, std::move($1), std::move($3)); }
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
expr_size
|
|
|
|
: expr_object DOT SIZE %prec SIZEOF
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_size::make(@$, std::move($1)); }
|
2023-09-24 08:36:27 -04:00
|
|
|
| expr_string DOT SIZE %prec SIZEOF
|
|
|
|
{ $$ = expr_size::make(@$, std::move($1)); }
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
expr_paren
|
|
|
|
: LPAREN expr RPAREN
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_paren::make(@$, std::move($2)); }
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
expr_object
|
2023-04-05 11:09:21 -04:00
|
|
|
: expr_call { $$ = std::move($1); }
|
|
|
|
| expr_method { $$ = std::move($1); }
|
|
|
|
| expr_array { $$ = std::move($1); }
|
|
|
|
| expr_field { $$ = std::move($1); }
|
|
|
|
| expr_game { $$ = std::move($1); }
|
|
|
|
| expr_self { $$ = std::move($1); }
|
|
|
|
| expr_anim { $$ = std::move($1); }
|
|
|
|
| expr_level { $$ = std::move($1); }
|
|
|
|
| expr_identifier { $$ = std::move($1); }
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
expr_thisthread
|
|
|
|
: THISTHREAD
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_thisthread::make(@$); };
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
expr_empty_array
|
|
|
|
: LBRACKET RBRACKET
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_empty_array::make(@$); };
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
expr_undefined
|
|
|
|
: UNDEFINED
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_undefined::make(@$); };
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
expr_game
|
|
|
|
: GAME
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_game::make(@$); };
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
expr_self
|
|
|
|
: SELF
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_self::make(@$); };
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
expr_anim
|
|
|
|
: ANIM
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_anim::make(@$); };
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
expr_level
|
|
|
|
: LEVEL
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_level::make(@$); };
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
expr_animation
|
|
|
|
: MOD IDENTIFIER %prec ANIMREF
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_animation::make(@$, $2); };
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
expr_animtree
|
|
|
|
: ANIMTREE
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_animtree::make(@$); };
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
expr_identifier_nosize
|
|
|
|
: IDENTIFIER
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_identifier::make(@$, $1); };
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
expr_identifier
|
|
|
|
: IDENTIFIER
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_identifier::make(@$, $1); };
|
2023-01-23 17:31:08 -05:00
|
|
|
| SIZE
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_identifier::make(@$, "size"); };
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
expr_path
|
2023-10-24 16:14:44 -04:00
|
|
|
: IDENTIFIER
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_path::make(@$, $1); };
|
2023-01-23 17:31:08 -05:00
|
|
|
| PATH
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_path::make(@$, $1); };
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
expr_istring
|
|
|
|
: ISTRING
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_istring::make(@$, $1); };
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
expr_string
|
|
|
|
: STRING
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_string::make(@$, $1); };
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
expr_vector
|
|
|
|
: LPAREN expr COMMA expr COMMA expr RPAREN
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_vector::make(@$, std::move($2), std::move($4), std::move($6)); };
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
expr_float
|
|
|
|
: SUB FLOAT %prec NEG
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_float::make(@$, "-" + $2); };
|
2023-01-23 17:31:08 -05:00
|
|
|
| FLOAT
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_float::make(@$, $1); };
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
expr_integer
|
|
|
|
: SUB INTEGER %prec NEG
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_integer::make(@$, "-" + $2); };
|
2023-01-23 17:31:08 -05:00
|
|
|
| INTEGER
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_integer::make(@$, $1); };
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
expr_false
|
|
|
|
: FALSE
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_false::make(@$); };
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
expr_true
|
|
|
|
: TRUE
|
2023-04-05 11:09:21 -04:00
|
|
|
{ $$ = expr_true::make(@$); };
|
2023-01-23 17:31:08 -05:00
|
|
|
;
|
|
|
|
|
|
|
|
%%
|
|
|
|
|
|
|
|
namespace xsk::gsc
|
|
|
|
{
|
|
|
|
|
|
|
|
void parser::error(location const& loc, std::string const& msg)
|
|
|
|
{
|
|
|
|
throw comp_error(loc, msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto parse_switch(stmt_switch& stm) -> void
|
|
|
|
{
|
2023-04-05 11:09:21 -04:00
|
|
|
auto body = stmt_list::make(stm.body->block->loc());
|
|
|
|
auto curr = stmt::ptr{ nullptr };
|
2023-01-23 17:31:08 -05:00
|
|
|
|
2023-01-24 06:53:39 -05:00
|
|
|
auto num = stm.body->block->list.size();
|
2023-01-23 17:31:08 -05:00
|
|
|
|
|
|
|
for (auto i = 0u; i < num; i++)
|
|
|
|
{
|
2023-01-24 06:53:39 -05:00
|
|
|
auto& entry = stm.body->block->list[0];
|
2023-01-23 17:31:08 -05:00
|
|
|
|
2023-04-05 11:09:21 -04:00
|
|
|
if (entry->is<stmt_case>() || entry->is<stmt_default>())
|
2023-01-23 17:31:08 -05:00
|
|
|
{
|
2023-04-05 11:09:21 -04:00
|
|
|
if (curr != nullptr)
|
2023-01-23 17:31:08 -05:00
|
|
|
{
|
2023-04-05 11:09:21 -04:00
|
|
|
body->list.push_back(std::move(curr));
|
2023-01-23 17:31:08 -05:00
|
|
|
}
|
|
|
|
|
2023-04-05 11:09:21 -04:00
|
|
|
curr = std::move(stm.body->block->list[0]);
|
2023-01-24 06:53:39 -05:00
|
|
|
stm.body->block->list.erase(stm.body->block->list.begin());
|
2023-01-23 17:31:08 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-04-05 11:09:21 -04:00
|
|
|
if (curr != nullptr)
|
2023-01-23 17:31:08 -05:00
|
|
|
{
|
2023-04-05 11:09:21 -04:00
|
|
|
if (curr->is<stmt_case>())
|
2023-01-23 17:31:08 -05:00
|
|
|
{
|
2023-04-05 11:09:21 -04:00
|
|
|
curr->as<stmt_case>().body->list.push_back(std::move(entry));
|
2023-01-24 06:53:39 -05:00
|
|
|
stm.body->block->list.erase(stm.body->block->list.begin());
|
2023-01-23 17:31:08 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-04-05 11:09:21 -04:00
|
|
|
curr->as<stmt_default>().body->list.push_back(std::move(entry));
|
2023-01-24 06:53:39 -05:00
|
|
|
stm.body->block->list.erase(stm.body->block->list.begin());
|
2023-01-23 17:31:08 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-04-05 11:09:21 -04:00
|
|
|
throw comp_error(entry->loc(), "missing case statement");
|
2023-01-23 17:31:08 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-05 11:09:21 -04:00
|
|
|
if (curr != nullptr)
|
2023-01-23 17:31:08 -05:00
|
|
|
{
|
2023-04-05 11:09:21 -04:00
|
|
|
body->list.push_back(std::move(curr));
|
2023-01-23 17:31:08 -05:00
|
|
|
}
|
|
|
|
|
2023-01-24 06:53:39 -05:00
|
|
|
stm.body->block = std::move(body);
|
2023-01-23 17:31:08 -05:00
|
|
|
}
|
|
|
|
|
2023-01-30 07:48:27 -05:00
|
|
|
extern std::unordered_map<token::kind, parser::token::token_kind_type> const tok_to_parser;
|
|
|
|
extern std::unordered_map<std::string_view, parser::token::token_kind_type> const keyword_map;
|
|
|
|
|
|
|
|
auto map_token(context const* ctx_, token& tok) -> parser::symbol_type
|
|
|
|
{
|
|
|
|
if (tok.type == token::NAME)
|
|
|
|
{
|
|
|
|
tok.data = ctx_->make_token(tok.data);
|
|
|
|
|
|
|
|
auto const it = keyword_map.find(tok.data);
|
|
|
|
|
|
|
|
if (it != keyword_map.end())
|
|
|
|
{
|
|
|
|
if (it->second == parser::token::WAITFRAME)
|
|
|
|
{
|
|
|
|
if (ctx_->props() & props::waitframe)
|
|
|
|
return parser::symbol_type(it->second, tok.pos);
|
|
|
|
}
|
|
|
|
else if (it->second == parser::token::ISDEFINED || it->second == parser::token::ISTRUE)
|
|
|
|
{
|
|
|
|
if (ctx_->props() & props::boolfuncs)
|
|
|
|
{
|
2023-02-17 12:56:19 -05:00
|
|
|
return parser::symbol_type(it->second, tok.pos);
|
2023-01-30 07:48:27 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return parser::symbol_type(it->second, tok.pos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return parser::symbol_type(parser::token::IDENTIFIER, std::move(tok.data), tok.pos);
|
|
|
|
}
|
|
|
|
else if (tok.type == token::PATH ||tok.type == token::STRING ||tok.type == token::ISTRING || tok.type == token::INT ||tok.type == token::FLT)
|
|
|
|
{
|
|
|
|
auto it = tok_to_parser.find(tok.type);
|
|
|
|
|
|
|
|
if (it != tok_to_parser.end())
|
|
|
|
{
|
|
|
|
return parser::symbol_type(it->second, std::move(tok.data), tok.pos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
auto it = tok_to_parser.find(tok.type);
|
|
|
|
|
|
|
|
if (it != tok_to_parser.end())
|
|
|
|
{
|
|
|
|
return parser::symbol_type(it->second, tok.pos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
throw error(fmt::format("unmapped token! {}", (u8)tok.type));
|
|
|
|
}
|
|
|
|
|
|
|
|
auto GSClex(context const* ctx_, preprocessor& ppr) -> parser::symbol_type
|
|
|
|
{
|
|
|
|
auto tok = ppr.process();
|
|
|
|
return map_token(ctx_, tok);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unordered_map<token::kind, parser::token::token_kind_type> const tok_to_parser
|
|
|
|
{{
|
|
|
|
{ token::NAME, parser::token::IDENTIFIER },
|
|
|
|
{ token::PATH, parser::token::PATH },
|
|
|
|
{ token::STRING, parser::token::STRING },
|
|
|
|
{ token::ISTRING, parser::token::ISTRING },
|
|
|
|
{ token::INT, parser::token::INTEGER },
|
|
|
|
{ token::FLT, parser::token::FLOAT },
|
|
|
|
{ token::PLUS, parser::token::ADD },
|
|
|
|
{ token::MINUS, parser::token::SUB },
|
|
|
|
{ token::STAR, parser::token::MUL },
|
|
|
|
{ token::DIV, parser::token::DIV },
|
|
|
|
{ token::MOD, parser::token::MOD },
|
|
|
|
{ token::BITOR, parser::token::BITWISE_OR },
|
|
|
|
{ token::BITAND, parser::token::BITWISE_AND },
|
|
|
|
{ token::BITEXOR, parser::token::BITWISE_EXOR },
|
|
|
|
{ token::ASSIGN, parser::token::ASSIGN },
|
|
|
|
{ token::PLUSEQ, parser::token::ASSIGN_ADD },
|
|
|
|
{ token::MINUSEQ, parser::token::ASSIGN_SUB },
|
|
|
|
{ token::STAREQ, parser::token::ASSIGN_MUL },
|
|
|
|
{ token::DIVEQ, parser::token::ASSIGN_DIV },
|
|
|
|
{ token::MODEQ, parser::token::ASSIGN_MOD },
|
|
|
|
{ token::BITOREQ, parser::token::ASSIGN_BW_OR },
|
|
|
|
{ token::BITANDEQ, parser::token::ASSIGN_BW_AND },
|
|
|
|
{ token::BITEXOREQ, parser::token::ASSIGN_BW_EXOR },
|
|
|
|
{ token::SHLEQ, parser::token::ASSIGN_LSHIFT },
|
|
|
|
{ token::SHREQ, parser::token::ASSIGN_RSHIFT },
|
|
|
|
{ token::TILDE, parser::token::COMPLEMENT },
|
|
|
|
{ token::BANG, parser::token::NOT },
|
|
|
|
{ token::GT, parser::token::GREATER },
|
|
|
|
{ token::LT, parser::token::LESS },
|
|
|
|
{ token::GE, parser::token::GREATER_EQUAL },
|
|
|
|
{ token::LE, parser::token::LESS_EQUAL },
|
|
|
|
{ token::NE, parser::token::INEQUALITY },
|
|
|
|
{ token::EQ, parser::token::EQUALITY },
|
|
|
|
{ token::OR, parser::token::OR },
|
|
|
|
{ token::AND, parser::token::AND },
|
|
|
|
{ token::SHL, parser::token::LSHIFT },
|
|
|
|
{ token::SHR, parser::token::RSHIFT },
|
|
|
|
{ token::INC, parser::token::INCREMENT },
|
|
|
|
{ token::DEC, parser::token::DECREMENT },
|
|
|
|
{ token::QMARK, parser::token::QMARK },
|
|
|
|
{ token::DOT, parser::token::DOT },
|
2023-02-17 10:44:38 -05:00
|
|
|
{ token::DOUBLEDOT, parser::token::DOUBLEDOT },
|
2023-01-30 07:48:27 -05:00
|
|
|
{ token::ELLIPSIS, parser::token::ELLIPSIS },
|
|
|
|
{ token::COMMA, parser::token::COMMA },
|
|
|
|
{ token::COLON, parser::token::COLON },
|
|
|
|
{ token::SEMICOLON, parser::token::SEMICOLON },
|
|
|
|
{ token::DOUBLECOLON, parser::token::DOUBLECOLON },
|
|
|
|
{ token::LBRACKET, parser::token::LBRACKET },
|
|
|
|
{ token::RBRACKET, parser::token::RBRACKET },
|
|
|
|
{ token::LBRACE, parser::token::LBRACE },
|
|
|
|
{ token::RBRACE, parser::token::RBRACE },
|
|
|
|
{ token::LPAREN, parser::token::LPAREN },
|
|
|
|
{ token::RPAREN, parser::token::RPAREN },
|
|
|
|
{ token::DEVBEGIN, parser::token::DEVBEGIN },
|
|
|
|
{ token::DEVEND, parser::token::DEVEND },
|
|
|
|
{ token::INLINE, parser::token::INLINE },
|
|
|
|
{ token::INCLUDE, parser::token::INCLUDE },
|
|
|
|
{ token::USINGTREE, parser::token::USINGTREE },
|
|
|
|
{ token::ANIMTREE, parser::token::ANIMTREE },
|
|
|
|
{ token::ENDON, parser::token::ENDON },
|
|
|
|
{ token::NOTIFY, parser::token::NOTIFY },
|
|
|
|
{ token::WAIT, parser::token::WAIT },
|
|
|
|
{ token::WAITTILL, parser::token::WAITTILL },
|
|
|
|
{ token::WAITTILLMATCH, parser::token::WAITTILLMATCH },
|
|
|
|
{ token::WAITTILLFRAMEEND, parser::token::WAITTILLFRAMEEND },
|
|
|
|
{ token::WAITFRAME, parser::token::WAITFRAME },
|
|
|
|
{ token::IF, parser::token::IF },
|
|
|
|
{ token::ELSE, parser::token::ELSE },
|
|
|
|
{ token::DO, parser::token::DO },
|
|
|
|
{ token::WHILE, parser::token::WHILE },
|
|
|
|
{ token::FOR, parser::token::FOR },
|
|
|
|
{ token::FOREACH, parser::token::FOREACH },
|
|
|
|
{ token::IN, parser::token::IN },
|
|
|
|
{ token::SWITCH, parser::token::SWITCH },
|
|
|
|
{ token::CASE, parser::token::CASE },
|
|
|
|
{ token::DEFAULT, parser::token::DEFAULT },
|
|
|
|
{ token::BREAK, parser::token::BREAK },
|
|
|
|
{ token::CONTINUE, parser::token::CONTINUE },
|
|
|
|
{ token::RETURN, parser::token::RETURN },
|
|
|
|
{ token::BREAKPOINT, parser::token::BREAKPOINT },
|
|
|
|
{ token::PROFBEGIN, parser::token::PROFBEGIN },
|
|
|
|
{ token::PROFEND, parser::token::PROFEND },
|
2023-02-01 10:39:46 -05:00
|
|
|
{ token::ASSERT, parser::token::ASSERT },
|
|
|
|
{ token::ASSERTEX, parser::token::ASSERTEX },
|
|
|
|
{ token::ASSERTMSG, parser::token::ASSERTMSG },
|
2023-01-30 07:48:27 -05:00
|
|
|
{ token::THREAD, parser::token::THREAD },
|
|
|
|
{ token::CHILDTHREAD, parser::token::CHILDTHREAD },
|
|
|
|
{ token::THISTHREAD, parser::token::THISTHREAD },
|
|
|
|
{ token::CALL, parser::token::CALL },
|
|
|
|
{ token::TRUE, parser::token::TRUE },
|
|
|
|
{ token::FALSE, parser::token::FALSE },
|
|
|
|
{ token::UNDEFINED, parser::token::UNDEFINED },
|
|
|
|
{ token::SIZE, parser::token::SIZE },
|
|
|
|
{ token::GAME, parser::token::GAME },
|
|
|
|
{ token::SELF, parser::token::SELF },
|
|
|
|
{ token::ANIM, parser::token::ANIM },
|
|
|
|
{ token::LEVEL, parser::token::LEVEL },
|
|
|
|
{ token::ISDEFINED, parser::token::ISDEFINED },
|
|
|
|
{ token::ISTRUE, parser::token::ISTRUE },
|
|
|
|
{ token::EOS, parser::token::GSCEOF },
|
|
|
|
{ token::HASH, parser::token::HASH }
|
|
|
|
}};
|
|
|
|
|
|
|
|
std::unordered_map<std::string_view, parser::token::token_kind_type> const keyword_map
|
|
|
|
{{
|
|
|
|
{ "endon", parser::token::ENDON },
|
|
|
|
{ "notify", parser::token::NOTIFY },
|
|
|
|
{ "wait", parser::token::WAIT },
|
|
|
|
{ "waittill", parser::token::WAITTILL },
|
|
|
|
{ "waittillmatch", parser::token::WAITTILLMATCH },
|
|
|
|
{ "waittillframeend", parser::token::WAITTILLFRAMEEND },
|
|
|
|
{ "waitframe", parser::token::WAITFRAME },
|
|
|
|
{ "if", parser::token::IF },
|
|
|
|
{ "else", parser::token::ELSE },
|
|
|
|
{ "do", parser::token::DO },
|
|
|
|
{ "while", parser::token::WHILE },
|
|
|
|
{ "for", parser::token::FOR },
|
|
|
|
{ "foreach", parser::token::FOREACH },
|
|
|
|
{ "in", parser::token::IN },
|
|
|
|
{ "switch", parser::token::SWITCH },
|
|
|
|
{ "case", parser::token::CASE },
|
|
|
|
{ "default", parser::token::DEFAULT },
|
|
|
|
{ "break", parser::token::BREAK },
|
|
|
|
{ "continue", parser::token::CONTINUE },
|
|
|
|
{ "return", parser::token::RETURN },
|
|
|
|
{ "breakpoint", parser::token::BREAKPOINT },
|
|
|
|
{ "prof_begin", parser::token::PROFBEGIN },
|
|
|
|
{ "prof_end", parser::token::PROFEND },
|
2023-02-01 10:39:46 -05:00
|
|
|
{ "assert", parser::token::ASSERT },
|
|
|
|
{ "assertex", parser::token::ASSERTEX },
|
|
|
|
{ "assertmsg", parser::token::ASSERTMSG },
|
2023-01-30 07:48:27 -05:00
|
|
|
{ "thread", parser::token::THREAD },
|
|
|
|
{ "childthread", parser::token::CHILDTHREAD },
|
|
|
|
{ "thisthread", parser::token::THISTHREAD },
|
|
|
|
{ "call", parser::token::CALL },
|
|
|
|
{ "true", parser::token::TRUE },
|
|
|
|
{ "false", parser::token::FALSE },
|
|
|
|
{ "undefined", parser::token::UNDEFINED },
|
|
|
|
{ "size", parser::token::SIZE },
|
|
|
|
{ "game", parser::token::GAME },
|
|
|
|
{ "self", parser::token::SELF },
|
|
|
|
{ "anim", parser::token::ANIM },
|
|
|
|
{ "level", parser::token::LEVEL },
|
|
|
|
{ "isdefined", parser::token::ISDEFINED },
|
|
|
|
{ "istrue", parser::token::ISTRUE },
|
|
|
|
}};
|
|
|
|
|
2023-01-23 17:31:08 -05:00
|
|
|
} // namespace xsk::gsc
|