| 1 | %left ';' | ||||||||||||||
| 2 | %right '=' ':=' '=!=' '::-' ':-' '|||' '+=' '-=' '*=' '%=' '**=' '/=' '^=' | ||||||||||||||
| 3 | %left '->' ':->' | ||||||||||||||
| 4 | %left ARRAYFETCH | ||||||||||||||
| 5 | #//%left '|' | ||||||||||||||
| 6 | %nonassoc ':' | ||||||||||||||
| 7 | %left '?' | ||||||||||||||
| 8 | %left '&&' '||' '!' '^^' | ||||||||||||||
| 9 | %left 'conforms' | ||||||||||||||
| 10 | %nonassoc '<' '>' '==' '!=' '>=' '<=' '<=>' | ||||||||||||||
| 11 | %left '+' '-' | ||||||||||||||
| 12 | %left 'per' | ||||||||||||||
| 13 | %left '*' '/' '%' ' ' | ||||||||||||||
| 14 | %right IMPLICIT | ||||||||||||||
| 15 | %left UMINUS | ||||||||||||||
| 16 | %left NAME | ||||||||||||||
| 17 | %right '^' '**' | ||||||||||||||
| 18 | %nonassoc '++' '--' | ||||||||||||||
| 19 | |||||||||||||||
| 20 | %{ | ||||||||||||||
| 21 | 4 | ▶ | use Data::Dumper; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 22 | 0 | my $s; # warning - not re-entrant | |||||||||||||
| 23 | my $fullstring; | ||||||||||||||
| 24 | 0 | my $charcount; | |||||||||||||
| 25 | 4 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 26 | 4 | ▶ | use Language::Farnsworth::Parser::Extra; #provides a really nasty regex for lots of fun unicode symbols | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 27 | 0 | my $uni = $Language::Farnsworth::Parser::Extra::regex; #get the really annoyingly named regex | |||||||||||||
| 28 | 0 | my $identifier = qr/(?:\w|$uni)(?:[\w\d]|$uni)*/; | |||||||||||||
| 29 | %} | ||||||||||||||
| 30 | |||||||||||||||
| 31 | 201 | ▶ | %% | ||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.2
Pod
undocumented
| |||||||||||||||
| 32 | 0 | ||||||||||||||
| 33 | 201 | ▶ | stma: {undef} | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||
| 34 | 314 | ▶ | | stmt { bless [ $_[1] ], 'Stmt' } | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 35 | 9459 | ▶ | | stmt ';' stma { bless [ $_[1], ref($_[3]) eq "Stmt" ? @{$_[3]} : $_[3]], 'Stmt' } | ||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||
| 36 | ; | ||||||||||||||
| 37 | |||||||||||||||
| 38 | 593 | ▶ | stmt: expr { $_[1] } | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 39 | 20 | ▶ | | 'var' NAME { bless [ $_[2] ], 'DeclareVar' } | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 40 | 72 | ▶ | | 'var' NAME '=' expr { bless [ $_[2], $_[4] ], 'DeclareVar' } | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 41 | 2 | ▶ | | 'defun' NAME '=' expr { bless [ @_[2,4] ], 'DeclareFunc' } | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 42 | 8680 | ▶ | | NAME ':=' expr { bless [@_[1,3]], 'UnitDef' } | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 43 | 0 | ▶ | | expr ':->' expr { bless [ @_[1,3] ], 'SetDisplay' } | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 44 | 36 | ▶ | | NAME '=!=' NAME { bless [ @_[1,3] ], 'DefineDimen' } | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 45 | 224 | ▶ | | expr '|||' NAME { bless [ @_[1,3] ], 'DefineCombo' } | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 46 | | if | ||||||||||||||
| 47 | | while | ||||||||||||||
| 48 | 36 | ▶ | | NAME '{' arglist '}' ':=' expr { bless [@_[1,3], (bless [$_[6]], 'Stmt')], 'FuncDef' } | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 49 | 80 | ▶ | | NAME '{' arglist '}' ':=' '{' stma '}' { bless [@_[1,3,7]], 'FuncDef' } | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 50 | ; | ||||||||||||||
| 51 | |||||||||||||||
| 52 | 16 | ▶ | ifstartcond: 'if' '(' expr ')' {$_[3]} | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 53 | ; | ||||||||||||||
| 54 | |||||||||||||||
| 55 | 24 | ▶ | ifstmts: '{' stma '}' {$_[2]} | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 56 | ; | ||||||||||||||
| 57 | |||||||||||||||
| 58 | 8 | ▶ | if: ifstartcond ifstmts {bless [@_[1,2], undef], 'If'} | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 59 | 8 | ▶ | | ifstartcond ifstmts 'else' ifstmts {bless [@_[1,2,4]], 'If'} | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 60 | ; | ||||||||||||||
| 61 | |||||||||||||||
| 62 | #not put in simply because i haven't decided if i even want c style for loops | ||||||||||||||
| 63 | #for : 'for' '(' expr ';' expr ';' expr ')' '{' stmt '}' | ||||||||||||||
| 64 | # { bless [ @_[3,5,7,10] ], 'For' } | ||||||||||||||
| 65 | # ; | ||||||||||||||
| 66 | |||||||||||||||
| 67 | 14 | ▶ | while: 'while' '(' expr ')' '{' stma '}' { bless [ @_[3,6] ], 'While' } | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 68 | ; | ||||||||||||||
| 69 | |||||||||||||||
| 70 | #// i hate bad syntax highlighting | ||||||||||||||
| 71 | #// ( ref($_[1]) eq 'Array' ? ( bless [@$_[1]], 'SubArray' ) : $_[1] ) | ||||||||||||||
| 72 | #// this is a really messed up looking tree building, BUT it allows me to detect when someone does something like [ [ 1,2,3], 1,2,3] versus, a = [1,2,3]; [a,1,2,3]; and allows me to act appropriately | ||||||||||||||
| 73 | |||||||||||||||
| 74 | 0 | ▶ | array: expr ',' array {bless [ ( ref($_[1]) eq 'Array' ? ( bless [@{$_[1]}], 'SubArray' ) : $_[1] ), ref($_[3]) eq 'Array' ? @{$_[3]} : $_[3] ], 'Array' } | ||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=13.1
Branch: 2 branches
| |||||||||||||||
| 75 | 267 | ▶ | | expr {bless [ ( ref($_[1]) eq 'Array' ? ( bless [@{$_[1]}], 'SubArray' ) : $_[1] ) ], 'Array'} | ||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||
| 76 | 43 | ▶ | | {bless [], 'Array'} #//need to do this for empty arrays | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 77 | 4 | ▶ | | ',' array {bless [ undef, ref($_[2]) eq 'Array' ? @{$_[2]} : $_[2] ], 'Array' } | ||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
Branch: 1 branch
| |||||||||||||||
| 78 | ; | ||||||||||||||
| 79 | |||||||||||||||
| 80 | constraint: expr #// this MIGHT have to change slightly, mostly to make it allow things like, flow, volume | ||||||||||||||
| 81 | 22 | ▶ | | '...' {bless [], 'VarArg'} #// for having variable arguments | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 82 | ; | ||||||||||||||
| 83 | |||||||||||||||
| 84 | 6 | ▶ | argelement: NAME '=' expr 'isa' constraint {bless [ $_[1], $_[3], $_[5], 0], 'Argele'} #default value AND constraint | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 85 | 76 | ▶ | | NAME 'isa' constraint {bless [ $_[1], undef, $_[3], 0], 'Argele'} #constraint | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 86 | 3 | ▶ | | NAME '=' expr {bless [ $_[1], $_[3], undef, 0], 'Argele'} #default value | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 87 | 112 | ▶ | | NAME {bless [ $_[1], undef, undef, 0], 'Argele'} | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 88 | 8 | ▶ | | NAME 'byref' 'isa' constraint {bless [ $_[1], undef, $_[4], 1], 'Argele'} #constraint | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 89 | 1 | ▶ | | NAME 'byref' {bless [ $_[1], undef, undef, 1], 'Argele'} | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 90 | ; | ||||||||||||||
| 91 | |||||||||||||||
| 92 | 69 | ▶ | arglistfilled: argelement ',' arglistfilled { bless [ $_[1], ref($_[3]) eq 'Arglist' ? @{$_[3]} : $_[3] ], 'Arglist' } | ||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
Branch: 1 branch
| |||||||||||||||
| 93 | 136 | ▶ | | argelement {bless [ $_[1] ], 'Arglist'} | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 94 | ; | ||||||||||||||
| 95 | |||||||||||||||
| 96 | arglist: arglistfilled | ||||||||||||||
| 97 | | | ||||||||||||||
| 98 | ; | ||||||||||||||
| 99 | |||||||||||||||
| 100 | 8924 | ▶ | number: NUMBER { bless [ $_[1] ], 'Num' } | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 101 | 3 | ▶ | | HEXNUMBER { bless [ $_[1] ], 'HexNum' } | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 102 | ; | ||||||||||||||
| 103 | |||||||||||||||
| 104 | value: number | ||||||||||||||
| 105 | 7 | ▶ | | DATE { bless [ $_[1] ], 'Date' } | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 106 | 34 | ▶ | | STRING { bless [ $_[1] ], 'String' } #this will have to be reparsed later, just before evaluating | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 107 | 52 | ▶ | | singleval '@' array '$' %prec ARRAYFETCH { bless [ @_[1,3] ], 'ArrayFetch' } | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 108 | 12373 | ▶ | | NAME %prec NAME { bless [ $_[1] ], 'Fetch' } | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 109 | 258 | ▶ | | '[' array ']' { $_[2] } | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 110 | | lambda | ||||||||||||||
| 111 | 0 | ▶ | | '&' NAME { bless [ $_[2] ], 'GetFunc' } | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 112 | ; | ||||||||||||||
| 113 | |||||||||||||||
| 114 | 416 | ▶ | parens: '(' expr ')' { bless [$_[2]], 'Paren' } #do this so i can tell where parens were later, so i can rebuild everything correctly | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 115 | ; | ||||||||||||||
| 116 | |||||||||||||||
| 117 | singleval: value | ||||||||||||||
| 118 | | parens | ||||||||||||||
| 119 | ; | ||||||||||||||
| 120 | |||||||||||||||
| 121 | 66 | ▶ | assignexpr: expr '=' expr { bless [ @_[1,3] ], 'Store' } | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 122 | ; | ||||||||||||||
| 123 | |||||||||||||||
| 124 | 0 | ▶ | assignexpr2: expr '+=' expr { bless [ @_[1,3] ], 'StoreAdd' } | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 125 | 0 | ▶ | | expr '-=' expr { bless [ @_[1,3] ], 'StoreSub' } | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 126 | 0 | ▶ | | expr '/=' expr { bless [ @_[1,3] ], 'StoreDiv' } | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 127 | 0 | ▶ | | expr '*=' expr { bless [ @_[1,3] ], 'StoreMul' } | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 128 | 0 | ▶ | | expr '%=' expr { bless [ @_[1,3] ], 'StoreMod' } | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 129 | 0 | ▶ | | expr '**=' expr { bless [ @_[1,3] ], 'StorePow' } | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 130 | 0 | ▶ | | expr '^=' expr { bless [ @_[1,3] ], 'StorePow' } | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 131 | ; | ||||||||||||||
| 132 | |||||||||||||||
| 133 | assigncomb: assignexpr | ||||||||||||||
| 134 | | assignexpr2 | ||||||||||||||
| 135 | ; | ||||||||||||||
| 136 | |||||||||||||||
| 137 | 28 | ▶ | lambda: '{`' arglist '`' stma '}' {bless [ @_[2,4] ], 'Lambda'} | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 138 | 0 | ▶ | | '{|' arglist '|' stma '}' {bless [ @_[2,4] ], 'Lambda'} | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 139 | ; | ||||||||||||||
| 140 | |||||||||||||||
| 141 | 52 | ▶ | multexpr: expr '*' expr { bless [ @_[1,3], '*'], 'Mul' } | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 142 | 204 | ▶ | | singleval singleval %prec IMPLICIT { bless [ @_[1,2], 'imp'], 'Mul' } | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 143 | 0 | ▶ | | singleval singleval expr %prec IMPLICIT { bless [bless([ @_[1,2], 'imp'], 'Mul'), $_[3], 'imp'], 'Mul' } | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 144 | 7021 | ▶ | | expr ' ' expr { bless [ @_[1,3], ''], 'Mul' } | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 145 | ; | ||||||||||||||
| 146 | |||||||||||||||
| 147 | 16 | ▶ | logic: expr '&&' expr { bless [ @_[1,3] ], 'And' } | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 148 | 0 | ▶ | | expr '||' expr { bless [ @_[1,3] ], 'Or' } | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 149 | 0 | ▶ | | expr '^^' expr { bless [ @_[1,3] ], 'Xor' } | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 150 | 4 | ▶ | | '!' singleval { bless [ $_[2] ], 'Not' } | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 151 | ; | ||||||||||||||
| 152 | |||||||||||||||
| 153 | 4 | ▶ | compare: expr '<' expr { bless [ @_[1,3] ], 'Lt' } | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 154 | 12 | ▶ | | expr '>' expr { bless [ @_[1,3] ], 'Gt' } | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 155 | 0 | ▶ | | expr '<=' expr { bless [ @_[1,3] ], 'Le' } | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 156 | 10 | ▶ | | expr '>=' expr { bless [ @_[1,3] ], 'Ge' } | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 157 | 16 | ▶ | | expr '==' expr { bless [ @_[1,3] ], 'Eq' } | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 158 | 5 | ▶ | | expr '<=>' expr { bless [ @_[1,3] ], 'Compare' } | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 159 | 0 | ▶ | | expr '!=' expr { bless [ @_[1,3] ], 'Ne' } | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 160 | ; | ||||||||||||||
| 161 | |||||||||||||||
| 162 | 0 | ▶ | crement: '++' singleval { bless [ $_[2] ], 'PreInc' } | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 163 | 0 | ▶ | | '--' singleval { bless [ $_[2] ], 'PreDec' } | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 164 | 0 | ▶ | | singleval '++' { bless [ $_[1] ], 'PostInc' } | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 165 | 0 | ▶ | | singleval '--' { bless [ $_[1] ], 'PostDec' } | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 166 | ; | ||||||||||||||
| 167 | |||||||||||||||
| 168 | 25 | ▶ | powexp: expr '**' expr { bless [ @_[1,3] ], 'Pow' } | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 169 | 983 | ▶ | | expr '^' expr { bless [ @_[1,3] ], 'Pow' } | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 170 | ; | ||||||||||||||
| 171 | |||||||||||||||
| 172 | 105 | ▶ | standardmath: expr '+' expr { bless [ @_[1,3]], 'Add' } | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 173 | 54 | ▶ | | expr '-' expr { bless [ @_[1,3]], 'Sub' } | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 174 | 2861 | ▶ | | expr '/' expr { bless [ @_[1,3], '/'], 'Div' } | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 175 | 1 | ▶ | | expr 'per' expr { bless [ @_[1,3], 'per' ], 'Div' } | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 176 | 0 | ▶ | | expr '%' expr { bless [ @_[1,3] ], 'Mod' } | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 177 | ; | ||||||||||||||
| 178 | |||||||||||||||
| 179 | exprnouminus: singleval | ||||||||||||||
| 180 | | multexpr | ||||||||||||||
| 181 | | powexp | ||||||||||||||
| 182 | | standardmath | ||||||||||||||
| 183 | 42 | ▶ | | expr 'conforms' expr { bless [ @_[1,3] ], 'Conforms' } | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 184 | 34 | ▶ | | expr '?' expr ':' expr { bless [@_[1,3,5]], 'Ternary' } | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 185 | | logic | ||||||||||||||
| 186 | | compare | ||||||||||||||
| 187 | | crement | ||||||||||||||
| 188 | 172 | ▶ | | NAME '::-' expr { bless [ @_[1,3] ], 'SetPrefix' } | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 189 | 168 | ▶ | | NAME ':-' expr { bless [ @_[1,3] ], 'SetPrefixAbrv' } | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 190 | 0 | ▶ | | expr '->' expr { bless [ @_[1,3]], 'Trans' } | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 191 | | assigncomb | ||||||||||||||
| 192 | ; | ||||||||||||||
| 193 | |||||||||||||||
| 194 | expr: exprnouminus | ||||||||||||||
| 195 | 161 | ▶ | | '-' expr %prec UMINUS { bless [ $_[2] , (bless ['-1'], 'Num'), '-name'], 'Mul' } #unary - | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 196 | 201 | ; | |||||||||||||
| 197 | %% | ||||||||||||||
| 198 | |||||||||||||||
| 199 | 201 | #helpers! | |||||||||||||
| 200 | 0 | my $ws = qr/[^\S\n]/; #whitespace without the \n | |||||||||||||
| 201 | |||||||||||||||
| 202 | sub yylex | ||||||||||||||
| 203 | 88212 | ▶ | { | ||||||||||||
|
Subroutine
yylex: called CC=27 SCAR=33.0
Pod
undocumented
| |||||||||||||||
| 204 | 4 | ▶ | no warnings 'exiting'; #needed because perl doesn't seem to like me using redo there now; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 205 | 88212 | my $line = $_[-2]; | |||||||||||||
| 206 | 88212 | my $charline = $_[-1]; | |||||||||||||
| 207 | 88212 | my $lastcharline = $_[-3]; | |||||||||||||
| 208 | 88212 | my $gotsingleval = $_[-4]; | |||||||||||||
| 209 | |||||||||||||||
| 210 | #remove \n or whatever from the string | ||||||||||||||
| 211 | 88212 | ▶ | if ($s =~ /\G$ws*\n$ws*/gc) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 212 | { | ||||||||||||||
| 213 | 16404 | $$line++; | |||||||||||||
| 214 | 16404 | $$lastcharline = $$charline; | |||||||||||||
| 215 | 16404 | $$charline = pos $s; | |||||||||||||
| 216 | #print "LEX: ${$line} ${$charline} || ".substr($s, $$charline, index($s, "\n", $$charline)-$$charline)."\n"; | ||||||||||||||
| 217 | redo | ||||||||||||||
| 218 | 16404 | } | |||||||||||||
| 219 | |||||||||||||||
| 220 | #this has got to be the most fucked up work around in the entire code base. | ||||||||||||||
| 221 | #i'm doing this to check if i've gotten something like; 2a so that i can insert a fictious space token. so that 2a**2 will properly parse as 2 * (a ** 2) | ||||||||||||||
| 222 | 71808 | ▶ | if ($$gotsingleval) #we had a number | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 223 | { | ||||||||||||||
| 224 | #print "INGOTNUMBER\n"; | ||||||||||||||
| 225 | 9372 | $$gotsingleval = 0; #unset it | |||||||||||||
| 226 | 9372 | ▶ | if ($s =~ /\G(?=$identifier| | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 227 | 0[xb]?[[:xdigit:]](?:[[:xdigit:].]+)| #hex octal or binary numbers | ||||||||||||||
| 228 | (?:\d+(\.\d*)?|\.\d+)(?:[Ee][Ee]?[-+]?\d+)| #scientific notation | ||||||||||||||
| 229 | (?:\d+(?:\.\d*)?|\.\d+)| #plain notation | ||||||||||||||
| 230 | (?:\($ws*) #paren value | ||||||||||||||
| 231 | )/gcx) #match opening array brace | ||||||||||||||
| 232 | {#<NUMBER><IDENTIFIER> needs a space (or a *, but we'll use \s for now) | ||||||||||||||
| 233 | #print "OMG IDENTIFIER!\n"; | ||||||||||||||
| 234 | 16 | return ' '; | |||||||||||||
| 235 | } | ||||||||||||||
| 236 | } | ||||||||||||||
| 237 | |||||||||||||||
| 238 | 71792 | $s =~ /\G\s*(?=\s)/gc; #skip whitespace up to a single space, makes \s+ always look like \s to the rest of the code, simplifies some regex below | |||||||||||||
| 239 | |||||||||||||||
| 240 | #1 while $s =~ /\G\s+/cg; #remove extra whitespace? | ||||||||||||||
| 241 | |||||||||||||||
| 242 | 71792 | ▶ | $s =~ m|\G\s*/\*.*?\*/\s*|gcs and redo; #skip C comments | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 243 | 71792 | ▶ | $s =~ m|\G\s*//.*(?=\n)?|gc and redo; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 244 | |||||||||||||||
| 245 | 64192 | ▶ | if ($s=~ /\G(?= | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 246 | 0x[[:xdigit:].]+| #hex octal or binary numbers | ||||||||||||||
| 247 | 0b[01.]+| | ||||||||||||||
| 248 | 0[0-7][0-7.]*| | ||||||||||||||
| 249 | (?:\d+(\.\d*)?|\.\d+)(?:[Ee][Ee]?[-+]?\d+)| #scientific notation | ||||||||||||||
| 250 | (?:\d+(?:\.\d*)?|\.\d+)| #plain notation | ||||||||||||||
| 251 | (?:$ws*\)) #paren value | ||||||||||||||
| 252 | )/cgx) | ||||||||||||||
| 253 | { | ||||||||||||||
| 254 | #print "GOT SINGLEVAL!"; | ||||||||||||||
| 255 | 9372 | $$gotsingleval = 1; #store the fact that the last token was a number of some kind, so that we can do funky stuff on the next token if its an identifier | |||||||||||||
| 256 | } | ||||||||||||||
| 257 | |||||||||||||||
| 258 | #i want a complete number regex | ||||||||||||||
| 259 | #The 'HEXNUMBER' is really just for numbers of different bases, e.g. Hexidecimal, Binary, and Octal | ||||||||||||||
| 260 | 64192 | ▶ | $s =~ /\G(0x[[:xdigit:].]+)/igc and return 'HEXNUMBER', $1; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 261 | 64191 | ▶ | $s =~ /\G(0b[01.]+)/igc and return 'HEXNUMBER', $1; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 262 | 64190 | ▶ | $s =~ /\G(0[0-7][0-7.]*)/igc and return 'HEXNUMBER', $1; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 263 | |||||||||||||||
| 264 | 64189 | ▶ | $s =~ /\G((\d+(\.\d*)?|\.\d+)([Ee][Ee]?[-+]?\d+))/gc | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 265 | and return 'NUMBER', $1; | ||||||||||||||
| 266 | 63677 | ▶ | $s =~ /\G((\d+(\.\d*)?|\.\d+))/gc | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 267 | and return 'NUMBER', $1; | ||||||||||||||
| 268 | |||||||||||||||
| 269 | |||||||||||||||
| 270 | |||||||||||||||
| 271 | #token out the date | ||||||||||||||
| 272 | 55265 | ▶ | $s =~ /\G\s*#([^#]*)#\s*/gc and return 'DATE', $1; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 273 | |||||||||||||||
| 274 | 55258 | ▶ | $s =~ /\G\s*"((\\.|[^"\\])*)"/gc #" bad syntax highlighters are annoying | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 275 | and return "STRING", $1; | ||||||||||||||
| 276 | |||||||||||||||
| 277 | #i'll probably ressurect this later too | ||||||||||||||
| 278 | #$s =~ /\G(do|for|elsif|else|if|print|while)\b/cg and return $1; | ||||||||||||||
| 279 | |||||||||||||||
| 280 | 55224 | ▶ | $s =~ /\G\s*(while|conforms|else|if)\b\s*/cg and return $1; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 281 | |||||||||||||||
| 282 | #seperated this to shorten the lines, and hopefully to make parts of it more readable | ||||||||||||||
| 283 | #$s =~ /\G$ws*()$ws*/icg and return lc $1; | ||||||||||||||
| 284 | |||||||||||||||
| 285 | #comparators | ||||||||||||||
| 286 | 55144 | ▶ | $s =~ /\G$ws*(==|!=|<=>|>=|<=)$ws*/icg and return lc $1; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 287 | |||||||||||||||
| 288 | #pre and post decrements, needs to be two statements for \s | ||||||||||||||
| 289 | 55113 | ▶ | $s =~ /\G$ws*(\+\+|--)$ws*/icg and return lc $1; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 290 | |||||||||||||||
| 291 | #farnsworth specific operators | ||||||||||||||
| 292 | 55113 | ▶ | $s =~ /\G$ws*(:=|->|:->)$ws*/icg and return lc $1; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 293 | |||||||||||||||
| 294 | 46317 | ▶ | $s =~ /\G$ws*(var\b|defun\b|per\b|isa\b|byref\b|\:?\:\-|\=\!\=|\|\|\|)$ws*/icg and return lc $1; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 295 | |||||||||||||||
| 296 | #assignment operators | ||||||||||||||
| 297 | 45523 | ▶ | $s =~ /\G$ws*(\*\*=|\+=|-=|\*=|\/=|%=|\^=|=)$ws*/icg and return lc $1; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 298 | |||||||||||||||
| 299 | #logical operators | ||||||||||||||
| 300 | 45374 | ▶ | $s =~ /\G$ws*(\^\^|\&\&|\|\||\!)$ws*/icg and return lc $1; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 301 | |||||||||||||||
| 302 | #math operators | ||||||||||||||
| 303 | 45354 | ▶ | $s =~ /\G$ws*(\*\*|\+|\*|-|\/|\%|\^)$ws*/icg and return lc $1; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 304 | |||||||||||||||
| 305 | 41113 | ▶ | $s =~ /\G$ws*(;|\{\s*\`|\{\s*\||\{|\}|\>|\<|\?|\:|\,|\.\.\.|\`)$ws*/cg and return $1; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 306 | 30819 | ▶ | $s =~ /\G$ws*(\)|\])/cg and return $1; #freaking quirky lexers! | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 307 | 30115 | ▶ | $s =~ /\G(\(|\[)$ws*/cg and return $1; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 308 | |||||||||||||||
| 309 | 29411 | ▶ | $s =~ /\G($identifier)/cg and return 'NAME', $1; #i need to handle -NAME later on when evaluating, or figure out a sane way to do it here | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 310 | 7305 | ▶ | $s =~ /\G(.)/cgs and return $1; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 311 | 196 | return ''; | |||||||||||||
| 312 | } | ||||||||||||||
| 313 | |||||||||||||||
| 314 | |||||||||||||||
| 315 | sub yylexwatch | ||||||||||||||
| 316 | 88212 | ▶ | { | ||||||||||||
|
Subroutine
yylexwatch: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 317 | #my $oldp = pos $s; | ||||||||||||||
| 318 | 88212 | my @r = &yylex; | |||||||||||||
| 319 | |||||||||||||||
| 320 | #my $charlines = $_[-1]; | ||||||||||||||
| 321 | #my $line = $_[-2]; | ||||||||||||||
| 322 | #my $pos = pos $s; | ||||||||||||||
| 323 | |||||||||||||||
| 324 | #print Dumper(\@_); | ||||||||||||||
| 325 | #my $nextn = index($s, "\n", $pos+1); | ||||||||||||||
| 326 | #print "LEX: ${$line} ${$charlines} $pos :: ".substr($s, $pos, $nextn).":: ".substr($s, $pos, $nextn-$pos+1)."\n"; | ||||||||||||||
| 327 | #$charcount+=pos $s; | ||||||||||||||
| 328 | #$s = substr($s, pos $s); | ||||||||||||||
| 329 | 64208 | return @r; | |||||||||||||
| 330 | } | ||||||||||||||
| 331 | |||||||||||||||
| 332 | sub yyerror | ||||||||||||||
| 333 | 1 | ▶ | { | ||||||||||||
|
Subroutine
yyerror: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 334 | 1 | my $pos = pos $s; | |||||||||||||
| 335 | 1 | my $charlines = $_[-1]; | |||||||||||||
| 336 | 1 | my $lines = $_[-2]; | |||||||||||||
| 337 | 1 | my $lastcharline = $_[-3]; | |||||||||||||
| 338 | 1 | my $gotnumber = $_[-4]; | |||||||||||||
| 339 | 1 | my $char = $pos-$charlines; | |||||||||||||
| 340 | |||||||||||||||
| 341 | 1 | substr($fullstring,$pos,0) = '<###YYLEX###>'; | |||||||||||||
| 342 | 1 | my $fewlines = substr($fullstring, $lastcharline, index($fullstring, "\n", index($fullstring, "\n", $pos)+1) - $lastcharline); | |||||||||||||
| 343 | 1 | $fewlines =~ s/^/### /mg; | |||||||||||||
| 344 | 1 | die "### Syntax Error \@ $lines : $char ($charlines $pos) of $fewlines\n"; | |||||||||||||
| 345 | } | ||||||||||||||
| 346 | |||||||||||||||
| 347 | sub parse | ||||||||||||||
| 348 | 197 | ▶ | { | ||||||||||||
|
Subroutine
parse: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 349 | 197 | $charcount=0; | |||||||||||||
| 350 | 197 | my $line = 1; | |||||||||||||
| 351 | 197 | my $charlines = 0; | |||||||||||||
| 352 | 197 | my $lastcharlines = 0; | |||||||||||||
| 353 | 197 | my $gotnumber = 0; | |||||||||||||
| 354 | 197 | my $self = shift; | |||||||||||||
| 355 | |||||||||||||||
| 356 | 197 | $s = join ' ', @_; | |||||||||||||
| 357 | 197 | $fullstring = $s; #preserve it for errors | |||||||||||||
| 358 | my $code = eval | ||||||||||||||
| 359 | 197 | ▶ | { $self->new(yylex => sub {yylexwatch(@_, \$lastcharlines, \$line, \$charlines, \$gotnumber)}, yyerror => sub {yyerror(@_, $lastcharlines, $line, $charlines, $gotnumber)})->YYParse }; | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 360 | 197 | ▶ | die $@ if $@; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 361 | 196 | $code | |||||||||||||
| 362 | } | ||||||||||||||
| 363 | |||||||||||||||
| 364 | 4 | 1; | |||||||||||||
| 365 | |||||||||||||||
| 366 | # vim: filetype=yacc | ||||||||||||||