Prexonite, a .NET hosted scripting language with a focus on meta-programming and embedded DSLs
0

Configure Feed

Select the types of activity you want to include in your feed.

before crlf conversion

Christian Klauser (Jul 1, 2016, 7:03 PM +0200) eae369d5 f52dd912

+2866 -2832
+12
.gitattributes
··· 1 + 2 + * binary 3 + 4 + *.xml text eol=lf 5 + *.cs text eol=lf 6 + *.sln text eol=lf 7 + *.csproj text eol=lf 8 + *.pxs text eol=lf 9 + *.md text eol=lf 10 + *.atg text eol=lf 11 + *.lex text eol=lf 12 + *.frame text eol=lf
+4 -1
.gitignore
··· 99 99 100 100 # Ignore files designated local-only 101 101 *.local.* 102 - *.local.dgml 102 + *.local.dgml 103 + 104 + *.iml 105 + .idea
+2850 -2831
Prexonite/Prexonite__gen.atg
··· 1 - //-- GENERATED BY PxCoco -merge --// 2 - //-- make sure to modify the source files instead of this one! --// 1 + //-- GENERATED BY PxCoco -merge --// 2 + //-- make sure to modify the source files instead of this one! --// 3 3 4 - #file:C:\Users\chris\Source\Repos\prx\Prexonite\Compiler\Grammar\Header.atg# 5 - /* 6 - * Prexonite, a scripting engine (Scripting Language -> Bytecode -> Virtual Machine) 7 - * Copyright (C) 2007 Christian "SealedSun" Klauser 8 - * E-mail sealedsun a.t gmail d.ot com 9 - * Web http://www.sealedsun.ch/ 10 - * 11 - * This program is free software; you can redistribute it and/or modify 12 - * it under the terms of the GNU General Public License as published by 13 - * the Free Software Foundation; either version 2 of the License, or 14 - * (at your option) any later version. 15 - * 16 - * Please contact me (sealedsun a.t gmail do.t com) if you need a different license. 17 - * 18 - * This program is distributed in the hope that it will be useful, 19 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 - * GNU General Public License for more details. 22 - * 23 - * You should have received a copy of the GNU General Public License along 24 - * with this program; if not, write to the Free Software Foundation, Inc., 25 - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 26 - */ 27 - 28 - //A comment 29 - using System.Collections.Generic; 30 - using System.Linq; 31 - using FatalError = Prexonite.Compiler.FatalCompilerException; 32 - using StringBuilder = System.Text.StringBuilder; 33 - using Prexonite.Compiler.Ast; 34 - using Prexonite.Types; 35 - using Prexonite.Modular; 36 - using Prexonite.Compiler.Internal; 37 - using Prexonite.Compiler.Symbolic; 38 - using Prexonite.Compiler.Symbolic.Internal; 39 - using Prexonite.Compiler.Symbolic.Compatibility; 40 - using Prexonite.Properties; 41 - 42 - COMPILER Prexonite 43 - 44 - /*-- Global scope --*/ 45 - 46 - 4 + #file:C:\Users\chris\Documents\GitHub\prx\Prexonite\Compiler\Grammar\Header.atg# 5 + /* 6 + * Prexonite, a scripting engine (Scripting Language -> Bytecode -> Virtual Machine) 7 + * Copyright (C) 2007 Christian "SealedSun" Klauser 8 + * E-mail sealedsun a.t gmail d.ot com 9 + * Web http://www.sealedsun.ch/ 10 + * 11 + * This program is free software; you can redistribute it and/or modify 12 + * it under the terms of the GNU General Public License as published by 13 + * the Free Software Foundation; either version 2 of the License, or 14 + * (at your option) any later version. 15 + * 16 + * Please contact me (sealedsun a.t gmail do.t com) if you need a different license. 17 + * 18 + * This program is distributed in the hope that it will be useful, 19 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 + * GNU General Public License for more details. 22 + * 23 + * You should have received a copy of the GNU General Public License along 24 + * with this program; if not, write to the Free Software Foundation, Inc., 25 + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 26 + */ 47 27 48 - #file:C:\Users\chris\Source\Repos\prx\Prexonite\Compiler\Grammar\Scanner.atg# 49 - /* 50 - * Prexonite, a scripting engine (Scripting Language -> Bytecode -> Virtual Machine) 51 - * Copyright (C) 2007 Christian "SealedSun" Klauser 52 - * E-mail sealedsun a.t gmail d.ot com 53 - * Web http://www.sealedsun.ch/ 54 - * 55 - * This program is free software; you can redistribute it and/or modify 56 - * it under the terms of the GNU General Public License as published by 57 - * the Free Software Foundation; either version 2 of the License, or 58 - * (at your option) any later version. 59 - * 60 - * Please contact me (sealedsun a.t gmail do.t com) if you need a different license. 61 - * 62 - * This program is distributed in the hope that it will be useful, 63 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 64 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 65 - * GNU General Public License for more details. 66 - * 67 - * You should have received a copy of the GNU General Public License along 68 - * with this program; if not, write to the Free Software Foundation, Inc., 69 - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 70 - */ 71 - 72 - /*---- SCANNER ------*/ 73 - 74 - IGNORECASE 75 - 76 - TOKENS 77 - //Basic token 78 - id 79 - anyId // $ in some situations, e.g., $"non-Prexonite id" 80 - lid 81 - ns 82 - version // 1.1.1, 1.2.3.4 83 - 84 - /*--------------------------------------------------------------------------------*/ 85 - integer 86 - /*--------------------------------------------------------------------------------*/ 87 - real // 1e, 1e5, 1.0e, 1.0e-5, 1.0e+03 88 - realLike // 1.0, 2.0, 2.3 //could also be a version 89 - /*--------------------------------------------------------------------------------*/ 90 - string 91 - 92 - /*--------------------------------------------------------------------------------*/ 93 - bitAnd // & 94 - assign // = 95 - comma // , 96 - dec // -- 97 - div // / 98 - dot // . 99 - eq // == 100 - gt // > 101 - ge // >= 102 - inc // ++ 103 - lbrace // { 104 - lbrack // [ 105 - lpar // ( 106 - lt // < 107 - le // <= 108 - minus // - 109 - ne // != 110 - bitOr // | 111 - plus // + 112 - pow // ^ 113 - rbrace // } 114 - rbrack // ] 115 - rpar // ) 116 - tilde // ~ 117 - times // * 118 - timessym // (*), but only in symbol transfer regions 119 - semicolon // ; 120 - colon // : 121 - doublecolon // :: 122 - coalescence //?? 123 - question // ? 124 - pointer// -> 125 - implementation // => 126 - at // @ 127 - appendleft // << 128 - appendright // >> 129 - 130 - 131 - //Handled by the scanner: 132 - var 133 - ref 134 - true 135 - false 136 - 137 - //Handled by keyword check 138 - BEGINKEYWORDS 139 - mod 140 - is 141 - as 142 - not 143 - enabled 144 - disabled 145 - function 146 - command 147 - asm 148 - declare 149 - build 150 - return 151 - in 152 - to 153 - add 154 - continue 155 - break 156 - yield 157 - or 158 - and 159 - xor 160 - label 161 - goto 162 - static 163 - null 164 - if 165 - unless 166 - else 167 - new 168 - coroutine 169 - from 170 - do 171 - does 172 - while 173 - until 174 - for 175 - foreach 176 - try 177 - catch 178 - finally 179 - throw 180 - then 181 - uusing //Coco/R does not accept "using" as a token name. 182 - macro 183 - lazy 184 - let 185 - method 186 - this 187 - namespace 188 - export 189 - ENDKEYWORDS 190 - 191 - //SPECIAL 192 - LPopExpr //has no textual representation. 193 - 194 - IGNORE '\r' + '\n' + '\t' 195 - 196 - /*------------------------------*/ 197 - /*---- Parser ------------------*/ 28 + //A comment 29 + using System.Collections.Generic; 30 + using System.Linq; 31 + using FatalError = Prexonite.Compiler.FatalCompilerException; 32 + using StringBuilder = System.Text.StringBuilder; 33 + using Prexonite.Compiler.Ast; 34 + using Prexonite.Types; 35 + using Prexonite.Modular; 36 + using Prexonite.Compiler.Internal; 37 + using Prexonite.Compiler.Symbolic; 38 + using Prexonite.Compiler.Symbolic.Internal; 39 + using Prexonite.Compiler.Symbolic.Compatibility; 40 + using Prexonite.Properties; 41 + 42 + COMPILER Prexonite 43 + 44 + /*-- Global scope --*/ 45 + 46 + 47 + 48 + #file:C:\Users\chris\Documents\GitHub\prx\Prexonite\Compiler\Grammar\Scanner.atg# 49 + /* 50 + * Prexonite, a scripting engine (Scripting Language -> Bytecode -> Virtual Machine) 51 + * Copyright (C) 2007 Christian "SealedSun" Klauser 52 + * E-mail sealedsun a.t gmail d.ot com 53 + * Web http://www.sealedsun.ch/ 54 + * 55 + * This program is free software; you can redistribute it and/or modify 56 + * it under the terms of the GNU General Public License as published by 57 + * the Free Software Foundation; either version 2 of the License, or 58 + * (at your option) any later version. 59 + * 60 + * Please contact me (sealedsun a.t gmail do.t com) if you need a different license. 61 + * 62 + * This program is distributed in the hope that it will be useful, 63 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 64 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 65 + * GNU General Public License for more details. 66 + * 67 + * You should have received a copy of the GNU General Public License along 68 + * with this program; if not, write to the Free Software Foundation, Inc., 69 + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 70 + */ 71 + 72 + /*---- SCANNER ------*/ 73 + 74 + IGNORECASE 75 + 76 + TOKENS 77 + //Basic token 78 + id 79 + anyId // $ in some situations, e.g., $"non-Prexonite id" 80 + lid 81 + ns 82 + version // 1.1.1, 1.2.3.4 83 + 84 + /*--------------------------------------------------------------------------------*/ 85 + integer 86 + /*--------------------------------------------------------------------------------*/ 87 + real // 1e, 1e5, 1.0e, 1.0e-5, 1.0e+03 88 + realLike // 1.0, 2.0, 2.3 //could also be a version 89 + /*--------------------------------------------------------------------------------*/ 90 + string 91 + 92 + /*--------------------------------------------------------------------------------*/ 93 + bitAnd // & 94 + assign // = 95 + comma // , 96 + dec // -- 97 + div // / 98 + dot // . 99 + eq // == 100 + gt // > 101 + ge // >= 102 + inc // ++ 103 + lbrace // { 104 + lbrack // [ 105 + lpar // ( 106 + lt // < 107 + le // <= 108 + minus // - 109 + ne // != 110 + bitOr // | 111 + plus // + 112 + pow // ^ 113 + rbrace // } 114 + rbrack // ] 115 + rpar // ) 116 + tilde // ~ 117 + times // * 118 + timessym // (*), but only in symbol transfer regions 119 + semicolon // ; 120 + colon // : 121 + doublecolon // :: 122 + coalescence //?? 123 + question // ? 124 + pointer// -> 125 + implementation // => 126 + at // @ 127 + appendleft // << 128 + appendright // >> 129 + deltaright // |> 130 + deltaleft // <| 131 + 132 + 133 + //Handled by the scanner: 134 + var 135 + ref 136 + true 137 + false 138 + 139 + //Handled by keyword check 140 + BEGINKEYWORDS 141 + mod 142 + is 143 + as 144 + not 145 + enabled 146 + disabled 147 + function 148 + command 149 + asm 150 + declare 151 + build 152 + return 153 + in 154 + to 155 + add 156 + continue 157 + break 158 + yield 159 + or 160 + and 161 + xor 162 + label 163 + goto 164 + static 165 + null 166 + if 167 + unless 168 + else 169 + new 170 + coroutine 171 + from 172 + do 173 + does 174 + while 175 + until 176 + for 177 + foreach 178 + try 179 + catch 180 + finally 181 + throw 182 + then 183 + uusing //Coco/R does not accept "using" as a token name. 184 + macro 185 + lazy 186 + let 187 + method 188 + this 189 + namespace 190 + export 191 + ENDKEYWORDS 192 + 193 + //SPECIAL 194 + LPopExpr //has no textual representation. 195 + 196 + IGNORE '\r' + '\n' + '\t' 197 + 198 + /*------------------------------*/ 199 + /*---- Parser ------------------*/ 198 200 PRODUCTIONS 199 - #file:C:\Users\chris\Source\Repos\prx\Prexonite\Compiler\Grammar\Parser.Assembler.atg# 200 - /* 201 - * Prexonite, a scripting engine (Scripting Language -> Bytecode -> Virtual Machine) 202 - * Copyright (C) 2007 Christian "SealedSun" Klauser 203 - * E-mail sealedsun a.t gmail d.ot com 204 - * Web http://www.sealedsun.ch/ 205 - * 206 - * This program is free software; you can redistribute it and/or modify 207 - * it under the terms of the GNU General Public License as published by 208 - * the Free Software Foundation; either version 2 of the License, or 209 - * (at your option) any later version. 210 - * 211 - * Please contact me (sealedsun a.t gmail do.t com) if you need a different license. 212 - * 213 - * This program is distributed in the hope that it will be useful, 214 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 215 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 216 - * GNU General Public License for more details. 217 - * 218 - * You should have received a copy of the GNU General Public License along 219 - * with this program; if not, write to the Free Software Foundation, Inc., 220 - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 221 - */ 222 - 223 - /* ---- Assembler Language ---- */ 224 - 225 - AsmStatementBlock<AstBlock block> 226 - = 227 - lbrace 228 - { 229 - AsmInstruction<block> 230 - } 231 - rbrace 232 - | AsmInstruction<block> semicolon 233 - . 234 - 235 - AsmInstruction<AstBlock block> (. int arguments = 0; 236 - string id; 237 - double dblArg; 238 - string insbase; string detail = null; 239 - bool bolArg; 240 - OpCode code; 241 - bool justEffect = false; 242 - int values; 243 - int rotations; 244 - int index; 245 - ISourcePosition pos; 246 - .) 247 - = 248 - //VARIABLE DECLARATION 249 - (. var isAutodereference = false; .) 250 - ( var | ref (. isAutodereference = true; .) 251 - ) (. pos = GetPosition(); .) 252 - AsmId<out id> 253 - 254 - (. //Store variable 255 - _ensureDefinedLocal(id,id,isAutodereference,pos,false); 256 - .) 257 - { comma (. pos = GetPosition(); .) 258 - AsmId<out id> 259 - (. //Store variable 260 - _ensureDefinedLocal(id,id,isAutodereference,pos,false); 261 - .) 262 - } 263 - | //OP ALIAS INSTRUCTIONS 264 - IF(isInOpAliasGroup()) 265 - AsmId<out insbase> 266 - [ dot AsmId<out detail> ] 267 - (. addOpAlias(block, insbase, detail); .) 268 - | //NULL INSTRUCTIONS 269 - IF(isInNullGroup()) 270 - AsmId<out insbase> 271 - [ dot AsmId<out detail> ] 272 - (. code = getOpCode(insbase, detail); 273 - addInstruction(block, new Instruction(code)); 274 - .) 275 - 276 - | //LABEL 277 - IF( isAsmInstruction("label",null) ) 278 - AsmId<out insbase> 279 - 280 - //Enter label 281 - AsmId<out id> 282 - (. addLabel(block, id); .) 283 - | //NOP/DATA INSTRUCTION 284 - IF(isAsmInstruction("nop", null)) 285 - AsmId<out insbase> (. var ins = new Instruction(OpCode.nop); .) 286 - [ plus AsmId<out id> (. ins = ins.With(id: id); .) 287 - ] 288 - (. addInstruction(block, ins); .) 289 - 290 - | //ROTATE INSTRUCTION 291 - IF(isAsmInstruction("rot", null)) 292 - AsmId<out insbase> 293 - dot Integer<out rotations> 294 - comma Integer<out values> 295 - //Create rot instruction 296 - (. addInstruction(block, Instruction.CreateRotate(rotations, values)); .) 297 - 298 - | //INDIRECT LOCAL CALL BY INDEX 299 - IF(isAsmInstruction("indloci", null)) 300 - [ at (. justEffect = true; .) 301 - ] 302 - AsmId<out insbase> 303 - dot Integer<out arguments> 304 - Integer<out index> 305 - //Create indloci instruction 306 - (. addInstruction(block, Instruction.CreateIndLocI(index, arguments, justEffect)); .) 307 - | //EXCHANGE INSTRUCTION 308 - IF(isAsmInstruction("swap", null)) 309 - AsmId<out insbase> 310 - (. addInstruction(block, Instruction.CreateExchange()); .) 311 - 312 - 313 - | //LOAD CONSTANT . REAL 314 - IF(isAsmInstruction("ldc", "real")) 315 - AsmId<out insbase> 316 - dot 317 - AsmId<out detail> 318 - SignedReal<out dblArg> 319 - (. addInstruction(block, Instruction.CreateConstant(dblArg)); .) 320 - 321 - 322 - | //LOAD CONSTANT . BOOL 323 - IF(isAsmInstruction("ldc", "bool")) 324 - AsmId<out insbase> 325 - dot 326 - AsmId<out detail> 327 - Boolean<out bolArg> 328 - (. addInstruction(block, Instruction.CreateConstant(bolArg)); .) 329 - 330 - 331 - | //INTEGER INSTRUCTIONS 332 - IF(isInIntegerGroup()) 333 - AsmId<out insbase> 334 - [ dot AsmId<out detail> ] 335 - SignedInteger<out arguments> 336 - (. code = getOpCode(insbase, detail); 337 - addInstruction(block, new Instruction(code, arguments)); 338 - .) 339 - 340 - | //JUMP INSTRUCTIONS 341 - IF(isInJumpGroup()) 342 - AsmId<out insbase> 343 - [ dot AsmId<out detail> ] 344 - (. Instruction ins = null; 345 - code = getOpCode(insbase, detail); 346 - .) 347 - //Symbolic: 348 - ( AsmId<out id> 349 - (. 350 - ins = new Instruction(code, -1, id); 351 - .) 352 - | Integer<out arguments> (. ins = new Instruction(code, arguments); .) 353 - ) (. addInstruction(block, ins); .) 354 - 355 - 356 - | //ID INSTRUCTIONS 357 - IF(isInIdGroup()) 358 - AsmId<out insbase> 359 - [ dot AsmId<out detail> ] 360 - AsmId<out id> 361 - (. code = getOpCode(insbase, detail); 362 - addInstruction(block, new Instruction(code, id)); 363 - .) 364 - 365 - 366 - | //ID+ARG INSTRUCTIONS 367 - IF(isInIdArgGroup()) 368 - [ at (. justEffect = true; .) 369 - ] 370 - AsmId<out insbase> 371 - ( dot Integer<out arguments> 372 - | (. arguments = 0; .) 373 - ) 374 - AsmId<out id> 375 - (. code = getOpCode(insbase, null); 376 - addInstruction(block, new Instruction(code, arguments, id, justEffect)); 377 - .) 378 - 379 - | //ARG INSTRUCTIONS 380 - IF(isInArgGroup()) 381 - [ at (. justEffect = true; .) 382 - ] 383 - AsmId<out insbase> 384 - ( dot Integer<out arguments> 385 - | (. arguments = 0; .) 386 - ) 387 - (. code = getOpCode(insbase, null); 388 - addInstruction(block, new Instruction(code, arguments, null, justEffect)); 389 - .) 390 - 391 - | //QUALID+ARG INSTRUCTIONS 392 - IF(isInQualidArgGroup()) 393 - [ at (. justEffect = true; .) 394 - ] 395 - AsmId<out insbase> 396 - ( dot Integer<out arguments> 397 - | (. arguments = 0; .) 398 - ) 399 - AsmQualid<out id> 400 - (. code = getOpCode(insbase, null); 401 - addInstruction(block, new Instruction(code, arguments, id, justEffect)); 402 - .) 403 - 404 - | //ERROR PRODUCTION: INVALID INSTRUCTION 405 - AsmId<out insbase> (. SemErr("Invalid assembler instruction \"" + insbase + "\" (" + t + ")."); .) 406 - 407 - . 408 - 409 - AsmId<out string id> (. id = "\\NoId\\"; .) 410 - = 411 - String<out id> 412 - | Id<out id> 413 - | ( mod 414 - | is 415 - | not 416 - // enabled 417 - // disabled 418 - // build 419 - | return 420 - | in 421 - | to 422 - // add 423 - | continue 424 - | break 425 - | or 426 - | and 427 - | xor 428 - | goto 429 - | null 430 - | else 431 - | if 432 - | unless 433 - | new 434 - | while 435 - | until 436 - | for 437 - | foreach 438 - | command 439 - | as 440 - | try 441 - | throw 442 - ) (. id = cache(t.val); .) 443 - . 444 - 445 - AsmQualid<out string qualid> 446 - (. .) 447 - = 448 - AsmId<out qualid> 201 + #file:C:\Users\chris\Documents\GitHub\prx\Prexonite\Compiler\Grammar\Parser.Assembler.atg# 202 + /* 203 + * Prexonite, a scripting engine (Scripting Language -> Bytecode -> Virtual Machine) 204 + * Copyright (C) 2007 Christian "SealedSun" Klauser 205 + * E-mail sealedsun a.t gmail d.ot com 206 + * Web http://www.sealedsun.ch/ 207 + * 208 + * This program is free software; you can redistribute it and/or modify 209 + * it under the terms of the GNU General Public License as published by 210 + * the Free Software Foundation; either version 2 of the License, or 211 + * (at your option) any later version. 212 + * 213 + * Please contact me (sealedsun a.t gmail do.t com) if you need a different license. 214 + * 215 + * This program is distributed in the hope that it will be useful, 216 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 217 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 218 + * GNU General Public License for more details. 219 + * 220 + * You should have received a copy of the GNU General Public License along 221 + * with this program; if not, write to the Free Software Foundation, Inc., 222 + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 223 + */ 224 + 225 + /* ---- Assembler Language ---- */ 226 + 227 + AsmStatementBlock<AstBlock block> 228 + = 229 + lbrace 230 + { 231 + AsmInstruction<block> 232 + } 233 + rbrace 234 + | AsmInstruction<block> semicolon 235 + . 236 + 237 + AsmInstruction<AstBlock block> (. int arguments = 0; 238 + string id; 239 + double dblArg; 240 + string insbase; string detail = null; 241 + bool bolArg; 242 + OpCode code; 243 + bool justEffect = false; 244 + int values; 245 + int rotations; 246 + int index; 247 + ISourcePosition pos; 248 + .) 249 + = 250 + //VARIABLE DECLARATION 251 + (. var isAutodereference = false; .) 252 + ( var | ref (. isAutodereference = true; .) 253 + ) (. pos = GetPosition(); .) 254 + AsmId<out id> 255 + 256 + (. //Store variable 257 + _ensureDefinedLocal(id,id,isAutodereference,pos,false); 258 + .) 259 + { comma (. pos = GetPosition(); .) 260 + AsmId<out id> 261 + (. //Store variable 262 + _ensureDefinedLocal(id,id,isAutodereference,pos,false); 263 + .) 264 + } 265 + | //OP ALIAS INSTRUCTIONS 266 + IF(isInOpAliasGroup()) 267 + AsmId<out insbase> 268 + [ dot AsmId<out detail> ] 269 + (. addOpAlias(block, insbase, detail); .) 270 + | //NULL INSTRUCTIONS 271 + IF(isInNullGroup()) 272 + AsmId<out insbase> 273 + [ dot AsmId<out detail> ] 274 + (. code = getOpCode(insbase, detail); 275 + addInstruction(block, new Instruction(code)); 276 + .) 277 + 278 + | //LABEL 279 + IF( isAsmInstruction("label",null) ) 280 + AsmId<out insbase> 281 + 282 + //Enter label 283 + AsmId<out id> 284 + (. addLabel(block, id); .) 285 + | //NOP/DATA INSTRUCTION 286 + IF(isAsmInstruction("nop", null)) 287 + AsmId<out insbase> (. var ins = new Instruction(OpCode.nop); .) 288 + [ plus AsmId<out id> (. ins = ins.With(id: id); .) 289 + ] 290 + (. addInstruction(block, ins); .) 291 + 292 + | //ROTATE INSTRUCTION 293 + IF(isAsmInstruction("rot", null)) 294 + AsmId<out insbase> 295 + dot Integer<out rotations> 296 + comma Integer<out values> 297 + //Create rot instruction 298 + (. addInstruction(block, Instruction.CreateRotate(rotations, values)); .) 299 + 300 + | //INDIRECT LOCAL CALL BY INDEX 301 + IF(isAsmInstruction("indloci", null)) 302 + [ at (. justEffect = true; .) 303 + ] 304 + AsmId<out insbase> 305 + dot Integer<out arguments> 306 + Integer<out index> 307 + //Create indloci instruction 308 + (. addInstruction(block, Instruction.CreateIndLocI(index, arguments, justEffect)); .) 309 + | //EXCHANGE INSTRUCTION 310 + IF(isAsmInstruction("swap", null)) 311 + AsmId<out insbase> 312 + (. addInstruction(block, Instruction.CreateExchange()); .) 313 + 314 + 315 + | //LOAD CONSTANT . REAL 316 + IF(isAsmInstruction("ldc", "real")) 317 + AsmId<out insbase> 318 + dot 319 + AsmId<out detail> 320 + SignedReal<out dblArg> 321 + (. addInstruction(block, Instruction.CreateConstant(dblArg)); .) 322 + 323 + 324 + | //LOAD CONSTANT . BOOL 325 + IF(isAsmInstruction("ldc", "bool")) 326 + AsmId<out insbase> 327 + dot 328 + AsmId<out detail> 329 + Boolean<out bolArg> 330 + (. addInstruction(block, Instruction.CreateConstant(bolArg)); .) 331 + 332 + 333 + | //INTEGER INSTRUCTIONS 334 + IF(isInIntegerGroup()) 335 + AsmId<out insbase> 336 + [ dot AsmId<out detail> ] 337 + SignedInteger<out arguments> 338 + (. code = getOpCode(insbase, detail); 339 + addInstruction(block, new Instruction(code, arguments)); 340 + .) 341 + 342 + | //JUMP INSTRUCTIONS 343 + IF(isInJumpGroup()) 344 + AsmId<out insbase> 345 + [ dot AsmId<out detail> ] 346 + (. Instruction ins = null; 347 + code = getOpCode(insbase, detail); 348 + .) 349 + //Symbolic: 350 + ( AsmId<out id> 351 + (. 352 + ins = new Instruction(code, -1, id); 353 + .) 354 + | Integer<out arguments> (. ins = new Instruction(code, arguments); .) 355 + ) (. addInstruction(block, ins); .) 356 + 357 + 358 + | //ID INSTRUCTIONS 359 + IF(isInIdGroup()) 360 + AsmId<out insbase> 361 + [ dot AsmId<out detail> ] 362 + AsmId<out id> 363 + (. code = getOpCode(insbase, detail); 364 + addInstruction(block, new Instruction(code, id)); 365 + .) 366 + 367 + 368 + | //ID+ARG INSTRUCTIONS 369 + IF(isInIdArgGroup()) 370 + [ at (. justEffect = true; .) 371 + ] 372 + AsmId<out insbase> 373 + ( dot Integer<out arguments> 374 + | (. arguments = 0; .) 375 + ) 376 + AsmId<out id> 377 + (. code = getOpCode(insbase, null); 378 + addInstruction(block, new Instruction(code, arguments, id, justEffect)); 379 + .) 380 + 381 + | //ARG INSTRUCTIONS 382 + IF(isInArgGroup()) 383 + [ at (. justEffect = true; .) 384 + ] 385 + AsmId<out insbase> 386 + ( dot Integer<out arguments> 387 + | (. arguments = 0; .) 388 + ) 389 + (. code = getOpCode(insbase, null); 390 + addInstruction(block, new Instruction(code, arguments, null, justEffect)); 391 + .) 392 + 393 + | //QUALID+ARG INSTRUCTIONS 394 + IF(isInQualidArgGroup()) 395 + [ at (. justEffect = true; .) 396 + ] 397 + AsmId<out insbase> 398 + ( dot Integer<out arguments> 399 + | (. arguments = 0; .) 400 + ) 401 + AsmQualid<out id> 402 + (. code = getOpCode(insbase, null); 403 + addInstruction(block, new Instruction(code, arguments, id, justEffect)); 404 + .) 405 + 406 + | //ERROR PRODUCTION: INVALID INSTRUCTION 407 + AsmId<out insbase> (. SemErr("Invalid assembler instruction \"" + insbase + "\" (" + t + ")."); .) 408 + 409 + . 410 + 411 + AsmId<out string id> (. id = "\\NoId\\"; .) 412 + = 413 + String<out id> 414 + | Id<out id> 415 + | ( mod 416 + | is 417 + | not 418 + // enabled 419 + // disabled 420 + // build 421 + | return 422 + | in 423 + | to 424 + // add 425 + | continue 426 + | break 427 + | or 428 + | and 429 + | xor 430 + | goto 431 + | null 432 + | else 433 + | if 434 + | unless 435 + | new 436 + | while 437 + | until 438 + | for 439 + | foreach 440 + | command 441 + | as 442 + | try 443 + | throw 444 + ) (. id = cache(t.val); .) 445 + . 446 + 447 + AsmQualid<out string qualid> 448 + (. .) 449 + = 450 + AsmId<out qualid> 451 + . 452 + #file:C:\Users\chris\Documents\GitHub\prx\Prexonite\Compiler\Grammar\Parser.Expression.atg# 453 + /* 454 + * Prexonite, a scripting engine (Scripting Language -> Bytecode -> Virtual Machine) 455 + * Copyright (C) 2007 Christian "SealedSun" Klauser 456 + * E-mail sealedsun a.t gmail d.ot com 457 + * Web http://www.sealedsun.ch/ 458 + * 459 + * This program is free software; you can redistribute it and/or modify 460 + * it under the terms of the GNU General Public License as published by 461 + * the Free Software Foundation; either version 2 of the License, or 462 + * (at your option) any later version. 463 + * 464 + * Please contact me (sealedsun a.t gmail do.t com) if you need a different license. 465 + * 466 + * This program is distributed in the hope that it will be useful, 467 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 468 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 469 + * GNU General Public License for more details. 470 + * 471 + * You should have received a copy of the GNU General Public License along 472 + * with this program; if not, write to the Free Software Foundation, Inc., 473 + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 474 + */ 475 + 476 + 477 + Expr<out AstExpr expr> (. AstConditionalExpression cexpr; expr = _NullNode(GetPosition()); .) 478 + = 479 + AtomicExpr<out expr> 480 + | (. bool isNegated = false; .) 481 + ( if 482 + | unless (. isNegated = true; .) 483 + ) 484 + lpar Expr<out expr> rpar (. cexpr = new AstConditionalExpression(this, expr, isNegated); .) 485 + Expr<out cexpr.IfExpression> 486 + else 487 + Expr<out cexpr.ElseExpression> (. expr = cexpr; .) 488 + . 489 + 490 + 491 + AtomicExpr<out AstExpr expr> 492 + (. AstExpr outerExpr; .) 493 + = 494 + AppendRightExpr<out expr> 495 + { 496 + then 497 + AppendRightExpr<out outerExpr> (. var thenExpr = Create.Call(GetPosition(), EntityRef.Command.Create(Engine.ThenAlias)); 498 + thenExpr.Arguments.Add(expr); 499 + thenExpr.Arguments.Add(outerExpr); 500 + expr = thenExpr; 501 + .) 502 + } 503 + . 504 + 505 + 506 + AppendRightExpr<out AstExpr expr> 507 + (. AstGetSet complex; .) 508 + = 509 + KeyValuePairExpr<out expr> 510 + { 511 + appendright 512 + GetCall<out complex> (. _appendRight(expr,complex); 513 + expr = complex; 514 + .) 515 + } 516 + . 517 + 518 + KeyValuePairExpr<out AstExpr expr> 519 + = 520 + OrExpr<out expr> 521 + [ colon (. AstExpr value; .) 522 + KeyValuePairExpr<out value> (. expr = new AstKeyValuePair(this, expr, value); .) 523 + ] 524 + . 525 + 526 + OrExpr<out AstExpr expr> 527 + (. AstExpr lhs, rhs; .) 528 + = 529 + AndExpr<out lhs> (. expr = lhs; .) 530 + [ or OrExpr<out rhs> (. expr = new AstLogicalOr(this, lhs, rhs); .) 531 + ] 532 + 533 + . 534 + 535 + AndExpr<out AstExpr expr> 536 + (. AstExpr lhs, rhs; .) 537 + = 538 + DeltaExpr<out lhs> (. expr = lhs; .) 539 + [ and AndExpr<out rhs> (. expr = new AstLogicalAnd(this, lhs, rhs); .) 540 + ] 541 + . 542 + 543 + DeltaExpr<out AstExpr expr> 544 + (. AstExpr lhs, rhs; BinaryOperator bop; UnaryOperator uop; .) 545 + = 546 + BitOrExpr<out lhs> (. expr = lhs; .) 547 + { ( deltaleft (. bop = BinaryOperator.DeltaLeft; uop = UnaryOperator.PostDeltaLeft; .) 548 + | deltaright (. bop = BinaryOperator.DeltaRight; uop = UnaryOperator.PostDeltaRight; .) 549 + ) 550 + ( BitOrExpr<out rhs> (. expr = Create.BinaryOperation(GetPosition(), expr, bop, rhs); .) 551 + | (. expr = Create.UnaryOperation(GetPosition(), uop, expr); .) 552 + ) 553 + } 554 + . 555 + 556 + BitOrExpr<out AstExpr expr> 557 + (. AstExpr lhs, rhs; .) 558 + = 559 + BitXorExpr<out lhs> (. expr = lhs; .) 560 + { bitOr BitXorExpr<out rhs> (. expr = Create.BinaryOperation(GetPosition(), expr, BinaryOperator.BitwiseOr, rhs); .) 561 + } 562 + . 563 + 564 + BitXorExpr<out AstExpr expr> 565 + (. AstExpr lhs, rhs; .) 566 + = 567 + BitAndExpr<out lhs> (. expr = lhs; .) 568 + { xor BitAndExpr<out rhs> 569 + (. expr = Create.BinaryOperation(GetPosition(), expr, BinaryOperator.ExclusiveOr, rhs); .) 570 + } 571 + . 572 + 573 + BitAndExpr<out AstExpr expr> 574 + (. AstExpr lhs, rhs; .) 575 + = 576 + NotExpr<out lhs> (. expr = lhs; .) 577 + { bitAnd NotExpr<out rhs> 578 + (. expr = Create.BinaryOperation(GetPosition(), expr, BinaryOperator.BitwiseAnd, rhs); .) 579 + } 580 + . 581 + 582 + NotExpr<out AstExpr expr> 583 + (. AstExpr lhs; bool isNot = false; .) 584 + = 585 + [ not (. isNot = true; .) 586 + ] 587 + EqlExpr<out lhs> (. expr = isNot ? Create.UnaryOperation(GetPosition(), UnaryOperator.LogicalNot, lhs) : lhs; .) 588 + . 589 + 590 + EqlExpr<out AstExpr expr> 591 + (. AstExpr lhs, rhs; BinaryOperator op; .) 592 + = 593 + RelExpr<out lhs> (. expr = lhs; .) 594 + { ( eq (. op = BinaryOperator.Equality; .) 595 + | ne (. op = BinaryOperator.Inequality; .) 596 + ) RelExpr<out rhs> (. expr = Create.BinaryOperation(GetPosition(), expr, op, rhs); .) 597 + } 598 + . 599 + 600 + RelExpr<out AstExpr expr> 601 + (. AstExpr lhs, rhs; BinaryOperator op; .) 602 + = 603 + CoalExpr<out lhs> (. expr = lhs; .) 604 + { ( lt (. op = BinaryOperator.LessThan; .) 605 + | le (. op = BinaryOperator.LessThanOrEqual; .) 606 + | gt (. op = BinaryOperator.GreaterThan; .) 607 + | ge (. op = BinaryOperator.GreaterThanOrEqual; .) 608 + ) CoalExpr<out rhs> (. expr = Create.BinaryOperation(GetPosition(), expr, op, rhs); .) 609 + } 610 + . 611 + 612 + CoalExpr<out AstExpr expr> 613 + (. AstExpr lhs, rhs; AstCoalescence coal = new AstCoalescence(this); .) 614 + = 615 + AddExpr<out lhs> (. expr = lhs; coal.Expressions.Add(lhs); .) 616 + { 617 + coalescence 618 + AddExpr<out rhs> (. expr = coal; coal.Expressions.Add(rhs); .) 619 + } 620 + . 621 + 622 + AddExpr<out AstExpr expr> 623 + (. AstExpr lhs,rhs; BinaryOperator op; .) 624 + = 625 + MulExpr<out lhs> (. expr = lhs; .) 626 + { ( plus (. op = BinaryOperator.Addition; .) 627 + | minus (. op = BinaryOperator.Subtraction; .) 628 + ) MulExpr<out rhs> (. expr = Create.BinaryOperation(GetPosition(), expr, op, rhs); .) 629 + } 630 + . 631 + 632 + MulExpr<out AstExpr expr> 633 + (. AstExpr lhs, rhs; BinaryOperator op; .) 634 + = 635 + PowExpr<out lhs> (. expr = lhs; .) 636 + { ( times (. op = BinaryOperator.Multiply; .) 637 + | div (. op = BinaryOperator.Division; .) 638 + | mod (. op = BinaryOperator.Modulus; .) 639 + ) PowExpr<out rhs> (. expr = Create.BinaryOperation(GetPosition(), expr, op, rhs); .) 640 + } 641 + . 642 + 643 + PowExpr<out AstExpr expr> 644 + (. AstExpr lhs, rhs; .) 645 + = 646 + AssignExpr<out lhs> (. expr = lhs; .) 647 + { pow AssignExpr<out rhs> (. expr = Create.BinaryOperation(GetPosition(), expr, BinaryOperator.Power, rhs); .) 648 + } 649 + . 650 + 651 + AssignExpr<out AstExpr expr> (. AstGetSet assignment; BinaryOperator setModifier = BinaryOperator.None; 652 + AstTypeExpr typeExpr; 653 + ISourcePosition position; 654 + .) 655 + = (. position = GetPosition(); .) 656 + PostfixUnaryExpr<out expr> 657 + (IF(isAssignmentOperator()) 658 + (. assignment = expr as AstGetSet; 659 + if(assignment == null) 660 + { 661 + SemErr(string.Format("Cannot assign to a {0}", 662 + expr.GetType().Name)); 663 + assignment = _NullNode(GetPosition()); //to prevent null references 664 + } 665 + assignment.Call = PCall.Set; 666 + .) 667 + ( 668 + ( assign (. setModifier = BinaryOperator.None; .) 669 + | plus assign (. setModifier = BinaryOperator.Addition; .) 670 + | minus assign (. setModifier = BinaryOperator.Subtraction; .) 671 + | times assign (. setModifier = BinaryOperator.Multiply; .) 672 + | div assign (. setModifier = BinaryOperator.Division; .) 673 + | bitAnd assign (. setModifier = BinaryOperator.BitwiseAnd; .) 674 + | bitOr assign (. setModifier = BinaryOperator.BitwiseOr; .) 675 + | coalescence assign (. setModifier = BinaryOperator.Coalescence; .) 676 + | deltaleft assign (. setModifier = BinaryOperator.DeltaLeft; .) 677 + | deltaright assign (. setModifier = BinaryOperator.DeltaRight; .) 678 + ) Expr<out expr> //(. expr = expr; .) 679 + 680 + | ( tilde assign (. setModifier = BinaryOperator.Cast; .) 681 + )TypeExpr<out typeExpr> (. expr = typeExpr; .) 682 + ) 683 + (. assignment.Arguments.Add(expr); 684 + if(setModifier == BinaryOperator.None) 685 + expr = assignment; 686 + else 687 + expr = Create.ModifyingAssignment(position,assignment,setModifier); 688 + .) 689 + |) 690 + . 691 + 692 + PostfixUnaryExpr<out AstExpr expr> 693 + (. AstTypeExpr type; AstGetSet extension; bool isInverted = false; .) 694 + = 695 + PrefixUnaryExpr<out expr> (. var position = GetPosition(); .) 696 + { tilde TypeExpr<out type> (. expr = new AstTypecast(this, expr, type); .) 697 + | is 698 + [ not (. isInverted = true; .) 699 + ] 700 + TypeExpr<out type> (. expr = new AstTypecheck(this, expr, type); 701 + if(isInverted) 702 + { 703 + ((AstTypecheck)expr).IsInverted = true; 704 + expr = Create.UnaryOperation(position, UnaryOperator.LogicalNot, expr); 705 + } 706 + .) 707 + | inc (. expr = Create.UnaryOperation(position, UnaryOperator.PostIncrement, expr); .) 708 + | dec (. expr = Create.UnaryOperation(position, UnaryOperator.PostDecrement, expr); .) 709 + | GetSetExtension<expr, out extension> 710 + (. expr = extension; .) 711 + } 712 + . 713 + 714 + PrefixUnaryExpr<out AstExpr expr> 715 + (. var prefixes = new Stack<UnaryOperator>(); .) 716 + = (. var position = GetPosition(); .) 717 + { plus 718 + | minus (. prefixes.Push(UnaryOperator.UnaryNegation); .) 719 + | inc (. prefixes.Push(UnaryOperator.PreIncrement); .) 720 + | dec (. prefixes.Push(UnaryOperator.PreDecrement); .) 721 + | deltaleft (. prefixes.Push(UnaryOperator.PreDeltaLeft); .) 722 + | deltaright (. prefixes.Push(UnaryOperator.PreDeltaRight); .) 723 + } 724 + Primary<out expr> 725 + (. while(prefixes.Count > 0) 726 + expr = Create.UnaryOperation(position, prefixes.Pop(), expr); 727 + .) 728 + . 729 + 730 + Primary<out AstExpr expr> 731 + (. expr = null; 732 + .) 733 + = 734 + (. _pushLexerState(Lexer.Asm); .) (. var blockExpr = Create.Block(GetPosition()); 735 + _PushScope(blockExpr); 736 + .) 737 + asm lpar { AsmInstruction<blockExpr> } rpar 738 + (. _popLexerState(); .) (. expr = blockExpr; 739 + _PopScope(blockExpr); 740 + .) 741 + | Constant<out expr> 742 + | ThisExpression<out expr> 743 + | CoroutineCreation<out expr> 744 + | ListLiteral<out expr> 745 + | HashLiteral<out expr> 746 + | LoopExpr<out expr> 747 + | (. AstThrow th; .) 748 + ThrowExpression<out th> (. expr = th; .) 749 + | IF(isLambdaExpression()) 750 + LambdaExpression<out expr> 751 + | LazyExpression<out expr> 752 + | lpar Expr<out expr> rpar 753 + | IF(_isNotNewDecl()) ObjectCreation<out expr> 754 + | GetInitiator<out expr> 755 + | LPopExpr lpar Expr<out expr> (. //This is a hack that makes string interpolation with expressions possible 756 + //The non-verbal token "LPopExpr" (has no character representation) is 757 + //returned by the lexer if the parser has to treat an expression in a special 758 + //way. This includes notifying the lexer when the expression has been parsed, as 759 + //well as injecting the necessary plus operator. 760 + _popLexerState(); _inject(_plus); .) 761 + rpar 762 + . 763 + 764 + Constant<out AstExpr expr> 765 + (. expr = null; int vi; double vr; bool vb; string vs; .) 766 + = 767 + Integer<out vi> (. expr = new AstConstant(this, vi); .) 768 + | Real<out vr> (. expr = new AstConstant(this, vr); .) 769 + | Boolean<out vb> (. expr = new AstConstant(this, vb); .) 770 + | String<out vs> (. expr = new AstConstant(this, vs); .) 771 + | Null (. expr = new AstConstant(this, null); .) 772 + . 773 + 774 + ListLiteral<out AstExpr expr> 775 + (. AstExpr iexpr; 776 + AstListLiteral lst = new AstListLiteral(this); 777 + expr = lst; 778 + bool missingExpr = false; 779 + .) 780 + = 781 + lbrack 782 + [ Expr<out iexpr> (. lst.Elements.Add(iexpr); .) 783 + { comma (. if(missingExpr) 784 + SemErr("Missing expression in list literal (two consecutive commas)."); 785 + .) 786 + ( Expr<out iexpr> (. lst.Elements.Add(iexpr); 787 + missingExpr = false; 788 + .) 789 + | (. missingExpr = true; .) 790 + ) 791 + } 792 + ] 793 + rbrack 794 + . 795 + 796 + HashLiteral<out AstExpr expr> 797 + (. AstExpr iexpr; 798 + AstHashLiteral hash = new AstHashLiteral(this); 799 + expr = hash; 800 + bool missingExpr = false; 801 + .) 802 + = 803 + lbrace 804 + [ Expr<out iexpr> (. hash.Elements.Add(iexpr); .) 805 + { comma (. if(missingExpr) 806 + SemErr("Missing expression in list literal (two consecutive commas)."); 807 + .) 808 + ( Expr<out iexpr> (. hash.Elements.Add(iexpr); 809 + missingExpr = false; 810 + .) 811 + | (. missingExpr = true; .) 812 + ) 813 + } 814 + ] 815 + rbrace 816 + . 817 + 818 + LoopExpr<out AstExpr expr> 819 + (. var dummyBlock = Create.Block(GetPosition()); 820 + _PushScope(dummyBlock); 821 + expr = _NullNode(GetPosition()); 822 + .) 823 + = 824 + ( WhileLoop<dummyBlock> 825 + | ForLoop<dummyBlock> 826 + | ForeachLoop<dummyBlock> 827 + ) (. _PopScope(dummyBlock); 828 + SemErr("Loop expressions are no longer supported."); 829 + .) 830 + . 831 + 832 + 833 + ObjectCreation<out AstExpr expr> 834 + (. AstTypeExpr type; 835 + ArgumentsProxy args; 836 + .) 837 + = 838 + new TypeExpr<out type> (. _fallbackObjectCreation(type, out expr, out args); .) 839 + Arguments<args> 840 + . 841 + 842 + CoroutineCreation<out AstExpr expr> 843 + (. 844 + AstCreateCoroutine cor = new AstCreateCoroutine(this); 845 + AstExpr iexpr; 846 + expr = cor; 847 + .) 848 + = 849 + coroutine Expr<out iexpr> (. cor.Expression = iexpr; .) 850 + [ for Arguments<cor.Arguments> ] 851 + . 852 + 853 + LambdaExpression<out AstExpr expr> 854 + (. PFunction func = TargetApplication.CreateFunction(generateLocalId()); 855 + func.Meta[Application.ImportKey] = target.Function.Meta[Application.ImportKey]; 856 + func.Meta[PFunction.ParentFunctionKey] = target.Function.Id; 857 + Loader.CreateFunctionTarget(func, target, GetPosition()); 858 + CompilerTarget ft = FunctionTargets[func]; 859 + ISourcePosition position; 860 + .) 861 + = 862 + (. position = GetPosition(); .) 863 + ( FormalArg<ft> 864 + | lpar 865 + [ FormalArg<ft> 866 + { comma 867 + FormalArg<ft> 868 + } 869 + ] 870 + rpar 871 + ) 872 + (. _PushScope(ft); .) 873 + implementation 874 + ( lbrace 875 + { Statement<ft.Ast> } 876 + rbrace 877 + | (. AstReturn ret = new AstReturn(this, ReturnVariant.Exit); .) 878 + Expr<out ret.Expression> (. ft.Ast.Add(ret); .) 879 + ) 880 + (. 881 + _PopScope(ft); 882 + if(errors.count == 0) 883 + { 884 + try { 885 + //Emit code for top-level block 886 + Ast[func].EmitCode(FunctionTargets[func],true,StackSemantics.Effect); 887 + FunctionTargets[func].FinishTarget(); 888 + } catch(Exception e) { 889 + SemErr("Exception during compilation of lambda expression.\n" + e); 890 + } 891 + } 892 + 893 + expr = Create.CreateClosure(position,EntityRef.Function.Create(func.Id,func.ParentApplication.Module.Name)); 894 + .) 895 + . 896 + 897 + LazyExpression<out AstExpr expr> 898 + (. PFunction func = TargetApplication.CreateFunction(generateLocalId()); 899 + func.Meta[Application.ImportKey] = target.Function.Meta[Application.ImportKey]; 900 + func.Meta[PFunction.ParentFunctionKey] = target.Function.Id; 901 + Loader.CreateFunctionTarget(func, target, GetPosition()); 902 + CompilerTarget ft = FunctionTargets[func]; 903 + ISourcePosition position; 904 + 905 + //Switch to nested target 906 + _PushScope(ft); 907 + .) 908 + = 909 + lazy (. position = GetPosition(); .) 910 + ( lbrace 911 + { Statement<ft.Ast> } 912 + rbrace 913 + | (. AstReturn ret = new AstReturn(this, ReturnVariant.Exit); .) 914 + Expr<out ret.Expression> (. ft.Ast.Add(ret); .) 915 + ) 916 + (. 917 + //Turn into capture by value 918 + var cap = ft._ToCaptureByValue(let_bindings(ft)); 919 + 920 + //Restore parent target 921 + _PopScope(ft); 922 + 923 + //Finish nested function 924 + if(errors.count == 0) 925 + { 926 + try { 927 + Ast[func].EmitCode(FunctionTargets[func],true,StackSemantics.Effect); 928 + FunctionTargets[func].FinishTarget(); 929 + } catch(Exception e) { 930 + SemErr("Exception during compilation of lazy expression.\n" + e); 931 + } 932 + } 933 + 934 + //Construct expr (appears in the place of lazy expression) 935 + var clo = Create.CreateClosure(position,EntityRef.Function.Create(func.Id,func.ParentApplication.Module.Name)); 936 + var thunk = Create.IndirectCall(position,Create.Reference(position,EntityRef.Command.Create(Engine.ThunkAlias))); 937 + thunk.Arguments.Add(clo); 938 + thunk.Arguments.AddRange(cap(this)); //Add captured values 939 + expr = thunk; 940 + .) 941 + . 942 + 943 + ThrowExpression<out AstThrow th> (. th = new AstThrow(this); .) 944 + = 945 + throw 946 + Expr<out th.Expression> 947 + . 948 + 949 + ThisExpression<out AstExpr expr> (. var position = GetPosition(); 950 + expr = Create.IndirectCall(position,Create.Null(position)); 951 + .) 952 + = 953 + this (. Loader.ReportMessage(Message.Error("Illegal use of reserved keyword `this`.",position,MessageClasses.ThisReserved)); .) 954 + . 955 + 956 + ExplicitTypeExpr<out AstTypeExpr type> (. type = null; .) 957 + = 958 + tilde PrexoniteTypeExpr<out type> 959 + | ClrTypeExpr<out type> 960 + . 961 + 962 + TypeExpr<out AstTypeExpr type> (. type = null; .) 963 + = 964 + PrexoniteTypeExpr<out type> 965 + | ClrTypeExpr<out type> 966 + . 967 + 968 + ClrTypeExpr<out AstTypeExpr type> 969 + (. string id; .) 970 + = 971 + (. StringBuilder typeId = new StringBuilder(); .) 972 + ( doublecolon 973 + | ns (. typeId.Append(t.val); typeId.Append('.'); .) 974 + ) 975 + { ns (. typeId.Append(t.val); typeId.Append('.'); .) 976 + } 977 + Id<out id> (. typeId.Append(id); 978 + type = new AstConstantTypeExpression(this, 979 + "Object(\"" + StringPType.Escape(typeId.ToString()) + "\")"); 980 + .) 981 + . 982 + 983 + PrexoniteTypeExpr<out AstTypeExpr type> 984 + (. string id = null; .) 985 + = 986 + ( Id<out id> | null (. id = NullPType.Literal; .) 987 + ) 988 + (. AstDynamicTypeExpression dType = new AstDynamicTypeExpression(this, id); .) 989 + [ lt 990 + [ TypeExprElement<dType.Arguments> 991 + { comma TypeExprElement<dType.Arguments> } 992 + ] 993 + gt 994 + ] 995 + (. type = dType; .) 996 + . 997 + 998 + TypeExprElement<. List<AstExpr> args .> 999 + (. AstExpr expr; AstTypeExpr type; .) 1000 + = 1001 + Constant<out expr> (. args.Add(expr); .) 1002 + | ExplicitTypeExpr<out type> (. args.Add(type); .) 1003 + | lpar Expr<out expr> rpar (. args.Add(expr); .) 1004 + . 1005 + #file:C:\Users\chris\Documents\GitHub\prx\Prexonite\Compiler\Grammar\Parser.GlobalScope.atg# 1006 + /* 1007 + * Prexonite, a scripting engine (Scripting Language -> Bytecode -> Virtual Machine) 1008 + * Copyright (C) 2007 Christian "SealedSun" Klauser 1009 + * E-mail sealedsun a.t gmail d.ot com 1010 + * Web http://www.sealedsun.ch/ 1011 + * 1012 + * This program is free software; you can redistribute it and/or modify 1013 + * it under the terms of the GNU General Public License as published by 1014 + * the Free Software Foundation; either version 2 of the License, or 1015 + * (at your option) any later version. 1016 + * 1017 + * Please contact me (sealedsun a.t gmail do.t com) if you need a different license. 1018 + * 1019 + * This program is distributed in the hope that it will be useful, 1020 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 1021 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1022 + * GNU General Public License for more details. 1023 + * 1024 + * You should have received a copy of the GNU General Public License along 1025 + * with this program; if not, write to the Free Software Foundation, Inc., 1026 + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 1027 + */ 1028 + 1029 + Prexonite 1030 + = 1031 + DeclarationLevel 1032 + EOF 1033 + . 1034 + 1035 + DeclarationLevel 1036 + (. PFunction func; .) 1037 + = 1038 + { [ (. if(PreflightModeEnabled) 1039 + { 1040 + ViolentlyAbortParse(); 1041 + return; 1042 + } 1043 + .) 1044 + GlobalVariableDefinition 1045 + | MetaAssignment<TargetApplication> 1046 + ] SYNC semicolon 1047 + | (. if(PreflightModeEnabled) 1048 + { 1049 + ViolentlyAbortParse(); 1050 + return; 1051 + } 1052 + .) 1053 + ( Declaration2 1054 + | GlobalCode 1055 + | BuildBlock 1056 + | FunctionDefinition<out func> 1057 + | NamespaceDeclaration 1058 + ) 1059 + } 1060 + . 1061 + 1062 + /*---- Meta information ----*/ 1063 + 1064 + MetaAssignment<IHasMetaTable metaTable> (. string key = null; MetaEntry entry = null; .) 1065 + = 1066 + ( is (. entry = true; .) 1067 + [not (. entry = false; .) 1068 + ] 1069 + GlobalId<out key> 1070 + | not (. entry = false; .) 1071 + GlobalId<out key> 1072 + | 1073 + GlobalId<out key> 1074 + ( enabled (. entry = true; .) 1075 + | disabled (. entry = false; .) 1076 + | MetaExpr<out entry> 1077 + | (. entry = true; .) 1078 + ) 1079 + | add (. MetaEntry subEntry; .) 1080 + MetaExpr<out subEntry> (. if(!subEntry.IsList) subEntry = (MetaEntry) subEntry.List; .) 1081 + to 1082 + GlobalId<out key> (. if(metaTable.Meta.ContainsKey(key)) 1083 + { 1084 + entry = metaTable.Meta[key]; 1085 + entry = entry.AddToList(subEntry.List); 1086 + } 1087 + else 1088 + { 1089 + entry = subEntry; 1090 + } 1091 + .) 1092 + ) (. if(entry == null || key == null) 1093 + SemErr("Meta assignment did not generate an entry."); 1094 + else 1095 + metaTable.Meta[key] = entry; 1096 + .) 1097 + . 1098 + 1099 + MetaExpr<out MetaEntry entry> 1100 + (. bool sw; int i; double r; entry = null; string str; Version v; .) 1101 + = 1102 + Boolean<out sw> (. entry = sw; .) 1103 + | Integer<out i> (. entry = i.ToString(CultureInfo.InvariantCulture); .) 1104 + | Real<out r> (. entry = r.ToString(CultureInfo.InvariantCulture); .) 1105 + | ( String<out str> (. entry = str; .) 1106 + | GlobalQualifiedId<out str> 1107 + (. entry = str; .) 1108 + ) 1109 + [ div 1110 + Version<out v> (. entry = new Prexonite.Modular.ModuleName(entry.Text,v); .) 1111 + ] 1112 + | lbrace (. List<MetaEntry> lst = new List<MetaEntry>(); 1113 + MetaEntry subEntry; 1114 + bool lastWasEmpty = false; 1115 + .) 1116 + [ MetaExpr<out subEntry> (. lst.Add(subEntry); .) 1117 + { comma (. if(lastWasEmpty) 1118 + SemErr("Missing meta expression in list (two consecutive commas)."); 1119 + .) 1120 + ( MetaExpr<out subEntry> 1121 + (. lst.Add(subEntry); 1122 + lastWasEmpty = false; 1123 + .) 1124 + | (. lastWasEmpty = true; .) 1125 + ) 1126 + } 1127 + ] 1128 + rbrace (. entry = (MetaEntry) lst.ToArray(); .) 1129 + . 1130 + 1131 + /* ---- Global variable definition --- */ 1132 + 1133 + GlobalVariableDefinition (. 1134 + string id = null; 1135 + List<string> aliases = new List<string>(); 1136 + string primaryAlias = null; 1137 + VariableDeclaration vari; 1138 + bool isAutodereferenced = false; 1139 + Symbol entry; 1140 + .) 1141 + = 1142 + 1143 + ( var 1144 + | ref (. isAutodereferenced = true; .) 1145 + ) (. var position = GetPosition(); .) 1146 + 1147 + ( GlobalId<out id> (. primaryAlias = id; .) 1148 + [ GlobalVariableAliasList<aliases> ] 1149 + | GlobalVariableAliasList<aliases> 1150 + (. id = null; .) 1151 + ) (. id = _assignPhysicalGlobalVariableSlot(id); 1152 + entry = Symbol.CreateDereference(Symbol.CreateReference( 1153 + EntityRef.Variable.Global.Create(id, TargetModule.Name), position),position); 1154 + if(isAutodereferenced) 1155 + { 1156 + entry = Symbol.CreateDereference(entry, position); 1157 + } 1158 + foreach(var alias in aliases) 1159 + Symbols.Declare(alias, entry); 1160 + DefineGlobalVariable(id,out vari); 1161 + .) 1162 + [ lbrack //Meta block for variables 1163 + [ MetaAssignment<vari> 1164 + { semicolon 1165 + [ MetaAssignment<vari> ] 1166 + } 1167 + ] 1168 + rbrack 1169 + ] (. if(primaryAlias != null && !_suppressPrimarySymbol(vari)) 1170 + Symbols.Declare(primaryAlias, entry); 1171 + .) 1172 + [ (. _pushLexerState(LocalState); .) 1173 + assign (. _PushScope(FunctionTargets[Application.InitializationId]); 1174 + AstExpr expr; 1175 + .) 1176 + Expr<out expr> 1177 + (. _popLexerState(); 1178 + if(errors.count == 0) 1179 + { 1180 + var complex = Create.Call(position, EntityRef.Variable.Global.Create(id,TargetModule.Name) ); 1181 + complex.Call = PCall.Set; 1182 + complex.Arguments.Add(expr); 1183 + target.Ast.Add(complex); 1184 + TargetApplication._RequireInitialization(); 1185 + Loader._EmitPartialInitializationCode(); 1186 + } 1187 + _PopScope(FunctionTargets[Application.InitializationId]); 1188 + .) 1189 + ] 1190 + . 1191 + 1192 + GlobalVariableAliasList<. IList<string> aliases .> 1193 + (. string id; .) 1194 + = 1195 + as GlobalId<out id> (. aliases.Add(id); .) 1196 + { comma 1197 + [ GlobalId<out id> (. aliases.Add(id); .) 1198 + ] 1199 + } 1200 + . 1201 + 1202 + /* ---- Global declaration ---- */ 1203 + 1204 + SymbolPrefix<SymbolBuilder symbol, out bool canBeRef> 1205 + (. canBeRef = true; .) // in order to avoid further errors when this production fails 1206 + = 1207 + ref (. symbol.Dereference(); .) 1208 + | pointer (. symbol.ReferenceTo(); canBeRef = false; .) 1209 + . 1210 + 1211 + EntityFactory<. bool canBeRef, out Func<string,ModuleName,EntityRef> entityFactory .> 1212 + (. entityFactory = null; bool projectNamespace = false; .) 1213 + = 1214 + ( var (. entityFactory = EntityRef.Variable.Global.Create; projectNamespace = true; .) 1215 + | function (. entityFactory = EntityRef.Function.Create; projectNamespace = true; .) 1216 + | command (. entityFactory = (id,_) => EntityRef.Command.Create(id); .) 1217 + | macro 1218 + ( function (. entityFactory = EntityRef.Function.Create; projectNamespace = true; .) 1219 + | command (. entityFactory = (id,_) => EntityRef.MacroCommand.Create(id); .) 1220 + | var (. entityFactory = EntityRef.Variable.Global.Create; projectNamespace = true; .) 1221 + ) 1222 + | (. if(canBeRef) 1223 + { 1224 + projectNamespace = true; 1225 + entityFactory = EntityRef.Variable.Global.Create; 1226 + } 1227 + else 1228 + { 1229 + // entityFactory already set to null 1230 + } 1231 + .) 1232 + ) (. // Transform physical IDs to reside in the current namespace. 1233 + // That way, forward declarations end up using the same physical 1234 + // name as the actual definition. 1235 + if(entityFactory != null && projectNamespace) { 1236 + var actualFactory = entityFactory; 1237 + entityFactory = (id,mn) => actualFactory(_assignPhysicalSlot(id),mn); 1238 + } 1239 + .) 449 1240 . 450 - #file:C:\Users\chris\Source\Repos\prx\Prexonite\Compiler\Grammar\Parser.Expression.atg# 451 - /* 452 - * Prexonite, a scripting engine (Scripting Language -> Bytecode -> Virtual Machine) 453 - * Copyright (C) 2007 Christian "SealedSun" Klauser 454 - * E-mail sealedsun a.t gmail d.ot com 455 - * Web http://www.sealedsun.ch/ 456 - * 457 - * This program is free software; you can redistribute it and/or modify 458 - * it under the terms of the GNU General Public License as published by 459 - * the Free Software Foundation; either version 2 of the License, or 460 - * (at your option) any later version. 461 - * 462 - * Please contact me (sealedsun a.t gmail do.t com) if you need a different license. 463 - * 464 - * This program is distributed in the hope that it will be useful, 465 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 466 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 467 - * GNU General Public License for more details. 468 - * 469 - * You should have received a copy of the GNU General Public License along 470 - * with this program; if not, write to the Free Software Foundation, Inc., 471 - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 472 - */ 473 - 474 - 475 - Expr<out AstExpr expr> (. AstConditionalExpression cexpr; expr = _NullNode(GetPosition()); .) 476 - = 477 - AtomicExpr<out expr> 478 - | (. bool isNegated = false; .) 479 - ( if 480 - | unless (. isNegated = true; .) 481 - ) 482 - lpar Expr<out expr> rpar (. cexpr = new AstConditionalExpression(this, expr, isNegated); .) 483 - Expr<out cexpr.IfExpression> 484 - else 485 - Expr<out cexpr.ElseExpression> (. expr = cexpr; .) 486 - . 487 - 488 - 489 - AtomicExpr<out AstExpr expr> 490 - (. AstExpr outerExpr; .) 491 - = 492 - AppendRightExpr<out expr> 493 - { 494 - then 495 - AppendRightExpr<out outerExpr> (. var thenExpr = Create.Call(GetPosition(), EntityRef.Command.Create(Engine.ThenAlias)); 496 - thenExpr.Arguments.Add(expr); 497 - thenExpr.Arguments.Add(outerExpr); 498 - expr = thenExpr; 499 - .) 500 - } 501 - . 502 - 503 - 504 - AppendRightExpr<out AstExpr expr> 505 - (. AstGetSet complex; .) 506 - = 507 - KeyValuePairExpr<out expr> 508 - { 509 - appendright 510 - GetCall<out complex> (. _appendRight(expr,complex); 511 - expr = complex; 512 - .) 513 - } 514 - . 515 - 516 - KeyValuePairExpr<out AstExpr expr> 517 - = 518 - OrExpr<out expr> 519 - [ colon (. AstExpr value; .) 520 - KeyValuePairExpr<out value> (. expr = new AstKeyValuePair(this, expr, value); .) 521 - ] 522 - . 523 - 524 - OrExpr<out AstExpr expr> 525 - (. AstExpr lhs, rhs; .) 526 - = 527 - AndExpr<out lhs> (. expr = lhs; .) 528 - [ or OrExpr<out rhs> (. expr = new AstLogicalOr(this, lhs, rhs); .) 529 - ] 530 - 531 - . 532 - 533 - AndExpr<out AstExpr expr> 534 - (. AstExpr lhs, rhs; .) 535 - = 536 - BitOrExpr<out lhs> (. expr = lhs; .) 537 - [ and AndExpr<out rhs> (. expr = new AstLogicalAnd(this, lhs, rhs); .) 538 - ] 539 - . 540 - 541 - BitOrExpr<out AstExpr expr> 542 - (. AstExpr lhs, rhs; .) 543 - = 544 - BitXorExpr<out lhs> (. expr = lhs; .) 545 - { bitOr BitXorExpr<out rhs> (. expr =Create.BinaryOperation(GetPosition(), expr, BinaryOperator.BitwiseOr, rhs); .) 546 - } 547 - . 548 - 549 - BitXorExpr<out AstExpr expr> 550 - (. AstExpr lhs, rhs; .) 551 - = 552 - BitAndExpr<out lhs> (. expr = lhs; .) 553 - { xor BitAndExpr<out rhs> 554 - (. expr = Create.BinaryOperation(GetPosition(), expr, BinaryOperator.ExclusiveOr, rhs); .) 555 - } 556 - . 557 - 558 - BitAndExpr<out AstExpr expr> 559 - (. AstExpr lhs, rhs; .) 560 - = 561 - NotExpr<out lhs> (. expr = lhs; .) 562 - { bitAnd NotExpr<out rhs> 563 - (. expr = Create.BinaryOperation(GetPosition(), expr, BinaryOperator.BitwiseAnd, rhs); .) 564 - } 565 - . 566 - 567 - NotExpr<out AstExpr expr> 568 - (. AstExpr lhs; bool isNot = false; .) 569 - = 570 - [ not (. isNot = true; .) 571 - ] 572 - EqlExpr<out lhs> (. expr = isNot ? Create.UnaryOperation(GetPosition(), UnaryOperator.LogicalNot, lhs) : lhs; .) 573 - . 574 - 575 - EqlExpr<out AstExpr expr> 576 - (. AstExpr lhs, rhs; BinaryOperator op; .) 577 - = 578 - RelExpr<out lhs> (. expr = lhs; .) 579 - { ( eq (. op = BinaryOperator.Equality; .) 580 - | ne (. op = BinaryOperator.Inequality; .) 581 - ) RelExpr<out rhs> (. expr = Create.BinaryOperation(GetPosition(), expr, op, rhs); .) 582 - } 583 - . 584 - 585 - RelExpr<out AstExpr expr> 586 - (. AstExpr lhs, rhs; BinaryOperator op; .) 587 - = 588 - CoalExpr<out lhs> (. expr = lhs; .) 589 - { ( lt (. op = BinaryOperator.LessThan; .) 590 - | le (. op = BinaryOperator.LessThanOrEqual; .) 591 - | gt (. op = BinaryOperator.GreaterThan; .) 592 - | ge (. op = BinaryOperator.GreaterThanOrEqual; .) 593 - ) CoalExpr<out rhs> (. expr = Create.BinaryOperation(GetPosition(), expr, op, rhs); .) 594 - } 595 - . 596 - 597 - CoalExpr<out AstExpr expr> 598 - (. AstExpr lhs, rhs; AstCoalescence coal = new AstCoalescence(this); .) 599 - = 600 - AddExpr<out lhs> (. expr = lhs; coal.Expressions.Add(lhs); .) 601 - { 602 - coalescence 603 - AddExpr<out rhs> (. expr = coal; coal.Expressions.Add(rhs); .) 604 - } 605 - . 606 - 607 - AddExpr<out AstExpr expr> 608 - (. AstExpr lhs,rhs; BinaryOperator op; .) 609 - = 610 - MulExpr<out lhs> (. expr = lhs; .) 611 - { ( plus (. op = BinaryOperator.Addition; .) 612 - | minus (. op = BinaryOperator.Subtraction; .) 613 - ) MulExpr<out rhs> (. expr = Create.BinaryOperation(GetPosition(), expr, op, rhs); .) 614 - } 615 - . 616 - 617 - MulExpr<out AstExpr expr> 618 - (. AstExpr lhs, rhs; BinaryOperator op; .) 619 - = 620 - PowExpr<out lhs> (. expr = lhs; .) 621 - { ( times (. op = BinaryOperator.Multiply; .) 622 - | div (. op = BinaryOperator.Division; .) 623 - | mod (. op = BinaryOperator.Modulus; .) 624 - ) PowExpr<out rhs> (. expr = Create.BinaryOperation(GetPosition(), expr, op, rhs); .) 625 - } 626 - . 627 - 628 - PowExpr<out AstExpr expr> 629 - (. AstExpr lhs, rhs; .) 630 - = 631 - AssignExpr<out lhs> (. expr = lhs; .) 632 - { pow AssignExpr<out rhs> (. expr = Create.BinaryOperation(GetPosition(), expr, BinaryOperator.Power, rhs); .) 633 - } 634 - . 635 - 636 - AssignExpr<out AstExpr expr> (. AstGetSet assignment; BinaryOperator setModifier = BinaryOperator.None; 637 - AstTypeExpr typeExpr; 638 - ISourcePosition position; 639 - .) 640 - = (. position = GetPosition(); .) 641 - PostfixUnaryExpr<out expr> 642 - (IF(isAssignmentOperator()) 643 - (. assignment = expr as AstGetSet; 644 - if(assignment == null) 645 - { 646 - SemErr(string.Format("Cannot assign to a {0}", 647 - expr.GetType().Name)); 648 - assignment = _NullNode(GetPosition()); //to prevent null references 649 - } 650 - assignment.Call = PCall.Set; 651 - .) 652 - ( 653 - ( assign (. setModifier = BinaryOperator.None; .) 654 - | plus assign (. setModifier = BinaryOperator.Addition; .) 655 - | minus assign (. setModifier = BinaryOperator.Subtraction; .) 656 - | times assign (. setModifier = BinaryOperator.Multiply; .) 657 - | div assign (. setModifier = BinaryOperator.Division; .) 658 - | bitAnd assign (. setModifier = BinaryOperator.BitwiseAnd; .) 659 - | bitOr assign (. setModifier = BinaryOperator.BitwiseOr; .) 660 - | coalescence assign (. setModifier = BinaryOperator.Coalescence; .) 661 - ) Expr<out expr> //(. expr = expr; .) 662 - 663 - | ( tilde assign (. setModifier = BinaryOperator.Cast; .) 664 - )TypeExpr<out typeExpr> (. expr = typeExpr; .) 665 - ) 666 - (. assignment.Arguments.Add(expr); 667 - if(setModifier == BinaryOperator.None) 668 - expr = assignment; 669 - else 670 - expr = Create.ModifyingAssignment(position,assignment,setModifier); 671 - .) 672 - |) 673 - . 674 - 675 - PostfixUnaryExpr<out AstExpr expr> 676 - (. AstTypeExpr type; AstGetSet extension; bool isInverted = false; .) 677 - = 678 - PrefixUnaryExpr<out expr> (. var position = GetPosition(); .) 679 - { tilde TypeExpr<out type> (. expr = new AstTypecast(this, expr, type); .) 680 - | is 681 - [ not (. isInverted = true; .) 682 - ] 683 - TypeExpr<out type> (. expr = new AstTypecheck(this, expr, type); 684 - if(isInverted) 685 - { 686 - ((AstTypecheck)expr).IsInverted = true; 687 - expr = Create.UnaryOperation(position, UnaryOperator.LogicalNot, expr); 688 - } 689 - .) 690 - | inc (. expr = Create.UnaryOperation(position, UnaryOperator.PostIncrement, expr); .) 691 - | dec (. expr = Create.UnaryOperation(position, UnaryOperator.PostDecrement, expr); .) 692 - | GetSetExtension<expr, out extension> 693 - (. expr = extension; .) 694 - } 695 - . 696 - 697 - PrefixUnaryExpr<out AstExpr expr> 698 - (. var prefixes = new Stack<UnaryOperator>(); .) 699 - = (. var position = GetPosition(); .) 700 - { plus 701 - | minus (. prefixes.Push(UnaryOperator.UnaryNegation); .) 702 - | inc (. prefixes.Push(UnaryOperator.PreIncrement); .) 703 - | dec (. prefixes.Push(UnaryOperator.PreDecrement); .) 704 - } 705 - Primary<out expr> 706 - (. while(prefixes.Count > 0) 707 - expr = Create.UnaryOperation(position, prefixes.Pop(), expr); 708 - .) 709 - . 710 - 711 - Primary<out AstExpr expr> 712 - (. expr = null; 713 - .) 714 - = 715 - (. _pushLexerState(Lexer.Asm); .) (. var blockExpr = Create.Block(GetPosition()); 716 - _PushScope(blockExpr); 717 - .) 718 - asm lpar { AsmInstruction<blockExpr> } rpar 719 - (. _popLexerState(); .) (. expr = blockExpr; 720 - _PopScope(blockExpr); 721 - .) 722 - | Constant<out expr> 723 - | ThisExpression<out expr> 724 - | CoroutineCreation<out expr> 725 - | ListLiteral<out expr> 726 - | HashLiteral<out expr> 727 - | LoopExpr<out expr> 728 - | (. AstThrow th; .) 729 - ThrowExpression<out th> (. expr = th; .) 730 - | IF(isLambdaExpression()) 731 - LambdaExpression<out expr> 732 - | LazyExpression<out expr> 733 - | lpar Expr<out expr> rpar 734 - | IF(_isNotNewDecl()) ObjectCreation<out expr> 735 - | GetInitiator<out expr> 736 - | LPopExpr lpar Expr<out expr> (. //This is a hack that makes string interpolation with expressions possible 737 - //The non-verbal token "LPopExpr" (has no character representation) is 738 - //returned by the lexer if the parser has to treat an expression in a special 739 - //way. This includes notifying the lexer when the expression has been parsed, as 740 - //well as injecting the necessary plus operator. 741 - _popLexerState(); _inject(_plus); .) 742 - rpar 743 - . 744 - 745 - Constant<out AstExpr expr> 746 - (. expr = null; int vi; double vr; bool vb; string vs; .) 747 - = 748 - Integer<out vi> (. expr = new AstConstant(this, vi); .) 749 - | Real<out vr> (. expr = new AstConstant(this, vr); .) 750 - | Boolean<out vb> (. expr = new AstConstant(this, vb); .) 751 - | String<out vs> (. expr = new AstConstant(this, vs); .) 752 - | Null (. expr = new AstConstant(this, null); .) 753 - . 754 - 755 - ListLiteral<out AstExpr expr> 756 - (. AstExpr iexpr; 757 - AstListLiteral lst = new AstListLiteral(this); 758 - expr = lst; 759 - bool missingExpr = false; 760 - .) 761 - = 762 - lbrack 763 - [ Expr<out iexpr> (. lst.Elements.Add(iexpr); .) 764 - { comma (. if(missingExpr) 765 - SemErr("Missing expression in list literal (two consecutive commas)."); 766 - .) 767 - ( Expr<out iexpr> (. lst.Elements.Add(iexpr); 768 - missingExpr = false; 769 - .) 770 - | (. missingExpr = true; .) 771 - ) 772 - } 773 - ] 774 - rbrack 775 - . 776 - 777 - HashLiteral<out AstExpr expr> 778 - (. AstExpr iexpr; 779 - AstHashLiteral hash = new AstHashLiteral(this); 780 - expr = hash; 781 - bool missingExpr = false; 782 - .) 783 - = 784 - lbrace 785 - [ Expr<out iexpr> (. hash.Elements.Add(iexpr); .) 786 - { comma (. if(missingExpr) 787 - SemErr("Missing expression in list literal (two consecutive commas)."); 788 - .) 789 - ( Expr<out iexpr> (. hash.Elements.Add(iexpr); 790 - missingExpr = false; 791 - .) 792 - | (. missingExpr = true; .) 793 - ) 794 - } 795 - ] 796 - rbrace 797 - . 798 - 799 - LoopExpr<out AstExpr expr> 800 - (. var dummyBlock = Create.Block(GetPosition()); 801 - _PushScope(dummyBlock); 802 - expr = _NullNode(GetPosition()); 803 - .) 804 - = 805 - ( WhileLoop<dummyBlock> 806 - | ForLoop<dummyBlock> 807 - | ForeachLoop<dummyBlock> 808 - ) (. _PopScope(dummyBlock); 809 - SemErr("Loop expressions are no longer supported."); 810 - .) 811 - . 812 - 813 - 814 - ObjectCreation<out AstExpr expr> 815 - (. AstTypeExpr type; 816 - ArgumentsProxy args; 817 - .) 818 - = 819 - new TypeExpr<out type> (. _fallbackObjectCreation(type, out expr, out args); .) 820 - Arguments<args> 821 - . 822 - 823 - CoroutineCreation<out AstExpr expr> 824 - (. 825 - AstCreateCoroutine cor = new AstCreateCoroutine(this); 826 - AstExpr iexpr; 827 - expr = cor; 828 - .) 829 - = 830 - coroutine Expr<out iexpr> (. cor.Expression = iexpr; .) 831 - [ for Arguments<cor.Arguments> ] 832 - . 833 - 834 - LambdaExpression<out AstExpr expr> 835 - (. PFunction func = TargetApplication.CreateFunction(generateLocalId()); 836 - func.Meta[Application.ImportKey] = target.Function.Meta[Application.ImportKey]; 837 - func.Meta[PFunction.ParentFunctionKey] = target.Function.Id; 838 - Loader.CreateFunctionTarget(func, target, GetPosition()); 839 - CompilerTarget ft = FunctionTargets[func]; 840 - ISourcePosition position; 841 - .) 842 - = 843 - (. position = GetPosition(); .) 844 - ( FormalArg<ft> 845 - | lpar 846 - [ FormalArg<ft> 847 - { comma 848 - FormalArg<ft> 849 - } 850 - ] 851 - rpar 852 - ) 853 - (. _PushScope(ft); .) 854 - implementation 855 - ( lbrace 856 - { Statement<ft.Ast> } 857 - rbrace 858 - | (. AstReturn ret = new AstReturn(this, ReturnVariant.Exit); .) 859 - Expr<out ret.Expression> (. ft.Ast.Add(ret); .) 860 - ) 861 - (. 862 - _PopScope(ft); 863 - if(errors.count == 0) 864 - { 865 - try { 866 - //Emit code for top-level block 867 - Ast[func].EmitCode(FunctionTargets[func],true,StackSemantics.Effect); 868 - FunctionTargets[func].FinishTarget(); 869 - } catch(Exception e) { 870 - SemErr("Exception during compilation of lambda expression.\n" + e); 871 - } 872 - } 873 - 874 - expr = Create.CreateClosure(position,EntityRef.Function.Create(func.Id,func.ParentApplication.Module.Name)); 875 - .) 876 - . 877 - 878 - LazyExpression<out AstExpr expr> 879 - (. PFunction func = TargetApplication.CreateFunction(generateLocalId()); 880 - func.Meta[Application.ImportKey] = target.Function.Meta[Application.ImportKey]; 881 - func.Meta[PFunction.ParentFunctionKey] = target.Function.Id; 882 - Loader.CreateFunctionTarget(func, target, GetPosition()); 883 - CompilerTarget ft = FunctionTargets[func]; 884 - ISourcePosition position; 885 - 886 - //Switch to nested target 887 - _PushScope(ft); 888 - .) 889 - = 890 - lazy (. position = GetPosition(); .) 891 - ( lbrace 892 - { Statement<ft.Ast> } 893 - rbrace 894 - | (. AstReturn ret = new AstReturn(this, ReturnVariant.Exit); .) 895 - Expr<out ret.Expression> (. ft.Ast.Add(ret); .) 896 - ) 897 - (. 898 - //Turn into capture by value 899 - var cap = ft._ToCaptureByValue(let_bindings(ft)); 900 - 901 - //Restore parent target 902 - _PopScope(ft); 903 - 904 - //Finish nested function 905 - if(errors.count == 0) 906 - { 907 - try { 908 - Ast[func].EmitCode(FunctionTargets[func],true,StackSemantics.Effect); 909 - FunctionTargets[func].FinishTarget(); 910 - } catch(Exception e) { 911 - SemErr("Exception during compilation of lazy expression.\n" + e); 912 - } 913 - } 914 - 915 - //Construct expr (appears in the place of lazy expression) 916 - var clo = Create.CreateClosure(position,EntityRef.Function.Create(func.Id,func.ParentApplication.Module.Name)); 917 - var thunk = Create.IndirectCall(position,Create.Reference(position,EntityRef.Command.Create(Engine.ThunkAlias))); 918 - thunk.Arguments.Add(clo); 919 - thunk.Arguments.AddRange(cap(this)); //Add captured values 920 - expr = thunk; 921 - .) 922 - . 923 - 924 - ThrowExpression<out AstThrow th> (. th = new AstThrow(this); .) 925 - = 926 - throw 927 - Expr<out th.Expression> 928 - . 929 - 930 - ThisExpression<out AstExpr expr> (. var position = GetPosition(); 931 - expr = Create.IndirectCall(position,Create.Null(position)); 932 - .) 933 - = 934 - this (. Loader.ReportMessage(Message.Error("Illegal use of reserved keyword `this`.",position,MessageClasses.ThisReserved)); .) 935 - . 936 - 937 - ExplicitTypeExpr<out AstTypeExpr type> (. type = null; .) 938 - = 939 - tilde PrexoniteTypeExpr<out type> 940 - | ClrTypeExpr<out type> 941 - . 942 - 943 - TypeExpr<out AstTypeExpr type> (. type = null; .) 944 - = 945 - PrexoniteTypeExpr<out type> 946 - | ClrTypeExpr<out type> 947 - . 948 - 949 - ClrTypeExpr<out AstTypeExpr type> 950 - (. string id; .) 951 - = 952 - (. StringBuilder typeId = new StringBuilder(); .) 953 - ( doublecolon 954 - | ns (. typeId.Append(t.val); typeId.Append('.'); .) 955 - ) 956 - { ns (. typeId.Append(t.val); typeId.Append('.'); .) 957 - } 958 - Id<out id> (. typeId.Append(id); 959 - type = new AstConstantTypeExpression(this, 960 - "Object(\"" + StringPType.Escape(typeId.ToString()) + "\")"); 961 - .) 962 - . 963 - 964 - PrexoniteTypeExpr<out AstTypeExpr type> 965 - (. string id = null; .) 966 - = 967 - ( Id<out id> | null (. id = NullPType.Literal; .) 968 - ) 969 - (. AstDynamicTypeExpression dType = new AstDynamicTypeExpression(this, id); .) 970 - [ lt 971 - [ TypeExprElement<dType.Arguments> 972 - { comma TypeExprElement<dType.Arguments> } 973 - ] 974 - gt 975 - ] 976 - (. type = dType; .) 977 - . 978 - 979 - TypeExprElement<. List<AstExpr> args .> 980 - (. AstExpr expr; AstTypeExpr type; .) 981 - = 982 - Constant<out expr> (. args.Add(expr); .) 983 - | ExplicitTypeExpr<out type> (. args.Add(type); .) 984 - | lpar Expr<out expr> rpar (. args.Add(expr); .) 1241 + 1242 + Declaration2 1243 + (. ModuleName module = TargetModule.Name; 1244 + var builder = new SymbolBuilder(); 1245 + Func<string,ModuleName,EntityRef> entityFactory; 1246 + bool canBeRef = false; 1247 + .) 1248 + = 1249 + SYNC 1250 + declare 1251 + ( { SymbolPrefix<builder, out canBeRef> } 1252 + EntityFactory<canBeRef, out entityFactory> 1253 + (. if(entityFactory == null) builder.AutoDereferenceEnabled = false; .) // For aliases, don't wrap in dereference 1254 + [colon] 1255 + DeclarationInstance2<entityFactory,module,builder.Clone(),preventOverride:false> 1256 + { comma [ DeclarationInstance2<entityFactory,module,builder.Clone(),preventOverride:false> ] } 1257 + semicolon 1258 + | lbrace 1259 + [ uusing ModuleName<out module> ] 1260 + { (. var runBuilder = builder.Clone(); .) 1261 + { SymbolPrefix<builder, out canBeRef> } 1262 + EntityFactory<canBeRef, out entityFactory> 1263 + (. if(entityFactory == null) runBuilder.AutoDereferenceEnabled = false; .) // For aliases, don't wrap in dereference 1264 + colon 1265 + DeclarationInstance2<entityFactory,module,runBuilder.Clone(),preventOverride:true> 1266 + { comma [ DeclarationInstance2<entityFactory,module,runBuilder.Clone(),preventOverride:true> ] } 1267 + } 1268 + rbrace 1269 + | lpar (. bool wasComma = false; .) 1270 + [ MExprBasedDeclaration 1271 + { comma (. if(wasComma) 1272 + { 1273 + Loader.ReportMessage(Message.Error("Double comma in declaration sequence.",GetPosition(),MessageClasses.DuplicateComma)); 1274 + } 1275 + wasComma = true; 1276 + .) 1277 + [ MExprBasedDeclaration 1278 + (. wasComma = false; .) 1279 + ] 1280 + } 1281 + ] 1282 + rpar [ semicolon ] 1283 + ) 1284 + . 1285 + 1286 + MExprBasedDeclaration (. string alias; 1287 + MExpr expr; 1288 + .) 1289 + = 1290 + Id<out alias> assign MExpr<out expr> 1291 + (. Symbol s = _parseSymbol(expr); 1292 + Symbols.Declare(alias,s); 1293 + .) 1294 + . 1295 + 1296 + MessageDirective<. 1297 + Func<string,ModuleName,EntityRef> entityFactory, 1298 + ModuleName module, 1299 + SymbolBuilder builder, 1300 + [CanBeNull] out string lhsId, 1301 + MessageSeverity severity, 1302 + bool preventOverride = false .> 1303 + (. string message; 1304 + string messageClass = null; 1305 + ISourcePosition position = GetPosition(); 1306 + string file; 1307 + int line; 1308 + int column; 1309 + .) 1310 + = 1311 + lpar 1312 + (null|String<out messageClass>) 1313 + [ colon 1314 + ( null 1315 + | String<out file> colon Integer<out line> colon Integer<out column> 1316 + (. position = new SourcePosition(file,line,column); .) 1317 + ) 1318 + ] 1319 + comma 1320 + String<out message> 1321 + comma (. builder.AddMessage(Message.Create(severity,message,position,messageClass)); .) 1322 + SymbolDirective<entityFactory,module,builder,out lhsId,preventOverride:preventOverride> 1323 + rpar 1324 + . 1325 + 1326 + SymbolDirective<. Func<string,ModuleName,EntityRef> entityFactory, 1327 + [CanBeNull] ModuleName module, 1328 + SymbolBuilder builder, 1329 + [CanBeNull] out string lhsId, 1330 + bool preventOverride = false .> 1331 + (. lhsId = null; .) 1332 + = 1333 + null (. /* don't do anything */ .) 1334 + | ( ref (. builder.Dereference(); .) 1335 + | pointer (. builder.ReferenceTo(); .) 1336 + ) 1337 + SymbolDirective<entityFactory,module,builder,out lhsId,preventOverride:preventOverride> 1338 + | IF(isSymbolDirective("INFO")) 1339 + id 1340 + MessageDirective<entityFactory,module,builder, out lhsId,MessageSeverity.Info,preventOverride:preventOverride> 1341 + | IF(isSymbolDirective("WARN")) 1342 + id 1343 + MessageDirective<entityFactory,module,builder, out lhsId,MessageSeverity.Warning,preventOverride:preventOverride> 1344 + | IF(isSymbolDirective("ERROR")) 1345 + id 1346 + MessageDirective<entityFactory,module,builder, out lhsId,MessageSeverity.Error,preventOverride:preventOverride> 1347 + | (. ISourcePosition position = GetPosition(); .) 1348 + Id<out lhsId> 1349 + [ div ModuleName<out module> 1350 + (. if(preventOverride) 1351 + { 1352 + Loader.ReportMessage(Message.Error( 1353 + "Specification of module name illegal at this point.", 1354 + position , 1355 + MessageClasses.UnexpectedModuleName)); 1356 + // Let control fall through, this is not a fatal error, 1357 + // just an enforcement of a stylistic rule. 1358 + } 1359 + .) 1360 + ] (. if(entityFactory != null) 1361 + { 1362 + builder.Entity = entityFactory(lhsId,module); 1363 + } 1364 + .) 1365 + . 1366 + 1367 + DeclarationInstance2<. 1368 + Func<string,ModuleName,EntityRef> entityFactory, 1369 + ModuleName module, 1370 + SymbolBuilder builder, 1371 + bool preventOverride = false .> 1372 + (. string lhsId; 1373 + string rhsId; 1374 + ISourcePosition position = GetPosition(); 1375 + .) 1376 + = 1377 + SymbolDirective<entityFactory,module,builder,out lhsId,preventOverride:preventOverride> 1378 + (. rhsId = lhsId; .) 1379 + [ as Id<out rhsId> ] 1380 + (. 1381 + if(entityFactory == null) 1382 + { 1383 + // We are declaring an alias to an existing symbol 1384 + Symbol existing; 1385 + if(lhsId == null) 1386 + { 1387 + if(rhsId == null) 1388 + { 1389 + Loader.ReportMessage(Message.Error( 1390 + "This symbol declaration requires an alias (e.g., `as theAlias`)", 1391 + GetPosition(), 1392 + MessageClasses.SymbolAliasMissing)); 1393 + // Since there is no name involved, not acting on this 1394 + // statement will not cause further errors 1395 + } 1396 + else 1397 + { 1398 + Symbols.Declare(rhsId, builder.WrapSymbol(null)); 1399 + } 1400 + } 1401 + else if(Symbols.TryGet(lhsId,out existing)) 1402 + { 1403 + // Declare $rhsId as an alias for the symbol that $lhsId points to 1404 + Symbols.Declare(rhsId, builder.WrapSymbol(existing)); 1405 + } 1406 + else 1407 + { 1408 + var msg = Message.Error(string.Format(Resources.Parser_Could_not_find_previous_declaration, lhsId), 1409 + position,MessageClasses.SymbolNotResolved); 1410 + // We report the message AND store it as a message symbol. 1411 + // That way, the symbol is at least declared, avoiding a spurious 1412 + // symbol not found message. 1413 + Loader.ReportMessage(msg); 1414 + Symbols.Declare(rhsId, Symbol.CreateMessage(msg,Symbol.CreateNil(msg.Position))); 1415 + } 1416 + } 1417 + else 1418 + { 1419 + 1420 + if(lhsId == null) 1421 + { 1422 + // For instance `declare var error(...,null)` can get us here 1423 + var msg = Message.Error("Entity name missing for declaration of a fresh symbol", 1424 + GetPosition(), 1425 + MessageClasses.EntityNameMissing); 1426 + Loader.ReportMessage(msg); 1427 + // Also create an error symbol for the alias (if one was declared) 1428 + if(rhsId != null) 1429 + Symbols.Declare(rhsId, Symbol.CreateMessage(msg,Symbol.CreateNil(msg.Position))); 1430 + } 1431 + else 1432 + { 1433 + // Use the builder to create a new symbol. 1434 + Symbols.Declare(rhsId, builder.ToSymbol()); 1435 + } 1436 + } 1437 + .) 1438 + . 1439 + 1440 + ModuleName<out ModuleName moduleName> 1441 + (. _pushLexerState(Lexer.YYINITIAL); //need global scope for Version 1442 + string id; 1443 + Version version = null; 1444 + .) 1445 + = 1446 + Id<out id> 1447 + [ div 1448 + Version<out version> 1449 + ] (. _popLexerState(); 1450 + moduleName = Loader.Cache[new ModuleName(id,version ?? new Version(0,0))]; 1451 + .) 1452 + . 1453 + 1454 + /* ---- Build Block ---- */ 1455 + 1456 + BuildBlock 1457 + = 1458 + SYNC build (. PFunction func = TargetApplication.CreateFunction(); 1459 + CompilerTarget buildBlockTarget = 1460 + Loader.CreateFunctionTarget(func, sourcePosition: GetPosition()); 1461 + _PushScope(buildBlockTarget); 1462 + Loader.DeclareBuildBlockCommands(target); 1463 + _pushLexerState(LocalState); 1464 + .) 1465 + 1466 + [ does ] 1467 + StatementBlock<target.Ast> 1468 + 1469 + (. _popLexerState(); 1470 + _PopScope(buildBlockTarget); 1471 + _compileAndExecuteBuildBlock(buildBlockTarget); 1472 + .) 1473 + . 1474 + 1475 + /* ---- Global Code ---- */ 1476 + 1477 + GlobalCode (. PFunction func = TargetApplication._InitializationFunction; 1478 + CompilerTarget ft = FunctionTargets[func]; 1479 + ISourcePosition position; 1480 + if(ft == null) 1481 + throw new PrexoniteException("Internal compilation error: InitializeFunction got lost."); 1482 + .) 1483 + = 1484 + (. _PushScope(ft); 1485 + _pushLexerState(LocalState); 1486 + .) 1487 + lbrace (. position = GetPosition(); .) 1488 + { Statement<target.Ast> } 1489 + rbrace 1490 + (. 1491 + try { 1492 + if(errors.count == 0) 1493 + { 1494 + TargetApplication._RequireInitialization(); 1495 + Loader._EmitPartialInitializationCode(); 1496 + } 1497 + } catch(Exception e) { 1498 + Loader.ReportMessage(Message.Error( 1499 + "Exception during compilation of initialization code.\n" + e, 1500 + position, 1501 + MessageClasses.ExceptionDuringCompilation)); 1502 + } finally { 1503 + //Symbols defined in this block are not available to further global code blocks 1504 + target.Symbols.ClearLocalDeclarations(); 1505 + _PopScope(ft); 1506 + _popLexerState(); 1507 + } 1508 + .) 1509 + . 1510 + 1511 + /* ---- Function definition ---- */ 1512 + 1513 + FunctionAliasList<. IList<string> aliases .> 1514 + (. String id; .) 1515 + = 1516 + as Id<out id> (. aliases.Add(id); .) 1517 + { comma 1518 + [ Id<out id> (. aliases.Add(id); .) 1519 + ] 1520 + } 1521 + . 1522 + 1523 + FunctionDefinition<out PFunction func> 1524 + (. 1525 + string primaryAlias = null; 1526 + List<string> funcAliases = new List<string>(); 1527 + string id = null; //The logical id (given in the source code) 1528 + string funcId; //The "physical" function id 1529 + bool isNested = target != null; 1530 + bool isCoroutine = false; 1531 + bool isMacro = false; 1532 + bool isLazy = false; 1533 + PFunction derBody = null; //The derived (coroutine/lazy) body function (carries a different name) 1534 + PFunction derStub = null; //The derived (coroutine/lazy) stub function (carries the name(s) specified) 1535 + string derId; //The name of the derived stub 1536 + CompilerTarget ct = null; //The compiler target for the function (as mentioned in the source code) 1537 + CompilerTarget cst = null; //The compiler target for a stub (coroutine/lazy) 1538 + Symbol symEntry = null; 1539 + ISourcePosition position; 1540 + bool missingArg = false; //Allow trailing comma, but not (,,) in formal arg list 1541 + .) 1542 + = 1543 + ( lazy [function] (. isLazy = true; .) 1544 + | function 1545 + | coroutine (. isCoroutine = true; .) 1546 + | macro [function] (. isMacro = true; .) 1547 + ) (. position = GetPosition(); .) 1548 + ( Id<out id> (. primaryAlias = id; .) 1549 + [ FunctionAliasList<funcAliases> ] 1550 + | FunctionAliasList<funcAliases> 1551 + ) (. 1552 + funcId = _assignPhysicalFunctionSlot(id); 1553 + if(Engine.StringsAreEqual(id, @"\init")) //Treat "\init" specially (that's the initialization code) 1554 + { 1555 + func = TargetApplication._InitializationFunction; 1556 + if(isNested) 1557 + Loader.ReportMessage(Message.Error("Cannot define initialization code inside another function.",position,MessageClasses.IllegalInitializationFunction)); 1558 + if(isCoroutine) 1559 + Loader.ReportMessage(Message.Error("Cannot define initialization code as a coroutine.",position,MessageClasses.IllegalInitializationFunction)); 1560 + if(isLazy) 1561 + Loader.ReportMessage(Message.Error("Cannot define initialization code as a lazy function.",position,MessageClasses.IllegalInitializationFunction)); 1562 + if(isMacro) 1563 + Loader.ReportMessage(Message.Error("Cannot define initialization code as a macro function.",position,MessageClasses.IllegalInitializationFunction)); 1564 + } 1565 + else 1566 + { 1567 + var localId = id; 1568 + 1569 + if(isNested) 1570 + { 1571 + if(isMacro) 1572 + Loader.ReportMessage(Message.Error("Inner macros are illegal. Macros must be top-level.",position,MessageClasses.InnerMacrosIllegal)); 1573 + 1574 + funcId = generateLocalId(funcId ?? "inner"); 1575 + 1576 + if(string.IsNullOrEmpty(localId)) 1577 + { 1578 + //Create shadow name 1579 + localId = generateLocalId(id ?? "inner"); 1580 + } 1581 + var innerSym = _ensureDefinedLocal(localId, localId, true, position,true); 1582 + foreach(var alias in funcAliases) 1583 + Symbols.Declare(alias, innerSym); 1584 + 1585 + } 1586 + 1587 + //Add function to application 1588 + if(TargetApplication.Functions.Contains(funcId) && !TargetApplication.Meta.GetDefault(Application.AllowOverridingKey,true)) 1589 + SemErr(t,"Application " + TargetApplication.Id + " does not allow overriding of function " + funcId + "."); 1590 + TargetApplication.Functions.Remove(funcId); 1591 + 1592 + func = TargetApplication.CreateFunction(funcId); 1593 + 1594 + if(isNested) 1595 + { 1596 + func.Meta[PFunction.LogicalIdKey] = localId; 1597 + if(isLazy) 1598 + mark_as_let(target.Function,localId); 1599 + } 1600 + 1601 + Loader.CreateFunctionTarget(func, target, position); 1602 + } 1603 + CompilerTarget ft = FunctionTargets[func]; 1604 + 1605 + //Generate derived stub 1606 + if(isCoroutine || isLazy) 1607 + { 1608 + derStub = func; 1609 + 1610 + //Create derived body function 1611 + derId = ft.GenerateLocalId(); 1612 + derBody = TargetApplication.CreateFunction(derId); 1613 + Loader.CreateFunctionTarget(derBody, ft, position); 1614 + derBody.Meta[PFunction.LogicalIdKey] = id ?? funcId; 1615 + if(isCoroutine) 1616 + { 1617 + derBody.Meta[PFunction.VolatileKey] = true; 1618 + derBody.Meta[PFunction.DeficiencyKey] = "Coroutine body can only be executed by VM anyway."; 1619 + derBody.Meta[Coroutine.IsCoroutineKey] = true; 1620 + } 1621 + 1622 + //Swap compiler target references 1623 + // -> Compile source code into derived body 1624 + // -> Let derived stub have the physical function id 1625 + ct = FunctionTargets[derBody]; 1626 + cst = ft; 1627 + } 1628 + 1629 + if(isNested) //Link to parent in case of a nested function 1630 + { 1631 + if(isLazy) 1632 + ft = ct; 1633 + } 1634 + .) 1635 + [ lpar 1636 + [ FormalArg<ft> 1637 + { comma (. if(missingArg) 1638 + { 1639 + SemErr("Missing formal argument (two consecutive commas)."); 1640 + } 1641 + .) 1642 + ( FormalArg<ft> (. missingArg = false; .) 1643 + | (. missingArg = true; .) 1644 + ) 1645 + } 1646 + ] 1647 + rpar 1648 + | FormalArg<ft> 1649 + { [comma] 1650 + FormalArg<ft> 1651 + } 1652 + ] (. if(isNested && isLazy) // keep this assignment for maintainability 1653 + // ReSharper disable RedundantAssignment 1654 + ft = cst; 1655 + // ReSharper restore RedundantAssignment 1656 + 1657 + if(target == null && 1658 + (!object.ReferenceEquals(func, TargetApplication._InitializationFunction)) && 1659 + (!isNested)) 1660 + { 1661 + //Add the name to the symbol table 1662 + symEntry = Symbol.CreateReference(EntityRef.Function.Create(func.Id, TargetModule.Name),GetPosition()); 1663 + if(isMacro) 1664 + symEntry = Symbol.CreateExpand(symEntry); 1665 + else 1666 + symEntry = Symbol.CreateDereference(symEntry); 1667 + 1668 + foreach(var alias in funcAliases) 1669 + Symbols.Declare(alias, symEntry); 1670 + 1671 + //Store the original (logical id, mentioned in the source code) 1672 + func.Meta[PFunction.LogicalIdKey] = id ?? funcId; 1673 + } 1674 + else 1675 + { 1676 + primaryAlias = null; 1677 + } 1678 + 1679 + //Target the derived (coroutine/lazy) body instead of the stub 1680 + if(isCoroutine || isLazy) 1681 + func = derBody; 1682 + .) 1683 + [ (. _pushLexerState(Lexer.YYINITIAL); .) 1684 + lbrack 1685 + [ MetaAssignment<func> 1686 + { semicolon 1687 + [MetaAssignment<func>] 1688 + } 1689 + ] 1690 + (. _popLexerState(); .) 1691 + rbrack 1692 + ] 1693 + (. 1694 + 1695 + if(primaryAlias != null && !_suppressPrimarySymbol(func)) 1696 + Symbols.Declare(primaryAlias, symEntry); 1697 + 1698 + //Imprint certain meta keys from parent function 1699 + if(isNested) 1700 + { 1701 + func.Meta[Application.ImportKey] = target.Function.Meta[Application.ImportKey]; 1702 + } 1703 + 1704 + //Copy stub parameters to body of lazy function 1705 + if(isLazy && !isNested) 1706 + { 1707 + foreach(var kvp in cst.Symbols.LocalDeclarations) 1708 + { 1709 + var paramId = kvp.Key; 1710 + var s = kvp.Value.ToSymbolEntry(); 1711 + //Lazy functions cannot have ref parameters 1712 + if(s.Interpretation != SymbolInterpretations.LocalObjectVariable) 1713 + SemErr("Lazy functions can only have value parameters (ref is not allowed)"); 1714 + ct.Function.Parameters.Add(s.InternalId); 1715 + ct.Symbols.Declare(paramId, kvp.Value); 1716 + } 1717 + } 1718 + .) 1719 + [ (. _pushLexerState(Lexer.Transfer); 1720 + ISourcePosition importKeywordPosition; 1721 + var importBuilder = SymbolStoreBuilder.Create(); 1722 + .) 1723 + namespace 1724 + ImportContextualKeyword<out importKeywordPosition> 1725 + NsTransferSpec<importBuilder> 1726 + { 1727 + comma 1728 + NsTransferSpec<importBuilder> 1729 + } 1730 + (. { // Copy imported symbols to import scope 1731 + var it = FunctionTargets[func]; 1732 + foreach(var entry in importBuilder.ToSymbolStore()) 1733 + it.ImportScope.Declare(entry.Key,entry.Value); 1734 + } 1735 + _popLexerState(); 1736 + .) 1737 + ] 1738 + (. 1739 + if(isLazy || isCoroutine) 1740 + { 1741 + //Push the stub, because it is the lexical parent of the body 1742 + _PushScope(cst); 1743 + } 1744 + _PushScope(FunctionTargets[func]); 1745 + Debug.Assert(target != null); // Mostly to tell ReSharper that target is not null. 1746 + _pushLexerState(LocalState); 1747 + if(isMacro) 1748 + target.SetupAsMacro(); 1749 + .) 1750 + ( does 1751 + StatementBlock<target.Ast> 1752 + | lbrace { Statement<target.Ast> } 1753 + rbrace 1754 + | IF(isFollowedByStatementBlock()) 1755 + implementation 1756 + StatementBlock<target.Ast> 1757 + | ( assign | implementation ) (. AstReturn ret = new AstReturn(this, ReturnVariant.Exit); .) 1758 + Expr<out ret.Expression> (. target.Ast.Add(ret); .) 1759 + semicolon 1760 + ) (. _popLexerState(); 1761 + _PopScope(FunctionTargets[func]); 1762 + if(isLazy || isCoroutine) 1763 + { 1764 + _PopScope(cst); 1765 + } 1766 + //Compile AST 1767 + if(errors.count == 0) 1768 + { 1769 + if(Engine.StringsAreEqual(func.Id, @"\init")) 1770 + { 1771 + try { 1772 + TargetApplication._RequireInitialization(); 1773 + Loader._EmitPartialInitializationCode(); 1774 + //Initialize function gets finished at the end of Loader.Load 1775 + } catch(Exception e) { 1776 + SemErr("Exception during compilation of initialization code." + e); 1777 + } 1778 + } 1779 + else 1780 + { 1781 + try { 1782 + //Apply compiler hooks for all kinds of functions (lazy/coroutine/macro) 1783 + FunctionTargets[func].ExecuteCompilerHooks(); 1784 + //Emit code for top-level block 1785 + Ast[func].EmitCode(FunctionTargets[func], true, StackSemantics.Effect); 1786 + FunctionTargets[func].FinishTarget(); 1787 + } catch(Exception e) { 1788 + SemErr("Exception during compilation of function body of " + id + ". " + e); 1789 + } 1790 + } 1791 + 1792 + if(isCoroutine) 1793 + { 1794 + try { 1795 + //Stub has to be returned into the physical slot mentioned in the source code 1796 + func = derStub; 1797 + //Generate code for the stub 1798 + AstCreateCoroutine crcor = new AstCreateCoroutine(this); 1799 + crcor.Expression = Create.CreateClosure(position,EntityRef.Function.Create(derBody.Id,derBody.ParentApplication.Module.Name)); 1800 + 1801 + AstReturn retst = new AstReturn(this, ReturnVariant.Exit); 1802 + retst.Expression = crcor; 1803 + cst.Ast.Add(retst); 1804 + //Emit code for top-level block 1805 + cst.Ast.EmitCode(cst,true,StackSemantics.Effect); 1806 + cst.FinishTarget(); 1807 + } catch(Exception e) { 1808 + SemErr("Exception during compilation of coroutine stub for " + id + ". " + e); 1809 + } 1810 + } 1811 + else if(isLazy) 1812 + { 1813 + derStub.Meta[PFunction.LazyKey] = true; 1814 + derStub.Meta["strict"] = true; 1815 + 1816 + //Stub has to be returned into the physical slot mentioned in the source code 1817 + func = derStub; 1818 + 1819 + //Generate code for the stub 1820 + AstExpr retVal; 1821 + 1822 + if(isNested) 1823 + { 1824 + //Nested lazy functions need a stub to capture their environment by value (handled by NestedFunction) 1825 + 1826 + //Generate stub code 1827 + retVal = Create.CreateClosure(position, EntityRef.Function.Create(ct.Function.Id, 1828 + ct.Function.ParentApplication.Module.Name)); 1829 + 1830 + //Inject asthunk-conversion code into body 1831 + var inject = derStub.Parameters.Select(par => 1832 + { 1833 + var getParam = Create.Call(position, EntityRef.Variable.Local.Create(par)); 1834 + var asThunkCall = Create.Call(position, EntityRef.Variable.Command.Create(Engine.AsThunkAlias)); 1835 + asThunkCall.Arguments.Add(getParam); 1836 + var setParam = Create.Call(position, EntityRef.Variable.Local.Create(par)); 1837 + setParam.Arguments.Add(asThunkCall); 1838 + return (AstNode) setParam; 1839 + }); 1840 + ct.Ast.InsertRange(0,inject); 1841 + } 1842 + else 1843 + { 1844 + //Global lazy functions don't technically need a stub. Might be removed later on 1845 + var call = Create.Call(position,EntityRef.Function.Create(ct.Function.Id, TargetModule.Name)); 1846 + 1847 + //Generate code for arguments (each wrapped in a `asThunk` command call) 1848 + foreach(var par in derStub.Parameters) 1849 + { 1850 + var getParam = Create.Call(position, EntityRef.Variable.Local.Create(par)); 1851 + 1852 + var asThunkCall = Create.Call(position, EntityRef.Command.Create(Engine.AsThunkAlias)); 1853 + 1854 + asThunkCall.Arguments.Add(getParam); 1855 + call.Arguments.Add(asThunkCall); 1856 + } 1857 + 1858 + retVal = call; 1859 + } 1860 + 1861 + 1862 + //Assemble return statement 1863 + var ret = new AstReturn(this, ReturnVariant.Exit); 1864 + ret.Expression = retVal; 1865 + 1866 + cst.Ast.Add(ret); 1867 + 1868 + try { 1869 + //Emit code for stub 1870 + cst.Ast.EmitCode(cst,true,StackSemantics.Effect); 1871 + cst.FinishTarget(); 1872 + } catch(Exception e) { 1873 + SemErr("Exception during compilation of lazy function stub for " + id + ". " + e); 1874 + } 1875 + } 1876 + } 1877 + .) 1878 + . 1879 + 1880 + FormalArg<CompilerTarget ft> (. string id; 1881 + bool isAutodereferenced = false; 1882 + ISourcePosition idPos; 1883 + .) 1884 + = 1885 + [ var | ref (. isAutodereferenced = true; .) 1886 + ] (. idPos = GetPosition(); .) 1887 + Id<out id> (. //Note: lazy functions need to copy the 1888 + // parameters of the stub to the body! 1889 + ft.Function.Parameters.Add(id); 1890 + var sym = Symbol.CreateDereference(Symbol.CreateReference( 1891 + EntityRef.Variable.Local.Create(id),idPos),idPos); 1892 + if(isAutodereferenced) 1893 + sym = Symbol.CreateDereference(sym,idPos); 1894 + ft.Symbols.Declare(id, sym); 1895 + .) 1896 + . 1897 + 1898 + GlobalId<out string id> (. id = "...no freaking id..."; .) 1899 + = 1900 + id (. id = cache(t.val); .) 1901 + | anyId String<out id> (. id = cache(id); .) 1902 + . 1903 + 1904 + GlobalQualifiedId<out string id> (. id = "\\NoId\\"; .) 1905 + = 1906 + GlobalId<out id> 1907 + | ns (. StringBuilder buffer = new StringBuilder(t.val); buffer.Append('.'); .) 1908 + { ns (. buffer.Append(t.val); buffer.Append('.'); .) 1909 + } 1910 + GlobalId<out id> (. buffer.Append(id); .) 1911 + (. id = cache(buffer.ToString()); .) 1912 + . 1913 + 1914 + NsQualifiedId<out QualifiedId qualifiedId> 1915 + (. bool _; .) 1916 + = 1917 + NsQualifiedIdImpl<false,out qualifiedId, out _> 1918 + . 1919 + 1920 + NsTransferSource<out bool hasWildcard, out QualifiedId qualifiedId> 1921 + (. hasWildcard = false; .) 1922 + = 1923 + NsQualifiedIdImpl<true, out qualifiedId, out hasWildcard> 1924 + . 1925 + 1926 + NsQualifiedIdImpl<bool allowWildcard, out QualifiedId qualifiedId, out bool hasWildcard> 1927 + (. qualifiedId = default(QualifiedId); 1928 + String part = null; 1929 + var parts = new List<String>(); 1930 + hasWildcard = false; 1931 + .) 1932 + = 1933 + GlobalId<out part> (. parts.Add(part); .) 1934 + { (. if(hasWildcard) 1935 + { 1936 + Create.ReportMessage(Message.Error( 1937 + "Unexpected qualified id parts after wildcard.", 1938 + GetPosition(), 1939 + MessageClasses.QualifiedIdPartsAfterWildcard 1940 + )); 1941 + } 1942 + .) 1943 + dot 1944 + ( GlobalId<out part> (. parts.Add(part); .) 1945 + | timessym (. parts.Add(OperatorNames.Prexonite.Multiplication); .) 1946 + | (. ISourcePosition starPos = GetPosition(); .) 1947 + times (. hasWildcard = true; 1948 + if(!allowWildcard) 1949 + { 1950 + Create.ReportMessage(Message.Error( 1951 + "Unexpected wildcard in qualified namespace name.", 1952 + starPos, 1953 + MessageClasses.UnexpectedWildcard)); 1954 + } 1955 + .) 1956 + ) 1957 + } (. qualifiedId = new QualifiedId(parts.ToArray()); .) 1958 + . 1959 + 1960 + NsTransferDirective<.ICollection<SymbolTransferDirective> directives.> 1961 + (. string externalId; 1962 + string internalId = null; .) 1963 + = (. var pos = GetPosition(); .) 1964 + ( times (. directives.Add(SymbolTransferDirective.CreateWildcard(pos)); .) 1965 + | GlobalId<out externalId> 1966 + ( implementation GlobalId<out internalId> 1967 + | (. internalId = externalId; .) 1968 + ) (. if(internalId == null) { 1969 + // internalId is null in case of a syntax error 1970 + internalId = externalId; 1971 + } 1972 + directives.Add(SymbolTransferDirective.CreateRename(pos, externalId, internalId)); 1973 + .) 1974 + | not 1975 + GlobalId<out externalId> (. directives.Add(SymbolTransferDirective.CreateDrop(pos, externalId)); .) 1976 + ) 1977 + . 1978 + 1979 + NsTransferDirectiveGroup<.ICollection<SymbolTransferDirective> directives.> 1980 + = 1981 + ( (. _pushLexerState(Lexer.YYINITIAL); .) 1982 + lpar 1983 + [ NsTransferDirective<directives> 1984 + { comma 1985 + [ NsTransferDirective<directives> 1986 + ] 1987 + } 1988 + ] (. _popLexerState(); .) 1989 + rpar 1990 + | (. var pos = GetPosition(); .) 1991 + timessym (. // timessym is a hack that lets `(*)`, which ordinarily appears as an identifier, 1992 + // be treated as `(` `*` `)` in this special case 1993 + directives.Add(SymbolTransferDirective.CreateWildcard(pos)); 1994 + .) 1995 + ) 1996 + . 1997 + 1998 + NsTransferSpec<SymbolStoreBuilder builder> 1999 + (. QualifiedId specRoot; 2000 + ISourcePosition pos; 2001 + ISymbolView<Symbol> sourceScope = null; 2002 + var hasWildcard = false; 2003 + .) 2004 + = 2005 + NsTransferSource<out hasWildcard, out specRoot> 2006 + (. var directives = new List<SymbolTransferDirective>(); 2007 + pos = GetPosition(); 2008 + .) 2009 + ( NsTransferDirectiveGroup<directives> 2010 + (. sourceScope = _resolveNamespace(Symbols,pos, specRoot); .) 2011 + | (. if(hasWildcard) 2012 + { 2013 + sourceScope = _resolveNamespace(Symbols,pos, specRoot); 2014 + directives.Add(SymbolTransferDirective.CreateWildcard(pos)); 2015 + } 2016 + else 2017 + { 2018 + var symId = specRoot[specRoot.Count-1]; 2019 + specRoot = specRoot.WithSuffixDropped(1); 2020 + sourceScope = _resolveNamespace(Symbols, pos, specRoot); 2021 + directives.Add(SymbolTransferDirective.CreateRename(pos,symId,symId)); 2022 + } 2023 + .) 2024 + ) (. if(sourceScope != null) 2025 + builder.Forward( 2026 + new SymbolOrigin.NamespaceImport(specRoot, pos), 2027 + sourceScope, 2028 + directives); 2029 + // if the source scope is null, something has gone wrong and the error should 2030 + // have already been reported 2031 + .) 2032 + . 2033 + 2034 + ImportContextualKeyword<out ISourcePosition importKeywordPosition> 2035 + (. string importKeyword; .) 2036 + = (. importKeywordPosition = GetPosition(); .) 2037 + // the `import` keyword, as a contextual keyword 2038 + GlobalId<out importKeyword> (. if(!Engine.StringsAreEqual(importKeyword,"import")){ 2039 + Loader.ReportMessage(Message.Error( 2040 + System.String.Format("Expected keyword 'import' or '{' instead of \"{0}\".",importKeyword), 2041 + importKeywordPosition, MessageClasses.ImportExpected)); 2042 + } 2043 + .) 985 2044 . 986 - #file:C:\Users\chris\Source\Repos\prx\Prexonite\Compiler\Grammar\Parser.GlobalScope.atg# 987 - /* 988 - * Prexonite, a scripting engine (Scripting Language -> Bytecode -> Virtual Machine) 989 - * Copyright (C) 2007 Christian "SealedSun" Klauser 990 - * E-mail sealedsun a.t gmail d.ot com 991 - * Web http://www.sealedsun.ch/ 992 - * 993 - * This program is free software; you can redistribute it and/or modify 994 - * it under the terms of the GNU General Public License as published by 995 - * the Free Software Foundation; either version 2 of the License, or 996 - * (at your option) any later version. 997 - * 998 - * Please contact me (sealedsun a.t gmail do.t com) if you need a different license. 999 - * 1000 - * This program is distributed in the hope that it will be useful, 1001 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 1002 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1003 - * GNU General Public License for more details. 1004 - * 1005 - * You should have received a copy of the GNU General Public License along 1006 - * with this program; if not, write to the Free Software Foundation, Inc., 1007 - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 1008 - */ 1009 - 1010 - Prexonite 1011 - = 1012 - DeclarationLevel 1013 - EOF 1014 - . 1015 - 1016 - DeclarationLevel 1017 - (. PFunction func; .) 1018 - = 1019 - { [ (. if(PreflightModeEnabled) 1020 - { 1021 - ViolentlyAbortParse(); 1022 - return; 1023 - } 1024 - .) 1025 - GlobalVariableDefinition 1026 - | MetaAssignment<TargetApplication> 1027 - ] SYNC semicolon 1028 - | (. if(PreflightModeEnabled) 1029 - { 1030 - ViolentlyAbortParse(); 1031 - return; 1032 - } 1033 - .) 1034 - ( Declaration2 1035 - | GlobalCode 1036 - | BuildBlock 1037 - | FunctionDefinition<out func> 1038 - | NamespaceDeclaration 1039 - ) 1040 - } 1041 - . 1042 - 1043 - /*---- Meta information ----*/ 1044 - 1045 - MetaAssignment<IHasMetaTable metaTable> (. string key = null; MetaEntry entry = null; .) 1046 - = 1047 - ( is (. entry = true; .) 1048 - [not (. entry = false; .) 1049 - ] 1050 - GlobalId<out key> 1051 - | not (. entry = false; .) 1052 - GlobalId<out key> 1053 - | 1054 - GlobalId<out key> 1055 - ( enabled (. entry = true; .) 1056 - | disabled (. entry = false; .) 1057 - | MetaExpr<out entry> 1058 - | (. entry = true; .) 1059 - ) 1060 - | add (. MetaEntry subEntry; .) 1061 - MetaExpr<out subEntry> (. if(!subEntry.IsList) subEntry = (MetaEntry) subEntry.List; .) 1062 - to 1063 - GlobalId<out key> (. if(metaTable.Meta.ContainsKey(key)) 1064 - { 1065 - entry = metaTable.Meta[key]; 1066 - entry = entry.AddToList(subEntry.List); 1067 - } 1068 - else 1069 - { 1070 - entry = subEntry; 1071 - } 1072 - .) 1073 - ) (. if(entry == null || key == null) 1074 - SemErr("Meta assignment did not generate an entry."); 1075 - else 1076 - metaTable.Meta[key] = entry; 1077 - .) 1078 - . 1079 - 1080 - MetaExpr<out MetaEntry entry> 1081 - (. bool sw; int i; double r; entry = null; string str; Version v; .) 1082 - = 1083 - Boolean<out sw> (. entry = sw; .) 1084 - | Integer<out i> (. entry = i.ToString(CultureInfo.InvariantCulture); .) 1085 - | Real<out r> (. entry = r.ToString(CultureInfo.InvariantCulture); .) 1086 - | ( String<out str> (. entry = str; .) 1087 - | GlobalQualifiedId<out str> 1088 - (. entry = str; .) 1089 - ) 1090 - [ div 1091 - Version<out v> (. entry = new Prexonite.Modular.ModuleName(entry.Text,v); .) 1092 - ] 1093 - | lbrace (. List<MetaEntry> lst = new List<MetaEntry>(); 1094 - MetaEntry subEntry; 1095 - bool lastWasEmpty = false; 1096 - .) 1097 - [ MetaExpr<out subEntry> (. lst.Add(subEntry); .) 1098 - { comma (. if(lastWasEmpty) 1099 - SemErr("Missing meta expression in list (two consecutive commas)."); 1100 - .) 1101 - ( MetaExpr<out subEntry> 1102 - (. lst.Add(subEntry); 1103 - lastWasEmpty = false; 1104 - .) 1105 - | (. lastWasEmpty = true; .) 1106 - ) 1107 - } 1108 - ] 1109 - rbrace (. entry = (MetaEntry) lst.ToArray(); .) 1110 - . 1111 - 1112 - /* ---- Global variable definition --- */ 1113 - 1114 - GlobalVariableDefinition (. 1115 - string id = null; 1116 - List<string> aliases = new List<string>(); 1117 - string primaryAlias = null; 1118 - VariableDeclaration vari; 1119 - bool isAutodereferenced = false; 1120 - Symbol entry; 1121 - .) 1122 - = 1123 - 1124 - ( var 1125 - | ref (. isAutodereferenced = true; .) 1126 - ) (. var position = GetPosition(); .) 1127 - 1128 - ( GlobalId<out id> (. primaryAlias = id; .) 1129 - [ GlobalVariableAliasList<aliases> ] 1130 - | GlobalVariableAliasList<aliases> 1131 - (. id = null; .) 1132 - ) (. id = _assignPhysicalGlobalVariableSlot(id); 1133 - entry = Symbol.CreateDereference(Symbol.CreateReference( 1134 - EntityRef.Variable.Global.Create(id, TargetModule.Name), position),position); 1135 - if(isAutodereferenced) 1136 - { 1137 - entry = Symbol.CreateDereference(entry, position); 1138 - } 1139 - foreach(var alias in aliases) 1140 - Symbols.Declare(alias, entry); 1141 - DefineGlobalVariable(id,out vari); 1142 - .) 1143 - [ lbrack //Meta block for variables 1144 - [ MetaAssignment<vari> 1145 - { semicolon 1146 - [ MetaAssignment<vari> ] 1147 - } 1148 - ] 1149 - rbrack 1150 - ] (. if(primaryAlias != null && !_suppressPrimarySymbol(vari)) 1151 - Symbols.Declare(primaryAlias, entry); 1152 - .) 1153 - [ (. _pushLexerState(Lexer.Local); .) 1154 - assign (. _PushScope(FunctionTargets[Application.InitializationId]); 1155 - AstExpr expr; 1156 - .) 1157 - Expr<out expr> 1158 - (. _popLexerState(); 1159 - if(errors.count == 0) 1160 - { 1161 - var complex = Create.Call(position, EntityRef.Variable.Global.Create(id,TargetModule.Name) ); 1162 - complex.Call = PCall.Set; 1163 - complex.Arguments.Add(expr); 1164 - target.Ast.Add(complex); 1165 - TargetApplication._RequireInitialization(); 1166 - Loader._EmitPartialInitializationCode(); 1167 - } 1168 - _PopScope(FunctionTargets[Application.InitializationId]); 1169 - .) 1170 - ] 1171 - . 1172 - 1173 - GlobalVariableAliasList<. IList<string> aliases .> 1174 - (. string id; .) 1175 - = 1176 - as GlobalId<out id> (. aliases.Add(id); .) 1177 - { comma 1178 - [ GlobalId<out id> (. aliases.Add(id); .) 1179 - ] 1180 - } 1181 - . 1182 - 1183 - /* ---- Global declaration ---- */ 1184 - 1185 - SymbolPrefix<SymbolBuilder symbol, out bool canBeRef> 1186 - (. canBeRef = true; .) // in order to avoid further errors when this production fails 1187 - = 1188 - ref (. symbol.Dereference(); .) 1189 - | pointer (. symbol.ReferenceTo(); canBeRef = false; .) 1190 - . 1191 - 1192 - EntityFactory<. bool canBeRef, out Func<string,ModuleName,EntityRef> entityFactory .> 1193 - (. entityFactory = null; bool projectNamespace = false; .) 1194 - = 1195 - ( var (. entityFactory = EntityRef.Variable.Global.Create; projectNamespace = true; .) 1196 - | function (. entityFactory = EntityRef.Function.Create; projectNamespace = true; .) 1197 - | command (. entityFactory = (id,_) => EntityRef.Command.Create(id); .) 1198 - | macro 1199 - ( function (. entityFactory = EntityRef.Function.Create; projectNamespace = true; .) 1200 - | command (. entityFactory = (id,_) => EntityRef.MacroCommand.Create(id); .) 1201 - | var (. entityFactory = EntityRef.Variable.Global.Create; projectNamespace = true; .) 1202 - ) 1203 - | (. if(canBeRef) 1204 - { 1205 - projectNamespace = true; 1206 - entityFactory = EntityRef.Variable.Global.Create; 1207 - } 1208 - else 1209 - { 1210 - // entityFactory already set to null 1211 - } 1212 - .) 1213 - ) (. // Transform physical IDs to reside in the current namespace. 1214 - // That way, forward declarations end up using the same physical 1215 - // name as the actual definition. 1216 - if(entityFactory != null && projectNamespace) { 1217 - var actualFactory = entityFactory; 1218 - entityFactory = (id,mn) => actualFactory(_assignPhysicalSlot(id),mn); 1219 - } 1220 - .) 1221 - . 1222 - 1223 - Declaration2 1224 - (. ModuleName module = TargetModule.Name; 1225 - var builder = new SymbolBuilder(); 1226 - Func<string,ModuleName,EntityRef> entityFactory; 1227 - bool canBeRef = false; 1228 - .) 1229 - = 1230 - SYNC 1231 - declare 1232 - ( { SymbolPrefix<builder, out canBeRef> } 1233 - EntityFactory<canBeRef, out entityFactory> 1234 - (. if(entityFactory == null) builder.AutoDereferenceEnabled = false; .) // For aliases, don't wrap in dereference 1235 - [colon] 1236 - DeclarationInstance2<entityFactory,module,builder.Clone(),preventOverride:false> 1237 - { comma [ DeclarationInstance2<entityFactory,module,builder.Clone(),preventOverride:false> ] } 1238 - semicolon 1239 - | lbrace 1240 - [ uusing ModuleName<out module> ] 1241 - { (. var runBuilder = builder.Clone(); .) 1242 - { SymbolPrefix<builder, out canBeRef> } 1243 - EntityFactory<canBeRef, out entityFactory> 1244 - (. if(entityFactory == null) runBuilder.AutoDereferenceEnabled = false; .) // For aliases, don't wrap in dereference 1245 - colon 1246 - DeclarationInstance2<entityFactory,module,runBuilder.Clone(),preventOverride:true> 1247 - { comma [ DeclarationInstance2<entityFactory,module,runBuilder.Clone(),preventOverride:true> ] } 1248 - } 1249 - rbrace 1250 - | lpar (. bool wasComma = false; .) 1251 - [ MExprBasedDeclaration 1252 - { comma (. if(wasComma) 1253 - { 1254 - Loader.ReportMessage(Message.Error("Double comma in declaration sequence.",GetPosition(),MessageClasses.DuplicateComma)); 1255 - } 1256 - wasComma = true; 1257 - .) 1258 - [ MExprBasedDeclaration 1259 - (. wasComma = false; .) 1260 - ] 1261 - } 1262 - ] 1263 - rpar [ semicolon ] 1264 - ) 1265 - . 1266 - 1267 - MExprBasedDeclaration (. string alias; 1268 - MExpr expr; 1269 - .) 1270 - = 1271 - Id<out alias> assign MExpr<out expr> 1272 - (. Symbol s = _parseSymbol(expr); 1273 - Symbols.Declare(alias,s); 1274 - .) 1275 - . 1276 - 1277 - MessageDirective<. 1278 - Func<string,ModuleName,EntityRef> entityFactory, 1279 - ModuleName module, 1280 - SymbolBuilder builder, 1281 - [CanBeNull] out string lhsId, 1282 - MessageSeverity severity, 1283 - bool preventOverride = false .> 1284 - (. string message; 1285 - string messageClass = null; 1286 - ISourcePosition position = GetPosition(); 1287 - string file; 1288 - int line; 1289 - int column; 1290 - .) 1291 - = 1292 - lpar 1293 - (null|String<out messageClass>) 1294 - [ colon 1295 - ( null 1296 - | String<out file> colon Integer<out line> colon Integer<out column> 1297 - (. position = new SourcePosition(file,line,column); .) 1298 - ) 1299 - ] 1300 - comma 1301 - String<out message> 1302 - comma (. builder.AddMessage(Message.Create(severity,message,position,messageClass)); .) 1303 - SymbolDirective<entityFactory,module,builder,out lhsId,preventOverride:preventOverride> 1304 - rpar 1305 - . 1306 - 1307 - SymbolDirective<. Func<string,ModuleName,EntityRef> entityFactory, 1308 - [CanBeNull] ModuleName module, 1309 - SymbolBuilder builder, 1310 - [CanBeNull] out string lhsId, 1311 - bool preventOverride = false .> 1312 - (. lhsId = null; .) 1313 - = 1314 - null (. /* don't do anything */ .) 1315 - | ( ref (. builder.Dereference(); .) 1316 - | pointer (. builder.ReferenceTo(); .) 1317 - ) 1318 - SymbolDirective<entityFactory,module,builder,out lhsId,preventOverride:preventOverride> 1319 - | IF(isSymbolDirective("INFO")) 1320 - id 1321 - MessageDirective<entityFactory,module,builder, out lhsId,MessageSeverity.Info,preventOverride:preventOverride> 1322 - | IF(isSymbolDirective("WARN")) 1323 - id 1324 - MessageDirective<entityFactory,module,builder, out lhsId,MessageSeverity.Warning,preventOverride:preventOverride> 1325 - | IF(isSymbolDirective("ERROR")) 1326 - id 1327 - MessageDirective<entityFactory,module,builder, out lhsId,MessageSeverity.Error,preventOverride:preventOverride> 1328 - | (. ISourcePosition position = GetPosition(); .) 1329 - Id<out lhsId> 1330 - [ div ModuleName<out module> 1331 - (. if(preventOverride) 1332 - { 1333 - Loader.ReportMessage(Message.Error( 1334 - "Specification of module name illegal at this point.", 1335 - position , 1336 - MessageClasses.UnexpectedModuleName)); 1337 - // Let control fall through, this is not a fatal error, 1338 - // just an enforcement of a stylistic rule. 1339 - } 1340 - .) 1341 - ] (. if(entityFactory != null) 1342 - { 1343 - builder.Entity = entityFactory(lhsId,module); 1344 - } 1345 - .) 1346 - . 1347 - 1348 - DeclarationInstance2<. 1349 - Func<string,ModuleName,EntityRef> entityFactory, 1350 - ModuleName module, 1351 - SymbolBuilder builder, 1352 - bool preventOverride = false .> 1353 - (. string lhsId; 1354 - string rhsId; 1355 - ISourcePosition position = GetPosition(); 1356 - .) 1357 - = 1358 - SymbolDirective<entityFactory,module,builder,out lhsId,preventOverride:preventOverride> 1359 - (. rhsId = lhsId; .) 1360 - [ as Id<out rhsId> ] 1361 - (. 1362 - if(entityFactory == null) 1363 - { 1364 - // We are declaring an alias to an existing symbol 1365 - Symbol existing; 1366 - if(lhsId == null) 1367 - { 1368 - if(rhsId == null) 1369 - { 1370 - Loader.ReportMessage(Message.Error( 1371 - "This symbol declaration requires an alias (e.g., `as theAlias`)", 1372 - GetPosition(), 1373 - MessageClasses.SymbolAliasMissing)); 1374 - // Since there is no name involved, not acting on this 1375 - // statement will not cause further errors 1376 - } 1377 - else 1378 - { 1379 - Symbols.Declare(rhsId, builder.WrapSymbol(null)); 1380 - } 1381 - } 1382 - else if(Symbols.TryGet(lhsId,out existing)) 1383 - { 1384 - // Declare $rhsId as an alias for the symbol that $lhsId points to 1385 - Symbols.Declare(rhsId, builder.WrapSymbol(existing)); 1386 - } 1387 - else 1388 - { 1389 - var msg = Message.Error(string.Format(Resources.Parser_Could_not_find_previous_declaration, lhsId), 1390 - position,MessageClasses.SymbolNotResolved); 1391 - // We report the message AND store it as a message symbol. 1392 - // That way, the symbol is at least declared, avoiding a spurious 1393 - // symbol not found message. 1394 - Loader.ReportMessage(msg); 1395 - Symbols.Declare(rhsId, Symbol.CreateMessage(msg,Symbol.CreateNil(msg.Position))); 1396 - } 1397 - } 1398 - else 1399 - { 1400 - 1401 - if(lhsId == null) 1402 - { 1403 - // For instance `declare var error(...,null)` can get us here 1404 - var msg = Message.Error("Entity name missing for declaration of a fresh symbol", 1405 - GetPosition(), 1406 - MessageClasses.EntityNameMissing); 1407 - Loader.ReportMessage(msg); 1408 - // Also create an error symbol for the alias (if one was declared) 1409 - if(rhsId != null) 1410 - Symbols.Declare(rhsId, Symbol.CreateMessage(msg,Symbol.CreateNil(msg.Position))); 1411 - } 1412 - else 1413 - { 1414 - // Use the builder to create a new symbol. 1415 - Symbols.Declare(rhsId, builder.ToSymbol()); 1416 - } 1417 - } 1418 - .) 1419 - . 1420 - 1421 - ModuleName<out ModuleName moduleName> 1422 - (. _pushLexerState(Lexer.YYINITIAL); //need global scope for Version 1423 - string id; 1424 - Version version = null; 1425 - .) 1426 - = 1427 - Id<out id> 1428 - [ div 1429 - Version<out version> 1430 - ] (. _popLexerState(); 1431 - moduleName = Loader.Cache[new ModuleName(id,version ?? new Version(0,0))]; 1432 - .) 1433 - . 1434 - 1435 - /* ---- Build Block ---- */ 1436 - 1437 - BuildBlock 1438 - = 1439 - SYNC build (. PFunction func = TargetApplication.CreateFunction(); 1440 - CompilerTarget buildBlockTarget = 1441 - Loader.CreateFunctionTarget(func, sourcePosition: GetPosition()); 1442 - _PushScope(buildBlockTarget); 1443 - Loader.DeclareBuildBlockCommands(target); 1444 - _pushLexerState(Lexer.Local); 1445 - .) 1446 - 1447 - [ does ] 1448 - StatementBlock<target.Ast> 1449 - 1450 - (. _popLexerState(); 1451 - _PopScope(buildBlockTarget); 1452 - _compileAndExecuteBuildBlock(buildBlockTarget); 1453 - .) 1454 - . 1455 - 1456 - /* ---- Global Code ---- */ 1457 - 1458 - GlobalCode (. PFunction func = TargetApplication._InitializationFunction; 1459 - CompilerTarget ft = FunctionTargets[func]; 1460 - ISourcePosition position; 1461 - if(ft == null) 1462 - throw new PrexoniteException("Internal compilation error: InitializeFunction got lost."); 1463 - .) 1464 - = 1465 - (. _PushScope(ft); 1466 - _pushLexerState(Lexer.Local); 1467 - .) 1468 - lbrace (. position = GetPosition(); .) 1469 - { Statement<target.Ast> } 1470 - rbrace 1471 - (. 1472 - try { 1473 - if(errors.count == 0) 1474 - { 1475 - TargetApplication._RequireInitialization(); 1476 - Loader._EmitPartialInitializationCode(); 1477 - } 1478 - } catch(Exception e) { 1479 - Loader.ReportMessage(Message.Error( 1480 - "Exception during compilation of initialization code.\n" + e, 1481 - position, 1482 - MessageClasses.ExceptionDuringCompilation)); 1483 - } finally { 1484 - //Symbols defined in this block are not available to further global code blocks 1485 - target.Symbols.ClearLocalDeclarations(); 1486 - _PopScope(ft); 1487 - _popLexerState(); 1488 - } 1489 - .) 1490 - . 1491 - 1492 - /* ---- Function definition ---- */ 1493 - 1494 - FunctionAliasList<. IList<string> aliases .> 1495 - (. String id; .) 1496 - = 1497 - as Id<out id> (. aliases.Add(id); .) 1498 - { comma 1499 - [ Id<out id> (. aliases.Add(id); .) 1500 - ] 1501 - } 1502 - . 1503 - 1504 - FunctionDefinition<out PFunction func> 1505 - (. 1506 - string primaryAlias = null; 1507 - List<string> funcAliases = new List<string>(); 1508 - string id = null; //The logical id (given in the source code) 1509 - string funcId; //The "physical" function id 1510 - bool isNested = target != null; 1511 - bool isCoroutine = false; 1512 - bool isMacro = false; 1513 - bool isLazy = false; 1514 - PFunction derBody = null; //The derived (coroutine/lazy) body function (carries a different name) 1515 - PFunction derStub = null; //The derived (coroutine/lazy) stub function (carries the name(s) specified) 1516 - string derId; //The name of the derived stub 1517 - CompilerTarget ct = null; //The compiler target for the function (as mentioned in the source code) 1518 - CompilerTarget cst = null; //The compiler target for a stub (coroutine/lazy) 1519 - Symbol symEntry = null; 1520 - ISourcePosition position; 1521 - bool missingArg = false; //Allow trailing comma, but not (,,) in formal arg list 1522 - .) 1523 - = 1524 - ( lazy [function] (. isLazy = true; .) 1525 - | function 1526 - | coroutine (. isCoroutine = true; .) 1527 - | macro [function] (. isMacro = true; .) 1528 - ) (. position = GetPosition(); .) 1529 - ( Id<out id> (. primaryAlias = id; .) 1530 - [ FunctionAliasList<funcAliases> ] 1531 - | FunctionAliasList<funcAliases> 1532 - ) (. 1533 - funcId = _assignPhysicalFunctionSlot(id); 1534 - if(Engine.StringsAreEqual(id, @"\init")) //Treat "\init" specially (that's the initialization code) 1535 - { 1536 - func = TargetApplication._InitializationFunction; 1537 - if(isNested) 1538 - Loader.ReportMessage(Message.Error("Cannot define initialization code inside another function.",position,MessageClasses.IllegalInitializationFunction)); 1539 - if(isCoroutine) 1540 - Loader.ReportMessage(Message.Error("Cannot define initialization code as a coroutine.",position,MessageClasses.IllegalInitializationFunction)); 1541 - if(isLazy) 1542 - Loader.ReportMessage(Message.Error("Cannot define initialization code as a lazy function.",position,MessageClasses.IllegalInitializationFunction)); 1543 - if(isMacro) 1544 - Loader.ReportMessage(Message.Error("Cannot define initialization code as a macro function.",position,MessageClasses.IllegalInitializationFunction)); 1545 - } 1546 - else 1547 - { 1548 - var localId = id; 1549 - 1550 - if(isNested) 1551 - { 1552 - if(isMacro) 1553 - Loader.ReportMessage(Message.Error("Inner macros are illegal. Macros must be top-level.",position,MessageClasses.InnerMacrosIllegal)); 1554 - 1555 - funcId = generateLocalId(funcId ?? "inner"); 1556 - 1557 - if(string.IsNullOrEmpty(localId)) 1558 - { 1559 - //Create shadow name 1560 - localId = generateLocalId(id ?? "inner"); 1561 - } 1562 - var innerSym = _ensureDefinedLocal(localId, localId, true, position,true); 1563 - foreach(var alias in funcAliases) 1564 - Symbols.Declare(alias, innerSym); 1565 - 1566 - } 1567 - 1568 - //Add function to application 1569 - if(TargetApplication.Functions.Contains(funcId) && !TargetApplication.Meta.GetDefault(Application.AllowOverridingKey,true)) 1570 - SemErr(t,"Application " + TargetApplication.Id + " does not allow overriding of function " + funcId + "."); 1571 - TargetApplication.Functions.Remove(funcId); 1572 - 1573 - func = TargetApplication.CreateFunction(funcId); 1574 - 1575 - if(isNested) 1576 - { 1577 - func.Meta[PFunction.LogicalIdKey] = localId; 1578 - if(isLazy) 1579 - mark_as_let(target.Function,localId); 1580 - } 1581 - 1582 - Loader.CreateFunctionTarget(func, target, position); 1583 - } 1584 - CompilerTarget ft = FunctionTargets[func]; 1585 - 1586 - //Generate derived stub 1587 - if(isCoroutine || isLazy) 1588 - { 1589 - derStub = func; 1590 - 1591 - //Create derived body function 1592 - derId = ft.GenerateLocalId(); 1593 - derBody = TargetApplication.CreateFunction(derId); 1594 - Loader.CreateFunctionTarget(derBody, ft, position); 1595 - derBody.Meta[PFunction.LogicalIdKey] = id ?? funcId; 1596 - if(isCoroutine) 1597 - { 1598 - derBody.Meta[PFunction.VolatileKey] = true; 1599 - derBody.Meta[PFunction.DeficiencyKey] = "Coroutine body can only be executed by VM anyway."; 1600 - derBody.Meta[Coroutine.IsCoroutineKey] = true; 1601 - } 1602 - 1603 - //Swap compiler target references 1604 - // -> Compile source code into derived body 1605 - // -> Let derived stub have the physical function id 1606 - ct = FunctionTargets[derBody]; 1607 - cst = ft; 1608 - } 1609 - 1610 - if(isNested) //Link to parent in case of a nested function 1611 - { 1612 - if(isLazy) 1613 - ft = ct; 1614 - } 1615 - .) 1616 - [ lpar 1617 - [ FormalArg<ft> 1618 - { comma (. if(missingArg) 1619 - { 1620 - SemErr("Missing formal argument (two consecutive commas)."); 1621 - } 1622 - .) 1623 - ( FormalArg<ft> (. missingArg = false; .) 1624 - | (. missingArg = true; .) 1625 - ) 1626 - } 1627 - ] 1628 - rpar 1629 - | FormalArg<ft> 1630 - { [comma] 1631 - FormalArg<ft> 1632 - } 1633 - ] (. if(isNested && isLazy) // keep this assignment for maintainability 1634 - // ReSharper disable RedundantAssignment 1635 - ft = cst; 1636 - // ReSharper restore RedundantAssignment 1637 - 1638 - if(target == null && 1639 - (!object.ReferenceEquals(func, TargetApplication._InitializationFunction)) && 1640 - (!isNested)) 1641 - { 1642 - //Add the name to the symbol table 1643 - symEntry = Symbol.CreateReference(EntityRef.Function.Create(func.Id, TargetModule.Name),GetPosition()); 1644 - if(isMacro) 1645 - symEntry = Symbol.CreateExpand(symEntry); 1646 - else 1647 - symEntry = Symbol.CreateDereference(symEntry); 1648 - 1649 - foreach(var alias in funcAliases) 1650 - Symbols.Declare(alias, symEntry); 1651 - 1652 - //Store the original (logical id, mentioned in the source code) 1653 - func.Meta[PFunction.LogicalIdKey] = id ?? funcId; 1654 - } 1655 - else 1656 - { 1657 - primaryAlias = null; 1658 - } 1659 - 1660 - //Target the derived (coroutine/lazy) body instead of the stub 1661 - if(isCoroutine || isLazy) 1662 - func = derBody; 1663 - .) 1664 - [ (. _pushLexerState(Lexer.YYINITIAL); .) 1665 - lbrack 1666 - [ MetaAssignment<func> 1667 - { semicolon 1668 - [MetaAssignment<func>] 1669 - } 1670 - ] 1671 - (. _popLexerState(); .) 1672 - rbrack 1673 - ] 1674 - (. 1675 - 1676 - if(primaryAlias != null && !_suppressPrimarySymbol(func)) 1677 - Symbols.Declare(primaryAlias, symEntry); 1678 - 1679 - //Imprint certain meta keys from parent function 1680 - if(isNested) 1681 - { 1682 - func.Meta[Application.ImportKey] = target.Function.Meta[Application.ImportKey]; 1683 - } 1684 - 1685 - //Copy stub parameters to body of lazy function 1686 - if(isLazy && !isNested) 1687 - { 1688 - foreach(var kvp in cst.Symbols.LocalDeclarations) 1689 - { 1690 - var paramId = kvp.Key; 1691 - var s = kvp.Value.ToSymbolEntry(); 1692 - //Lazy functions cannot have ref parameters 1693 - if(s.Interpretation != SymbolInterpretations.LocalObjectVariable) 1694 - SemErr("Lazy functions can only have value parameters (ref is not allowed)"); 1695 - ct.Function.Parameters.Add(s.InternalId); 1696 - ct.Symbols.Declare(paramId, kvp.Value); 1697 - } 1698 - } 1699 - .) 1700 - [ (. _pushLexerState(Lexer.Transfer); 1701 - ISourcePosition importKeywordPosition; 1702 - var importBuilder = SymbolStoreBuilder.Create(); 1703 - .) 1704 - namespace 1705 - ImportContextualKeyword<out importKeywordPosition> 1706 - NsTransferSpec<importBuilder> 1707 - { 1708 - comma 1709 - NsTransferSpec<importBuilder> 1710 - } 1711 - (. { // Copy imported symbols to import scope 1712 - var it = FunctionTargets[func]; 1713 - foreach(var entry in importBuilder.ToSymbolStore()) 1714 - it.ImportScope.Declare(entry.Key,entry.Value); 1715 - } 1716 - _popLexerState(); 1717 - .) 1718 - ] 1719 - (. 1720 - if(isLazy || isCoroutine) 1721 - { 1722 - //Push the stub, because it is the lexical parent of the body 1723 - _PushScope(cst); 1724 - } 1725 - _PushScope(FunctionTargets[func]); 1726 - Debug.Assert(target != null); // Mostly to tell ReSharper that target is not null. 1727 - _pushLexerState(Lexer.Local); 1728 - if(isMacro) 1729 - target.SetupAsMacro(); 1730 - .) 1731 - ( does 1732 - StatementBlock<target.Ast> 1733 - | lbrace { Statement<target.Ast> } 1734 - rbrace 1735 - | IF(isFollowedByStatementBlock()) 1736 - implementation 1737 - StatementBlock<target.Ast> 1738 - | ( assign | implementation ) (. AstReturn ret = new AstReturn(this, ReturnVariant.Exit); .) 1739 - Expr<out ret.Expression> (. target.Ast.Add(ret); .) 1740 - semicolon 1741 - ) (. _popLexerState(); 1742 - _PopScope(FunctionTargets[func]); 1743 - if(isLazy || isCoroutine) 1744 - { 1745 - _PopScope(cst); 1746 - } 1747 - //Compile AST 1748 - if(errors.count == 0) 1749 - { 1750 - if(Engine.StringsAreEqual(func.Id, @"\init")) 1751 - { 1752 - try { 1753 - TargetApplication._RequireInitialization(); 1754 - Loader._EmitPartialInitializationCode(); 1755 - //Initialize function gets finished at the end of Loader.Load 1756 - } catch(Exception e) { 1757 - SemErr("Exception during compilation of initialization code." + e); 1758 - } 1759 - } 1760 - else 1761 - { 1762 - try { 1763 - //Apply compiler hooks for all kinds of functions (lazy/coroutine/macro) 1764 - FunctionTargets[func].ExecuteCompilerHooks(); 1765 - //Emit code for top-level block 1766 - Ast[func].EmitCode(FunctionTargets[func], true, StackSemantics.Effect); 1767 - FunctionTargets[func].FinishTarget(); 1768 - } catch(Exception e) { 1769 - SemErr("Exception during compilation of function body of " + id + ". " + e); 1770 - } 1771 - } 1772 - 1773 - if(isCoroutine) 1774 - { 1775 - try { 1776 - //Stub has to be returned into the physical slot mentioned in the source code 1777 - func = derStub; 1778 - //Generate code for the stub 1779 - AstCreateCoroutine crcor = new AstCreateCoroutine(this); 1780 - crcor.Expression = Create.CreateClosure(position,EntityRef.Function.Create(derBody.Id,derBody.ParentApplication.Module.Name)); 1781 - 1782 - AstReturn retst = new AstReturn(this, ReturnVariant.Exit); 1783 - retst.Expression = crcor; 1784 - cst.Ast.Add(retst); 1785 - //Emit code for top-level block 1786 - cst.Ast.EmitCode(cst,true,StackSemantics.Effect); 1787 - cst.FinishTarget(); 1788 - } catch(Exception e) { 1789 - SemErr("Exception during compilation of coroutine stub for " + id + ". " + e); 1790 - } 1791 - } 1792 - else if(isLazy) 1793 - { 1794 - derStub.Meta[PFunction.LazyKey] = true; 1795 - derStub.Meta["strict"] = true; 1796 - 1797 - //Stub has to be returned into the physical slot mentioned in the source code 1798 - func = derStub; 1799 - 1800 - //Generate code for the stub 1801 - AstExpr retVal; 1802 - 1803 - if(isNested) 1804 - { 1805 - //Nested lazy functions need a stub to capture their environment by value (handled by NestedFunction) 1806 - 1807 - //Generate stub code 1808 - retVal = Create.CreateClosure(position, EntityRef.Function.Create(ct.Function.Id, 1809 - ct.Function.ParentApplication.Module.Name)); 1810 - 1811 - //Inject asthunk-conversion code into body 1812 - var inject = derStub.Parameters.Select(par => 1813 - { 1814 - var getParam = Create.Call(position, EntityRef.Variable.Local.Create(par)); 1815 - var asThunkCall = Create.Call(position, EntityRef.Variable.Command.Create(Engine.AsThunkAlias)); 1816 - asThunkCall.Arguments.Add(getParam); 1817 - var setParam = Create.Call(position, EntityRef.Variable.Local.Create(par)); 1818 - setParam.Arguments.Add(asThunkCall); 1819 - return (AstNode) setParam; 1820 - }); 1821 - ct.Ast.InsertRange(0,inject); 1822 - } 1823 - else 1824 - { 1825 - //Global lazy functions don't technically need a stub. Might be removed later on 1826 - var call = Create.Call(position,EntityRef.Function.Create(ct.Function.Id, TargetModule.Name)); 1827 - 1828 - //Generate code for arguments (each wrapped in a `asThunk` command call) 1829 - foreach(var par in derStub.Parameters) 1830 - { 1831 - var getParam = Create.Call(position, EntityRef.Variable.Local.Create(par)); 1832 - 1833 - var asThunkCall = Create.Call(position, EntityRef.Command.Create(Engine.AsThunkAlias)); 1834 - 1835 - asThunkCall.Arguments.Add(getParam); 1836 - call.Arguments.Add(asThunkCall); 1837 - } 1838 - 1839 - retVal = call; 1840 - } 1841 - 1842 - 1843 - //Assemble return statement 1844 - var ret = new AstReturn(this, ReturnVariant.Exit); 1845 - ret.Expression = retVal; 1846 - 1847 - cst.Ast.Add(ret); 1848 - 1849 - try { 1850 - //Emit code for stub 1851 - cst.Ast.EmitCode(cst,true,StackSemantics.Effect); 1852 - cst.FinishTarget(); 1853 - } catch(Exception e) { 1854 - SemErr("Exception during compilation of lazy function stub for " + id + ". " + e); 1855 - } 1856 - } 1857 - } 1858 - .) 1859 - . 1860 - 1861 - FormalArg<CompilerTarget ft> (. string id; 1862 - bool isAutodereferenced = false; 1863 - ISourcePosition idPos; 1864 - .) 1865 - = 1866 - [ var | ref (. isAutodereferenced = true; .) 1867 - ] (. idPos = GetPosition(); .) 1868 - Id<out id> (. //Note: lazy functions need to copy the 1869 - // parameters of the stub to the body! 1870 - ft.Function.Parameters.Add(id); 1871 - var sym = Symbol.CreateDereference(Symbol.CreateReference( 1872 - EntityRef.Variable.Local.Create(id),idPos),idPos); 1873 - if(isAutodereferenced) 1874 - sym = Symbol.CreateDereference(sym,idPos); 1875 - ft.Symbols.Declare(id, sym); 1876 - .) 1877 - . 1878 - 1879 - GlobalId<out string id> (. id = "...no freaking id..."; .) 1880 - = 1881 - id (. id = cache(t.val); .) 1882 - | anyId String<out id> (. id = cache(id); .) 1883 - . 1884 - 1885 - GlobalQualifiedId<out string id> (. id = "\\NoId\\"; .) 1886 - = 1887 - GlobalId<out id> 1888 - | ns (. StringBuilder buffer = new StringBuilder(t.val); buffer.Append('.'); .) 1889 - { ns (. buffer.Append(t.val); buffer.Append('.'); .) 1890 - } 1891 - GlobalId<out id> (. buffer.Append(id); .) 1892 - (. id = cache(buffer.ToString()); .) 1893 - . 1894 - 1895 - NsQualifiedId<out QualifiedId qualifiedId> 1896 - (. bool _; .) 1897 - = 1898 - NsQualifiedIdImpl<false,out qualifiedId, out _> 1899 - . 1900 - 1901 - NsTransferSource<out bool hasWildcard, out QualifiedId qualifiedId> 1902 - (. hasWildcard = false; .) 1903 - = 1904 - NsQualifiedIdImpl<true, out qualifiedId, out hasWildcard> 1905 - . 1906 - 1907 - NsQualifiedIdImpl<bool allowWildcard, out QualifiedId qualifiedId, out bool hasWildcard> 1908 - (. qualifiedId = default(QualifiedId); 1909 - String part = null; 1910 - var parts = new List<String>(); 1911 - hasWildcard = false; 1912 - .) 1913 - = 1914 - GlobalId<out part> (. parts.Add(part); .) 1915 - { (. if(hasWildcard) 1916 - { 1917 - Create.ReportMessage(Message.Error( 1918 - "Unexpected qualified id parts after wildcard.", 1919 - GetPosition(), 1920 - MessageClasses.QualifiedIdPartsAfterWildcard 1921 - )); 1922 - } 1923 - .) 1924 - dot 1925 - ( GlobalId<out part> (. parts.Add(part); .) 1926 - | timessym (. parts.Add(OperatorNames.Prexonite.Multiplication); .) 1927 - | (. ISourcePosition starPos = GetPosition(); .) 1928 - times (. hasWildcard = true; 1929 - if(!allowWildcard) 1930 - { 1931 - Create.ReportMessage(Message.Error( 1932 - "Unexpected wildcard in qualified namespace name.", 1933 - starPos, 1934 - MessageClasses.UnexpectedWildcard)); 1935 - } 1936 - .) 1937 - ) 1938 - } (. qualifiedId = new QualifiedId(parts.ToArray()); .) 1939 - . 1940 - 1941 - NsTransferDirective<.ICollection<SymbolTransferDirective> directives.> 1942 - (. string externalId; 1943 - string internalId = null; .) 1944 - = (. var pos = GetPosition(); .) 1945 - ( times (. directives.Add(SymbolTransferDirective.CreateWildcard(pos)); .) 1946 - | GlobalId<out externalId> 1947 - ( implementation GlobalId<out internalId> 1948 - | (. internalId = externalId; .) 1949 - ) (. if(internalId == null) { 1950 - // internalId is null in case of a syntax error 1951 - internalId = externalId; 1952 - } 1953 - directives.Add(SymbolTransferDirective.CreateRename(pos, externalId, internalId)); 1954 - .) 1955 - | not 1956 - GlobalId<out externalId> (. directives.Add(SymbolTransferDirective.CreateDrop(pos, externalId)); .) 1957 - ) 1958 - . 1959 - 1960 - NsTransferDirectiveGroup<.ICollection<SymbolTransferDirective> directives.> 1961 - = 1962 - ( (. _pushLexerState(Lexer.YYINITIAL); .) 1963 - lpar 1964 - [ NsTransferDirective<directives> 1965 - { comma 1966 - [ NsTransferDirective<directives> 1967 - ] 1968 - } 1969 - ] (. _popLexerState(); .) 1970 - rpar 1971 - | (. var pos = GetPosition(); .) 1972 - timessym (. // timessym is a hack that lets `(*)`, which ordinarily appears as an identifier, 1973 - // be treated as `(` `*` `)` in this special case 1974 - directives.Add(SymbolTransferDirective.CreateWildcard(pos)); 1975 - .) 1976 - ) 1977 - . 1978 - 1979 - NsTransferSpec<SymbolStoreBuilder builder> 1980 - (. QualifiedId specRoot; 1981 - ISourcePosition pos; 1982 - ISymbolView<Symbol> sourceScope = null; 1983 - var hasWildcard = false; 1984 - .) 1985 - = 1986 - NsTransferSource<out hasWildcard, out specRoot> 1987 - (. var directives = new List<SymbolTransferDirective>(); 1988 - pos = GetPosition(); 1989 - .) 1990 - ( NsTransferDirectiveGroup<directives> 1991 - (. sourceScope = _resolveNamespace(Symbols,pos, specRoot); .) 1992 - | (. if(hasWildcard) 1993 - { 1994 - sourceScope = _resolveNamespace(Symbols,pos, specRoot); 1995 - directives.Add(SymbolTransferDirective.CreateWildcard(pos)); 1996 - } 1997 - else 1998 - { 1999 - var symId = specRoot[specRoot.Count-1]; 2000 - specRoot = specRoot.WithSuffixDropped(1); 2001 - sourceScope = _resolveNamespace(Symbols, pos, specRoot); 2002 - directives.Add(SymbolTransferDirective.CreateRename(pos,symId,symId)); 2003 - } 2004 - .) 2005 - ) (. if(sourceScope != null) 2006 - builder.Forward( 2007 - new SymbolOrigin.NamespaceImport(specRoot, pos), 2008 - sourceScope, 2009 - directives); 2010 - // if the source scope is null, something has gone wrong and the error should 2011 - // have already been reported 2012 - .) 2013 - . 2014 - 2015 - ImportContextualKeyword<out ISourcePosition importKeywordPosition> 2016 - (. string importKeyword; .) 2017 - = (. importKeywordPosition = GetPosition(); .) 2018 - // the `import` keyword, as a contextual keyword 2019 - GlobalId<out importKeyword> (. if(!Engine.StringsAreEqual(importKeyword,"import")){ 2020 - Loader.ReportMessage(Message.Error( 2021 - System.String.Format("Expected keyword 'import' or '{' instead of \"{0}\".",importKeyword), 2022 - importKeywordPosition, MessageClasses.ImportExpected)); 2023 - } 2024 - .) 2025 - . 2026 - 2027 - NamespaceDeclaration (. QualifiedId fullNsId; 2028 - DeclarationScope scope = null; 2029 - ISourcePosition qualIdPos,exportPos; 2030 - List<SymbolTransferDirective> directives; 2031 - SymbolOrigin origin; 2032 - var implicitSelfImport = true; 2033 - .) 2034 - = (. .) 2035 - namespace (. qualIdPos = GetPosition(); .) 2036 - NsQualifiedId<out fullNsId> (. var declBuilder = _prepareDeclScope(fullNsId, qualIdPos); .) 2037 - [ (. ISourcePosition importKeywordPosition; 2038 - _pushLexerState(Lexer.Transfer); 2039 - .) 2040 - ImportContextualKeyword<out importKeywordPosition> 2041 - // optional explicit import from current namespace exports 2042 - ( (. var groupPos = GetPosition(); 2043 - origin = new SymbolOrigin.NamespaceImport(declBuilder.Prefix,groupPos); 2044 - directives = new List<SymbolTransferDirective>(); 2045 - .) 2046 - NsTransferDirectiveGroup<directives> 2047 - (. declBuilder.LocalScopeBuilder.Forward( 2048 - origin, 2049 - declBuilder.Namespace, 2050 - directives); 2051 - implicitSelfImport = false; 2052 - .) 2053 - | [ NsTransferSpec<declBuilder.LocalScopeBuilder> 2054 - ] 2055 - ) 2056 - // optional imports from other namespaces 2057 - { comma 2058 - [ NsTransferSpec<declBuilder.LocalScopeBuilder> 2059 - ] 2060 - } (. _popLexerState(); .) 2061 - ] 2062 - /* body */ (. if(implicitSelfImport) 2063 - { 2064 - origin = new SymbolOrigin.NamespaceImport( 2065 - declBuilder.Prefix,qualIdPos); 2066 - declBuilder.LocalScopeBuilder.Forward( 2067 - origin, 2068 - declBuilder.Namespace, 2069 - SymbolTransferDirective.CreateWildcard(qualIdPos).Singleton() 2070 - ); 2071 - } 2072 - Loader.PushScope(declBuilder.ToDeclarationScope()); 2073 - .) 2074 - lbrace 2075 - DeclarationLevel (. exportPos = GetPosition(); // this position is used when there is no export-spec 2076 - .) 2077 - rbrace (. scope = _popDeclScope(); 2078 - var exportBuilder = SymbolStoreBuilder.Create(); .) 2079 - ( (. _pushLexerState(Lexer.Transfer); .) 2080 - export 2081 - ( (. exportPos = GetPosition(); // this is a more accurate position 2082 - origin = _privateDeclarationOrigin(exportPos,scope); 2083 - directives = new List<SymbolTransferDirective>(); 2084 - .) 2085 - ( NsTransferDirectiveGroup<directives> 2086 - (. exportBuilder.Forward(origin, 2087 - _indexExportedSymbols(scope.Store), directives); .) 2088 - | dot times (. exportBuilder.Forward(origin, 2089 - _indexExportedSymbols(scope.Store), 2090 - SymbolTransferDirective.CreateWildcard(exportPos).Singleton()); .) 2091 - ) 2092 - [ { comma 2093 - NsTransferSpec<exportBuilder> 2094 - } 2095 - semicolon 2096 - ] 2097 - | NsTransferSpec<exportBuilder> 2098 - semicolon 2099 - ) (. _popLexerState(); .) 2100 - | (. // In the absence of an export spec, we export 2101 - // everything declared inside the namespace declaration. 2102 - // This is equivalent to `export(*)` 2103 - exportBuilder.Forward( 2104 - _privateDeclarationOrigin(exportPos,scope), 2105 - _indexExportedSymbols(scope.Store), 2106 - SymbolTransferDirective.CreateWildcard(exportPos).Singleton()); 2107 - .) 2108 - ) (. _updateNamespace(scope, exportBuilder); .) 2045 + 2046 + NamespaceDeclaration (. QualifiedId fullNsId; 2047 + DeclarationScope scope = null; 2048 + ISourcePosition qualIdPos,exportPos; 2049 + List<SymbolTransferDirective> directives; 2050 + SymbolOrigin origin; 2051 + var implicitSelfImport = true; 2052 + .) 2053 + = (. .) 2054 + namespace (. qualIdPos = GetPosition(); .) 2055 + NsQualifiedId<out fullNsId> (. var declBuilder = _prepareDeclScope(fullNsId, qualIdPos); .) 2056 + [ (. ISourcePosition importKeywordPosition; 2057 + _pushLexerState(Lexer.Transfer); 2058 + .) 2059 + ImportContextualKeyword<out importKeywordPosition> 2060 + // optional explicit import from current namespace exports 2061 + ( (. var groupPos = GetPosition(); 2062 + origin = new SymbolOrigin.NamespaceImport(declBuilder.Prefix,groupPos); 2063 + directives = new List<SymbolTransferDirective>(); 2064 + .) 2065 + NsTransferDirectiveGroup<directives> 2066 + (. declBuilder.LocalScopeBuilder.Forward( 2067 + origin, 2068 + declBuilder.Namespace, 2069 + directives); 2070 + implicitSelfImport = false; 2071 + .) 2072 + | [ NsTransferSpec<declBuilder.LocalScopeBuilder> 2073 + ] 2074 + ) 2075 + // optional imports from other namespaces 2076 + { comma 2077 + [ NsTransferSpec<declBuilder.LocalScopeBuilder> 2078 + ] 2079 + } (. _popLexerState(); .) 2080 + ] 2081 + /* body */ (. if(implicitSelfImport) 2082 + { 2083 + origin = new SymbolOrigin.NamespaceImport( 2084 + declBuilder.Prefix,qualIdPos); 2085 + declBuilder.LocalScopeBuilder.Forward( 2086 + origin, 2087 + declBuilder.Namespace, 2088 + SymbolTransferDirective.CreateWildcard(qualIdPos).Singleton() 2089 + ); 2090 + } 2091 + Loader.PushScope(declBuilder.ToDeclarationScope()); 2092 + .) 2093 + lbrace 2094 + DeclarationLevel (. exportPos = GetPosition(); // this position is used when there is no export-spec 2095 + .) 2096 + rbrace (. scope = _popDeclScope(); 2097 + var exportBuilder = SymbolStoreBuilder.Create(); .) 2098 + ( (. _pushLexerState(Lexer.Transfer); .) 2099 + export 2100 + ( (. exportPos = GetPosition(); // this is a more accurate position 2101 + origin = _privateDeclarationOrigin(exportPos,scope); 2102 + directives = new List<SymbolTransferDirective>(); 2103 + .) 2104 + ( NsTransferDirectiveGroup<directives> 2105 + (. exportBuilder.Forward(origin, 2106 + _indexExportedSymbols(scope.Store), directives); .) 2107 + | dot times (. exportBuilder.Forward(origin, 2108 + _indexExportedSymbols(scope.Store), 2109 + SymbolTransferDirective.CreateWildcard(exportPos).Singleton()); .) 2110 + ) 2111 + [ { comma 2112 + NsTransferSpec<exportBuilder> 2113 + } 2114 + semicolon 2115 + ] 2116 + | NsTransferSpec<exportBuilder> 2117 + semicolon 2118 + ) (. _popLexerState(); .) 2119 + | (. // In the absence of an export spec, we export 2120 + // everything declared inside the namespace declaration. 2121 + // This is equivalent to `export(*)` 2122 + exportBuilder.Forward( 2123 + _privateDeclarationOrigin(exportPos,scope), 2124 + _indexExportedSymbols(scope.Store), 2125 + SymbolTransferDirective.CreateWildcard(exportPos).Singleton()); 2126 + .) 2127 + ) (. _updateNamespace(scope, exportBuilder); .) 2109 2128 . 2110 - #file:C:\Users\chris\Source\Repos\prx\Prexonite\Compiler\Grammar\Parser.Helper.atg# 2129 + #file:C:\Users\chris\Documents\GitHub\prx\Prexonite\Compiler\Grammar\Parser.Helper.atg# 2111 2130 /* 2112 2131 * Prexonite, a scripting engine (Scripting Language -> Bytecode -> Virtual Machine) 2113 2132 * Copyright (C) 2007 Christian "SealedSun" Klauser ··· 2298 2317 | 2299 2318 Null (. expr = new MExpr.MAtom(GetPosition(), null); .) 2300 2319 . 2301 - #file:C:\Users\chris\Source\Repos\prx\Prexonite\Compiler\Grammar\Parser.Statement.atg# 2302 - /* 2303 - * Prexonite, a scripting engine (Scripting Language -> Bytecode -> Virtual Machine) 2304 - * Copyright (C) 2007 Christian "SealedSun" Klauser 2305 - * E-mail sealedsun a.t gmail d.ot com 2306 - * Web http://www.sealedsun.ch/ 2307 - * 2308 - * This program is free software; you can redistribute it and/or modify 2309 - * it under the terms of the GNU General Public License as published by 2310 - * the Free Software Foundation; either version 2 of the License, or 2311 - * (at your option) any later version. 2312 - * 2313 - * Please contact me (sealedsun a.t gmail do.t com) if you need a different license. 2314 - * 2315 - * This program is distributed in the hope that it will be useful, 2316 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 2317 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 2318 - * GNU General Public License for more details. 2319 - * 2320 - * You should have received a copy of the GNU General Public License along 2321 - * with this program; if not, write to the Free Software Foundation, Inc., 2322 - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 2323 - */ 2324 - 2325 - StatementBlock<AstBlock block> 2326 - = 2327 - Statement<block> 2328 - . 2329 - 2330 - Statement<AstBlock block> 2331 - = 2332 - ( IF( isLabel() ) 2333 - ExplicitLabel<block> 2334 - | [ SimpleStatement<block> ] semicolon 2335 - | StructureStatement<block> 2336 - ) 2337 - { and Statement<block> 2338 - } 2339 - . 2340 - 2341 - SimpleStatement<AstBlock block> 2342 - = 2343 - ExplicitGoTo<block> 2344 - | GetSetComplex<block> 2345 - | Return<block> 2346 - | Throw<block> 2347 - | LetBindingStmt<block> 2348 - . 2349 - 2350 - StructureStatement<AstBlock block> 2351 - = 2352 - (. _pushLexerState(Lexer.Asm); .) 2353 - asm AsmStatementBlock<block> 2354 - (. _popLexerState(); .) 2355 - | Condition<block> 2356 - | Declaration2 2357 - | WhileLoop<block> 2358 - | ForLoop<block> 2359 - | ForeachLoop<block> 2360 - | NestedFunction<block> 2361 - | TryCatchFinally<block> 2362 - | Using<block> 2363 - | lbrace 2364 - { 2365 - Statement<block> 2366 - } 2367 - rbrace 2368 - . 2369 - 2370 - GetSetComplex<AstBlock block> 2371 - (. AstGetSet complex; 2372 - AstExpr expr; 2373 - AstNode node; 2374 - .) 2375 - = 2376 - //GetSet Initiator 2377 - GetInitiator<out expr> (. complex = expr as AstGetSet; .) 2378 - 2379 - //GetSet Extensions 2380 - { GetSetExtension<expr, out complex> (. expr = complex; .) 2381 - } 2382 - //GetSet Terminator 2383 - ( (. if(expr != null) // Happens in case of an error 2384 - block.Add(expr); 2385 - .) 2386 - | (. var pos = GetPosition(); 2387 - if(complex == null) 2388 - { 2389 - Loader.ReportMessage(Message.Error("Expected an LValue (Get/Set-Complex) for ++,-- or assignment statement.",pos,MessageClasses.LValueExpected)); 2390 - complex = Create.IndirectCall(pos,Create.Null(pos)); 2391 - } 2392 - .) 2393 - ( inc (. block.Add(Create.UnaryOperation(pos, UnaryOperator.PostIncrement, complex)); .) 2394 - | dec (. block.Add(Create.UnaryOperation(pos, UnaryOperator.PostDecrement, complex)); .) 2395 - | Assignment<complex, out node> (. if(complex == null && node == null) 2396 - { 2397 - // An error ocurred during parsing prior to this point. 2398 - // Don't add the null node to the block to avoid a ArgumentNullException 2399 - } 2400 - else if(node == null) 2401 - { 2402 - Loader.ReportMessage(Message.Error("Internal error during translation of assignment. This is likely caused by an error reported previously.",GetPosition(),MessageClasses.ParserInternal)); 2403 - } 2404 - else 2405 - { 2406 - block.Add(node); 2407 - } 2408 - .) 2409 - | AppendRightTermination<ref complex> 2410 - { AppendRightTermination<ref complex> 2411 - } 2412 - (. block.Add(complex); .) 2413 - ) 2414 - ) 2415 - . 2416 - 2417 - AppendRightTermination<ref AstGetSet complex> 2418 - (. AstGetSet rhs; .) 2419 - = 2420 - appendright 2421 - GetCall<out rhs> (. _appendRight(complex,rhs); 2422 - complex = rhs; 2423 - .) 2424 - . 2425 - 2426 - GetSetExtension<AstExpr subject, out AstGetSet extension> 2427 - (. extension = null; string id; 2428 - if(subject == null) 2429 - { 2430 - SemErr("Member access not preceded by a proper expression."); 2431 - subject = new AstConstant(this,null); 2432 - } 2433 - .) 2434 - 2435 - = 2436 - IF( isIndirectCall() ) 2437 - dot (. extension = new AstIndirectCall(this, PCall.Get, subject); .) 2438 - Arguments<extension.Arguments> 2439 - | dot 2440 - Id<out id> (. var ns = subject as AstNamespaceUsage; 2441 - if(ns == null) 2442 - { 2443 - // Ordinary member access 2444 - extension = new AstGetSetMemberAccess(this, PCall.Get, subject, id); 2445 - } 2446 - else 2447 - { 2448 - // Namespace lookup 2449 - extension = _useSymbol(ns.Namespace, id, GetPosition()); 2450 - // write down qualified path 2451 - AstNamespaceUsage subns = extension as AstNamespaceUsage; 2452 - if(subns != null && subns.ReferencePath == null) 2453 - { 2454 - subns.ReferencePath = ns.ReferencePath + new QualifiedId(id); 2455 - } 2456 - } 2457 - .) 2458 - Arguments<extension.Arguments> 2459 - | (. 2460 - AstExpr expr; 2461 - extension = new AstGetSetMemberAccess(this, PCall.Get, subject, ""); 2462 - .) 2463 - lbrack [ 2464 - Expr<out expr> (. extension.Arguments.Add(expr); .) 2465 - { WEAK comma Expr<out expr> (. extension.Arguments.Add(expr); .) 2466 - } 2467 - ] 2468 - rbrack 2469 - . 2470 - 2471 - GetInitiator<out AstExpr complex> 2472 - (. complex = null; 2473 - AstGetSet actualComplex = null; 2474 - AstGetSetStatic staticCall = null; 2475 - AstGetSet member = null; 2476 - AstExpr expr; 2477 - List<AstExpr> args = new List<AstExpr>(); 2478 - string id; 2479 - int placeholderIndex = -1; 2480 - .) 2481 - = 2482 - //Actual value 2483 - ( SymbolicUsage<out actualComplex> 2484 - (. complex = actualComplex; .) 2485 - | VariableDeclaration<out actualComplex> 2486 - (. complex = actualComplex; .) 2487 - | StaticCall<out staticCall> 2488 - | lpar Expr<out expr> (. args.Add(expr); .) 2489 - { comma Expr<out expr> (. args.Add(expr); .) //multiple expressions can only be used as arguments 2490 - } 2491 - rpar 2492 - ( GetSetExtension<expr, out member> 2493 - (. if(args.Count > 1) 2494 - SemErr("A member access cannot have multiple subjects. (Did you mean '>>'?)"); 2495 - .) 2496 - | appendright 2497 - GetCall<out actualComplex> (. _appendRight(args,actualComplex); 2498 - complex = actualComplex; 2499 - .) 2500 - ) 2501 - ) 2502 - (. complex = 2503 - staticCall ?? 2504 - member ?? 2505 - complex; 2506 - .) 2507 - //Reference 2508 - | pointer (. var ptrCount = 1; .) 2509 - { pointer (. ptrCount++; .) 2510 - } 2511 - Id<out id> (. complex = _assembleReference(id, ptrCount); .) 2512 - | question 2513 - [ Integer<out placeholderIndex> ] (. complex = new AstPlaceholder(this, 0 <= placeholderIndex ? (int?)placeholderIndex : null); .) 2514 - . 2515 - 2516 - VariableDeclaration<out AstGetSet complex> 2517 - (. string id, physicalId; 2518 - bool isOverrideDecl = false; 2519 - bool seenVar = false; 2520 - int refCount = 1; 2521 - bool isUnbound = false; 2522 - bool isStatic = false; 2523 - Symbol sym, varSym; 2524 - .) 2525 - = 2526 - [ new (. isUnbound = true; .) 2527 - ] 2528 - ( static (. isStatic = true; .) 2529 - { ref (. refCount++; .) 2530 - } 2531 - [ var ] 2532 - | ( var (. seenVar = true; .) 2533 - | ref (. refCount++; .) 2534 - ) 2535 - { ( var (. if(seenVar) 2536 - { 2537 - Loader.ReportMessage(Message.Error("Duplicate ocurrence of `var` in local variable declaration.",GetPosition(),MessageClasses.DuplicateVar)); 2538 - // This is just a stylistic rule. There are no consequences to having duplicate `var` keywords in a declaration. 2539 - } 2540 - seenVar = true; 2541 - .) 2542 - | ref (. refCount++; .) 2543 - ) 2544 - } 2545 - ) 2546 - [ new (. isOverrideDecl = true; .) 2547 - ] (. ISourcePosition position = GetPosition(); .) 2548 - Id<out id> (. physicalId = id; 2549 - if(isStatic) 2550 - { 2551 - physicalId = target.Function.Id + "\\static\\" + id; 2552 - VariableDeclaration vari; 2553 - if(isOverrideDecl) 2554 - { 2555 - if(TargetModule.Variables.Contains(physicalId)) 2556 - physicalId = target.GenerateLocalId(physicalId); 2557 - } 2558 - 2559 - DefineGlobalVariable(physicalId, out vari); 2560 - varSym = Symbol.CreateReference(EntityRef.Variable.Global.Create(physicalId,TargetModule.Name),position); 2561 - 2562 - if(isUnbound) 2563 - { 2564 - Loader.ReportMessage(Message.Error("Unbinding of global (or static) variables is not currently supported.",position,MessageClasses.GlobalUnbindNotSupported)); 2565 - isUnbound = false; 2566 - } 2567 - } 2568 - else 2569 - { 2570 - if(isOverrideDecl) 2571 - { 2572 - if(target.Function.Variables.Contains(physicalId)) 2573 - physicalId = target.GenerateLocalId(physicalId); 2574 - target.Function.Variables.Add(physicalId); 2575 - } 2576 - else if(!isOuterVariable(physicalId)) 2577 - { 2578 - target.Function.Variables.Add(physicalId); 2579 - } 2580 - 2581 - varSym = Symbol.CreateReference(EntityRef.Variable.Local.Create(physicalId),position); 2582 - // Create.ExprFor will request outer variables where necessary. 2583 - } 2584 - 2585 - // Apply ref's (one ref is implied, see initialization of refCount) 2586 - // Note: we retain the original symbol to generate the AST node 2587 - sym = varSym; 2588 - while(refCount-- > 0) 2589 - sym = Symbol.CreateDereference(sym); 2590 - 2591 - // Declare the symbol in the current scope and assemble an AST node 2592 - Symbols.Declare(id,sym); 2593 - complex = Create.ExprFor(position, Symbol.CreateDereference(varSym)) as AstGetSet; 2594 - 2595 - if(complex == null) 2596 - { 2597 - Loader.ReportMessage(Message.Error("Expected variable declaration to result in LValue.",position,MessageClasses.LValueExpected)); 2598 - complex = Create.IndirectCall(position,Create.Null(position)); 2599 - } 2600 - else if(isUnbound) 2601 - { 2602 - // Wrap variable access in NewDecl 2603 - var newDecl = new AstGetSetNewDecl(position,physicalId,complex); 2604 - complex = newDecl; 2605 - } 2606 - .) 2607 - . 2608 - 2609 - SymbolicUsage<out AstGetSet complex> 2610 - (. string id; ISourcePosition position; 2611 - .) 2612 - = (. position = GetPosition(); .) 2613 - Id<out id> (. complex = _useSymbol(Symbols, id, position); .) 2614 - Arguments<complex.Arguments> 2615 - . 2616 - 2617 - StaticCall<out AstGetSetStatic staticCall> 2618 - (. AstTypeExpr typeExpr; 2619 - string memberId; 2620 - .) 2621 - = 2622 - ExplicitTypeExpr<out typeExpr> 2623 - dot Id<out memberId> (. staticCall = new AstGetSetStatic(this, PCall.Get, typeExpr, memberId); .) 2624 - Arguments<staticCall.Arguments> 2625 - . 2626 - //Fallback in case of a syntax error to avoid NullReferenceExceptions 2627 - ExplicitLabel<AstBlock block> (. string id = "--\\NotAnId\\--"; .) 2628 - = 2629 - ( Id<out id> colon 2630 - | lid (. id = cache(t.val.Substring(0,t.val.Length-1)); .) 2631 - ) (. block.Statements.Add(new AstExplicitLabel(this, id)); .) 2632 - . 2633 - 2634 - ExplicitGoTo<AstBlock block> (. string id; .) 2635 - = 2636 - goto 2637 - Id<out id> (. block.Statements.Add(new AstExplicitGoTo(this, id)); .) 2638 - . 2639 - 2640 - Assignment<AstGetSet lvalue, out AstNode node> 2641 - (. AstExpr expr = null; 2642 - BinaryOperator setModifier = BinaryOperator.None; 2643 - AstTypeExpr typeExpr; 2644 - node = lvalue; 2645 - ISourcePosition position; 2646 - .) 2647 - = (. position = GetPosition(); .) 2648 - ( 2649 - ( ( assign ) (. setModifier = BinaryOperator.None; .) 2650 - | plus assign (. setModifier = BinaryOperator.Addition; .) 2651 - | minus assign (. setModifier = BinaryOperator.Subtraction; .) 2652 - | times assign (. setModifier = BinaryOperator.Multiply; .) 2653 - | div assign (. setModifier = BinaryOperator.Division; .) 2654 - | bitAnd assign (. setModifier = BinaryOperator.BitwiseAnd; .) 2655 - | bitOr assign (. setModifier = BinaryOperator.BitwiseOr; .) 2656 - | coalescence assign (. setModifier = BinaryOperator.Coalescence; .) 2657 - ) Expr<out expr> //(. expr = expr; .) 2658 - 2659 - | ( tilde assign (. setModifier = BinaryOperator.Cast; .) 2660 - ) TypeExpr<out typeExpr> (. expr = typeExpr; .) 2661 - ) 2662 - (. if(expr == null) 2663 - { 2664 - Loader.ReportMessage(Message.Error("Internal error during translation of assignment. This is likely caused by an error reported previously.",GetPosition(),MessageClasses.ParserInternal)); 2665 - } 2666 - else 2667 - { 2668 - lvalue.Arguments.Add(expr); 2669 - } 2670 - lvalue.Call = PCall.Set; 2671 - if(setModifier != BinaryOperator.None) 2672 - node = Create.ModifyingAssignment(position,lvalue,setModifier); 2673 - .) 2674 - . 2675 - 2676 - Condition<AstBlock block> 2677 - (. AstExpr expr; bool isNegative = false; .) 2678 - = 2679 - ( if (. /* isNegative is already false */ .) 2680 - | unless (. isNegative = true; .) 2681 - ) 2682 - 2683 - lpar Expr<out expr> rpar (. if(expr == null) 2684 - expr = _createUnknownExpr(); 2685 - AstCondition cond = Create.Condition(GetPosition(), expr, isNegative); 2686 - _PushScope(cond.IfBlock); 2687 - .) 2688 - 2689 - StatementBlock<cond.IfBlock> 2690 - (. _PopScope(cond.IfBlock); .) 2691 - 2692 - 2693 - [ else (. _PushScope(cond.ElseBlock); .) 2694 - StatementBlock<cond.ElseBlock> 2695 - (. _PopScope(cond.ElseBlock); .) 2696 - ] (. block.Add(cond); .) 2697 - . 2698 - 2699 - WhileLoop<AstBlock block> 2700 - (. AstWhileLoop loop = new AstWhileLoop(GetPosition(),CurrentBlock); .) 2701 - = 2702 - ( ( while | until (. loop.IsPositive = false; .) 2703 - ) 2704 - lpar Expr<out loop.Condition> rpar 2705 - (. _PushScope(loop.Block); //EndBlock is common for both loops 2706 - .) 2707 - StatementBlock<loop.Block> 2708 - 2709 - | do (. _PushScope(loop.Block); 2710 - loop.IsPrecondition = false; 2711 - .) 2712 - StatementBlock<loop.Block> 2713 - ( while | until (. loop.IsPositive = false; .) 2714 - ) 2715 - lpar Expr<out loop.Condition> rpar 2716 - ) (. _PopScope(loop.Block); block.Add(loop); .) 2717 - . 2718 - 2719 - ForLoop<AstBlock block> (. AstForLoop loop; 2720 - AstExpr condition; 2721 - .) 2722 - = 2723 - for (. loop = new AstForLoop(GetPosition(), CurrentBlock); 2724 - _PushScope(loop.Initialize); 2725 - .) 2726 - lpar StatementBlock<loop.Initialize> 2727 - ( (. 2728 - _PushScope(loop.NextIteration); 2729 - .) 2730 - do StatementBlock<loop.NextIteration> 2731 - (. loop.IsPrecondition = false; .) 2732 - ( while 2733 - | until (. loop.IsPositive = false; .) 2734 - ) (. _PopScope(loop.NextIteration); .) 2735 - Expr<out condition> (. loop.Condition = condition; 2736 - _PushScope(loop.NextIteration); 2737 - .) 2738 - | [ while 2739 - | until (. loop.IsPositive = false; .) 2740 - ] 2741 - Expr<out condition> (. loop.Condition = condition; .) 2742 - semicolon (. _PushScope(loop.NextIteration); .) 2743 - SimpleStatement<loop.NextIteration> 2744 - [ semicolon ] 2745 - ) 2746 - rpar (. _PushScope(loop.Block); .) 2747 - StatementBlock<loop.Block> (. _PopScope(loop.Block); 2748 - _PopScope(loop.NextIteration); 2749 - _PopScope(loop.Initialize); 2750 - block.Add(loop); 2751 - .) 2752 - . 2753 - 2754 - ForeachLoop<AstBlock block> 2755 - = 2756 - foreach (. AstForeachLoop loop = Create.ForeachLoop(GetPosition()); 2757 - _PushScope(loop.Block); 2758 - .) 2759 - lpar 2760 - GetCall<out loop.Element> 2761 - in 2762 - Expr<out loop.List> 2763 - rpar 2764 - StatementBlock<loop.Block> 2765 - (. _PopScope(loop.Block); 2766 - block.Add(loop); 2767 - .) 2768 - . 2769 - 2770 - GetCall<out AstGetSet complex> // This is used in placed where an LValue is expected 2771 - // as the name of this production so helpfully suggests ;-) 2772 - // Thus checking for LValue-ness is required and expected. 2773 - (. AstGetSet getMember = null; 2774 - AstExpr expr; 2775 - .) 2776 - = 2777 - GetInitiator<out expr> 2778 - (. complex = expr as AstGetSet; 2779 - if(complex == null) 2780 - { 2781 - var pos = GetPosition(); 2782 - Loader.ReportMessage(Message.Error("Expected an LValue (Get/Set-Complex) for ++,-- or assignment statement.",pos,MessageClasses.LValueExpected)); 2783 - complex = Create.IndirectCall(pos,Create.Null(pos)); 2784 - } 2785 - .) 2786 - { GetSetExtension<complex, out getMember> 2787 - (. complex = getMember; .) 2788 - } 2789 - . 2790 - 2791 - Return<AstBlock block> (. AstReturn ret = null; 2792 - AstExplicitGoTo jump = null; 2793 - AstExpr expr; 2794 - AstLoopBlock bl = target.CurrentLoopBlock; 2795 - .) 2796 - = 2797 - ( 2798 - ( 2799 - return (. ret = new AstReturn(this, ReturnVariant.Exit); .) 2800 - | yield (. ret = new AstReturn(this, ReturnVariant.Continue); .) 2801 - ) 2802 - [ Expr<out expr> (. ret.Expression = expr; .) 2803 - | assign (. ret.ReturnVariant = ReturnVariant.Set; .) 2804 - Expr<out expr> (. ret.Expression = expr; .) 2805 - (. SemErr("Return value assignment is no longer supported. You must use local variables instead."); .) 2806 - ] 2807 - | break (. if(bl == null) 2808 - ret = new AstReturn(this, ReturnVariant.Break); 2809 - else 2810 - jump = new AstExplicitGoTo(this, bl.BreakLabel); 2811 - .) 2812 - | continue (. if(bl == null) 2813 - ret = new AstReturn(this, ReturnVariant.Continue); 2814 - else 2815 - jump = new AstExplicitGoTo(this, bl.ContinueLabel); 2816 - .) 2817 - ) (. block.Add((AstNode)ret ?? jump); .) 2818 - . 2819 - 2820 - NestedFunction<AstBlock block> 2821 - (. PFunction func; .) 2822 - = 2823 - FunctionDefinition<out func> 2824 - (. 2825 - string logicalId = func.Meta[PFunction.LogicalIdKey]; 2826 - func.Meta[PFunction.ParentFunctionKey] = target.Function.Id; 2827 - 2828 - CompilerTarget ft = FunctionTargets[func]; 2829 - var pos = GetPosition(); 2830 - var setVar = Create.IndirectCall(pos,Create.Reference(pos,EntityRef.Variable.Local.Create(logicalId)),PCall.Set); 2831 - if(func.Meta[PFunction.LazyKey].Switch) 2832 - { 2833 - //Capture environment by value 2834 - var ps = ft._ToCaptureByValue(let_bindings(ft)); 2835 - ft._DetermineSharedNames(); //Need to re-determine shared names since 2836 - // _ToCaptureByValue does not automatically modify shared names 2837 - var clos = Create.CreateClosure(pos, EntityRef.Function.Create(func.Id, 2838 - func.ParentApplication.Module.Name)); 2839 - var callStub = Create.IndirectCall(pos, clos); 2840 - callStub.Arguments.AddRange(ps(this)); 2841 - setVar.Arguments.Add(callStub); 2842 - } 2843 - else if(ft.OuterVariables.Count > 0) 2844 - { 2845 - setVar.Arguments.Add( Create.CreateClosure(GetPosition(), EntityRef.Function.Create(func.Id, 2846 - func.ParentApplication.Module.Name)) ); 2847 - } 2848 - else 2849 - { 2850 - setVar.Arguments.Add( new AstReference(GetPosition(), EntityRef.Function.Create(func.Id,func.ParentApplication.Module.Name)) ); 2851 - } 2852 - block.Add(setVar); 2853 - .) 2854 - . 2855 - 2856 - LetBindingStmt<AstBlock block> 2857 - = 2858 - let LetBinder<block> { comma LetBinder<block> } 2859 - . 2860 - 2861 - LetBinder<AstBlock block> 2862 - (. string id = null; 2863 - AstExpr thunk; 2864 - .) 2865 - = (. var position = GetPosition(); .) 2866 - Id<out id> (. //Declare local "let" variable 2867 - _ensureDefinedLocal(id,id,false,position,false); 2868 - mark_as_let(target.Function, id); 2869 - if(la.kind == _assign) 2870 - _inject(_lazy,"lazy"); 2871 - .) 2872 - [ assign 2873 - LazyExpression<out thunk> 2874 - (. 2875 - //Assign thunk to that variable 2876 - var assign = Create.Call(position, EntityRef.Variable.Local.Create(id), PCall.Set); 2877 - assign.Arguments.Add(thunk); 2878 - block.Add(assign); 2879 - .) 2880 - ] 2881 - . 2882 - 2883 - TryCatchFinally<AstBlock block> 2884 - (. var a = Create.TryCatchFinally(GetPosition()); 2885 - AstGetSet excVar; 2886 - .) 2887 - = 2888 - try (. _PushScope(a); 2889 - _PushScope(a.TryBlock); 2890 - .) 2891 - lbrace 2892 - { Statement<a.TryBlock> 2893 - } 2894 - rbrace (. /* Don't pop try-block scope here. */ .) 2895 - [ catch (. _PushScope(a.CatchBlock); .) 2896 - ( lpar 2897 - GetCall<out excVar> (. a.ExceptionVar = excVar; .) 2898 - rpar 2899 - | (. SemErr(la,"catch-clauses that don't store the exception are illegal."); .) 2900 - ) 2901 - lbrace 2902 - { Statement<a.CatchBlock> 2903 - } 2904 - rbrace (. _PopScope(a.CatchBlock);.) 2905 - 2906 - [ 2907 - finally (. _PushScope(a.FinallyBlock); .) 2908 - lbrace 2909 - { Statement<a.FinallyBlock> 2910 - } 2911 - rbrace (. _PopScope(a.FinallyBlock); .) 2912 - ] 2913 - 2914 - | finally (. _PushScope(a.FinallyBlock); .) 2915 - lbrace 2916 - { Statement<a.FinallyBlock> 2917 - } 2918 - rbrace (. _PopScope(a.FinallyBlock); .) 2919 - 2920 - [ (. _PushScope(a.CatchBlock); .) 2921 - catch 2922 - ( lpar 2923 - GetCall<out excVar> 2924 - (. a.ExceptionVar = excVar; .) 2925 - rpar 2926 - | (. SemErr(la,"catch-clauses that don't store the exception are illegal."); .) 2927 - ) 2928 - lbrace 2929 - { Statement<a.CatchBlock> 2930 - } 2931 - rbrace 2932 - (. _PopScope(a.CatchBlock); .) 2933 - ] 2934 - ] 2935 - (. _PopScope(a.TryBlock); 2936 - _PopScope(a); 2937 - block.Add(a); 2938 - .) 2939 - . 2940 - 2941 - Throw<AstBlock block> 2942 - (. AstThrow th; .) 2943 - = 2944 - ThrowExpression<out th> 2945 - (. block.Add(th); .) 2946 - . 2947 - 2948 - Using<AstBlock block> 2949 - (. AstUsing use = Create.Using(GetPosition()); 2950 - AstExpr e; 2951 - .) 2952 - = 2953 - (. _PushScope(use); 2954 - _PushScope(use.Block); .) 2955 - uusing lpar Expr<out e> rpar 2956 - (. use.ResourceExpression = e; .) 2957 - 2958 - StatementBlock<use.Block> 2959 - (. _PopScope(use.Block); 2960 - _PopScope(use); 2961 - block.Add(use); 2962 - .) 2963 - . 2964 - 2965 - Arguments<ArgumentsProxy args> 2966 - (. 2967 - AstExpr expr; 2968 - bool missingArg = false; 2969 - .) 2970 - = 2971 - [ 2972 - lpar 2973 - [ Expr<out expr> (. args.Add(expr); .) 2974 - { comma (. if(missingArg) 2975 - SemErr("Missing argument expression (two consecutive commas)"); 2976 - .) 2977 - ( Expr<out expr> 2978 - (. args.Add(expr); 2979 - missingArg = false; 2980 - .) 2981 - | (. missingArg = true; .) 2982 - ) 2983 - } 2984 - ] 2985 - rpar 2986 - ] 2987 - (. args.RememberRightAppendPosition(); .) 2988 - [ 2989 - appendleft 2990 - ( 2991 - IF(la.kind == _lpar && (!isLambdaExpression())) 2992 - lpar 2993 - [ Expr<out expr> (. args.Add(expr); .) 2994 - { comma 2995 - Expr<out expr> 2996 - (. args.Add(expr); .) 2997 - } 2998 - ] 2999 - rpar 3000 - | Expr<out expr> (. args.Add(expr); .) 3001 - ) 3002 - ] 2320 + #file:C:\Users\chris\Documents\GitHub\prx\Prexonite\Compiler\Grammar\Parser.Statement.atg# 2321 + /* 2322 + * Prexonite, a scripting engine (Scripting Language -> Bytecode -> Virtual Machine) 2323 + * Copyright (C) 2007 Christian "SealedSun" Klauser 2324 + * E-mail sealedsun a.t gmail d.ot com 2325 + * Web http://www.sealedsun.ch/ 2326 + * 2327 + * This program is free software; you can redistribute it and/or modify 2328 + * it under the terms of the GNU General Public License as published by 2329 + * the Free Software Foundation; either version 2 of the License, or 2330 + * (at your option) any later version. 2331 + * 2332 + * Please contact me (sealedsun a.t gmail do.t com) if you need a different license. 2333 + * 2334 + * This program is distributed in the hope that it will be useful, 2335 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 2336 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 2337 + * GNU General Public License for more details. 2338 + * 2339 + * You should have received a copy of the GNU General Public License along 2340 + * with this program; if not, write to the Free Software Foundation, Inc., 2341 + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 2342 + */ 2343 + 2344 + StatementBlock<AstBlock block> 2345 + = 2346 + Statement<block> 3003 2347 . 3004 - #file:C:\Users\chris\Source\Repos\prx\Prexonite\Compiler\Grammar\Footer.atg# 3005 - /* 3006 - * Prexonite, a scripting engine (Scripting Language -> Bytecode -> Virtual Machine) 3007 - * Copyright (C) 2007 Christian "SealedSun" Klauser 3008 - * E-mail sealedsun a.t gmail d.ot com 3009 - * Web http://www.sealedsun.ch/ 3010 - * 3011 - * This program is free software; you can redistribute it and/or modify 3012 - * it under the terms of the GNU General Public License as published by 3013 - * the Free Software Foundation; either version 2 of the License, or 3014 - * (at your option) any later version. 3015 - * 3016 - * Please contact me (sealedsun a.t gmail do.t com) if you need a different license. 3017 - * 3018 - * This program is distributed in the hope that it will be useful, 3019 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 3020 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 3021 - * GNU General Public License for more details. 3022 - * 3023 - * You should have received a copy of the GNU General Public License along 3024 - * with this program; if not, write to the Free Software Foundation, Inc., 3025 - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 3026 - */ 3027 - 3028 - END Prexonite.#file:default# 2348 + 2349 + Statement<AstBlock block> 2350 + = 2351 + ( IF( isLabel() ) 2352 + ExplicitLabel<block> 2353 + | [ SimpleStatement<block> ] semicolon 2354 + | StructureStatement<block> 2355 + ) 2356 + { and Statement<block> 2357 + } 2358 + . 2359 + 2360 + SimpleStatement<AstBlock block> 2361 + = 2362 + ExplicitGoTo<block> 2363 + | GetSetComplex<block> 2364 + | Return<block> 2365 + | Throw<block> 2366 + | LetBindingStmt<block> 2367 + . 2368 + 2369 + StructureStatement<AstBlock block> 2370 + = 2371 + (. _pushLexerState(Lexer.Asm); .) 2372 + asm AsmStatementBlock<block> 2373 + (. _popLexerState(); .) 2374 + | Condition<block> 2375 + | Declaration2 2376 + | WhileLoop<block> 2377 + | ForLoop<block> 2378 + | ForeachLoop<block> 2379 + | NestedFunction<block> 2380 + | TryCatchFinally<block> 2381 + | Using<block> 2382 + | lbrace 2383 + { 2384 + Statement<block> 2385 + } 2386 + rbrace 2387 + . 2388 + 2389 + GetSetComplex<AstBlock block> 2390 + (. AstGetSet complex; 2391 + AstExpr expr; 2392 + AstNode node; 2393 + .) 2394 + = 2395 + //GetSet Initiator 2396 + GetInitiator<out expr> (. complex = expr as AstGetSet; .) 2397 + 2398 + //GetSet Extensions 2399 + { GetSetExtension<expr, out complex> (. expr = complex; .) 2400 + } 2401 + //GetSet Terminator 2402 + ( (. if(expr != null) // Happens in case of an error 2403 + block.Add(expr); 2404 + .) 2405 + | (. var pos = GetPosition(); 2406 + if(complex == null) 2407 + { 2408 + Loader.ReportMessage(Message.Error("Expected an LValue (Get/Set-Complex) for ++,-- or assignment statement.",pos,MessageClasses.LValueExpected)); 2409 + complex = Create.IndirectCall(pos,Create.Null(pos)); 2410 + } 2411 + .) 2412 + ( inc (. block.Add(Create.UnaryOperation(pos, UnaryOperator.PostIncrement, complex)); .) 2413 + | dec (. block.Add(Create.UnaryOperation(pos, UnaryOperator.PostDecrement, complex)); .) 2414 + | Assignment<complex, out node> (. if(complex == null && node == null) 2415 + { 2416 + // An error ocurred during parsing prior to this point. 2417 + // Don't add the null node to the block to avoid a ArgumentNullException 2418 + } 2419 + else if(node == null) 2420 + { 2421 + Loader.ReportMessage(Message.Error("Internal error during translation of assignment. This is likely caused by an error reported previously.",GetPosition(),MessageClasses.ParserInternal)); 2422 + } 2423 + else 2424 + { 2425 + block.Add(node); 2426 + } 2427 + .) 2428 + | AppendRightTermination<ref complex> 2429 + { AppendRightTermination<ref complex> 2430 + } 2431 + (. block.Add(complex); .) 2432 + ) 2433 + ) 2434 + . 2435 + 2436 + AppendRightTermination<ref AstGetSet complex> 2437 + (. AstGetSet rhs; .) 2438 + = 2439 + appendright 2440 + GetCall<out rhs> (. _appendRight(complex,rhs); 2441 + complex = rhs; 2442 + .) 2443 + . 2444 + 2445 + GetSetExtension<AstExpr subject, out AstGetSet extension> 2446 + (. extension = null; string id; 2447 + if(subject == null) 2448 + { 2449 + SemErr("Member access not preceded by a proper expression."); 2450 + subject = new AstConstant(this,null); 2451 + } 2452 + .) 2453 + 2454 + = 2455 + IF( isIndirectCall() ) 2456 + dot (. extension = new AstIndirectCall(this, PCall.Get, subject); .) 2457 + Arguments<extension.Arguments> 2458 + | dot 2459 + Id<out id> (. var ns = subject as AstNamespaceUsage; 2460 + if(ns == null) 2461 + { 2462 + // Ordinary member access 2463 + extension = new AstGetSetMemberAccess(this, PCall.Get, subject, id); 2464 + } 2465 + else 2466 + { 2467 + // Namespace lookup 2468 + extension = _useSymbol(ns.Namespace, id, GetPosition()); 2469 + // write down qualified path 2470 + AstNamespaceUsage subns = extension as AstNamespaceUsage; 2471 + if(subns != null && subns.ReferencePath == null) 2472 + { 2473 + subns.ReferencePath = ns.ReferencePath + new QualifiedId(id); 2474 + } 2475 + } 2476 + .) 2477 + Arguments<extension.Arguments> 2478 + | (. 2479 + AstExpr expr; 2480 + extension = new AstGetSetMemberAccess(this, PCall.Get, subject, ""); 2481 + .) 2482 + lbrack [ 2483 + Expr<out expr> (. extension.Arguments.Add(expr); .) 2484 + { WEAK comma Expr<out expr> (. extension.Arguments.Add(expr); .) 2485 + } 2486 + ] 2487 + rbrack 2488 + . 2489 + 2490 + GetInitiator<out AstExpr complex> 2491 + (. complex = null; 2492 + AstGetSet actualComplex = null; 2493 + AstGetSetStatic staticCall = null; 2494 + AstGetSet member = null; 2495 + AstExpr expr; 2496 + List<AstExpr> args = new List<AstExpr>(); 2497 + string id; 2498 + int placeholderIndex = -1; 2499 + .) 2500 + = 2501 + //Actual value 2502 + ( SymbolicUsage<out actualComplex> 2503 + (. complex = actualComplex; .) 2504 + | VariableDeclaration<out actualComplex> 2505 + (. complex = actualComplex; .) 2506 + | StaticCall<out staticCall> 2507 + | lpar Expr<out expr> (. args.Add(expr); .) 2508 + { comma Expr<out expr> (. args.Add(expr); .) //multiple expressions can only be used as arguments 2509 + } 2510 + rpar 2511 + ( GetSetExtension<expr, out member> 2512 + (. if(args.Count > 1) 2513 + SemErr("A member access cannot have multiple subjects. (Did you mean '>>'?)"); 2514 + .) 2515 + | appendright 2516 + GetCall<out actualComplex> (. _appendRight(args,actualComplex); 2517 + complex = actualComplex; 2518 + .) 2519 + ) 2520 + ) 2521 + (. complex = 2522 + staticCall ?? 2523 + member ?? 2524 + complex; 2525 + .) 2526 + //Reference 2527 + | pointer (. var ptrCount = 1; .) 2528 + { pointer (. ptrCount++; .) 2529 + } 2530 + Id<out id> (. complex = _assembleReference(id, ptrCount); .) 2531 + | question 2532 + [ Integer<out placeholderIndex> ] (. complex = new AstPlaceholder(this, 0 <= placeholderIndex ? (int?)placeholderIndex : null); .) 2533 + . 2534 + 2535 + VariableDeclaration<out AstGetSet complex> 2536 + (. string id, physicalId; 2537 + bool isOverrideDecl = false; 2538 + bool seenVar = false; 2539 + int refCount = 1; 2540 + bool isUnbound = false; 2541 + bool isStatic = false; 2542 + Symbol sym, varSym; 2543 + .) 2544 + = 2545 + [ new (. isUnbound = true; .) 2546 + ] 2547 + ( static (. isStatic = true; .) 2548 + { ref (. refCount++; .) 2549 + } 2550 + [ var ] 2551 + | ( var (. seenVar = true; .) 2552 + | ref (. refCount++; .) 2553 + ) 2554 + { ( var (. if(seenVar) 2555 + { 2556 + Loader.ReportMessage(Message.Error("Duplicate ocurrence of `var` in local variable declaration.",GetPosition(),MessageClasses.DuplicateVar)); 2557 + // This is just a stylistic rule. There are no consequences to having duplicate `var` keywords in a declaration. 2558 + } 2559 + seenVar = true; 2560 + .) 2561 + | ref (. refCount++; .) 2562 + ) 2563 + } 2564 + ) 2565 + [ new (. isOverrideDecl = true; .) 2566 + ] (. ISourcePosition position = GetPosition(); .) 2567 + Id<out id> (. physicalId = id; 2568 + if(isStatic) 2569 + { 2570 + physicalId = target.Function.Id + "\\static\\" + id; 2571 + VariableDeclaration vari; 2572 + if(isOverrideDecl) 2573 + { 2574 + if(TargetModule.Variables.Contains(physicalId)) 2575 + physicalId = target.GenerateLocalId(physicalId); 2576 + } 2577 + 2578 + DefineGlobalVariable(physicalId, out vari); 2579 + varSym = Symbol.CreateReference(EntityRef.Variable.Global.Create(physicalId,TargetModule.Name),position); 2580 + 2581 + if(isUnbound) 2582 + { 2583 + Loader.ReportMessage(Message.Error("Unbinding of global (or static) variables is not currently supported.",position,MessageClasses.GlobalUnbindNotSupported)); 2584 + isUnbound = false; 2585 + } 2586 + } 2587 + else 2588 + { 2589 + if(isOverrideDecl) 2590 + { 2591 + if(target.Function.Variables.Contains(physicalId)) 2592 + physicalId = target.GenerateLocalId(physicalId); 2593 + target.Function.Variables.Add(physicalId); 2594 + } 2595 + else if(!isOuterVariable(physicalId)) 2596 + { 2597 + target.Function.Variables.Add(physicalId); 2598 + } 2599 + 2600 + varSym = Symbol.CreateReference(EntityRef.Variable.Local.Create(physicalId),position); 2601 + // Create.ExprFor will request outer variables where necessary. 2602 + } 2603 + 2604 + // Apply ref's (one ref is implied, see initialization of refCount) 2605 + // Note: we retain the original symbol to generate the AST node 2606 + sym = varSym; 2607 + while(refCount-- > 0) 2608 + sym = Symbol.CreateDereference(sym); 2609 + 2610 + // Declare the symbol in the current scope and assemble an AST node 2611 + Symbols.Declare(id,sym); 2612 + complex = Create.ExprFor(position, Symbol.CreateDereference(varSym)) as AstGetSet; 2613 + 2614 + if(complex == null) 2615 + { 2616 + Loader.ReportMessage(Message.Error("Expected variable declaration to result in LValue.",position,MessageClasses.LValueExpected)); 2617 + complex = Create.IndirectCall(position,Create.Null(position)); 2618 + } 2619 + else if(isUnbound) 2620 + { 2621 + // Wrap variable access in NewDecl 2622 + var newDecl = new AstGetSetNewDecl(position,physicalId,complex); 2623 + complex = newDecl; 2624 + } 2625 + .) 2626 + . 2627 + 2628 + SymbolicUsage<out AstGetSet complex> 2629 + (. string id; ISourcePosition position; 2630 + .) 2631 + = (. position = GetPosition(); .) 2632 + Id<out id> (. complex = _useSymbol(Symbols, id, position); .) 2633 + Arguments<complex.Arguments> 2634 + . 2635 + 2636 + StaticCall<out AstGetSetStatic staticCall> 2637 + (. AstTypeExpr typeExpr; 2638 + string memberId; 2639 + .) 2640 + = 2641 + ExplicitTypeExpr<out typeExpr> 2642 + dot Id<out memberId> (. staticCall = new AstGetSetStatic(this, PCall.Get, typeExpr, memberId); .) 2643 + Arguments<staticCall.Arguments> 2644 + . 2645 + //Fallback in case of a syntax error to avoid NullReferenceExceptions 2646 + ExplicitLabel<AstBlock block> (. string id = "--\\NotAnId\\--"; .) 2647 + = 2648 + ( Id<out id> colon 2649 + | lid (. id = cache(t.val.Substring(0,t.val.Length-1)); .) 2650 + ) (. block.Statements.Add(new AstExplicitLabel(this, id)); .) 2651 + . 2652 + 2653 + ExplicitGoTo<AstBlock block> (. string id; .) 2654 + = 2655 + goto 2656 + Id<out id> (. block.Statements.Add(new AstExplicitGoTo(this, id)); .) 2657 + . 2658 + 2659 + Assignment<AstGetSet lvalue, out AstNode node> 2660 + (. AstExpr expr = null; 2661 + BinaryOperator setModifier = BinaryOperator.None; 2662 + AstTypeExpr typeExpr; 2663 + node = lvalue; 2664 + ISourcePosition position; 2665 + .) 2666 + = (. position = GetPosition(); .) 2667 + ( 2668 + ( ( assign ) (. setModifier = BinaryOperator.None; .) 2669 + | plus assign (. setModifier = BinaryOperator.Addition; .) 2670 + | minus assign (. setModifier = BinaryOperator.Subtraction; .) 2671 + | times assign (. setModifier = BinaryOperator.Multiply; .) 2672 + | div assign (. setModifier = BinaryOperator.Division; .) 2673 + | bitAnd assign (. setModifier = BinaryOperator.BitwiseAnd; .) 2674 + | bitOr assign (. setModifier = BinaryOperator.BitwiseOr; .) 2675 + | coalescence assign (. setModifier = BinaryOperator.Coalescence; .) 2676 + ) Expr<out expr> //(. expr = expr; .) 2677 + 2678 + | ( tilde assign (. setModifier = BinaryOperator.Cast; .) 2679 + ) TypeExpr<out typeExpr> (. expr = typeExpr; .) 2680 + ) 2681 + (. if(expr == null) 2682 + { 2683 + Loader.ReportMessage(Message.Error("Internal error during translation of assignment. This is likely caused by an error reported previously.",GetPosition(),MessageClasses.ParserInternal)); 2684 + } 2685 + else 2686 + { 2687 + lvalue.Arguments.Add(expr); 2688 + } 2689 + lvalue.Call = PCall.Set; 2690 + if(setModifier != BinaryOperator.None) 2691 + node = Create.ModifyingAssignment(position,lvalue,setModifier); 2692 + .) 2693 + . 2694 + 2695 + Condition<AstBlock block> 2696 + (. AstExpr expr; bool isNegative = false; .) 2697 + = 2698 + ( if (. /* isNegative is already false */ .) 2699 + | unless (. isNegative = true; .) 2700 + ) 2701 + 2702 + lpar Expr<out expr> rpar (. if(expr == null) 2703 + expr = _createUnknownExpr(); 2704 + AstCondition cond = Create.Condition(GetPosition(), expr, isNegative); 2705 + _PushScope(cond.IfBlock); 2706 + .) 2707 + 2708 + StatementBlock<cond.IfBlock> 2709 + (. _PopScope(cond.IfBlock); .) 2710 + 2711 + 2712 + [ else (. _PushScope(cond.ElseBlock); .) 2713 + StatementBlock<cond.ElseBlock> 2714 + (. _PopScope(cond.ElseBlock); .) 2715 + ] (. block.Add(cond); .) 2716 + . 2717 + 2718 + WhileLoop<AstBlock block> 2719 + (. AstWhileLoop loop = new AstWhileLoop(GetPosition(),CurrentBlock); .) 2720 + = 2721 + ( ( while | until (. loop.IsPositive = false; .) 2722 + ) 2723 + lpar Expr<out loop.Condition> rpar 2724 + (. _PushScope(loop.Block); //EndBlock is common for both loops 2725 + .) 2726 + StatementBlock<loop.Block> 2727 + 2728 + | do (. _PushScope(loop.Block); 2729 + loop.IsPrecondition = false; 2730 + .) 2731 + StatementBlock<loop.Block> 2732 + ( while | until (. loop.IsPositive = false; .) 2733 + ) 2734 + lpar Expr<out loop.Condition> rpar 2735 + ) (. _PopScope(loop.Block); block.Add(loop); .) 2736 + . 2737 + 2738 + ForLoop<AstBlock block> (. AstForLoop loop; 2739 + AstExpr condition; 2740 + .) 2741 + = 2742 + for (. loop = new AstForLoop(GetPosition(), CurrentBlock); 2743 + _PushScope(loop.Initialize); 2744 + .) 2745 + lpar StatementBlock<loop.Initialize> 2746 + ( (. 2747 + _PushScope(loop.NextIteration); 2748 + .) 2749 + do StatementBlock<loop.NextIteration> 2750 + (. loop.IsPrecondition = false; .) 2751 + ( while 2752 + | until (. loop.IsPositive = false; .) 2753 + ) (. _PopScope(loop.NextIteration); .) 2754 + Expr<out condition> (. loop.Condition = condition; 2755 + _PushScope(loop.NextIteration); 2756 + .) 2757 + | [ while 2758 + | until (. loop.IsPositive = false; .) 2759 + ] 2760 + Expr<out condition> (. loop.Condition = condition; .) 2761 + semicolon (. _PushScope(loop.NextIteration); .) 2762 + SimpleStatement<loop.NextIteration> 2763 + [ semicolon ] 2764 + ) 2765 + rpar (. _PushScope(loop.Block); .) 2766 + StatementBlock<loop.Block> (. _PopScope(loop.Block); 2767 + _PopScope(loop.NextIteration); 2768 + _PopScope(loop.Initialize); 2769 + block.Add(loop); 2770 + .) 2771 + . 2772 + 2773 + ForeachLoop<AstBlock block> 2774 + = 2775 + foreach (. AstForeachLoop loop = Create.ForeachLoop(GetPosition()); 2776 + _PushScope(loop.Block); 2777 + .) 2778 + lpar 2779 + GetCall<out loop.Element> 2780 + in 2781 + Expr<out loop.List> 2782 + rpar 2783 + StatementBlock<loop.Block> 2784 + (. _PopScope(loop.Block); 2785 + block.Add(loop); 2786 + .) 2787 + . 2788 + 2789 + GetCall<out AstGetSet complex> // This is used in placed where an LValue is expected 2790 + // as the name of this production so helpfully suggests ;-) 2791 + // Thus checking for LValue-ness is required and expected. 2792 + (. AstGetSet getMember = null; 2793 + AstExpr expr; 2794 + .) 2795 + = 2796 + GetInitiator<out expr> 2797 + (. complex = expr as AstGetSet; 2798 + if(complex == null) 2799 + { 2800 + var pos = GetPosition(); 2801 + Loader.ReportMessage(Message.Error("Expected an LValue (Get/Set-Complex) for ++,-- or assignment statement.",pos,MessageClasses.LValueExpected)); 2802 + complex = Create.IndirectCall(pos,Create.Null(pos)); 2803 + } 2804 + .) 2805 + { GetSetExtension<complex, out getMember> 2806 + (. complex = getMember; .) 2807 + } 2808 + . 2809 + 2810 + Return<AstBlock block> (. AstReturn ret = null; 2811 + AstExplicitGoTo jump = null; 2812 + AstExpr expr; 2813 + AstLoopBlock bl = target.CurrentLoopBlock; 2814 + .) 2815 + = 2816 + ( 2817 + ( 2818 + return (. ret = new AstReturn(this, ReturnVariant.Exit); .) 2819 + | yield (. ret = new AstReturn(this, ReturnVariant.Continue); .) 2820 + ) 2821 + [ Expr<out expr> (. ret.Expression = expr; .) 2822 + | assign (. ret.ReturnVariant = ReturnVariant.Set; .) 2823 + Expr<out expr> (. ret.Expression = expr; .) 2824 + (. SemErr("Return value assignment is no longer supported. You must use local variables instead."); .) 2825 + ] 2826 + | break (. if(bl == null) 2827 + ret = new AstReturn(this, ReturnVariant.Break); 2828 + else 2829 + jump = new AstExplicitGoTo(this, bl.BreakLabel); 2830 + .) 2831 + | continue (. if(bl == null) 2832 + ret = new AstReturn(this, ReturnVariant.Continue); 2833 + else 2834 + jump = new AstExplicitGoTo(this, bl.ContinueLabel); 2835 + .) 2836 + ) (. block.Add((AstNode)ret ?? jump); .) 2837 + . 2838 + 2839 + NestedFunction<AstBlock block> 2840 + (. PFunction func; .) 2841 + = 2842 + FunctionDefinition<out func> 2843 + (. 2844 + string logicalId = func.Meta[PFunction.LogicalIdKey]; 2845 + func.Meta[PFunction.ParentFunctionKey] = target.Function.Id; 2846 + 2847 + CompilerTarget ft = FunctionTargets[func]; 2848 + var pos = GetPosition(); 2849 + var setVar = Create.IndirectCall(pos,Create.Reference(pos,EntityRef.Variable.Local.Create(logicalId)),PCall.Set); 2850 + if(func.Meta[PFunction.LazyKey].Switch) 2851 + { 2852 + //Capture environment by value 2853 + var ps = ft._ToCaptureByValue(let_bindings(ft)); 2854 + ft._DetermineSharedNames(); //Need to re-determine shared names since 2855 + // _ToCaptureByValue does not automatically modify shared names 2856 + var clos = Create.CreateClosure(pos, EntityRef.Function.Create(func.Id, 2857 + func.ParentApplication.Module.Name)); 2858 + var callStub = Create.IndirectCall(pos, clos); 2859 + callStub.Arguments.AddRange(ps(this)); 2860 + setVar.Arguments.Add(callStub); 2861 + } 2862 + else if(ft.OuterVariables.Count > 0) 2863 + { 2864 + setVar.Arguments.Add( Create.CreateClosure(GetPosition(), EntityRef.Function.Create(func.Id, 2865 + func.ParentApplication.Module.Name)) ); 2866 + } 2867 + else 2868 + { 2869 + setVar.Arguments.Add( new AstReference(GetPosition(), EntityRef.Function.Create(func.Id,func.ParentApplication.Module.Name)) ); 2870 + } 2871 + block.Add(setVar); 2872 + .) 2873 + . 2874 + 2875 + LetBindingStmt<AstBlock block> 2876 + = 2877 + let LetBinder<block> { comma LetBinder<block> } 2878 + . 2879 + 2880 + LetBinder<AstBlock block> 2881 + (. string id = null; 2882 + AstExpr thunk; 2883 + .) 2884 + = (. var position = GetPosition(); .) 2885 + Id<out id> (. //Declare local "let" variable 2886 + _ensureDefinedLocal(id,id,false,position,false); 2887 + mark_as_let(target.Function, id); 2888 + if(la.kind == _assign) 2889 + _inject(_lazy,"lazy"); 2890 + .) 2891 + [ assign 2892 + LazyExpression<out thunk> 2893 + (. 2894 + //Assign thunk to that variable 2895 + var assign = Create.Call(position, EntityRef.Variable.Local.Create(id), PCall.Set); 2896 + assign.Arguments.Add(thunk); 2897 + block.Add(assign); 2898 + .) 2899 + ] 2900 + . 2901 + 2902 + TryCatchFinally<AstBlock block> 2903 + (. var a = Create.TryCatchFinally(GetPosition()); 2904 + AstGetSet excVar; 2905 + .) 2906 + = 2907 + try (. _PushScope(a); 2908 + _PushScope(a.TryBlock); 2909 + .) 2910 + lbrace 2911 + { Statement<a.TryBlock> 2912 + } 2913 + rbrace (. /* Don't pop try-block scope here. */ .) 2914 + [ catch (. _PushScope(a.CatchBlock); .) 2915 + ( lpar 2916 + GetCall<out excVar> (. a.ExceptionVar = excVar; .) 2917 + rpar 2918 + | (. SemErr(la,"catch-clauses that don't store the exception are illegal."); .) 2919 + ) 2920 + lbrace 2921 + { Statement<a.CatchBlock> 2922 + } 2923 + rbrace (. _PopScope(a.CatchBlock);.) 2924 + 2925 + [ 2926 + finally (. _PushScope(a.FinallyBlock); .) 2927 + lbrace 2928 + { Statement<a.FinallyBlock> 2929 + } 2930 + rbrace (. _PopScope(a.FinallyBlock); .) 2931 + ] 2932 + 2933 + | finally (. _PushScope(a.FinallyBlock); .) 2934 + lbrace 2935 + { Statement<a.FinallyBlock> 2936 + } 2937 + rbrace (. _PopScope(a.FinallyBlock); .) 2938 + 2939 + [ (. _PushScope(a.CatchBlock); .) 2940 + catch 2941 + ( lpar 2942 + GetCall<out excVar> 2943 + (. a.ExceptionVar = excVar; .) 2944 + rpar 2945 + | (. SemErr(la,"catch-clauses that don't store the exception are illegal."); .) 2946 + ) 2947 + lbrace 2948 + { Statement<a.CatchBlock> 2949 + } 2950 + rbrace 2951 + (. _PopScope(a.CatchBlock); .) 2952 + ] 2953 + ] 2954 + (. _PopScope(a.TryBlock); 2955 + _PopScope(a); 2956 + block.Add(a); 2957 + .) 2958 + . 2959 + 2960 + Throw<AstBlock block> 2961 + (. AstThrow th; .) 2962 + = 2963 + ThrowExpression<out th> 2964 + (. block.Add(th); .) 2965 + . 2966 + 2967 + Using<AstBlock block> 2968 + (. AstUsing use = Create.Using(GetPosition()); 2969 + AstExpr e; 2970 + .) 2971 + = 2972 + (. _PushScope(use); 2973 + _PushScope(use.Block); .) 2974 + uusing lpar Expr<out e> rpar 2975 + (. use.ResourceExpression = e; .) 2976 + 2977 + StatementBlock<use.Block> 2978 + (. _PopScope(use.Block); 2979 + _PopScope(use); 2980 + block.Add(use); 2981 + .) 2982 + . 2983 + 2984 + Arguments<ArgumentsProxy args> 2985 + (. 2986 + AstExpr expr; 2987 + bool missingArg = false; 2988 + .) 2989 + = 2990 + [ 2991 + lpar 2992 + [ Expr<out expr> (. args.Add(expr); .) 2993 + { comma (. if(missingArg) 2994 + SemErr("Missing argument expression (two consecutive commas)"); 2995 + .) 2996 + ( Expr<out expr> 2997 + (. args.Add(expr); 2998 + missingArg = false; 2999 + .) 3000 + | (. missingArg = true; .) 3001 + ) 3002 + } 3003 + ] 3004 + rpar 3005 + ] 3006 + (. args.RememberRightAppendPosition(); .) 3007 + [ 3008 + appendleft 3009 + ( 3010 + IF(la.kind == _lpar && (!isLambdaExpression())) 3011 + lpar 3012 + [ Expr<out expr> (. args.Add(expr); .) 3013 + { comma 3014 + Expr<out expr> 3015 + (. args.Add(expr); .) 3016 + } 3017 + ] 3018 + rpar 3019 + | Expr<out expr> (. args.Add(expr); .) 3020 + ) 3021 + ] 3022 + . 3023 + #file:C:\Users\chris\Documents\GitHub\prx\Prexonite\Compiler\Grammar\Footer.atg# 3024 + /* 3025 + * Prexonite, a scripting engine (Scripting Language -> Bytecode -> Virtual Machine) 3026 + * Copyright (C) 2007 Christian "SealedSun" Klauser 3027 + * E-mail sealedsun a.t gmail d.ot com 3028 + * Web http://www.sealedsun.ch/ 3029 + * 3030 + * This program is free software; you can redistribute it and/or modify 3031 + * it under the terms of the GNU General Public License as published by 3032 + * the Free Software Foundation; either version 2 of the License, or 3033 + * (at your option) any later version. 3034 + * 3035 + * Please contact me (sealedsun a.t gmail do.t com) if you need a different license. 3036 + * 3037 + * This program is distributed in the hope that it will be useful, 3038 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 3039 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 3040 + * GNU General Public License for more details. 3041 + * 3042 + * You should have received a copy of the GNU General Public License along 3043 + * with this program; if not, write to the Free Software Foundation, Inc., 3044 + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 3045 + */ 3046 + 3047 + END Prexonite.#file:default#