RPerl

 view release on metacpan or  search on metacpan

lib/RPerl/GrammarMedium.eyp  view on Meta::CPAN

%token CONSTANT_CALL_SCOPED  = /((?:[a-zA-Z]\w*)(?:::[a-zA-Z]\w*)*(?:::[A-Z0-9_]*)\(\))/  # optionally-scoped constant call; ex. 'MY_CONST()' or 'Foo::Bar::BAZ_CONST()'
%token WORD_SCOPED           = /((?:[a-zA-Z]\w*)?(?:::[a-zA-Z]\w*)+)/    # optionally-scoped word; ex. 'my_word' or 'My_Word' or 'Foo::Bar::baz_word'
%token STDOUT_STDERR         = /(\{\*STDOUT\}|\{\*STDERR\})/             # '{*STDOUT}' or '{*STDERR}'
%token STDIN                 = /(<STDIN>)/                               # '<STDIN>'
%token ARGV                  = /(\@ARGV)/                                # '@ARGV'
%token ENV                   = /(\%ENV)/                                 # '%ENV'

# FEATURE BOUNTY #000, 1_000 CodeCoin: Implement all Perl functions AKA builtins (PERLOPS_PERLTYPES) as C++ functions (CPPOPS_*TYPES)
# Affects OP01_NAMED, OP01_NAMED_VOID, and OP10_NAMED_UNARY below, corresponding RPerl::Test::Operator* and C++ code;  http://perldoc.perl.org/perlfunc.html

# [[[ LEXICON TOKENS, OPERATORS ]]]

# LEXICAL MATCHING: earlier declaration gets tried first, must be in correct order for all regexes to match
# DEV NOTE: tokens which are all letters (or, ne, x, print, open, ETC) & are always followed by whitespace when tidy (NOT not or argumentless next, last, croak, return, exit, chdir, etc)
# must be explicitly made to match the trailing whitespace in the regular expressions below, in order to avoid incorrectly matching substrings of user-defined words
%token OP24_LOGICAL_OR_XOR       = /(or|xor)\s/                  # precedence 24 infix: logical 'or' and 'xor', equivalent to '||' except for precedence
%token OP23_LOGICAL_AND          = /(and)\s/                     # precedence 23 infix: logical 'and', equivalent to '&&' except for precedence
%token OP22_LOGICAL_NEG          = /(not)/                       # precedence 22 prefix: logical negation 'not', equivalent to '!' except for precedence
%token OP21_LIST_COMMA           = /(,)/                         # precedence 21 infix: "list operators (rightward)" [1] AKA comma ','
%token OP20_HASH_FATARROW        = /(=>)/                        # precedence 20 infix: hash entry fat arrow AKA fat comma '=>'
%token OP19_LOOP_CONTROL_SCOLON  = /(next;|last;)/               # precedence 19 prefix void: loop control 'next;', 'last;'
%token OP19_LOOP_CONTROL         = /(next|last|redo)\s/          # precedence 19 prefix void: same as above, except allows 'redo' and requires loop label
%token OP18_TERNARY              = /(\?)/                        # precedence 18 infix: ternary conditional '?'
%token OP17_LIST_RANGE           = /(\.\.)/                      # precedence 17 infix: range '..'
%token OP16_LOGICAL_OR           = /(\|\|)/                      # precedence 16 infix: logical or '||'
%token OP15_LOGICAL_AND          = /(&&)/                        # precedence 15 infix: logical and '&&'
%token OP14_BITWISE_OR_XOR       = /(\||\^)/                     # precedence 14 infix: bitwise or '|', bitwise xor '^'
%token OP13_BITWISE_AND          = /(&)/                         # precedence 13 infix: bitwise and '&'
%token OP12_COMPARE_EQ_NE        = /(==|!=|<=>|eq|ne|cmp)\s/     # precedence 12 infix: comparison numeric equal '==', numeric not equal '!=', numeric three-way '<=>', string equal 'eq', string not equal 'ne', string three-way 'cmp'
%token OP09_BITWISE_SHIFT        = /(<<|>>)/                     # precedence 09 infix: bitwise shift left '<<', shift right '>>'
                                                                 # precedence 10 prefix: "named unary operators" [1] and Programming Perl, Chapter 3, List of All Named Unary Operators; 'scalar' not 'scalartype'
%token OP10_NAMED_UNARY_SCOLON   = /(-A;|-B;|-C;|-M;|-O;|-R;|-S;|-T;|-W;|-X;|-b;|-c;|-d;|-e;|-f;|-g;|-k;|-l;|-o;|-p;|-r;|-s;|-t;|-u;|-w;|-x;|-z;|alarm;|caller;|chdir;|chroot;|cos;|defined;|delete;|do;|eval;|exists;|gethostbyname;|getnetbyname;|getpgr...
%token OP10_NAMED_UNARY          = /(-A\s|-B\s|-C\s|-M\s|-O\s|-R\s|-S\s|-T\s|-W\s|-X\s|-b\s|-c\s|-d\s|-e\s|-f\s|-g\s|-k\s|-l\s|-o\s|-p\s|-r\s|-s\s|-t\s|-u\s|-w\s|-x\s|-z\s|alarm\s|caller\s|chdir\s|chroot\s|cos\s|defined\s|delete\s|do\s|eval\s|exists\...
%token OP19_VARIABLE_ASSIGN_BY   = /(\+=|-=|\*=|\/=|\.=)/        # precedence 19 infix: add assign '+=', subtract assign '-=', multiply assign '*=', divide assign '/=', string concatenation assign '.='
%token OP08_STRING_CAT           = /(\.)/                        # precedence 08 infix: string concatenate '.'
%token OP03_MATH_INC_DEC         = /(\+\+|--)/                   # precedence 03 prefix and postfix: increment '++', decrement '--'
%token OP04_MATH_POW             = /(\*\*)/                      # precedence 04 infix: arithmetic exponent AKA power '**'
%token OP07_MATH_MULT_DIV_MOD    = /(\*|\/|\%|sse_mul|sse_div)/  # precedence 07 infix: arithmetic multiply '*', divide '/', modulo '%', SSE multiply 'sse_mul', SSE divide 'sse_div'
%token OP07_STRING_REPEAT        = /(x)\s/                       # precedence 07 infix: string repetition 'x'
%token OP06_REGEX_PATTERN        = /([ms]\/.*(?:\/.*)?\/[a-z]*)/ # precedence 06 infix: regular expression pattern; ex. 'm/foo.*/xms' or 's/foo/bar/gxms'
%token OP06_REGEX_BIND           = /(=\~|!\~)/                   # precedence 06 infix: regular expression bind '=~', bind not '!~'
%token OP05_LOGICAL_NEG          = /(!)/                         # precedence 05 prefix: logical negation '!'
%token OP05_BITWISE_NEG_LPAREN   = /(\~\()/                      # precedence 05 prefix: bitwise negation '~', AKA one's complement; include paren to disambiguate from regex or smartmatch
%token OP02_HASH_THINARROW       = /(->\{)/                      # precedence 02 infix: thin arrow, hash dereference and retrieval '->{'
%token OP02_ARRAY_THINARROW      = /(->\[)/                      # precedence 02 infix: thin arrow, array dereference and retrieval '->['
%token OP02_METHOD_THINARROW_NEW = /(->new\()/                   # precedence 02 infix: thin arrow, class constructor '->new('
%token OP02_METHOD_THINARROW     = /(->[a-zA-Z]\w*)/             # precedence 02 infix: thin arrow, method dereference and call; ex. '->foo' or '->Bar23'
%token OP05_MATH_NEG_LPAREN      = /(-\()/                       # precedence 05 prefix: arithmetic negative '-('; include paren to disambiguate from literal negative sign and subtraction operator
%token OP08_MATH_ADD_SUB         = /(\+|-\s|sse_add|sse_sub)/    # precedence 08 infix: arithmetic add '+', subtract '-', SSE add 'sse_add', SSE subtract 'sse_sub'
%token OP11_COMPARE_LT_GT        = /(<=|>=|<|>|le|ge|lt|gt)\s/   # precedence 11 infix: numeric comparison less or equal '<=', greater or equal '>=', less than '<', greater than '>'; string comparison less or equal 'le', greater or equal 'ge', less t...
%token OP19_VARIABLE_ASSIGN      = /(=)/                         # precedence 19 infix: assign '='
%token OP01_PRINT                = /(print|printf)\s/            # precedence 01 prefix void: 'print' or 'printf' to STDOUT, STDERR, or filehandle
%token OP01_NAMED_VOID_SCOLON    = /(croak;|die;|exit;|return;)/ # precedence 01 prefix void: "terms and list operators (leftward)" [1] AKA builtins, no return value; 'croak;', 'die;', 'exit;', 'return;'
%token OP01_NAMED_VOID_LPAREN    = /(croak\(|exit\(|return\()/   # precedence 01 prefix void: same as above, except w/ parenthesis & w/out semicolon & w/out die; 'croak(', 'exit(', 'return('; ProhibitParensWithBuiltins excepts return() & exit(...); R...
%token OP01_NAMED_VOID           = /(croak|die|exit|return)\s/   # precedence 01 prefix void: same as above, except accepts argument(s); 'croak', 'die', 'exit', 'return'
%token OP01_QW                   = /(qw\([^()]*\))/              # precedence 01 closed: quote word; ex. 'qw()' or 'qw(foo bar baz)' or 'qw(Foo23 BarBax Ba_z 123)'
%token OP01_OPEN                 = /(open)\s/                    # precedence 01 prefix: 'open' filehandle
%token OP01_CLOSE                = /(close)\s/                   # precedence 01 prefix: 'close' filehandle
                                                                 # precedence 01 prefix: "terms and list operators (leftward)" [1] AKA builtins; http://perl5.git.perl.org/perl.git/blob/HEAD:/t/op/cproto.t [2]
# w/out all-uppercase Perl system builtin keywords ('__DATA__', 'AUTOLOAD', 'CHECK', etc); named unary operators above ('defined', 'exists', etc); and RPerl keywords ('use', 'our', 'my', 'package', 'for', etc)
%token OP01_NAMED_SCOLON         = /(abs;|accept;|atan2;|bind;|binmode;|bless;|break;|chmod;|chomp;|chop;|chown;|chr;|closedir;|connect;|continue;|crypt;|dbmclose;|dbmopen;|default;|dump;|each;|endgrent;|endhostent;|endnetent;|endprotoent;|endpwent;|...
%token OP01_NAMED                = /(abs\s|accept\s|atan2\s|bind\s|binmode\s|bless\s|break\s|chmod\s|chomp\s|chop\s|chown\s|chr\s|closedir\s|connect\s|continue\s|crypt\s|dbmclose\s|dbmopen\s|default\s|dump\s|each\s|endgrent\s|endhostent\s|endnetent\s...

# [[[ SYNTAX, OPERATOR PRECEDENCE & ASSOCIATIVITY ]]]

# later declaration gets higher priority; http://perldoc.perl.org/perlop.html#Operator-Precedence-and-Associativity [1]
%left       OP24_LOGICAL_OR_XOR
%left       OP23_LOGICAL_AND
%right      OP22_LOGICAL_NEG
%left       OP21_LIST_COMMA
%left       OP20_HASH_FATARROW
%right      OP19_LOOP_CONTROL_SCOLON
%right      OP19_LOOP_CONTROL
%right      OP19_VARIABLE_ASSIGN_BY
%right      OP19_VARIABLE_ASSIGN
%right      OP18_TERNARY
%nonassoc   OP17_LIST_RANGE
%left       OP16_LOGICAL_OR
%left       OP15_LOGICAL_AND
%left       OP14_BITWISE_OR_XOR
%left       OP13_BITWISE_AND
%nonassoc   OP12_COMPARE_EQ_NE
%nonassoc   OP11_COMPARE_LT_GT
%nonassoc   OP10_NAMED_UNARY
%nonassoc   OP10_NAMED_UNARY_SCOLON
%left       OP09_BITWISE_SHIFT
%left       OP08_STRING_CAT
%left       OP08_MATH_ADD_SUB
%left       OP07_MATH_MULT_DIV_MOD
%left       OP07_STRING_REPEAT
%left       OP06_REGEX_BIND
%left       OP06_REGEX_PATTERN
%right      OP05_MATH_NEG_LPAREN
%right      OP05_LOGICAL_NEG
%right      OP05_BITWISE_NEG_LPAREN
%right      OP04_MATH_POW
%nonassoc   OP03_MATH_INC_DEC
%left       OP02_HASH_THINARROW
%left       OP02_ARRAY_THINARROW
%left       OP02_METHOD_THINARROW_NEW
%left       OP02_METHOD_THINARROW
%left       OP01_NAMED
%left       OP01_NAMED_SCOLON
%left       OP01_CLOSE
%left       OP01_OPEN
%left       OP01_QW
%left       OP01_NAMED_VOID_SCOLON
%left       OP01_NAMED_VOID_LPAREN
%left       OP01_NAMED_VOID
%left       OP01_PRINT

# [[[ LEXICON TOKENS, PUNCTUATION & USER-DEFINED WORDS ]]]

%token COLON                = /(:)/                           # ':'
%token LPAREN_MY            = /(\(\s*my)/                     # '(my'
%token LPAREN               = /(\()/                          # '('
%token LBRACKET             = /(\[)/                          # '['
%token LBRACE               = /(\{)/                          # '{'
%token WORD                 = /([a-z]\w*|[A-Z]\w*[a-z]\w*)/   # lowercase letter followed by optional word characters; or uppercase letter followed by at least one lowercase letter and optional word characters; ex. 'foo' or 'foo23' or 'Foo23'
%token WORD_UPPERCASE       = /([A-Z][A-Z0-9_]*|[A-Z])/       # single uppercase letter, or uppercase letter followed by uppercase letters, numbers, and underscores; ex. 'FOO' or 'FOOBAR_42_HOWDY'

%%



( run in 2.117 seconds using v1.01-cache-2.11-cpan-99c4e6809bf )