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.

Slicing works for indirect call.

Christian Klauser (May 27, 2017, 1:17 PM +0200) dafe201c 76600a00

+3640 -3524
+1
Prexonite.sln.DotSettings
··· 31 31 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, &#xD; 32 32 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING &#xD; 33 33 IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</s:String> 34 + <s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=LocalFunctions/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String> 34 35 <s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateStaticReadonly/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" /&gt;</s:String> 35 36 <s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/UserRules/=3d1afed0_002D8eeb_002D476b_002Db81f_002D68998a8855fe/@EntryIndexedValue">&lt;Policy&gt;&lt;Descriptor Staticness="Static, Instance" AccessRightKinds="Private" Description="Private members"&gt;&lt;ElementKinds&gt;&lt;Kind Name="FIELD" /&gt;&lt;Kind Name="READONLY_FIELD" /&gt;&lt;Kind Name="METHOD" /&gt;&lt;Kind Name="PROPERTY" /&gt;&lt;Kind Name="EVENT" /&gt;&lt;/ElementKinds&gt;&lt;/Descriptor&gt;&lt;Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" /&gt;&lt;/Policy&gt;</s:String> 36 37 <s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/UserRules/=a0ea5b45_002Df3e8_002D489b_002Da1bf_002D6fe14030968c/@EntryIndexedValue">&lt;Policy&gt;&lt;Descriptor Staticness="Static, Instance" AccessRightKinds="Internal" Description="Internal methods and properties"&gt;&lt;ElementKinds&gt;&lt;Kind Name="METHOD" /&gt;&lt;Kind Name="PROPERTY" /&gt;&lt;/ElementKinds&gt;&lt;/Descriptor&gt;&lt;Policy Inspect="True" Prefix="_" Suffix="" Style="AaBb" /&gt;&lt;/Policy&gt;</s:String>
+165 -165
Prexonite/Commands/List/FoldL.cs
··· 1 - // Prexonite 2 - // 3 - // Copyright (c) 2014, Christian Klauser 4 - // All rights reserved. 5 - // 6 - // Redistribution and use in source and binary forms, with or without modification, 7 - // are permitted provided that the following conditions are met: 8 - // 9 - // Redistributions of source code must retain the above copyright notice, 10 - // this list of conditions and the following disclaimer. 11 - // Redistributions in binary form must reproduce the above copyright notice, 12 - // this list of conditions and the following disclaimer in the 13 - // documentation and/or other materials provided with the distribution. 14 - // The names of the contributors may be used to endorse or 15 - // promote products derived from this software without specific prior written permission. 16 - // 17 - // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 - // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 - // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 - // IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 21 - // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 - // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 - // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 - // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 25 - // IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 - using System; 27 - using System.Collections.Generic; 28 - using Prexonite.Compiler.Cil; 29 - using Prexonite.Types; 30 - 31 - namespace Prexonite.Commands.List 32 - { 33 - /// <summary> 34 - /// Implementation of the foldl function. 35 - /// </summary> 36 - /// <remarks> 37 - /// <code>function foldl(ref f, left, source) 38 - /// { 39 - /// foreach(var right in source) 40 - /// left = f(left,right); 41 - /// return left; 42 - /// }</code> 43 - /// </remarks> 44 - public class FoldL : PCommand, ICilCompilerAware 45 - { 46 - #region Singleton 47 - 48 - private FoldL() 49 - { 50 - } 51 - 52 - private static readonly FoldL _instance = new FoldL(); 53 - 54 - public static FoldL Instance 55 - { 56 - get { return _instance; } 57 - } 58 - 59 - #endregion 60 - 61 - public static PValue Run( 62 - StackContext sctx, IIndirectCall f, PValue left, IEnumerable<PValue> source) 63 - { 64 - if (sctx == null) 65 - throw new ArgumentNullException(nameof(sctx)); 66 - if (f == null) 67 - throw new ArgumentNullException(nameof(f)); 68 - if (left == null) 69 - left = PType.Null.CreatePValue(); 70 - if (source == null) 71 - source = new PValue[] {}; 72 - 73 - foreach (var right in source) 74 - { 75 - left = f.IndirectCall(sctx, new[] {left, right}); 76 - } 77 - return left; 78 - } 79 - 80 - public static PValue RunStatically(StackContext sctx, PValue[] args) 81 - { 82 - if (sctx == null) 83 - throw new ArgumentNullException(nameof(sctx)); 84 - if (args == null) 85 - throw new ArgumentNullException(nameof(args)); 86 - 87 - //Get f 88 - IIndirectCall f; 89 - if (args.Length < 1) 90 - throw new PrexoniteException("The foldl command requires a function argument."); 91 - else 92 - f = args[0]; 93 - 94 - //Get left 95 - PValue left; 96 - if (args.Length < 2) 97 - left = null; 98 - else 99 - left = args[1]; 100 - 101 - //Get the source 102 - IEnumerable<PValue> source; 103 - if (args.Length == 3) 104 - { 105 - var psource = args[2]; 106 - source = Map._ToEnumerable(sctx, psource) ?? new[] {psource}; 107 - } 108 - else 109 - { 110 - var lstsource = new List<PValue>(); 111 - for (var i = 1; i < args.Length; i++) 112 - { 113 - var multiple = Map._ToEnumerable(sctx, args[i]); 114 - if (multiple != null) 115 - lstsource.AddRange(multiple); 116 - else 117 - lstsource.Add(args[i]); 118 - } 119 - source = lstsource; 120 - } 121 - 122 - return Run(sctx, f, left, source); 123 - } 124 - 125 - public override PValue Run(StackContext sctx, PValue[] args) 126 - { 127 - return RunStatically(sctx, args); 128 - } 129 - 130 - /// <summary> 131 - /// A flag indicating whether the command acts like a pure function. 132 - /// </summary> 133 - /// <remarks> 134 - /// Pure commands can be applied at compile time. 135 - /// </remarks> 136 - [Obsolete] 137 - public override bool IsPure 138 - { 139 - get { return false; } //indirect call 140 - } 141 - 142 - #region ICilCompilerAware Members 143 - 144 - /// <summary> 145 - /// Asses qualification and preferences for a certain instruction. 146 - /// </summary> 147 - /// <param name = "ins">The instruction that is about to be compiled.</param> 148 - /// <returns>A set of <see cref = "CompilationFlags" />.</returns> 149 - CompilationFlags ICilCompilerAware.CheckQualification(Instruction ins) 150 - { 151 - return CompilationFlags.PrefersRunStatically; 152 - } 153 - 154 - /// <summary> 155 - /// Provides a custom compiler routine for emitting CIL byte code for a specific instruction. 156 - /// </summary> 157 - /// <param name = "state">The compiler state.</param> 158 - /// <param name = "ins">The instruction to compile.</param> 159 - void ICilCompilerAware.ImplementInCil(CompilerState state, Instruction ins) 160 - { 161 - throw new NotSupportedException(); 162 - } 163 - 164 - #endregion 165 - } 1 + // Prexonite 2 + // 3 + // Copyright (c) 2014, Christian Klauser 4 + // All rights reserved. 5 + // 6 + // Redistribution and use in source and binary forms, with or without modification, 7 + // are permitted provided that the following conditions are met: 8 + // 9 + // Redistributions of source code must retain the above copyright notice, 10 + // this list of conditions and the following disclaimer. 11 + // Redistributions in binary form must reproduce the above copyright notice, 12 + // this list of conditions and the following disclaimer in the 13 + // documentation and/or other materials provided with the distribution. 14 + // The names of the contributors may be used to endorse or 15 + // promote products derived from this software without specific prior written permission. 16 + // 17 + // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 + // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 + // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 + // IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 21 + // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 + // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 + // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 + // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 25 + // IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 + using System; 27 + using System.Collections.Generic; 28 + using Prexonite.Compiler.Cil; 29 + using Prexonite.Types; 30 + 31 + namespace Prexonite.Commands.List 32 + { 33 + /// <summary> 34 + /// Implementation of the foldl function. 35 + /// </summary> 36 + /// <remarks> 37 + /// <code>function foldl(ref f, left, source) 38 + /// { 39 + /// foreach(var right in source) 40 + /// left = f(left,right); 41 + /// return left; 42 + /// }</code> 43 + /// </remarks> 44 + public class FoldL : PCommand, ICilCompilerAware 45 + { 46 + #region Singleton 47 + 48 + private FoldL() 49 + { 50 + } 51 + 52 + private static readonly FoldL _instance = new FoldL(); 53 + 54 + public static FoldL Instance 55 + { 56 + get { return _instance; } 57 + } 58 + 59 + #endregion 60 + 61 + public static PValue Run( 62 + StackContext sctx, IIndirectCall f, PValue left, IEnumerable<PValue> source) 63 + { 64 + if (sctx == null) 65 + throw new ArgumentNullException(nameof(sctx)); 66 + if (f == null) 67 + throw new ArgumentNullException(nameof(f)); 68 + if (left == null) 69 + left = PType.Null.CreatePValue(); 70 + if (source == null) 71 + source = new PValue[] {}; 72 + 73 + foreach (var right in source) 74 + { 75 + left = f.IndirectCall(sctx, new[] {left, right}); 76 + } 77 + return left; 78 + } 79 + 80 + public static PValue RunStatically(StackContext sctx, PValue[] args) 81 + { 82 + if (sctx == null) 83 + throw new ArgumentNullException(nameof(sctx)); 84 + if (args == null) 85 + throw new ArgumentNullException(nameof(args)); 86 + 87 + //Get f 88 + IIndirectCall f; 89 + if (args.Length < 1) 90 + throw new PrexoniteException("The foldl command requires a function argument."); 91 + else 92 + f = args[0]; 93 + 94 + //Get left 95 + PValue left; 96 + if (args.Length < 2) 97 + left = null; 98 + else 99 + left = args[1]; 100 + 101 + //Get the source 102 + IEnumerable<PValue> source; 103 + if (args.Length == 3) 104 + { 105 + var psource = args[2]; 106 + source = Map._ToEnumerable(sctx, psource) ?? new[] {psource}; 107 + } 108 + else 109 + { 110 + var lstsource = new List<PValue>(); 111 + for (var i = 2; i < args.Length; i++) 112 + { 113 + var multiple = Map._ToEnumerable(sctx, args[i]); 114 + if (multiple != null) 115 + lstsource.AddRange(multiple); 116 + else 117 + lstsource.Add(args[i]); 118 + } 119 + source = lstsource; 120 + } 121 + 122 + return Run(sctx, f, left, source); 123 + } 124 + 125 + public override PValue Run(StackContext sctx, PValue[] args) 126 + { 127 + return RunStatically(sctx, args); 128 + } 129 + 130 + /// <summary> 131 + /// A flag indicating whether the command acts like a pure function. 132 + /// </summary> 133 + /// <remarks> 134 + /// Pure commands can be applied at compile time. 135 + /// </remarks> 136 + [Obsolete] 137 + public override bool IsPure 138 + { 139 + get { return false; } //indirect call 140 + } 141 + 142 + #region ICilCompilerAware Members 143 + 144 + /// <summary> 145 + /// Asses qualification and preferences for a certain instruction. 146 + /// </summary> 147 + /// <param name = "ins">The instruction that is about to be compiled.</param> 148 + /// <returns>A set of <see cref = "CompilationFlags" />.</returns> 149 + CompilationFlags ICilCompilerAware.CheckQualification(Instruction ins) 150 + { 151 + return CompilationFlags.PrefersRunStatically; 152 + } 153 + 154 + /// <summary> 155 + /// Provides a custom compiler routine for emitting CIL byte code for a specific instruction. 156 + /// </summary> 157 + /// <param name = "state">The compiler state.</param> 158 + /// <param name = "ins">The instruction to compile.</param> 159 + void ICilCompilerAware.ImplementInCil(CompilerState state, Instruction ins) 160 + { 161 + throw new NotSupportedException(); 162 + } 163 + 164 + #endregion 165 + } 166 166 }
+5
Prexonite/Compiler/AST/AstArgumentSplice.cs
··· 79 79 target.Factory.Null(splice.Position).EmitValueCode(target); 80 80 } 81 81 } 82 + 83 + public override string ToString() 84 + { 85 + return $"*({ArgumentList})"; 86 + } 82 87 } 83 88 }
+1 -1
Prexonite/Compiler/AST/AstIndirectCall.cs
··· 254 254 callNode.Arguments.Add(Subject); 255 255 foreach (AstExpr argument in Arguments) 256 256 { 257 - if (argument is AstArgumentSplice splice && splice.IsSplicedPlaceholder) 257 + if (argument is AstArgumentSplice splice) 258 258 { 259 259 flushCurrentBatch(); 260 260 callNode.Arguments.Add(splice.ArgumentList);
+557 -551
Prexonite/Compiler/Grammar/Parser.Expression.atg
··· 1 - /* 2 - * Prexonite, a scripting engine (Scripting Language -> Bytecode -> Virtual Machine) 3 - * Copyright (C) 2007 Christian "SealedSun" Klauser 4 - * E-mail sealedsun a.t gmail d.ot com 5 - * Web http://www.sealedsun.ch/ 6 - * 7 - * This program is free software; you can redistribute it and/or modify 8 - * it under the terms of the GNU General Public License as published by 9 - * the Free Software Foundation; either version 2 of the License, or 10 - * (at your option) any later version. 11 - * 12 - * Please contact me (sealedsun a.t gmail do.t com) if you need a different license. 13 - * 14 - * This program is distributed in the hope that it will be useful, 15 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 - * GNU General Public License for more details. 18 - * 19 - * You should have received a copy of the GNU General Public License along 20 - * with this program; if not, write to the Free Software Foundation, Inc., 21 - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 22 - */ 23 - 24 - 25 - Expr<out AstExpr expr> (. AstConditionalExpression cexpr; expr = _NullNode(GetPosition()); .) 26 - = 27 - AtomicExpr<out expr> 28 - | (. bool isNegated = false; .) 29 - ( if 30 - | unless (. isNegated = true; .) 31 - ) 32 - lpar Expr<out expr> rpar (. cexpr = new AstConditionalExpression(this, expr, isNegated); .) 33 - Expr<out cexpr.IfExpression> 34 - else 35 - Expr<out cexpr.ElseExpression> (. expr = cexpr; .) 36 - . 37 - 38 - 39 - AtomicExpr<out AstExpr expr> 40 - (. AstExpr outerExpr; .) 41 - = 42 - AppendRightExpr<out expr> 43 - { 44 - then 45 - AppendRightExpr<out outerExpr> (. var thenExpr = Create.Call(GetPosition(), EntityRef.Command.Create(Engine.ThenAlias)); 46 - thenExpr.Arguments.Add(expr); 47 - thenExpr.Arguments.Add(outerExpr); 48 - expr = thenExpr; 49 - .) 50 - } 51 - . 52 - 53 - 54 - AppendRightExpr<out AstExpr expr> 55 - (. AstGetSet complex; .) 56 - = 57 - KeyValuePairExpr<out expr> 58 - { 59 - appendright 60 - GetCall<out complex> (. _appendRight(expr,complex); 61 - expr = complex; 62 - .) 63 - } 64 - . 65 - 66 - KeyValuePairExpr<out AstExpr expr> 67 - = 68 - OrExpr<out expr> 69 - [ colon (. AstExpr value; .) 70 - KeyValuePairExpr<out value> (. expr = new AstKeyValuePair(this, expr, value); .) 71 - ] 72 - . 73 - 74 - OrExpr<out AstExpr expr> 75 - (. AstExpr lhs, rhs; .) 76 - = 77 - AndExpr<out lhs> (. expr = lhs; .) 78 - [ or OrExpr<out rhs> (. expr = new AstLogicalOr(this, lhs, rhs); .) 79 - ] 80 - 81 - . 82 - 83 - AndExpr<out AstExpr expr> 84 - (. AstExpr lhs, rhs; .) 85 - = 86 - DeltaExpr<out lhs> (. expr = lhs; .) 87 - [ and AndExpr<out rhs> (. expr = new AstLogicalAnd(this, lhs, rhs); .) 88 - ] 89 - . 90 - 91 - DeltaExpr<out AstExpr expr> 92 - (. AstExpr lhs, rhs; BinaryOperator bop; UnaryOperator uop; .) 93 - = 94 - BitOrExpr<out lhs> (. expr = lhs; .) 95 - { ( deltaleft (. bop = BinaryOperator.DeltaLeft; uop = UnaryOperator.PostDeltaLeft; .) 96 - | deltaright (. bop = BinaryOperator.DeltaRight; uop = UnaryOperator.PostDeltaRight; .) 97 - ) 98 - ( BitOrExpr<out rhs> (. expr = Create.BinaryOperation(GetPosition(), expr, bop, rhs); .) 99 - | (. expr = Create.UnaryOperation(GetPosition(), uop, expr); .) 100 - ) 101 - } 102 - . 103 - 104 - BitOrExpr<out AstExpr expr> 105 - (. AstExpr lhs, rhs; .) 106 - = 107 - BitXorExpr<out lhs> (. expr = lhs; .) 108 - { bitOr BitXorExpr<out rhs> (. expr = Create.BinaryOperation(GetPosition(), expr, BinaryOperator.BitwiseOr, rhs); .) 109 - } 110 - . 111 - 112 - BitXorExpr<out AstExpr expr> 113 - (. AstExpr lhs, rhs; .) 114 - = 115 - BitAndExpr<out lhs> (. expr = lhs; .) 116 - { xor BitAndExpr<out rhs> 117 - (. expr = Create.BinaryOperation(GetPosition(), expr, BinaryOperator.ExclusiveOr, rhs); .) 118 - } 119 - . 120 - 121 - BitAndExpr<out AstExpr expr> 122 - (. AstExpr lhs, rhs; .) 123 - = 124 - NotExpr<out lhs> (. expr = lhs; .) 125 - { bitAnd NotExpr<out rhs> 126 - (. expr = Create.BinaryOperation(GetPosition(), expr, BinaryOperator.BitwiseAnd, rhs); .) 127 - } 128 - . 129 - 130 - NotExpr<out AstExpr expr> 131 - (. AstExpr lhs; bool isNot = false; .) 132 - = 133 - [ not (. isNot = true; .) 134 - ] 135 - EqlExpr<out lhs> (. expr = isNot ? Create.UnaryOperation(GetPosition(), UnaryOperator.LogicalNot, lhs) : lhs; .) 136 - . 137 - 138 - EqlExpr<out AstExpr expr> 139 - (. AstExpr lhs, rhs; BinaryOperator op; .) 140 - = 141 - RelExpr<out lhs> (. expr = lhs; .) 142 - { ( eq (. op = BinaryOperator.Equality; .) 143 - | ne (. op = BinaryOperator.Inequality; .) 144 - ) RelExpr<out rhs> (. expr = Create.BinaryOperation(GetPosition(), expr, op, rhs); .) 145 - } 146 - . 147 - 148 - RelExpr<out AstExpr expr> 149 - (. AstExpr lhs, rhs; BinaryOperator op; .) 150 - = 151 - CoalExpr<out lhs> (. expr = lhs; .) 152 - { ( lt (. op = BinaryOperator.LessThan; .) 153 - | le (. op = BinaryOperator.LessThanOrEqual; .) 154 - | gt (. op = BinaryOperator.GreaterThan; .) 155 - | ge (. op = BinaryOperator.GreaterThanOrEqual; .) 156 - ) CoalExpr<out rhs> (. expr = Create.BinaryOperation(GetPosition(), expr, op, rhs); .) 157 - } 158 - . 159 - 160 - CoalExpr<out AstExpr expr> 161 - (. AstExpr lhs, rhs; AstCoalescence coal = new AstCoalescence(this); .) 162 - = 163 - AddExpr<out lhs> (. expr = lhs; coal.Expressions.Add(lhs); .) 164 - { 165 - coalescence 166 - AddExpr<out rhs> (. expr = coal; coal.Expressions.Add(rhs); .) 167 - } 168 - . 169 - 170 - AddExpr<out AstExpr expr> 171 - (. AstExpr lhs,rhs; BinaryOperator op; .) 172 - = 173 - MulExpr<out lhs> (. expr = lhs; .) 174 - { ( plus (. op = BinaryOperator.Addition; .) 175 - | minus (. op = BinaryOperator.Subtraction; .) 176 - ) MulExpr<out rhs> (. expr = Create.BinaryOperation(GetPosition(), expr, op, rhs); .) 177 - } 178 - . 179 - 180 - MulExpr<out AstExpr expr> 181 - (. AstExpr lhs, rhs; BinaryOperator op; .) 182 - = 183 - PowExpr<out lhs> (. expr = lhs; .) 184 - { ( times (. op = BinaryOperator.Multiply; .) 185 - | div (. op = BinaryOperator.Division; .) 186 - | mod (. op = BinaryOperator.Modulus; .) 187 - ) PowExpr<out rhs> (. expr = Create.BinaryOperation(GetPosition(), expr, op, rhs); .) 188 - } 189 - . 190 - 191 - PowExpr<out AstExpr expr> 192 - (. AstExpr lhs, rhs; .) 193 - = 194 - AssignExpr<out lhs> (. expr = lhs; .) 195 - { pow AssignExpr<out rhs> (. expr = Create.BinaryOperation(GetPosition(), expr, BinaryOperator.Power, rhs); .) 196 - } 197 - . 198 - 199 - AssignExpr<out AstExpr expr> (. AstGetSet assignment; BinaryOperator setModifier = BinaryOperator.None; 200 - AstTypeExpr typeExpr; 201 - ISourcePosition position; 202 - .) 203 - = (. position = GetPosition(); .) 204 - PostfixUnaryExpr<out expr> 205 - (IF(isAssignmentOperator()) 206 - (. assignment = expr as AstGetSet; 207 - if(assignment == null) 208 - { 209 - SemErr(string.Format("Cannot assign to a {0}", 210 - expr.GetType().Name)); 211 - assignment = _NullNode(GetPosition()); //to prevent null references 212 - } 213 - assignment.Call = PCall.Set; 214 - .) 215 - ( 216 - ( assign (. setModifier = BinaryOperator.None; .) 217 - | plus assign (. setModifier = BinaryOperator.Addition; .) 218 - | minus assign (. setModifier = BinaryOperator.Subtraction; .) 219 - | times assign (. setModifier = BinaryOperator.Multiply; .) 220 - | div assign (. setModifier = BinaryOperator.Division; .) 221 - | bitAnd assign (. setModifier = BinaryOperator.BitwiseAnd; .) 222 - | bitOr assign (. setModifier = BinaryOperator.BitwiseOr; .) 223 - | coalescence assign (. setModifier = BinaryOperator.Coalescence; .) 224 - | deltaleft assign (. setModifier = BinaryOperator.DeltaLeft; .) 225 - | deltaright assign (. setModifier = BinaryOperator.DeltaRight; .) 226 - ) Expr<out expr> //(. expr = expr; .) 227 - 228 - | ( tilde assign (. setModifier = BinaryOperator.Cast; .) 229 - )TypeExpr<out typeExpr> (. expr = typeExpr; .) 230 - ) 231 - (. assignment.Arguments.Add(expr); 232 - if(setModifier == BinaryOperator.None) 233 - expr = assignment; 234 - else 235 - expr = Create.ModifyingAssignment(position,assignment,setModifier); 236 - .) 237 - |) 238 - . 239 - 240 - PostfixUnaryExpr<out AstExpr expr> 241 - (. AstTypeExpr type; AstGetSet extension; bool isInverted = false; .) 242 - = 243 - PrefixUnaryExpr<out expr> (. var position = GetPosition(); .) 244 - { tilde TypeExpr<out type> (. expr = new AstTypecast(this, expr, type); .) 245 - | is 246 - [ not (. isInverted = true; .) 247 - ] 248 - TypeExpr<out type> (. expr = new AstTypecheck(this, expr, type); 249 - if(isInverted) 250 - { 251 - ((AstTypecheck)expr).IsInverted = true; 252 - expr = Create.UnaryOperation(position, UnaryOperator.LogicalNot, expr); 253 - } 254 - .) 255 - | inc (. expr = Create.UnaryOperation(position, UnaryOperator.PostIncrement, expr); .) 256 - | dec (. expr = Create.UnaryOperation(position, UnaryOperator.PostDecrement, expr); .) 257 - | GetSetExtension<expr, out extension> 258 - (. expr = extension; .) 259 - } 260 - . 261 - 262 - PrefixUnaryExpr<out AstExpr expr> 263 - (. var prefixes = new Stack<UnaryOperator>(); .) 264 - = (. var position = GetPosition(); .) 265 - { plus 266 - | minus (. prefixes.Push(UnaryOperator.UnaryNegation); .) 267 - | inc (. prefixes.Push(UnaryOperator.PreIncrement); .) 268 - | dec (. prefixes.Push(UnaryOperator.PreDecrement); .) 269 - | deltaleft (. prefixes.Push(UnaryOperator.PreDeltaLeft); .) 270 - | deltaright (. prefixes.Push(UnaryOperator.PreDeltaRight); .) 271 - } 272 - Primary<out expr> 273 - (. while(prefixes.Count > 0) 274 - expr = Create.UnaryOperation(position, prefixes.Pop(), expr); 275 - .) 276 - . 277 - 278 - Primary<out AstExpr expr> 279 - (. expr = null; 280 - .) 281 - = 282 - (. _pushLexerState(Lexer.Asm); .) (. var blockExpr = Create.Block(GetPosition()); 283 - _PushScope(blockExpr); 284 - .) 285 - asm lpar { AsmInstruction<blockExpr> } rpar 286 - (. _popLexerState(); .) (. expr = blockExpr; 287 - _PopScope(blockExpr); 288 - .) 289 - | Constant<out expr> 290 - | ThisExpression<out expr> 291 - | CoroutineCreation<out expr> 292 - | ListLiteral<out expr> 293 - | HashLiteral<out expr> 294 - | LoopExpr<out expr> 295 - | (. AstThrow th; .) 296 - ThrowExpression<out th> (. expr = th; .) 297 - | IF(isLambdaExpression()) 298 - LambdaExpression<out expr> 299 - | LazyExpression<out expr> 300 - | lpar Expr<out expr> rpar 301 - | IF(_isNotNewDecl()) ObjectCreation<out expr> 302 - | GetInitiator<out expr> 303 - | LPopExpr lpar Expr<out expr> (. //This is a hack that makes string interpolation with expressions possible 304 - //The non-verbal token "LPopExpr" (has no character representation) is 305 - //returned by the lexer if the parser has to treat an expression in a special 306 - //way. This includes notifying the lexer when the expression has been parsed, as 307 - //well as injecting the necessary plus operator. 308 - _popLexerState(); _inject(_plus); .) 309 - rpar 310 - . 311 - 312 - Constant<out AstExpr expr> 313 - (. expr = null; int vi; double vr; bool vb; string vs; .) 314 - = 315 - Integer<out vi> (. expr = new AstConstant(this, vi); .) 316 - | Real<out vr> (. expr = new AstConstant(this, vr); .) 317 - | Boolean<out vb> (. expr = new AstConstant(this, vb); .) 318 - | String<out vs> (. expr = new AstConstant(this, vs); .) 319 - | Null (. expr = new AstConstant(this, null); .) 320 - . 321 - 322 - ListLiteral<out AstExpr expr> 323 - (. AstExpr iexpr; 324 - AstListLiteral lst = new AstListLiteral(this); 325 - expr = lst; 326 - bool missingExpr = false; 327 - .) 328 - = 329 - lbrack 330 - [ Expr<out iexpr> (. lst.Elements.Add(iexpr); .) 331 - { comma (. if(missingExpr) 332 - SemErr("Missing expression in list literal (two consecutive commas)."); 333 - .) 334 - ( Expr<out iexpr> (. lst.Elements.Add(iexpr); 335 - missingExpr = false; 336 - .) 337 - | (. missingExpr = true; .) 338 - ) 339 - } 340 - ] 341 - rbrack 342 - . 343 - 344 - HashLiteral<out AstExpr expr> 345 - (. AstExpr iexpr; 346 - AstHashLiteral hash = new AstHashLiteral(this); 347 - expr = hash; 348 - bool missingExpr = false; 349 - .) 350 - = 351 - lbrace 352 - [ Expr<out iexpr> (. hash.Elements.Add(iexpr); .) 353 - { comma (. if(missingExpr) 354 - SemErr("Missing expression in list literal (two consecutive commas)."); 355 - .) 356 - ( Expr<out iexpr> (. hash.Elements.Add(iexpr); 357 - missingExpr = false; 358 - .) 359 - | (. missingExpr = true; .) 360 - ) 361 - } 362 - ] 363 - rbrace 364 - . 365 - 366 - LoopExpr<out AstExpr expr> 367 - (. var dummyBlock = Create.Block(GetPosition()); 368 - _PushScope(dummyBlock); 369 - expr = _NullNode(GetPosition()); 370 - .) 371 - = 372 - ( WhileLoop<dummyBlock> 373 - | ForLoop<dummyBlock> 374 - | ForeachLoop<dummyBlock> 375 - ) (. _PopScope(dummyBlock); 376 - SemErr("Loop expressions are no longer supported."); 377 - .) 378 - . 379 - 380 - 381 - ObjectCreation<out AstExpr expr> 382 - (. AstTypeExpr type; 383 - ArgumentsProxy args; 384 - .) 385 - = 386 - new TypeExpr<out type> (. _fallbackObjectCreation(type, out expr, out args); .) 387 - Arguments<args> 388 - . 389 - 390 - CoroutineCreation<out AstExpr expr> 391 - (. 392 - AstCreateCoroutine cor = new AstCreateCoroutine(this); 393 - AstExpr iexpr; 394 - expr = cor; 395 - .) 396 - = 397 - coroutine Expr<out iexpr> (. cor.Expression = iexpr; .) 398 - [ for Arguments<cor.Arguments> ] 399 - . 400 - 401 - LambdaExpression<out AstExpr expr> 402 - (. PFunction func = TargetApplication.CreateFunction(generateLocalId()); 403 - func.Meta[Application.ImportKey] = target.Function.Meta[Application.ImportKey]; 404 - func.Meta[PFunction.ParentFunctionKey] = target.Function.Id; 405 - Loader.CreateFunctionTarget(func, target, GetPosition()); 406 - CompilerTarget ft = FunctionTargets[func]; 407 - ISourcePosition position; 408 - .) 409 - = 410 - (. position = GetPosition(); .) 411 - ( FormalArg<ft> 412 - | lpar 413 - [ FormalArg<ft> 414 - { comma 415 - FormalArg<ft> 416 - } 417 - ] 418 - rpar 419 - ) 420 - (. _PushScope(ft); .) 421 - implementation 422 - ( lbrace 423 - { Statement<ft.Ast> } 424 - rbrace 425 - | (. AstReturn ret = new AstReturn(this, ReturnVariant.Exit); .) 426 - Expr<out ret.Expression> (. ft.Ast.Add(ret); .) 427 - ) 428 - (. 429 - _PopScope(ft); 430 - if(errors.count == 0) 431 - { 432 - try { 433 - //Emit code for top-level block 434 - Ast[func].EmitCode(FunctionTargets[func],true,StackSemantics.Effect); 435 - FunctionTargets[func].FinishTarget(); 436 - } catch(Exception e) { 437 - SemErr("Exception during compilation of lambda expression.\n" + e); 438 - } 439 - } 440 - 441 - expr = Create.CreateClosure(position,EntityRef.Function.Create(func.Id,func.ParentApplication.Module.Name)); 442 - .) 443 - . 444 - 445 - LazyExpression<out AstExpr expr> 446 - (. PFunction func = TargetApplication.CreateFunction(generateLocalId()); 447 - func.Meta[Application.ImportKey] = target.Function.Meta[Application.ImportKey]; 448 - func.Meta[PFunction.ParentFunctionKey] = target.Function.Id; 449 - Loader.CreateFunctionTarget(func, target, GetPosition()); 450 - CompilerTarget ft = FunctionTargets[func]; 451 - ISourcePosition position; 452 - 453 - //Switch to nested target 454 - _PushScope(ft); 455 - .) 456 - = 457 - lazy (. position = GetPosition(); .) 458 - ( lbrace 459 - { Statement<ft.Ast> } 460 - rbrace 461 - | (. AstReturn ret = new AstReturn(this, ReturnVariant.Exit); .) 462 - Expr<out ret.Expression> (. ft.Ast.Add(ret); .) 463 - ) 464 - (. 465 - //Turn into capture by value 466 - var cap = ft._ToCaptureByValue(let_bindings(ft)); 467 - 468 - //Restore parent target 469 - _PopScope(ft); 470 - 471 - //Finish nested function 472 - if(errors.count == 0) 473 - { 474 - try { 475 - Ast[func].EmitCode(FunctionTargets[func],true,StackSemantics.Effect); 476 - FunctionTargets[func].FinishTarget(); 477 - } catch(Exception e) { 478 - SemErr("Exception during compilation of lazy expression.\n" + e); 479 - } 480 - } 481 - 482 - //Construct expr (appears in the place of lazy expression) 483 - var clo = Create.CreateClosure(position,EntityRef.Function.Create(func.Id,func.ParentApplication.Module.Name)); 484 - var thunk = Create.IndirectCall(position,Create.Reference(position,EntityRef.Command.Create(Engine.ThunkAlias))); 485 - thunk.Arguments.Add(clo); 486 - thunk.Arguments.AddRange(cap(this)); //Add captured values 487 - expr = thunk; 488 - .) 489 - . 490 - 491 - ThrowExpression<out AstThrow th> (. th = new AstThrow(this); .) 492 - = 493 - throw 494 - Expr<out th.Expression> 495 - . 496 - 497 - ThisExpression<out AstExpr expr> (. var position = GetPosition(); 498 - expr = Create.IndirectCall(position,Create.Null(position)); 499 - .) 500 - = 501 - this (. Loader.ReportMessage(Message.Error("Illegal use of reserved keyword `this`.",position,MessageClasses.ThisReserved)); .) 502 - . 503 - 504 - ExplicitTypeExpr<out AstTypeExpr type> (. type = null; .) 505 - = 506 - tilde PrexoniteTypeExpr<out type> 507 - | ClrTypeExpr<out type> 508 - . 509 - 510 - TypeExpr<out AstTypeExpr type> (. type = null; .) 511 - = 512 - PrexoniteTypeExpr<out type> 513 - | ClrTypeExpr<out type> 514 - . 515 - 516 - ClrTypeExpr<out AstTypeExpr type> 517 - (. string id; .) 518 - = 519 - (. StringBuilder typeId = new StringBuilder(); .) 520 - ( doublecolon 521 - | ns (. typeId.Append(t.val); typeId.Append('.'); .) 522 - ) 523 - { ns (. typeId.Append(t.val); typeId.Append('.'); .) 524 - } 525 - Id<out id> (. typeId.Append(id); 526 - type = new AstConstantTypeExpression(this, 527 - "Object(\"" + StringPType.Escape(typeId.ToString()) + "\")"); 528 - .) 529 - . 530 - 531 - PrexoniteTypeExpr<out AstTypeExpr type> 532 - (. string id = null; .) 533 - = 534 - ( Id<out id> | null (. id = NullPType.Literal; .) 535 - ) 536 - (. AstDynamicTypeExpression dType = new AstDynamicTypeExpression(this, id); .) 537 - [ lt 538 - [ TypeExprElement<dType.Arguments> 539 - { comma TypeExprElement<dType.Arguments> } 540 - ] 541 - gt 542 - ] 543 - (. type = dType; .) 544 - . 545 - 546 - TypeExprElement<. List<AstExpr> args .> 547 - (. AstExpr expr; AstTypeExpr type; .) 548 - = 549 - Constant<out expr> (. args.Add(expr); .) 550 - | ExplicitTypeExpr<out type> (. args.Add(type); .) 551 - | lpar Expr<out expr> rpar (. args.Add(expr); .) 1 + /* 2 + * Prexonite, a scripting engine (Scripting Language -> Bytecode -> Virtual Machine) 3 + * Copyright (C) 2007 Christian "SealedSun" Klauser 4 + * E-mail sealedsun a.t gmail d.ot com 5 + * Web http://www.sealedsun.ch/ 6 + * 7 + * This program is free software; you can redistribute it and/or modify 8 + * it under the terms of the GNU General Public License as published by 9 + * the Free Software Foundation; either version 2 of the License, or 10 + * (at your option) any later version. 11 + * 12 + * Please contact me (sealedsun a.t gmail do.t com) if you need a different license. 13 + * 14 + * This program is distributed in the hope that it will be useful, 15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 + * GNU General Public License for more details. 18 + * 19 + * You should have received a copy of the GNU General Public License along 20 + * with this program; if not, write to the Free Software Foundation, Inc., 21 + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 22 + */ 23 + 24 + 25 + Expr<out AstExpr expr> (. AstConditionalExpression cexpr; expr = _NullNode(GetPosition()); .) 26 + = 27 + AtomicExpr<out expr> 28 + | (. bool isNegated = false; .) 29 + ( if 30 + | unless (. isNegated = true; .) 31 + ) 32 + lpar Expr<out expr> rpar (. cexpr = new AstConditionalExpression(this, expr, isNegated); .) 33 + Expr<out cexpr.IfExpression> 34 + else 35 + Expr<out cexpr.ElseExpression> (. expr = cexpr; .) 36 + . 37 + 38 + 39 + AtomicExpr<out AstExpr expr> 40 + (. AstExpr outerExpr; .) 41 + = 42 + AppendRightExpr<out expr> 43 + { 44 + then 45 + AppendRightExpr<out outerExpr> (. var thenExpr = Create.Call(GetPosition(), EntityRef.Command.Create(Engine.ThenAlias)); 46 + thenExpr.Arguments.Add(expr); 47 + thenExpr.Arguments.Add(outerExpr); 48 + expr = thenExpr; 49 + .) 50 + } 51 + . 52 + 53 + 54 + AppendRightExpr<out AstExpr expr> 55 + (. AstGetSet complex; .) 56 + = 57 + KeyValuePairExpr<out expr> 58 + { 59 + appendright 60 + GetCall<out complex> (. _appendRight(expr,complex); 61 + expr = complex; 62 + .) 63 + } 64 + . 65 + 66 + KeyValuePairExpr<out AstExpr expr> 67 + = 68 + OrExpr<out expr> 69 + [ colon (. AstExpr value; .) 70 + KeyValuePairExpr<out value> (. expr = new AstKeyValuePair(this, expr, value); .) 71 + ] 72 + . 73 + 74 + OrExpr<out AstExpr expr> 75 + (. AstExpr lhs, rhs; .) 76 + = 77 + AndExpr<out lhs> (. expr = lhs; .) 78 + [ or OrExpr<out rhs> (. expr = new AstLogicalOr(this, lhs, rhs); .) 79 + ] 80 + 81 + . 82 + 83 + AndExpr<out AstExpr expr> 84 + (. AstExpr lhs, rhs; .) 85 + = 86 + DeltaExpr<out lhs> (. expr = lhs; .) 87 + [ and AndExpr<out rhs> (. expr = new AstLogicalAnd(this, lhs, rhs); .) 88 + ] 89 + . 90 + 91 + DeltaExpr<out AstExpr expr> 92 + (. AstExpr lhs, rhs; BinaryOperator bop; UnaryOperator uop; .) 93 + = 94 + BitOrExpr<out lhs> (. expr = lhs; .) 95 + { ( deltaleft (. bop = BinaryOperator.DeltaLeft; uop = UnaryOperator.PostDeltaLeft; .) 96 + | deltaright (. bop = BinaryOperator.DeltaRight; uop = UnaryOperator.PostDeltaRight; .) 97 + ) 98 + ( BitOrExpr<out rhs> (. expr = Create.BinaryOperation(GetPosition(), expr, bop, rhs); .) 99 + | (. expr = Create.UnaryOperation(GetPosition(), uop, expr); .) 100 + ) 101 + } 102 + . 103 + 104 + BitOrExpr<out AstExpr expr> 105 + (. AstExpr lhs, rhs; .) 106 + = 107 + BitXorExpr<out lhs> (. expr = lhs; .) 108 + { bitOr BitXorExpr<out rhs> (. expr = Create.BinaryOperation(GetPosition(), expr, BinaryOperator.BitwiseOr, rhs); .) 109 + } 110 + . 111 + 112 + BitXorExpr<out AstExpr expr> 113 + (. AstExpr lhs, rhs; .) 114 + = 115 + BitAndExpr<out lhs> (. expr = lhs; .) 116 + { xor BitAndExpr<out rhs> 117 + (. expr = Create.BinaryOperation(GetPosition(), expr, BinaryOperator.ExclusiveOr, rhs); .) 118 + } 119 + . 120 + 121 + BitAndExpr<out AstExpr expr> 122 + (. AstExpr lhs, rhs; .) 123 + = 124 + NotExpr<out lhs> (. expr = lhs; .) 125 + { bitAnd NotExpr<out rhs> 126 + (. expr = Create.BinaryOperation(GetPosition(), expr, BinaryOperator.BitwiseAnd, rhs); .) 127 + } 128 + . 129 + 130 + NotExpr<out AstExpr expr> 131 + (. AstExpr lhs; bool isNot = false; .) 132 + = 133 + [ not (. isNot = true; .) 134 + ] 135 + EqlExpr<out lhs> (. expr = isNot ? Create.UnaryOperation(GetPosition(), UnaryOperator.LogicalNot, lhs) : lhs; .) 136 + . 137 + 138 + EqlExpr<out AstExpr expr> 139 + (. AstExpr lhs, rhs; BinaryOperator op; .) 140 + = 141 + RelExpr<out lhs> (. expr = lhs; .) 142 + { ( eq (. op = BinaryOperator.Equality; .) 143 + | ne (. op = BinaryOperator.Inequality; .) 144 + ) RelExpr<out rhs> (. expr = Create.BinaryOperation(GetPosition(), expr, op, rhs); .) 145 + } 146 + . 147 + 148 + RelExpr<out AstExpr expr> 149 + (. AstExpr lhs, rhs; BinaryOperator op; .) 150 + = 151 + CoalExpr<out lhs> (. expr = lhs; .) 152 + { ( lt (. op = BinaryOperator.LessThan; .) 153 + | le (. op = BinaryOperator.LessThanOrEqual; .) 154 + | gt (. op = BinaryOperator.GreaterThan; .) 155 + | ge (. op = BinaryOperator.GreaterThanOrEqual; .) 156 + ) CoalExpr<out rhs> (. expr = Create.BinaryOperation(GetPosition(), expr, op, rhs); .) 157 + } 158 + . 159 + 160 + CoalExpr<out AstExpr expr> 161 + (. AstExpr lhs, rhs; AstCoalescence coal = new AstCoalescence(this); .) 162 + = 163 + AddExpr<out lhs> (. expr = lhs; coal.Expressions.Add(lhs); .) 164 + { 165 + coalescence 166 + AddExpr<out rhs> (. expr = coal; coal.Expressions.Add(rhs); .) 167 + } 168 + . 169 + 170 + AddExpr<out AstExpr expr> 171 + (. AstExpr lhs,rhs; BinaryOperator op; .) 172 + = 173 + MulExpr<out lhs> (. expr = lhs; .) 174 + { ( plus (. op = BinaryOperator.Addition; .) 175 + | minus (. op = BinaryOperator.Subtraction; .) 176 + ) MulExpr<out rhs> (. expr = Create.BinaryOperation(GetPosition(), expr, op, rhs); .) 177 + } 178 + . 179 + 180 + MulExpr<out AstExpr expr> 181 + (. AstExpr lhs, rhs; BinaryOperator op; .) 182 + = 183 + PowExpr<out lhs> (. expr = lhs; .) 184 + { ( times (. op = BinaryOperator.Multiply; .) 185 + | div (. op = BinaryOperator.Division; .) 186 + | mod (. op = BinaryOperator.Modulus; .) 187 + ) PowExpr<out rhs> (. expr = Create.BinaryOperation(GetPosition(), expr, op, rhs); .) 188 + } 189 + . 190 + 191 + PowExpr<out AstExpr expr> 192 + (. AstExpr lhs, rhs; .) 193 + = 194 + AssignExpr<out lhs> (. expr = lhs; .) 195 + { pow AssignExpr<out rhs> (. expr = Create.BinaryOperation(GetPosition(), expr, BinaryOperator.Power, rhs); .) 196 + } 197 + . 198 + 199 + AssignExpr<out AstExpr expr> (. AstGetSet assignment; BinaryOperator setModifier = BinaryOperator.None; 200 + AstTypeExpr typeExpr; 201 + ISourcePosition position; 202 + .) 203 + = (. position = GetPosition(); .) 204 + PostfixUnaryExpr<out expr> 205 + (IF(isAssignmentOperator()) 206 + (. assignment = expr as AstGetSet; 207 + if(assignment == null) 208 + { 209 + SemErr(string.Format("Cannot assign to a {0}", 210 + expr.GetType().Name)); 211 + assignment = _NullNode(GetPosition()); //to prevent null references 212 + } 213 + assignment.Call = PCall.Set; 214 + .) 215 + ( 216 + ( assign (. setModifier = BinaryOperator.None; .) 217 + | plus assign (. setModifier = BinaryOperator.Addition; .) 218 + | minus assign (. setModifier = BinaryOperator.Subtraction; .) 219 + | times assign (. setModifier = BinaryOperator.Multiply; .) 220 + | div assign (. setModifier = BinaryOperator.Division; .) 221 + | bitAnd assign (. setModifier = BinaryOperator.BitwiseAnd; .) 222 + | bitOr assign (. setModifier = BinaryOperator.BitwiseOr; .) 223 + | coalescence assign (. setModifier = BinaryOperator.Coalescence; .) 224 + | deltaleft assign (. setModifier = BinaryOperator.DeltaLeft; .) 225 + | deltaright assign (. setModifier = BinaryOperator.DeltaRight; .) 226 + ) Expr<out expr> //(. expr = expr; .) 227 + 228 + | ( tilde assign (. setModifier = BinaryOperator.Cast; .) 229 + )TypeExpr<out typeExpr> (. expr = typeExpr; .) 230 + ) 231 + (. assignment.Arguments.Add(expr); 232 + if(setModifier == BinaryOperator.None) 233 + expr = assignment; 234 + else 235 + expr = Create.ModifyingAssignment(position,assignment,setModifier); 236 + .) 237 + |) 238 + . 239 + 240 + PostfixUnaryExpr<out AstExpr expr> 241 + (. AstTypeExpr type; AstGetSet extension; bool isInverted = false; .) 242 + = 243 + PrefixUnaryExpr<out expr> (. var position = GetPosition(); .) 244 + { tilde TypeExpr<out type> (. expr = new AstTypecast(this, expr, type); .) 245 + | is 246 + [ not (. isInverted = true; .) 247 + ] 248 + TypeExpr<out type> (. expr = new AstTypecheck(this, expr, type); 249 + if(isInverted) 250 + { 251 + ((AstTypecheck)expr).IsInverted = true; 252 + expr = Create.UnaryOperation(position, UnaryOperator.LogicalNot, expr); 253 + } 254 + .) 255 + | inc (. expr = Create.UnaryOperation(position, UnaryOperator.PostIncrement, expr); .) 256 + | dec (. expr = Create.UnaryOperation(position, UnaryOperator.PostDecrement, expr); .) 257 + | GetSetExtension<expr, out extension> 258 + (. expr = extension; .) 259 + } 260 + . 261 + 262 + PrefixUnaryExpr<out AstExpr expr> 263 + (. var prefixes = new Stack<(bool IsSplice, UnaryOperator Op)>(); .) 264 + = (. var position = GetPosition(); .) 265 + { plus // don't need to do anything for '+expr' 266 + | minus (. prefixes.Push((false, UnaryOperator.UnaryNegation)); .) 267 + | times (. prefixes.Push((true, UnaryOperator.None)); .) 268 + | inc (. prefixes.Push((false, UnaryOperator.PreIncrement)); .) 269 + | dec (. prefixes.Push((false, UnaryOperator.PreDecrement)); .) 270 + | deltaleft (. prefixes.Push((false, UnaryOperator.PreDeltaLeft)); .) 271 + | deltaright (. prefixes.Push((false, UnaryOperator.PreDeltaRight)); .) 272 + } 273 + Primary<out expr> 274 + (. while(prefixes.Count > 0) { 275 + var prefix = prefixes.Pop(); 276 + if(prefix.IsSplice) 277 + expr = Create.ArgumentSplice(position, expr); 278 + else 279 + expr = Create.UnaryOperation(position, prefix.Op, expr); 280 + } 281 + .) 282 + . 283 + 284 + Primary<out AstExpr expr> 285 + (. expr = null; 286 + .) 287 + = 288 + (. _pushLexerState(Lexer.Asm); .) (. var blockExpr = Create.Block(GetPosition()); 289 + _PushScope(blockExpr); 290 + .) 291 + asm lpar { AsmInstruction<blockExpr> } rpar 292 + (. _popLexerState(); .) (. expr = blockExpr; 293 + _PopScope(blockExpr); 294 + .) 295 + | Constant<out expr> 296 + | ThisExpression<out expr> 297 + | CoroutineCreation<out expr> 298 + | ListLiteral<out expr> 299 + | HashLiteral<out expr> 300 + | LoopExpr<out expr> 301 + | (. AstThrow th; .) 302 + ThrowExpression<out th> (. expr = th; .) 303 + | IF(isLambdaExpression()) 304 + LambdaExpression<out expr> 305 + | LazyExpression<out expr> 306 + | lpar Expr<out expr> rpar 307 + | IF(_isNotNewDecl()) ObjectCreation<out expr> 308 + | GetInitiator<out expr> 309 + | LPopExpr lpar Expr<out expr> (. //This is a hack that makes string interpolation with expressions possible 310 + //The non-verbal token "LPopExpr" (has no character representation) is 311 + //returned by the lexer if the parser has to treat an expression in a special 312 + //way. This includes notifying the lexer when the expression has been parsed, as 313 + //well as injecting the necessary plus operator. 314 + _popLexerState(); _inject(_plus); .) 315 + rpar 316 + . 317 + 318 + Constant<out AstExpr expr> 319 + (. expr = null; int vi; double vr; bool vb; string vs; .) 320 + = 321 + Integer<out vi> (. expr = new AstConstant(this, vi); .) 322 + | Real<out vr> (. expr = new AstConstant(this, vr); .) 323 + | Boolean<out vb> (. expr = new AstConstant(this, vb); .) 324 + | String<out vs> (. expr = new AstConstant(this, vs); .) 325 + | Null (. expr = new AstConstant(this, null); .) 326 + . 327 + 328 + ListLiteral<out AstExpr expr> 329 + (. AstExpr iexpr; 330 + AstListLiteral lst = new AstListLiteral(this); 331 + expr = lst; 332 + bool missingExpr = false; 333 + .) 334 + = 335 + lbrack 336 + [ Expr<out iexpr> (. lst.Elements.Add(iexpr); .) 337 + { comma (. if(missingExpr) 338 + SemErr("Missing expression in list literal (two consecutive commas)."); 339 + .) 340 + ( Expr<out iexpr> (. lst.Elements.Add(iexpr); 341 + missingExpr = false; 342 + .) 343 + | (. missingExpr = true; .) 344 + ) 345 + } 346 + ] 347 + rbrack 348 + . 349 + 350 + HashLiteral<out AstExpr expr> 351 + (. AstExpr iexpr; 352 + AstHashLiteral hash = new AstHashLiteral(this); 353 + expr = hash; 354 + bool missingExpr = false; 355 + .) 356 + = 357 + lbrace 358 + [ Expr<out iexpr> (. hash.Elements.Add(iexpr); .) 359 + { comma (. if(missingExpr) 360 + SemErr("Missing expression in list literal (two consecutive commas)."); 361 + .) 362 + ( Expr<out iexpr> (. hash.Elements.Add(iexpr); 363 + missingExpr = false; 364 + .) 365 + | (. missingExpr = true; .) 366 + ) 367 + } 368 + ] 369 + rbrace 370 + . 371 + 372 + LoopExpr<out AstExpr expr> 373 + (. var dummyBlock = Create.Block(GetPosition()); 374 + _PushScope(dummyBlock); 375 + expr = _NullNode(GetPosition()); 376 + .) 377 + = 378 + ( WhileLoop<dummyBlock> 379 + | ForLoop<dummyBlock> 380 + | ForeachLoop<dummyBlock> 381 + ) (. _PopScope(dummyBlock); 382 + SemErr("Loop expressions are no longer supported."); 383 + .) 384 + . 385 + 386 + 387 + ObjectCreation<out AstExpr expr> 388 + (. AstTypeExpr type; 389 + ArgumentsProxy args; 390 + .) 391 + = 392 + new TypeExpr<out type> (. _fallbackObjectCreation(type, out expr, out args); .) 393 + Arguments<args> 394 + . 395 + 396 + CoroutineCreation<out AstExpr expr> 397 + (. 398 + AstCreateCoroutine cor = new AstCreateCoroutine(this); 399 + AstExpr iexpr; 400 + expr = cor; 401 + .) 402 + = 403 + coroutine Expr<out iexpr> (. cor.Expression = iexpr; .) 404 + [ for Arguments<cor.Arguments> ] 405 + . 406 + 407 + LambdaExpression<out AstExpr expr> 408 + (. PFunction func = TargetApplication.CreateFunction(generateLocalId()); 409 + func.Meta[Application.ImportKey] = target.Function.Meta[Application.ImportKey]; 410 + func.Meta[PFunction.ParentFunctionKey] = target.Function.Id; 411 + Loader.CreateFunctionTarget(func, target, GetPosition()); 412 + CompilerTarget ft = FunctionTargets[func]; 413 + ISourcePosition position; 414 + .) 415 + = 416 + (. position = GetPosition(); .) 417 + ( FormalArg<ft> 418 + | lpar 419 + [ FormalArg<ft> 420 + { comma 421 + FormalArg<ft> 422 + } 423 + ] 424 + rpar 425 + ) 426 + (. _PushScope(ft); .) 427 + implementation 428 + ( lbrace 429 + { Statement<ft.Ast> } 430 + rbrace 431 + | (. AstReturn ret = new AstReturn(this, ReturnVariant.Exit); .) 432 + Expr<out ret.Expression> (. ft.Ast.Add(ret); .) 433 + ) 434 + (. 435 + _PopScope(ft); 436 + if(errors.count == 0) 437 + { 438 + try { 439 + //Emit code for top-level block 440 + Ast[func].EmitCode(FunctionTargets[func],true,StackSemantics.Effect); 441 + FunctionTargets[func].FinishTarget(); 442 + } catch(Exception e) { 443 + SemErr("Exception during compilation of lambda expression.\n" + e); 444 + } 445 + } 446 + 447 + expr = Create.CreateClosure(position,EntityRef.Function.Create(func.Id,func.ParentApplication.Module.Name)); 448 + .) 449 + . 450 + 451 + LazyExpression<out AstExpr expr> 452 + (. PFunction func = TargetApplication.CreateFunction(generateLocalId()); 453 + func.Meta[Application.ImportKey] = target.Function.Meta[Application.ImportKey]; 454 + func.Meta[PFunction.ParentFunctionKey] = target.Function.Id; 455 + Loader.CreateFunctionTarget(func, target, GetPosition()); 456 + CompilerTarget ft = FunctionTargets[func]; 457 + ISourcePosition position; 458 + 459 + //Switch to nested target 460 + _PushScope(ft); 461 + .) 462 + = 463 + lazy (. position = GetPosition(); .) 464 + ( lbrace 465 + { Statement<ft.Ast> } 466 + rbrace 467 + | (. AstReturn ret = new AstReturn(this, ReturnVariant.Exit); .) 468 + Expr<out ret.Expression> (. ft.Ast.Add(ret); .) 469 + ) 470 + (. 471 + //Turn into capture by value 472 + var cap = ft._ToCaptureByValue(let_bindings(ft)); 473 + 474 + //Restore parent target 475 + _PopScope(ft); 476 + 477 + //Finish nested function 478 + if(errors.count == 0) 479 + { 480 + try { 481 + Ast[func].EmitCode(FunctionTargets[func],true,StackSemantics.Effect); 482 + FunctionTargets[func].FinishTarget(); 483 + } catch(Exception e) { 484 + SemErr("Exception during compilation of lazy expression.\n" + e); 485 + } 486 + } 487 + 488 + //Construct expr (appears in the place of lazy expression) 489 + var clo = Create.CreateClosure(position,EntityRef.Function.Create(func.Id,func.ParentApplication.Module.Name)); 490 + var thunk = Create.IndirectCall(position,Create.Reference(position,EntityRef.Command.Create(Engine.ThunkAlias))); 491 + thunk.Arguments.Add(clo); 492 + thunk.Arguments.AddRange(cap(this)); //Add captured values 493 + expr = thunk; 494 + .) 495 + . 496 + 497 + ThrowExpression<out AstThrow th> (. th = new AstThrow(this); .) 498 + = 499 + throw 500 + Expr<out th.Expression> 501 + . 502 + 503 + ThisExpression<out AstExpr expr> (. var position = GetPosition(); 504 + expr = Create.IndirectCall(position,Create.Null(position)); 505 + .) 506 + = 507 + this (. Loader.ReportMessage(Message.Error("Illegal use of reserved keyword `this`.",position,MessageClasses.ThisReserved)); .) 508 + . 509 + 510 + ExplicitTypeExpr<out AstTypeExpr type> (. type = null; .) 511 + = 512 + tilde PrexoniteTypeExpr<out type> 513 + | ClrTypeExpr<out type> 514 + . 515 + 516 + TypeExpr<out AstTypeExpr type> (. type = null; .) 517 + = 518 + PrexoniteTypeExpr<out type> 519 + | ClrTypeExpr<out type> 520 + . 521 + 522 + ClrTypeExpr<out AstTypeExpr type> 523 + (. string id; .) 524 + = 525 + (. StringBuilder typeId = new StringBuilder(); .) 526 + ( doublecolon 527 + | ns (. typeId.Append(t.val); typeId.Append('.'); .) 528 + ) 529 + { ns (. typeId.Append(t.val); typeId.Append('.'); .) 530 + } 531 + Id<out id> (. typeId.Append(id); 532 + type = new AstConstantTypeExpression(this, 533 + "Object(\"" + StringPType.Escape(typeId.ToString()) + "\")"); 534 + .) 535 + . 536 + 537 + PrexoniteTypeExpr<out AstTypeExpr type> 538 + (. string id = null; .) 539 + = 540 + ( Id<out id> | null (. id = NullPType.Literal; .) 541 + ) 542 + (. AstDynamicTypeExpression dType = new AstDynamicTypeExpression(this, id); .) 543 + [ lt 544 + [ TypeExprElement<dType.Arguments> 545 + { comma TypeExprElement<dType.Arguments> } 546 + ] 547 + gt 548 + ] 549 + (. type = dType; .) 550 + . 551 + 552 + TypeExprElement<. List<AstExpr> args .> 553 + (. AstExpr expr; AstTypeExpr type; .) 554 + = 555 + Constant<out expr> (. args.Add(expr); .) 556 + | ExplicitTypeExpr<out type> (. args.Add(type); .) 557 + | lpar Expr<out expr> rpar (. args.Add(expr); .) 552 558 .
+366 -358
Prexonite/Compiler/Lexer.cs
··· 1 - /* The following code was generated by CSFlex 1.4 on 22.05.2017 */ 1 + /* The following code was generated by CSFlex 1.4 on 27.05.2017 */ 2 2 3 3 #line 1 "Prexonite.lex" 4 4 /* ··· 41 41 /** 42 42 * This class is a scanner generated by <a href="http://www.sourceforge.net/projects/csflex/">C# Flex</a>, based on 43 43 * <a href="http://www.jflex.de/">JFlex</a>, version 1.4 44 - * on 22.05.2017 from the specification file 44 + * on 27.05.2017 from the specification file 45 45 * <tt>Prexonite.lex</tt> 46 46 */ 47 47 class Lexer: Prexonite.Internal.IScanner { ··· 192 192 1, 27, 1, 28, 1, 29, 2, 30, 1, 31, 1, 32, 1, 33, 2, 34, 193 193 1, 35, 1, 34, 1, 36, 1, 37, 1, 38, 1, 39, 1, 40, 1, 30, 194 194 1, 41, 1, 3, 1, 10, 1, 5, 1, 11, 2, 0, 1, 42, 1, 43, 195 - 1, 44, 1, 45, 1, 46, 1, 6, 1, 0, 1, 47, 2, 3, 1, 48, 196 - 14, 0, 1, 49, 1, 50, 1, 14, 1, 0, 3, 3, 1, 51, 1, 52, 195 + 1, 44, 1, 45, 1, 46, 1, 47, 1, 6, 1, 0, 1, 48, 2, 3, 196 + 1, 49, 14, 0, 1, 50, 1, 51, 1, 14, 1, 0, 3, 3, 1, 52, 197 197 1, 53, 1, 54, 1, 55, 1, 56, 1, 57, 1, 58, 1, 59, 1, 60, 198 - 1, 61, 1, 62, 1, 63, 1, 64, 1, 65, 1, 0, 1, 66, 1, 0, 199 - 1, 67, 1, 68, 1, 69, 1, 70, 1, 71, 1, 72, 1, 73, 1, 74, 200 - 1, 75, 1, 76, 1, 77, 1, 0, 1, 78, 1, 0, 1, 79, 1, 80, 198 + 1, 61, 1, 62, 1, 63, 1, 64, 1, 65, 1, 66, 1, 0, 1, 67, 199 + 1, 0, 1, 68, 1, 69, 1, 70, 1, 71, 1, 72, 1, 73, 1, 74, 200 + 1, 75, 1, 76, 1, 77, 1, 78, 1, 0, 1, 79, 1, 0, 1, 80, 201 201 1, 81, 1, 82, 1, 83, 1, 84, 1, 85, 1, 86, 1, 87, 1, 88, 202 - 1, 89, 1, 90, 1, 91, 1, 92, 1, 43, 1, 0, 1, 93, 1, 94, 203 - 2, 0, 2, 3, 1, 0, 1, 95, 1, 0, 1, 96, 1, 0, 1, 97, 204 - 1, 98, 5, 0, 1, 99, 1, 100, 1, 101, 2, 0, 1, 102, 1, 0, 205 - 1, 103, 2, 0, 1, 2, 1, 104, 1, 3, 1, 105, 1, 106, 1, 0, 206 - 1, 107, 1, 0, 1, 85, 1, 89, 1, 92, 1, 108, 2, 0, 1, 109, 207 - 1, 6, 1, 110, 1, 111, 1, 112, 1, 113, 1, 114, 1, 115, 4, 0, 208 - 1, 116, 1, 0, 1, 117, 1, 118, 1, 119, 1, 120, 1, 0, 1, 3, 209 - 1, 106, 1, 0, 1, 107, 1, 0, 1, 121, 1, 0, 1, 122, 1, 123, 210 - 1, 124, 1, 125, 1, 126, 1, 127, 1, 128, 1, 129, 1, 106, 1, 0, 211 - 1, 107, 2, 0, 2, 106, 2, 107, 1, 122, 6, 0, 0 }; 202 + 1, 89, 1, 90, 1, 91, 1, 92, 1, 93, 1, 43, 1, 0, 1, 94, 203 + 1, 95, 2, 0, 2, 3, 1, 0, 1, 96, 1, 0, 1, 97, 1, 0, 204 + 1, 98, 1, 99, 5, 0, 1, 100, 1, 101, 1, 102, 2, 0, 1, 103, 205 + 1, 0, 1, 104, 2, 0, 1, 2, 1, 105, 1, 3, 1, 106, 1, 107, 206 + 1, 0, 1, 108, 1, 0, 1, 86, 1, 90, 1, 93, 1, 109, 2, 0, 207 + 1, 110, 1, 6, 1, 111, 1, 112, 1, 113, 1, 114, 1, 115, 1, 116, 208 + 4, 0, 1, 117, 1, 0, 1, 118, 1, 119, 1, 120, 1, 121, 1, 0, 209 + 1, 3, 1, 107, 1, 0, 1, 108, 1, 0, 1, 122, 1, 0, 1, 123, 210 + 1, 124, 1, 125, 1, 126, 1, 127, 1, 128, 1, 129, 1, 130, 1, 107, 211 + 1, 0, 1, 108, 2, 0, 2, 107, 2, 108, 1, 123, 6, 0, 0 }; 212 212 213 213 private static int [] zzUnpackAction() { 214 - int [] result = new int[241]; 214 + int [] result = new int[242]; 215 215 int offset = 0; 216 216 offset = zzUnpackAction(ZZ_ACTION_PACKED_0, offset, result); 217 217 return result; ··· 245 245 0, 0x0208, 0, 0x0208, 0, 0x0208, 0, 0x0784, 0, 0x07b8, 0, 0x0208, 0, 0x0208, 0, 0x07ec, 246 246 0, 0x0208, 0, 0x0820, 0, 0x0208, 0, 0x0208, 0, 0x0854, 0, 0x0888, 0, 0x0208, 0, 0x08bc, 247 247 0, 0x08f0, 0, 0x0924, 0, 0x0958, 0, 0x098c, 0, 0x09c0, 0, 0x0208, 0, 0x0208, 0, 0x0208, 248 - 0, 0x09f4, 0, 0x0208, 0, 0x0a28, 0, 0x0a5c, 0, 0x0270, 0, 0x0a90, 0, 0x0ac4, 0, 0x0208, 249 - 0, 0x0af8, 0, 0x0b2c, 0, 0x0b60, 0, 0x0b94, 0, 0x0bc8, 0, 0x0bfc, 0, 0x0c30, 0, 0x0c64, 250 - 0, 0x0c98, 0, 0x0ccc, 0, 0x0d00, 0, 0x0d34, 0, 0x0d68, 0, 0x0d9c, 0, 0x0208, 0, 0x0208, 251 - 0, 0x0dd0, 0, 0x0e04, 0, 0x0e38, 0, 0x0e6c, 0, 0x0ea0, 0, 0x0208, 0, 0x0208, 0, 0x0208, 248 + 0, 0x09f4, 0, 0x0208, 0, 0x0208, 0, 0x0a28, 0, 0x0a5c, 0, 0x0270, 0, 0x0a90, 0, 0x0ac4, 249 + 0, 0x0208, 0, 0x0af8, 0, 0x0b2c, 0, 0x0b60, 0, 0x0b94, 0, 0x0bc8, 0, 0x0bfc, 0, 0x0c30, 250 + 0, 0x0c64, 0, 0x0c98, 0, 0x0ccc, 0, 0x0d00, 0, 0x0d34, 0, 0x0d68, 0, 0x0d9c, 0, 0x0208, 251 + 0, 0x0208, 0, 0x0dd0, 0, 0x0e04, 0, 0x0e38, 0, 0x0e6c, 0, 0x0ea0, 0, 0x0208, 0, 0x0208, 252 252 0, 0x0208, 0, 0x0208, 0, 0x0208, 0, 0x0208, 0, 0x0208, 0, 0x0208, 0, 0x0208, 0, 0x0208, 253 - 0, 0x0208, 0, 0x0208, 0, 0x0208, 0, 0x0208, 0, 0x0ed4, 0, 0x0208, 0, 0x0f08, 0, 0x0208, 253 + 0, 0x0208, 0, 0x0208, 0, 0x0208, 0, 0x0208, 0, 0x0208, 0, 0x0ed4, 0, 0x0208, 0, 0x0f08, 254 254 0, 0x0208, 0, 0x0208, 0, 0x0208, 0, 0x0208, 0, 0x0208, 0, 0x0208, 0, 0x0208, 0, 0x0208, 255 - 0, 0x0208, 0, 0x0208, 0, 0x0f3c, 0, 0x0208, 0, 0x0f70, 0, 0x0208, 0, 0x0208, 0, 0x0208, 256 - 0, 0x0208, 0, 0x0208, 0, 0x0208, 0, 0x0fa4, 0, 0x0208, 0, 0x0208, 0, 0x0208, 0, 0x0fd8, 257 - 0, 0x0208, 0, 0x0208, 0, 0x100c, 0, 0x1040, 0, 0x1074, 0, 0x10a8, 0, 0x0208, 0, 0x10dc, 258 - 0, 0x1110, 0, 0x1144, 0, 0x1178, 0, 0x11ac, 0, 0x0208, 0, 0x11e0, 0, 0x0208, 0, 0x1214, 259 - 0, 0x0208, 0, 0x0208, 0, 0x1248, 0, 0x127c, 0, 0x12b0, 0, 0x12e4, 0, 0x1318, 0, 0x0208, 260 - 0, 0x0208, 0, 0x0208, 0, 0x134c, 0, 0x1380, 0, 0x0208, 0, 0x13b4, 0, 0x0208, 0, 0x13e8, 261 - 0, 0x141c, 0, 0x0e04, 0, 0x0270, 0, 0x1450, 0, 0x0270, 0, 0x1484, 0, 0x14b8, 0, 0x14ec, 262 - 0, 0x1520, 0, 0x0208, 0, 0x0208, 0, 0x0208, 0, 0x0208, 0, 0x1554, 0, 0x1588, 0, 0x0208, 263 - 0, 0x0208, 0, 0x0270, 0, 0x0270, 0, 0x0208, 0, 0x0208, 0, 0x0208, 0, 0x0208, 0, 0x15bc, 264 - 0, 0x15f0, 0, 0x1624, 0, 0x1658, 0, 0x0208, 0, 0x168c, 0, 0x0208, 0, 0x0208, 0, 0x0208, 265 - 0, 0x0208, 0, 0x16c0, 0, 0x16f4, 0, 0x1728, 0, 0x175c, 0, 0x1790, 0, 0x17c4, 0, 0x17f8, 266 - 0, 0x182c, 0, 0x1860, 0, 0x0208, 0, 0x0208, 0, 0x0208, 0, 0x0208, 0, 0x0208, 0, 0x0208, 267 - 0, 0x0270, 0, 0x1894, 0, 0x18c8, 0, 0x18fc, 0, 0x1930, 0, 0x1964, 0, 0x0208, 0, 0x1998, 268 - 0, 0x0208, 0, 0x19cc, 0, 0x1a00, 0, 0x1a34, 0, 0x1a68, 0, 0x1a9c, 0, 0x1ad0, 0, 0x1894, 269 - 0, 0x18fc, 0 }; 255 + 0, 0x0208, 0, 0x0208, 0, 0x0208, 0, 0x0f3c, 0, 0x0208, 0, 0x0f70, 0, 0x0208, 0, 0x0208, 256 + 0, 0x0208, 0, 0x0208, 0, 0x0208, 0, 0x0208, 0, 0x0fa4, 0, 0x0208, 0, 0x0208, 0, 0x0208, 257 + 0, 0x0fd8, 0, 0x0208, 0, 0x0208, 0, 0x100c, 0, 0x1040, 0, 0x1074, 0, 0x10a8, 0, 0x0208, 258 + 0, 0x10dc, 0, 0x1110, 0, 0x1144, 0, 0x1178, 0, 0x11ac, 0, 0x0208, 0, 0x11e0, 0, 0x0208, 259 + 0, 0x1214, 0, 0x0208, 0, 0x0208, 0, 0x1248, 0, 0x127c, 0, 0x12b0, 0, 0x12e4, 0, 0x1318, 260 + 0, 0x0208, 0, 0x0208, 0, 0x0208, 0, 0x134c, 0, 0x1380, 0, 0x0208, 0, 0x13b4, 0, 0x0208, 261 + 0, 0x13e8, 0, 0x141c, 0, 0x0e04, 0, 0x0270, 0, 0x1450, 0, 0x0270, 0, 0x1484, 0, 0x14b8, 262 + 0, 0x14ec, 0, 0x1520, 0, 0x0208, 0, 0x0208, 0, 0x0208, 0, 0x0208, 0, 0x1554, 0, 0x1588, 263 + 0, 0x0208, 0, 0x0208, 0, 0x0270, 0, 0x0270, 0, 0x0208, 0, 0x0208, 0, 0x0208, 0, 0x0208, 264 + 0, 0x15bc, 0, 0x15f0, 0, 0x1624, 0, 0x1658, 0, 0x0208, 0, 0x168c, 0, 0x0208, 0, 0x0208, 265 + 0, 0x0208, 0, 0x0208, 0, 0x16c0, 0, 0x16f4, 0, 0x1728, 0, 0x175c, 0, 0x1790, 0, 0x17c4, 266 + 0, 0x17f8, 0, 0x182c, 0, 0x1860, 0, 0x0208, 0, 0x0208, 0, 0x0208, 0, 0x0208, 0, 0x0208, 267 + 0, 0x0208, 0, 0x0270, 0, 0x1894, 0, 0x18c8, 0, 0x18fc, 0, 0x1930, 0, 0x1964, 0, 0x0208, 268 + 0, 0x1998, 0, 0x0208, 0, 0x19cc, 0, 0x1a00, 0, 0x1a34, 0, 0x1a68, 0, 0x1a9c, 0, 0x1ad0, 269 + 0, 0x1894, 0, 0x18fc, 0 }; 270 270 271 271 private static int [] zzUnpackRowMap() { 272 - int [] result = new int[241]; 272 + int [] result = new int[242]; 273 273 int offset = 0; 274 274 offset = zzUnpackRowMap(ZZ_ROWMAP_PACKED_0, offset, result); 275 275 return result; ··· 329 329 4, 13, 5, 0, 8, 13, 1, 69, 2, 0, 1, 13, 12, 0, 2, 13, 330 330 5, 0, 1, 70, 52, 0, 1, 71, 35, 0, 1, 72, 19, 0, 3, 16, 331 331 40, 0, 1, 13, 1, 73, 1, 13, 1, 73, 2, 0, 2, 73, 1, 13, 332 - 1, 0, 1, 13, 1, 0, 1, 74, 1, 73, 2, 0, 4, 73, 5, 0, 333 - 1, 13, 7, 73, 1, 69, 2, 0, 1, 73, 12, 0, 2, 73, 15, 0, 334 - 1, 75, 1, 76, 36, 0, 4, 13, 2, 0, 3, 13, 1, 0, 1, 13, 335 - 2, 0, 1, 13, 2, 0, 1, 13, 1, 77, 2, 13, 5, 0, 2, 13, 336 - 1, 78, 5, 13, 1, 69, 2, 0, 1, 13, 12, 0, 2, 13, 1, 0, 332 + 1, 0, 1, 13, 1, 0, 1, 74, 1, 73, 2, 0, 4, 73, 1, 75, 333 + 4, 0, 1, 13, 7, 73, 1, 69, 2, 0, 1, 73, 12, 0, 2, 73, 334 + 15, 0, 1, 76, 1, 77, 36, 0, 4, 13, 2, 0, 3, 13, 1, 0, 335 + 1, 13, 2, 0, 1, 13, 2, 0, 1, 13, 1, 78, 2, 13, 5, 0, 336 + 2, 13, 1, 79, 5, 13, 1, 69, 2, 0, 1, 13, 12, 0, 2, 13, 337 + 1, 0, 4, 13, 2, 0, 3, 13, 1, 0, 1, 13, 2, 0, 1, 13, 338 + 2, 0, 1, 13, 1, 80, 2, 13, 5, 0, 8, 13, 1, 69, 2, 0, 339 + 1, 13, 12, 0, 2, 13, 13, 0, 1, 81, 43, 0, 1, 82, 1, 83, 340 + 8, 0, 1, 84, 1, 85, 7, 0, 1, 86, 1, 87, 1, 0, 1, 88, 341 + 9, 0, 1, 89, 1, 90, 1, 91, 1, 92, 1, 93, 1, 94, 1, 95, 342 + 32, 0, 1, 96, 17, 0, 1, 97, 11, 0, 1, 98, 1, 0, 1, 98, 343 + 2, 0, 2, 98, 5, 0, 1, 98, 2, 0, 4, 98, 6, 0, 7, 98, 344 + 3, 0, 1, 98, 12, 0, 2, 98, 1, 0, 1, 12, 1, 0, 1, 12, 345 + 21, 0, 1, 68, 1, 12, 1, 99, 25, 0, 3, 13, 1, 100, 2, 0, 346 + 3, 13, 1, 0, 1, 13, 2, 0, 1, 13, 2, 0, 4, 13, 5, 0, 347 + 8, 13, 1, 69, 2, 0, 1, 13, 12, 0, 2, 13, 1, 0, 4, 13, 348 + 2, 0, 3, 13, 1, 0, 1, 13, 2, 0, 1, 13, 2, 0, 4, 13, 349 + 5, 0, 5, 13, 1, 101, 2, 13, 1, 69, 2, 0, 1, 13, 12, 0, 350 + 2, 13, 1, 0, 4, 13, 2, 0, 3, 13, 1, 0, 1, 13, 2, 0, 351 + 1, 13, 2, 0, 4, 13, 5, 0, 5, 13, 1, 102, 2, 13, 1, 69, 352 + 2, 0, 1, 13, 12, 0, 2, 13, 34, 0, 1, 103, 56, 0, 1, 104, 353 + 52, 0, 1, 105, 1, 0, 1, 106, 33, 0, 1, 107, 51, 0, 1, 108, 354 + 17, 0, 1, 109, 33, 0, 1, 110, 15, 0, 1, 111, 2, 0, 1, 112, 355 + 55, 0, 1, 113, 4, 0, 8, 47, 1, 0, 1, 47, 2, 0, 1, 47, 356 + 2, 0, 37, 47, 8, 0, 1, 114, 4, 0, 1, 115, 1, 51, 2, 0, 357 + 1, 116, 8, 0, 1, 117, 1, 118, 1, 119, 1, 120, 1, 121, 1, 122, 358 + 1, 0, 1, 123, 5, 0, 1, 124, 10, 0, 1, 125, 1, 126, 8, 52, 359 + 1, 0, 1, 52, 2, 0, 1, 52, 2, 0, 37, 52, 8, 0, 1, 127, 360 + 4, 0, 1, 128, 1, 129, 2, 0, 1, 130, 8, 0, 1, 131, 1, 132, 361 + 1, 133, 1, 134, 1, 135, 1, 136, 1, 0, 1, 137, 5, 0, 1, 138, 362 + 10, 0, 1, 139, 1, 140, 2, 0, 1, 141, 1, 0, 1, 141, 2, 0, 363 + 2, 141, 5, 0, 1, 141, 2, 0, 4, 141, 1, 0, 1, 142, 4, 0, 364 + 7, 141, 3, 0, 1, 141, 12, 0, 2, 141, 13, 0, 1, 143, 51, 0, 365 + 1, 144, 40, 0, 1, 145, 1, 0, 1, 145, 2, 0, 2, 145, 5, 0, 366 + 1, 145, 2, 0, 4, 145, 1, 0, 1, 146, 4, 0, 7, 145, 3, 0, 367 + 1, 145, 12, 0, 2, 145, 1, 0, 4, 13, 2, 0, 3, 13, 1, 0, 368 + 1, 13, 2, 0, 1, 13, 2, 0, 4, 13, 5, 0, 2, 13, 1, 79, 369 + 5, 13, 1, 69, 2, 0, 1, 13, 12, 0, 2, 13, 13, 0, 1, 147, 370 + 39, 0, 2, 148, 1, 0, 1, 148, 1, 0, 1, 149, 1, 148, 1, 0, 371 + 1, 148, 1, 0, 1, 148, 2, 0, 1, 148, 2, 0, 4, 148, 5, 0, 372 + 8, 148, 3, 0, 1, 148, 4, 0, 1, 72, 7, 0, 2, 148, 5, 0, 373 + 1, 82, 1, 83, 8, 0, 1, 84, 1, 150, 7, 0, 1, 86, 1, 87, 374 + 1, 0, 1, 88, 9, 0, 1, 89, 1, 90, 1, 91, 1, 92, 1, 93, 375 + 1, 94, 1, 95, 9, 0, 1, 151, 24, 0, 1, 151, 59, 0, 1, 152, 376 + 18, 0, 4, 73, 2, 0, 3, 73, 1, 0, 1, 73, 2, 0, 1, 73, 377 + 2, 0, 4, 73, 5, 0, 8, 73, 1, 153, 2, 0, 1, 73, 12, 0, 378 + 2, 73, 10, 76, 2, 0, 40, 76, 16, 77, 1, 154, 35, 77, 1, 0, 337 379 4, 13, 2, 0, 3, 13, 1, 0, 1, 13, 2, 0, 1, 13, 2, 0, 338 - 1, 13, 1, 79, 2, 13, 5, 0, 8, 13, 1, 69, 2, 0, 1, 13, 339 - 12, 0, 2, 13, 13, 0, 1, 80, 43, 0, 1, 81, 1, 82, 8, 0, 340 - 1, 83, 1, 84, 7, 0, 1, 85, 1, 86, 1, 0, 1, 87, 9, 0, 341 - 1, 88, 1, 89, 1, 90, 1, 91, 1, 92, 1, 93, 1, 94, 32, 0, 342 - 1, 95, 17, 0, 1, 96, 11, 0, 1, 97, 1, 0, 1, 97, 2, 0, 343 - 2, 97, 5, 0, 1, 97, 2, 0, 4, 97, 6, 0, 7, 97, 3, 0, 344 - 1, 97, 12, 0, 2, 97, 1, 0, 1, 12, 1, 0, 1, 12, 21, 0, 345 - 1, 68, 1, 12, 1, 98, 25, 0, 3, 13, 1, 99, 2, 0, 3, 13, 346 - 1, 0, 1, 13, 2, 0, 1, 13, 2, 0, 4, 13, 5, 0, 8, 13, 380 + 4, 13, 5, 0, 3, 13, 1, 155, 4, 13, 1, 69, 2, 0, 1, 13, 381 + 12, 0, 2, 13, 1, 0, 3, 13, 1, 156, 2, 0, 3, 13, 1, 0, 382 + 1, 13, 2, 0, 1, 13, 2, 0, 4, 13, 5, 0, 8, 13, 1, 69, 383 + 2, 0, 1, 13, 12, 0, 2, 13, 5, 0, 1, 157, 17, 0, 1, 158, 384 + 34, 0, 1, 159, 16, 0, 1, 160, 1, 0, 1, 161, 49, 0, 1, 162, 385 + 51, 0, 1, 163, 52, 0, 1, 164, 67, 0, 1, 165, 2, 0, 1, 166, 386 + 26, 0, 1, 167, 51, 0, 1, 168, 56, 0, 1, 169, 51, 0, 1, 170, 387 + 51, 0, 1, 171, 18, 0, 1, 172, 33, 0, 1, 173, 50, 0, 1, 174, 388 + 1, 175, 50, 0, 1, 176, 1, 177, 15, 0, 1, 178, 12, 0, 4, 98, 389 + 2, 0, 3, 98, 1, 0, 1, 98, 2, 0, 1, 98, 2, 0, 4, 98, 390 + 5, 0, 8, 98, 3, 0, 1, 98, 12, 0, 2, 98, 1, 0, 2, 179, 391 + 1, 0, 1, 179, 14, 0, 1, 179, 6, 0, 1, 179, 3, 0, 2, 179, 392 + 18, 0, 1, 179, 2, 0, 4, 13, 2, 0, 3, 13, 1, 0, 1, 13, 393 + 2, 0, 1, 13, 2, 0, 4, 13, 5, 0, 4, 13, 1, 180, 3, 13, 347 394 1, 69, 2, 0, 1, 13, 12, 0, 2, 13, 1, 0, 4, 13, 2, 0, 348 395 3, 13, 1, 0, 1, 13, 2, 0, 1, 13, 2, 0, 4, 13, 5, 0, 349 - 5, 13, 1, 100, 2, 13, 1, 69, 2, 0, 1, 13, 12, 0, 2, 13, 396 + 6, 13, 1, 181, 1, 13, 1, 69, 2, 0, 1, 13, 12, 0, 2, 13, 350 397 1, 0, 4, 13, 2, 0, 3, 13, 1, 0, 1, 13, 2, 0, 1, 13, 351 - 2, 0, 4, 13, 5, 0, 5, 13, 1, 101, 2, 13, 1, 69, 2, 0, 352 - 1, 13, 12, 0, 2, 13, 34, 0, 1, 102, 56, 0, 1, 103, 52, 0, 353 - 1, 104, 1, 0, 1, 105, 33, 0, 1, 106, 51, 0, 1, 107, 17, 0, 354 - 1, 108, 33, 0, 1, 109, 15, 0, 1, 110, 2, 0, 1, 111, 55, 0, 355 - 1, 112, 4, 0, 8, 47, 1, 0, 1, 47, 2, 0, 1, 47, 2, 0, 356 - 37, 47, 8, 0, 1, 113, 4, 0, 1, 114, 1, 51, 2, 0, 1, 115, 357 - 8, 0, 1, 116, 1, 117, 1, 118, 1, 119, 1, 120, 1, 121, 1, 0, 358 - 1, 122, 5, 0, 1, 123, 10, 0, 1, 124, 1, 125, 8, 52, 1, 0, 359 - 1, 52, 2, 0, 1, 52, 2, 0, 37, 52, 8, 0, 1, 126, 4, 0, 360 - 1, 127, 1, 128, 2, 0, 1, 129, 8, 0, 1, 130, 1, 131, 1, 132, 361 - 1, 133, 1, 134, 1, 135, 1, 0, 1, 136, 5, 0, 1, 137, 10, 0, 362 - 1, 138, 1, 139, 2, 0, 1, 140, 1, 0, 1, 140, 2, 0, 2, 140, 363 - 5, 0, 1, 140, 2, 0, 4, 140, 1, 0, 1, 141, 4, 0, 7, 140, 364 - 3, 0, 1, 140, 12, 0, 2, 140, 13, 0, 1, 142, 51, 0, 1, 143, 365 - 40, 0, 1, 144, 1, 0, 1, 144, 2, 0, 2, 144, 5, 0, 1, 144, 366 - 2, 0, 4, 144, 1, 0, 1, 145, 4, 0, 7, 144, 3, 0, 1, 144, 367 - 12, 0, 2, 144, 1, 0, 4, 13, 2, 0, 3, 13, 1, 0, 1, 13, 368 - 2, 0, 1, 13, 2, 0, 4, 13, 5, 0, 2, 13, 1, 78, 5, 13, 369 - 1, 69, 2, 0, 1, 13, 12, 0, 2, 13, 13, 0, 1, 146, 39, 0, 370 - 2, 147, 1, 0, 1, 147, 1, 0, 1, 148, 1, 147, 1, 0, 1, 147, 371 - 1, 0, 1, 147, 2, 0, 1, 147, 2, 0, 4, 147, 5, 0, 8, 147, 372 - 3, 0, 1, 147, 4, 0, 1, 72, 7, 0, 2, 147, 5, 0, 1, 81, 373 - 1, 82, 8, 0, 1, 83, 1, 149, 7, 0, 1, 85, 1, 86, 1, 0, 374 - 1, 87, 9, 0, 1, 88, 1, 89, 1, 90, 1, 91, 1, 92, 1, 93, 375 - 1, 94, 9, 0, 1, 150, 24, 0, 1, 150, 59, 0, 1, 151, 18, 0, 376 - 4, 73, 2, 0, 3, 73, 1, 0, 1, 73, 2, 0, 1, 73, 2, 0, 377 - 4, 73, 5, 0, 8, 73, 1, 152, 2, 0, 1, 73, 12, 0, 2, 73, 378 - 10, 75, 2, 0, 40, 75, 16, 76, 1, 153, 35, 76, 1, 0, 4, 13, 379 - 2, 0, 3, 13, 1, 0, 1, 13, 2, 0, 1, 13, 2, 0, 4, 13, 380 - 5, 0, 3, 13, 1, 154, 4, 13, 1, 69, 2, 0, 1, 13, 12, 0, 381 - 2, 13, 1, 0, 3, 13, 1, 155, 2, 0, 3, 13, 1, 0, 1, 13, 382 - 2, 0, 1, 13, 2, 0, 4, 13, 5, 0, 8, 13, 1, 69, 2, 0, 383 - 1, 13, 12, 0, 2, 13, 5, 0, 1, 156, 17, 0, 1, 157, 34, 0, 384 - 1, 158, 16, 0, 1, 159, 1, 0, 1, 160, 49, 0, 1, 161, 51, 0, 385 - 1, 162, 52, 0, 1, 163, 67, 0, 1, 164, 2, 0, 1, 165, 26, 0, 386 - 1, 166, 51, 0, 1, 167, 56, 0, 1, 168, 51, 0, 1, 169, 51, 0, 387 - 1, 170, 18, 0, 1, 171, 33, 0, 1, 172, 50, 0, 1, 173, 1, 174, 388 - 50, 0, 1, 175, 1, 176, 15, 0, 1, 177, 12, 0, 4, 97, 2, 0, 389 - 3, 97, 1, 0, 1, 97, 2, 0, 1, 97, 2, 0, 4, 97, 5, 0, 390 - 8, 97, 3, 0, 1, 97, 12, 0, 2, 97, 1, 0, 2, 178, 1, 0, 391 - 1, 178, 14, 0, 1, 178, 6, 0, 1, 178, 3, 0, 2, 178, 18, 0, 392 - 1, 178, 2, 0, 4, 13, 2, 0, 3, 13, 1, 0, 1, 13, 2, 0, 393 - 1, 13, 2, 0, 4, 13, 5, 0, 4, 13, 1, 179, 3, 13, 1, 69, 398 + 2, 0, 4, 13, 5, 0, 2, 13, 1, 182, 5, 13, 1, 69, 2, 0, 399 + 1, 13, 12, 0, 2, 13, 1, 0, 2, 183, 1, 0, 1, 183, 14, 0, 400 + 1, 183, 6, 0, 1, 183, 3, 0, 2, 183, 18, 0, 1, 183, 2, 0, 401 + 2, 184, 1, 0, 1, 184, 14, 0, 1, 184, 6, 0, 1, 184, 3, 0, 402 + 2, 184, 18, 0, 1, 184, 2, 0, 2, 185, 1, 0, 1, 185, 14, 0, 403 + 1, 185, 6, 0, 1, 185, 3, 0, 2, 185, 18, 0, 1, 185, 2, 0, 404 + 2, 186, 1, 0, 1, 186, 14, 0, 1, 186, 6, 0, 1, 186, 3, 0, 405 + 2, 186, 18, 0, 1, 186, 2, 0, 4, 141, 2, 0, 3, 141, 1, 0, 406 + 1, 141, 2, 0, 1, 141, 2, 0, 4, 141, 5, 0, 8, 141, 3, 0, 407 + 1, 141, 1, 0, 1, 187, 10, 0, 2, 141, 1, 0, 4, 145, 2, 0, 408 + 3, 145, 1, 0, 1, 145, 2, 0, 1, 145, 2, 0, 4, 145, 5, 0, 409 + 8, 145, 3, 0, 1, 145, 1, 0, 1, 188, 10, 0, 2, 145, 1, 0, 410 + 2, 148, 1, 0, 1, 148, 1, 0, 2, 148, 1, 0, 1, 148, 1, 0, 411 + 1, 148, 2, 0, 1, 148, 2, 0, 4, 148, 3, 0, 1, 189, 1, 0, 412 + 8, 148, 3, 0, 1, 148, 12, 0, 2, 148, 1, 0, 2, 148, 1, 0, 413 + 1, 148, 2, 0, 1, 148, 1, 0, 1, 148, 1, 0, 1, 148, 2, 0, 414 + 1, 148, 2, 0, 4, 148, 5, 0, 8, 148, 3, 0, 1, 148, 12, 0, 415 + 2, 148, 23, 0, 1, 190, 29, 0, 1, 151, 1, 0, 1, 151, 1, 191, 416 + 20, 0, 1, 192, 1, 151, 59, 0, 1, 193, 17, 0, 15, 77, 1, 194, 417 + 1, 154, 35, 77, 1, 0, 3, 13, 1, 195, 2, 0, 3, 13, 1, 0, 418 + 1, 13, 2, 0, 1, 13, 2, 0, 4, 13, 5, 0, 8, 13, 1, 69, 394 419 2, 0, 1, 13, 12, 0, 2, 13, 1, 0, 4, 13, 2, 0, 3, 13, 395 - 1, 0, 1, 13, 2, 0, 1, 13, 2, 0, 4, 13, 5, 0, 6, 13, 396 - 1, 180, 1, 13, 1, 69, 2, 0, 1, 13, 12, 0, 2, 13, 1, 0, 397 - 4, 13, 2, 0, 3, 13, 1, 0, 1, 13, 2, 0, 1, 13, 2, 0, 398 - 4, 13, 5, 0, 2, 13, 1, 181, 5, 13, 1, 69, 2, 0, 1, 13, 399 - 12, 0, 2, 13, 1, 0, 2, 182, 1, 0, 1, 182, 14, 0, 1, 182, 400 - 6, 0, 1, 182, 3, 0, 2, 182, 18, 0, 1, 182, 2, 0, 2, 183, 401 - 1, 0, 1, 183, 14, 0, 1, 183, 6, 0, 1, 183, 3, 0, 2, 183, 402 - 18, 0, 1, 183, 2, 0, 2, 184, 1, 0, 1, 184, 14, 0, 1, 184, 403 - 6, 0, 1, 184, 3, 0, 2, 184, 18, 0, 1, 184, 2, 0, 2, 185, 404 - 1, 0, 1, 185, 14, 0, 1, 185, 6, 0, 1, 185, 3, 0, 2, 185, 405 - 18, 0, 1, 185, 2, 0, 4, 140, 2, 0, 3, 140, 1, 0, 1, 140, 406 - 2, 0, 1, 140, 2, 0, 4, 140, 5, 0, 8, 140, 3, 0, 1, 140, 407 - 1, 0, 1, 186, 10, 0, 2, 140, 1, 0, 4, 144, 2, 0, 3, 144, 408 - 1, 0, 1, 144, 2, 0, 1, 144, 2, 0, 4, 144, 5, 0, 8, 144, 409 - 3, 0, 1, 144, 1, 0, 1, 187, 10, 0, 2, 144, 1, 0, 2, 147, 410 - 1, 0, 1, 147, 1, 0, 2, 147, 1, 0, 1, 147, 1, 0, 1, 147, 411 - 2, 0, 1, 147, 2, 0, 4, 147, 3, 0, 1, 188, 1, 0, 8, 147, 412 - 3, 0, 1, 147, 12, 0, 2, 147, 1, 0, 2, 147, 1, 0, 1, 147, 413 - 2, 0, 1, 147, 1, 0, 1, 147, 1, 0, 1, 147, 2, 0, 1, 147, 414 - 2, 0, 4, 147, 5, 0, 8, 147, 3, 0, 1, 147, 12, 0, 2, 147, 415 - 23, 0, 1, 189, 29, 0, 1, 150, 1, 0, 1, 150, 1, 190, 20, 0, 416 - 1, 191, 1, 150, 59, 0, 1, 192, 17, 0, 15, 76, 1, 193, 1, 153, 417 - 35, 76, 1, 0, 3, 13, 1, 194, 2, 0, 3, 13, 1, 0, 1, 13, 418 - 2, 0, 1, 13, 2, 0, 4, 13, 5, 0, 8, 13, 1, 69, 2, 0, 419 - 1, 13, 12, 0, 2, 13, 1, 0, 4, 13, 2, 0, 3, 13, 1, 0, 420 - 1, 13, 2, 0, 1, 13, 2, 0, 3, 13, 1, 195, 5, 0, 8, 13, 421 - 1, 69, 2, 0, 1, 13, 12, 0, 2, 13, 23, 0, 1, 196, 51, 0, 422 - 1, 197, 51, 0, 1, 198, 51, 0, 1, 199, 70, 0, 1, 200, 49, 0, 423 - 1, 201, 39, 0, 1, 202, 42, 0, 1, 203, 55, 0, 1, 204, 1, 0, 424 - 1, 205, 49, 0, 1, 206, 51, 0, 1, 207, 51, 0, 1, 208, 51, 0, 425 - 1, 209, 1, 0, 1, 210, 27, 0, 4, 13, 2, 0, 3, 13, 1, 0, 426 - 1, 13, 2, 0, 1, 13, 2, 0, 3, 13, 1, 211, 5, 0, 8, 13, 427 - 1, 69, 2, 0, 1, 13, 12, 0, 2, 13, 1, 0, 2, 212, 1, 0, 428 - 1, 212, 14, 0, 1, 212, 6, 0, 1, 212, 3, 0, 2, 212, 18, 0, 429 - 1, 212, 2, 0, 2, 213, 1, 0, 1, 213, 14, 0, 1, 213, 6, 0, 430 - 1, 213, 3, 0, 2, 213, 18, 0, 1, 213, 2, 0, 2, 214, 1, 0, 431 - 1, 214, 14, 0, 1, 214, 6, 0, 1, 214, 3, 0, 2, 214, 18, 0, 432 - 1, 214, 2, 0, 2, 215, 1, 0, 1, 215, 14, 0, 1, 215, 6, 0, 433 - 1, 215, 3, 0, 2, 215, 18, 0, 1, 215, 2, 0, 1, 216, 3, 0, 434 - 2, 217, 19, 0, 1, 216, 26, 0, 1, 218, 24, 0, 1, 218, 48, 0, 435 - 1, 219, 51, 0, 1, 220, 51, 0, 1, 221, 51, 0, 1, 222, 51, 0, 436 - 1, 223, 51, 0, 1, 224, 29, 0, 3, 13, 1, 225, 2, 0, 3, 13, 437 - 1, 0, 1, 13, 2, 0, 1, 13, 2, 0, 4, 13, 5, 0, 8, 13, 438 - 1, 69, 2, 0, 1, 13, 12, 0, 2, 13, 1, 0, 2, 226, 1, 0, 439 - 1, 226, 14, 0, 1, 226, 6, 0, 1, 226, 3, 0, 2, 226, 18, 0, 440 - 1, 226, 2, 0, 2, 227, 1, 0, 1, 227, 14, 0, 1, 227, 6, 0, 441 - 1, 227, 3, 0, 2, 227, 18, 0, 1, 227, 2, 0, 2, 228, 1, 0, 442 - 1, 228, 14, 0, 1, 228, 6, 0, 1, 228, 3, 0, 2, 228, 18, 0, 443 - 1, 228, 2, 0, 2, 229, 1, 0, 1, 229, 14, 0, 1, 229, 6, 0, 444 - 1, 229, 3, 0, 2, 229, 18, 0, 1, 229, 2, 0, 1, 216, 1, 0, 445 - 1, 216, 22, 0, 1, 216, 26, 0, 1, 216, 24, 0, 1, 216, 26, 0, 446 - 1, 218, 1, 0, 1, 218, 21, 0, 1, 230, 1, 218, 26, 0, 2, 231, 447 - 1, 0, 1, 231, 14, 0, 1, 231, 6, 0, 1, 231, 3, 0, 2, 231, 448 - 18, 0, 1, 231, 2, 0, 2, 232, 1, 0, 1, 232, 14, 0, 1, 232, 449 - 6, 0, 1, 232, 3, 0, 2, 232, 18, 0, 1, 232, 2, 0, 2, 233, 450 - 1, 0, 1, 233, 14, 0, 1, 233, 6, 0, 1, 233, 3, 0, 2, 233, 451 - 18, 0, 1, 233, 2, 0, 2, 234, 1, 0, 1, 234, 14, 0, 1, 234, 452 - 6, 0, 1, 234, 3, 0, 2, 234, 18, 0, 1, 234, 2, 0, 1, 235, 453 - 24, 0, 1, 235, 26, 0, 2, 236, 1, 0, 1, 236, 14, 0, 1, 236, 454 - 6, 0, 1, 236, 3, 0, 2, 236, 18, 0, 1, 236, 2, 0, 2, 237, 455 - 1, 0, 1, 237, 14, 0, 1, 237, 6, 0, 1, 237, 3, 0, 2, 237, 456 - 18, 0, 1, 237, 2, 0, 1, 235, 1, 0, 1, 235, 22, 0, 1, 235, 457 - 26, 0, 2, 238, 1, 0, 1, 238, 14, 0, 1, 238, 6, 0, 1, 238, 458 - 3, 0, 2, 238, 18, 0, 1, 238, 2, 0, 2, 239, 1, 0, 1, 239, 459 - 14, 0, 1, 239, 6, 0, 1, 239, 3, 0, 2, 239, 18, 0, 1, 239, 460 - 2, 0, 2, 240, 1, 0, 1, 240, 14, 0, 1, 240, 6, 0, 1, 240, 461 - 3, 0, 2, 240, 18, 0, 1, 240, 2, 0, 2, 241, 1, 0, 1, 241, 462 - 14, 0, 1, 241, 6, 0, 1, 241, 3, 0, 2, 241, 18, 0, 1, 241, 463 - 1, 0, 0 }; 420 + 1, 0, 1, 13, 2, 0, 1, 13, 2, 0, 3, 13, 1, 196, 5, 0, 421 + 8, 13, 1, 69, 2, 0, 1, 13, 12, 0, 2, 13, 23, 0, 1, 197, 422 + 51, 0, 1, 198, 51, 0, 1, 199, 51, 0, 1, 200, 70, 0, 1, 201, 423 + 49, 0, 1, 202, 39, 0, 1, 203, 42, 0, 1, 204, 55, 0, 1, 205, 424 + 1, 0, 1, 206, 49, 0, 1, 207, 51, 0, 1, 208, 51, 0, 1, 209, 425 + 51, 0, 1, 210, 1, 0, 1, 211, 27, 0, 4, 13, 2, 0, 3, 13, 426 + 1, 0, 1, 13, 2, 0, 1, 13, 2, 0, 3, 13, 1, 212, 5, 0, 427 + 8, 13, 1, 69, 2, 0, 1, 13, 12, 0, 2, 13, 1, 0, 2, 213, 428 + 1, 0, 1, 213, 14, 0, 1, 213, 6, 0, 1, 213, 3, 0, 2, 213, 429 + 18, 0, 1, 213, 2, 0, 2, 214, 1, 0, 1, 214, 14, 0, 1, 214, 430 + 6, 0, 1, 214, 3, 0, 2, 214, 18, 0, 1, 214, 2, 0, 2, 215, 431 + 1, 0, 1, 215, 14, 0, 1, 215, 6, 0, 1, 215, 3, 0, 2, 215, 432 + 18, 0, 1, 215, 2, 0, 2, 216, 1, 0, 1, 216, 14, 0, 1, 216, 433 + 6, 0, 1, 216, 3, 0, 2, 216, 18, 0, 1, 216, 2, 0, 1, 217, 434 + 3, 0, 2, 218, 19, 0, 1, 217, 26, 0, 1, 219, 24, 0, 1, 219, 435 + 48, 0, 1, 220, 51, 0, 1, 221, 51, 0, 1, 222, 51, 0, 1, 223, 436 + 51, 0, 1, 224, 51, 0, 1, 225, 29, 0, 3, 13, 1, 226, 2, 0, 437 + 3, 13, 1, 0, 1, 13, 2, 0, 1, 13, 2, 0, 4, 13, 5, 0, 438 + 8, 13, 1, 69, 2, 0, 1, 13, 12, 0, 2, 13, 1, 0, 2, 227, 439 + 1, 0, 1, 227, 14, 0, 1, 227, 6, 0, 1, 227, 3, 0, 2, 227, 440 + 18, 0, 1, 227, 2, 0, 2, 228, 1, 0, 1, 228, 14, 0, 1, 228, 441 + 6, 0, 1, 228, 3, 0, 2, 228, 18, 0, 1, 228, 2, 0, 2, 229, 442 + 1, 0, 1, 229, 14, 0, 1, 229, 6, 0, 1, 229, 3, 0, 2, 229, 443 + 18, 0, 1, 229, 2, 0, 2, 230, 1, 0, 1, 230, 14, 0, 1, 230, 444 + 6, 0, 1, 230, 3, 0, 2, 230, 18, 0, 1, 230, 2, 0, 1, 217, 445 + 1, 0, 1, 217, 22, 0, 1, 217, 26, 0, 1, 217, 24, 0, 1, 217, 446 + 26, 0, 1, 219, 1, 0, 1, 219, 21, 0, 1, 231, 1, 219, 26, 0, 447 + 2, 232, 1, 0, 1, 232, 14, 0, 1, 232, 6, 0, 1, 232, 3, 0, 448 + 2, 232, 18, 0, 1, 232, 2, 0, 2, 233, 1, 0, 1, 233, 14, 0, 449 + 1, 233, 6, 0, 1, 233, 3, 0, 2, 233, 18, 0, 1, 233, 2, 0, 450 + 2, 234, 1, 0, 1, 234, 14, 0, 1, 234, 6, 0, 1, 234, 3, 0, 451 + 2, 234, 18, 0, 1, 234, 2, 0, 2, 235, 1, 0, 1, 235, 14, 0, 452 + 1, 235, 6, 0, 1, 235, 3, 0, 2, 235, 18, 0, 1, 235, 2, 0, 453 + 1, 236, 24, 0, 1, 236, 26, 0, 2, 237, 1, 0, 1, 237, 14, 0, 454 + 1, 237, 6, 0, 1, 237, 3, 0, 2, 237, 18, 0, 1, 237, 2, 0, 455 + 2, 238, 1, 0, 1, 238, 14, 0, 1, 238, 6, 0, 1, 238, 3, 0, 456 + 2, 238, 18, 0, 1, 238, 2, 0, 1, 236, 1, 0, 1, 236, 22, 0, 457 + 1, 236, 26, 0, 2, 239, 1, 0, 1, 239, 14, 0, 1, 239, 6, 0, 458 + 1, 239, 3, 0, 2, 239, 18, 0, 1, 239, 2, 0, 2, 240, 1, 0, 459 + 1, 240, 14, 0, 1, 240, 6, 0, 1, 240, 3, 0, 2, 240, 18, 0, 460 + 1, 240, 2, 0, 2, 241, 1, 0, 1, 241, 14, 0, 1, 241, 6, 0, 461 + 1, 241, 3, 0, 2, 241, 18, 0, 1, 241, 2, 0, 2, 242, 1, 0, 462 + 1, 242, 14, 0, 1, 242, 6, 0, 1, 242, 3, 0, 2, 242, 18, 0, 463 + 1, 242, 1, 0, 0 }; 464 464 465 465 private static int [] zzUnpackTrans() { 466 466 int [] result = new int[6916]; ··· 504 504 10, 0, 1, 9, 5, 1, 1, 9, 2, 1, 1, 9, 4, 1, 1, 9, 505 505 7, 1, 3, 9, 5, 1, 3, 9, 1, 1, 2, 9, 2, 1, 3, 9, 506 506 2, 1, 2, 9, 1, 1, 1, 9, 1, 1, 2, 9, 2, 1, 1, 9, 507 - 4, 1, 2, 0, 3, 9, 1, 1, 1, 9, 1, 1, 1, 0, 3, 1, 507 + 4, 1, 2, 0, 3, 9, 1, 1, 2, 9, 1, 1, 1, 0, 3, 1, 508 508 1, 9, 14, 0, 2, 9, 1, 1, 1, 0, 3, 1, 15, 9, 1, 0, 509 509 1, 9, 1, 0, 11, 9, 1, 0, 1, 9, 1, 0, 6, 9, 1, 1, 510 510 3, 9, 1, 1, 2, 9, 2, 1, 1, 0, 1, 1, 1, 9, 2, 0, ··· 516 516 1, 9, 1, 1, 1, 9, 2, 1, 6, 0, 0 }; 517 517 518 518 private static int [] zzUnpackAttribute() { 519 - int [] result = new int[241]; 519 + int [] result = new int[242]; 520 520 int offset = 0; 521 521 offset = zzUnpackAttribute(ZZ_ATTRIBUTE_PACKED_0, offset, result); 522 522 return result; ··· 1028 1028 zzMarkedPos = zzMarkedPosL; 1029 1029 1030 1030 switch (zzAction < 0 ? zzAction : ZZ_ACTION[zzAction]) { 1031 - case 90: 1031 + case 91: 1032 1032 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1033 1033 { 1034 - #line 336 "Prexonite.lex" 1034 + #line 338 "Prexonite.lex" 1035 1035 string fragment = buffer.ToString(); 1036 1036 buffer.Length = 0; 1037 1037 PushState(_surroundingLocalState); ··· 1049 1049 case 11: 1050 1050 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1051 1051 { 1052 - #line 185 "Prexonite.lex" 1052 + #line 187 "Prexonite.lex" 1053 1053 return tok(Parser._lpar); 1054 1054 #line default 1055 1055 } ··· 1057 1057 case 12: 1058 1058 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1059 1059 { 1060 - #line 186 "Prexonite.lex" 1060 + #line 188 "Prexonite.lex" 1061 1061 return tok(Parser._rpar); 1062 1062 #line default 1063 1063 } ··· 1070 1070 #line default 1071 1071 } 1072 1072 break; 1073 - case 106: 1073 + case 107: 1074 1074 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1075 1075 { 1076 - #line 250 "Prexonite.lex" 1076 + #line 252 "Prexonite.lex" 1077 1077 buffer.Append(_unescapeChar(yytext())); 1078 1078 #line default 1079 1079 } 1080 1080 break; 1081 - case 86: 1081 + case 87: 1082 1082 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1083 1083 { 1084 - #line 290 "Prexonite.lex" 1084 + #line 292 "Prexonite.lex" 1085 1085 string fragment = buffer.ToString(); 1086 1086 buffer.Length = 0; 1087 1087 PushState(_surroundingLocalState); ··· 1096 1096 #line default 1097 1097 } 1098 1098 break; 1099 - case 81: 1099 + case 82: 1100 1100 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1101 1101 { 1102 - #line 270 "Prexonite.lex" 1102 + #line 272 "Prexonite.lex" 1103 1103 buffer.Append("\v"); 1104 1104 #line default 1105 1105 } 1106 1106 break; 1107 - case 113: 1107 + case 114: 1108 1108 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1109 1109 { 1110 - #line 178 "Prexonite.lex" 1110 + #line 180 "Prexonite.lex" 1111 1111 return tok(Parser._id,OperatorNames.Prexonite.Decrement); 1112 1112 #line default 1113 1113 } ··· 1115 1115 case 31: 1116 1116 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1117 1117 { 1118 - #line 232 "Prexonite.lex" 1118 + #line 234 "Prexonite.lex" 1119 1119 PopState(); 1120 1120 ret(tok(Parser._string, buffer.ToString())); 1121 1121 buffer.Length = 0; ··· 1123 1123 #line default 1124 1124 } 1125 1125 break; 1126 - case 124: 1126 + case 125: 1127 1127 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1128 1128 { 1129 - #line 180 "Prexonite.lex" 1129 + #line 182 "Prexonite.lex" 1130 1130 return tok(Parser._id,OperatorNames.Prexonite.UnaryDeltaLeftPost); 1131 1131 #line default 1132 1132 } ··· 1134 1134 case 33: 1135 1135 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1136 1136 { 1137 - #line 260 "Prexonite.lex" 1137 + #line 262 "Prexonite.lex" 1138 1138 buffer.Append(yytext()); 1139 1139 #line default 1140 1140 } 1141 1141 break; 1142 - case 91: 1142 + case 92: 1143 1143 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1144 1144 { 1145 1145 #line 98 "Prexonite.lex" ··· 1147 1147 #line default 1148 1148 } 1149 1149 break; 1150 - case 111: 1150 + case 112: 1151 1151 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1152 1152 { 1153 1153 #line 86 "Prexonite.lex" ··· 1158 1158 case 30: 1159 1159 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1160 1160 { 1161 - #line 351 "Prexonite.lex" 1161 + #line 353 "Prexonite.lex" 1162 1162 throw new PrexoniteException(System.String.Format("Invalid character \"{0}\" detected on line {1} in {2}.", yytext(), yyline, File)); 1163 1163 #line default 1164 1164 } ··· 1166 1166 case 16: 1167 1167 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1168 1168 { 1169 - #line 160 "Prexonite.lex" 1169 + #line 162 "Prexonite.lex" 1170 1170 return tok(Parser._lbrace); 1171 1171 #line default 1172 1172 } ··· 1179 1179 #line default 1180 1180 } 1181 1181 break; 1182 - case 78: 1182 + case 79: 1183 1183 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1184 1184 { 1185 - #line 269 "Prexonite.lex" 1185 + #line 271 "Prexonite.lex" 1186 1186 buffer.Append("\r"); 1187 1187 #line default 1188 1188 } 1189 1189 break; 1190 - case 87: 1190 + case 88: 1191 1191 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1192 1192 { 1193 - #line 310 "Prexonite.lex" 1193 + #line 312 "Prexonite.lex" 1194 1194 buffer.Append("\""); 1195 1195 #line default 1196 1196 } ··· 1198 1198 case 17: 1199 1199 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1200 1200 { 1201 - #line 161 "Prexonite.lex" 1201 + #line 163 "Prexonite.lex" 1202 1202 return tok(Parser._lbrack); 1203 1203 #line default 1204 1204 } 1205 1205 break; 1206 - case 118: 1206 + case 119: 1207 1207 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1208 1208 { 1209 - #line 173 "Prexonite.lex" 1209 + #line 175 "Prexonite.lex" 1210 1210 return tok(Parser._id,OperatorNames.Prexonite.GreaterThanOrEqual); 1211 1211 #line default 1212 1212 } 1213 1213 break; 1214 - case 76: 1214 + case 77: 1215 1215 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1216 1216 { 1217 - #line 271 "Prexonite.lex" 1217 + #line 273 "Prexonite.lex" 1218 1218 buffer.Append("\t"); 1219 1219 #line default 1220 1220 } ··· 1230 1230 case 9: 1231 1231 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1232 1232 { 1233 - #line 191 "Prexonite.lex" 1233 + #line 193 "Prexonite.lex" 1234 1234 return tok(Parser._times); 1235 1235 #line default 1236 1236 } 1237 1237 break; 1238 - case 99: 1238 + case 100: 1239 1239 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1240 1240 { 1241 - #line 166 "Prexonite.lex" 1241 + #line 168 "Prexonite.lex" 1242 1242 return tok(Parser._id,OperatorNames.Prexonite.Power); 1243 1243 #line default 1244 1244 } 1245 1245 break; 1246 - case 109: 1246 + case 110: 1247 1247 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1248 1248 { 1249 1249 #line 146 "Prexonite.lex" ··· 1255 1255 case 13: 1256 1256 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1257 1257 { 1258 - #line 194 "Prexonite.lex" 1258 + #line 196 "Prexonite.lex" 1259 1259 return tok(Parser._assign); 1260 1260 #line default 1261 1261 } ··· 1263 1263 case 26: 1264 1264 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1265 1265 { 1266 - #line 212 "Prexonite.lex" 1266 + #line 214 "Prexonite.lex" 1267 1267 return tok(Parser._question); 1268 1268 #line default 1269 1269 } 1270 1270 break; 1271 - case 83: 1271 + case 84: 1272 1272 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1273 1273 { 1274 - #line 266 "Prexonite.lex" 1274 + #line 268 "Prexonite.lex" 1275 1275 buffer.Append("\b"); 1276 1276 #line default 1277 1277 } 1278 1278 break; 1279 - case 80: 1279 + case 81: 1280 1280 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1281 1281 { 1282 - #line 265 "Prexonite.lex" 1282 + #line 267 "Prexonite.lex" 1283 1283 buffer.Append("\a"); 1284 1284 #line default 1285 1285 } 1286 1286 break; 1287 - case 79: 1287 + case 80: 1288 1288 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1289 1289 { 1290 - #line 267 "Prexonite.lex" 1290 + #line 269 "Prexonite.lex" 1291 1291 buffer.Append("\f"); 1292 1292 #line default 1293 1293 } 1294 1294 break; 1295 - case 70: 1295 + case 71: 1296 1296 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1297 1297 { 1298 - #line 239 "Prexonite.lex" 1298 + #line 241 "Prexonite.lex" 1299 1299 /* nothing to do */ 1300 1300 #line default 1301 1301 } ··· 1303 1303 case 8: 1304 1304 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1305 1305 { 1306 - #line 192 "Prexonite.lex" 1306 + #line 194 "Prexonite.lex" 1307 1307 return tok(Parser._div); 1308 1308 #line default 1309 1309 } ··· 1311 1311 case 42: 1312 1312 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1313 1313 { 1314 - #line 207 "Prexonite.lex" 1314 + #line 209 "Prexonite.lex" 1315 1315 return tok(Parser._inc); 1316 1316 #line default 1317 1317 } ··· 1319 1319 case 20: 1320 1320 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1321 1321 { 1322 - #line 199 "Prexonite.lex" 1322 + #line 201 "Prexonite.lex" 1323 1323 return tok(Parser._bitOr); 1324 1324 #line default 1325 1325 } 1326 1326 break; 1327 - case 84: 1327 + case 85: 1328 1328 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1329 1329 { 1330 - #line 268 "Prexonite.lex" 1330 + #line 270 "Prexonite.lex" 1331 1331 buffer.Append("\n"); 1332 1332 #line default 1333 1333 } 1334 1334 break; 1335 - case 120: 1335 + case 121: 1336 1336 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1337 1337 { 1338 - #line 183 "Prexonite.lex" 1338 + #line 185 "Prexonite.lex" 1339 1339 return tok(Parser._id,OperatorNames.Prexonite.BinaryDeltaLeft); 1340 1340 #line default 1341 1341 } ··· 1343 1343 case 24: 1344 1344 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1345 1345 { 1346 - #line 188 "Prexonite.lex" 1346 + #line 190 "Prexonite.lex" 1347 1347 return tok(Parser._rbrace); 1348 1348 #line default 1349 1349 } 1350 1350 break; 1351 - case 125: 1351 + case 126: 1352 1352 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1353 1353 { 1354 - #line 169 "Prexonite.lex" 1354 + #line 171 "Prexonite.lex" 1355 1355 return tok(Parser._id,OperatorNames.Prexonite.ExclusiveOr); 1356 1356 #line default 1357 1357 } 1358 1358 break; 1359 - case 54: 1359 + case 55: 1360 1360 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1361 1361 { 1362 - #line 196 "Prexonite.lex" 1362 + #line 198 "Prexonite.lex" 1363 1363 return tok(Parser._deltaright); 1364 1364 #line default 1365 1365 } 1366 1366 break; 1367 - case 105: 1367 + case 106: 1368 1368 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1369 1369 { 1370 1370 #line 143 "Prexonite.lex" ··· 1375 1375 case 23: 1376 1376 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1377 1377 { 1378 - #line 187 "Prexonite.lex" 1378 + #line 189 "Prexonite.lex" 1379 1379 return tok(Parser._rbrack); 1380 1380 #line default 1381 1381 } ··· 1388 1388 #line default 1389 1389 } 1390 1390 break; 1391 - case 119: 1391 + case 120: 1392 1392 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1393 1393 { 1394 - #line 175 "Prexonite.lex" 1394 + #line 177 "Prexonite.lex" 1395 1395 return tok(Parser._id,OperatorNames.Prexonite.LessThanOrEqual); 1396 1396 #line default 1397 1397 } ··· 1399 1399 case 25: 1400 1400 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1401 1401 { 1402 - #line 209 "Prexonite.lex" 1402 + #line 211 "Prexonite.lex" 1403 1403 return tok(Parser._tilde); 1404 1404 #line default 1405 1405 } 1406 1406 break; 1407 - case 92: 1407 + case 93: 1408 1408 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1409 1409 { 1410 1410 #line 115 "Prexonite.lex" ··· 1423 1423 #line default 1424 1424 } 1425 1425 break; 1426 - case 62: 1426 + case 63: 1427 1427 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1428 1428 { 1429 - #line 237 "Prexonite.lex" 1429 + #line 239 "Prexonite.lex" 1430 1430 buffer.Append("\\"); 1431 1431 #line default 1432 1432 } 1433 1433 break; 1434 + case 47: 1435 + if (ZZ_SPURIOUS_WARNINGS_SUCK) 1436 + { 1437 + #line 157 "Prexonite.lex" 1438 + return multiple(tok(Parser._var), tok(Parser._id, PFunction.ArgumentListId)); 1439 + #line default 1440 + } 1441 + break; 1434 1442 case 2: 1435 1443 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1436 1444 { ··· 1439 1447 #line default 1440 1448 } 1441 1449 break; 1442 - case 85: 1450 + case 86: 1443 1451 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1444 1452 { 1445 - #line 277 "Prexonite.lex" 1453 + #line 279 "Prexonite.lex" 1446 1454 string clipped; 1447 1455 string id = _pruneSmartStringIdentifier(yytext(), out clipped); 1448 1456 string fragment = buffer.ToString(); ··· 1459 1467 #line default 1460 1468 } 1461 1469 break; 1462 - case 51: 1470 + case 52: 1463 1471 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1464 1472 { 1465 - #line 210 "Prexonite.lex" 1473 + #line 212 "Prexonite.lex" 1466 1474 return tok(Parser._doublecolon); 1467 1475 #line default 1468 1476 } ··· 1470 1478 case 39: 1471 1479 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1472 1480 { 1473 - #line 320 "Prexonite.lex" 1481 + #line 322 "Prexonite.lex" 1474 1482 buffer.Append(yytext()); 1475 1483 #line default 1476 1484 } ··· 1478 1486 case 40: 1479 1487 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1480 1488 { 1481 - #line 316 "Prexonite.lex" 1489 + #line 318 "Prexonite.lex" 1482 1490 PopState(); 1483 1491 ret(tok(Parser._string, buffer.ToString())); 1484 1492 buffer.Length = 0; ··· 1486 1494 #line default 1487 1495 } 1488 1496 break; 1489 - case 57: 1497 + case 58: 1490 1498 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1491 1499 { 1492 - #line 225 "Prexonite.lex" 1500 + #line 227 "Prexonite.lex" 1493 1501 return tok(Parser._appendright); 1494 1502 #line default 1495 1503 } 1496 1504 break; 1497 - case 127: 1505 + case 128: 1498 1506 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1499 1507 { 1500 - #line 181 "Prexonite.lex" 1508 + #line 183 "Prexonite.lex" 1501 1509 return tok(Parser._id,OperatorNames.Prexonite.UnaryDeltaRightPre); 1502 1510 #line default 1503 1511 } 1504 1512 break; 1505 - case 77: 1513 + case 66: 1506 1514 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1507 1515 { 1508 - #line 264 "Prexonite.lex" 1516 + #line 242 "Prexonite.lex" 1509 1517 buffer.Append("\0"); 1510 1518 #line default 1511 1519 } 1512 1520 break; 1513 - case 53: 1521 + case 54: 1514 1522 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1515 1523 { 1516 - #line 198 "Prexonite.lex" 1524 + #line 200 "Prexonite.lex" 1517 1525 return tok(Parser._or); 1518 1526 #line default 1519 1527 } 1520 1528 break; 1521 - case 93: 1529 + case 94: 1522 1530 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1523 1531 { 1524 1532 #line 135 "Prexonite.lex" ··· 1526 1534 #line default 1527 1535 } 1528 1536 break; 1529 - case 129: 1537 + case 130: 1530 1538 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1531 1539 { 1532 1540 #line 142 "Prexonite.lex" ··· 1534 1542 #line default 1535 1543 } 1536 1544 break; 1537 - case 110: 1545 + case 111: 1538 1546 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1539 1547 { 1540 1548 #line 141 "Prexonite.lex" ··· 1545 1553 case 4: 1546 1554 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1547 1555 { 1548 - #line 189 "Prexonite.lex" 1556 + #line 191 "Prexonite.lex" 1549 1557 return tok(Parser._plus); 1550 1558 #line default 1551 1559 } 1552 1560 break; 1553 - case 60: 1561 + case 61: 1554 1562 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1555 1563 { 1556 - #line 226 "Prexonite.lex" 1564 + #line 228 "Prexonite.lex" 1557 1565 return tok(Parser._appendleft); 1558 1566 #line default 1559 1567 } 1560 1568 break; 1561 - case 102: 1569 + case 103: 1562 1570 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1563 1571 { 1564 - #line 172 "Prexonite.lex" 1572 + #line 174 "Prexonite.lex" 1565 1573 return tok(Parser._id,OperatorNames.Prexonite.GreaterThan); 1566 1574 #line default 1567 1575 } 1568 1576 break; 1569 - case 98: 1577 + case 99: 1570 1578 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1571 1579 { 1572 1580 #line 105 "Prexonite.lex" ··· 1574 1582 #line default 1575 1583 } 1576 1584 break; 1577 - case 88: 1585 + case 89: 1578 1586 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1579 1587 { 1580 - #line 321 "Prexonite.lex" 1588 + #line 323 "Prexonite.lex" 1581 1589 buffer.Append("\""); 1582 1590 #line default 1583 1591 } 1584 1592 break; 1585 - case 63: 1593 + case 64: 1586 1594 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1587 1595 { 1588 - #line 238 "Prexonite.lex" 1596 + #line 240 "Prexonite.lex" 1589 1597 buffer.Append("\""); 1590 1598 #line default 1591 1599 } 1592 1600 break; 1593 - case 49: 1601 + case 50: 1594 1602 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1595 1603 { 1596 - #line 201 "Prexonite.lex" 1604 + #line 203 "Prexonite.lex" 1597 1605 return tok(Parser._eq); 1598 1606 #line default 1599 1607 } ··· 1601 1609 case 43: 1602 1610 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1603 1611 { 1604 - #line 208 "Prexonite.lex" 1612 + #line 210 "Prexonite.lex" 1605 1613 return tok(Parser._dec); 1606 1614 #line default 1607 1615 } 1608 1616 break; 1609 - case 94: 1617 + case 95: 1610 1618 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1611 1619 { 1612 1620 #line 149 "Prexonite.lex" ··· 1618 1626 case 15: 1619 1627 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1620 1628 { 1621 - #line 215 "Prexonite.lex" 1629 + #line 217 "Prexonite.lex" 1622 1630 return tok(Parser._colon); 1623 1631 #line default 1624 1632 } ··· 1626 1634 case 29: 1627 1635 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1628 1636 { 1629 - #line 236 "Prexonite.lex" 1637 + #line 238 "Prexonite.lex" 1630 1638 buffer.Append(yytext()); 1631 1639 #line default 1632 1640 } ··· 1634 1642 case 28: 1635 1643 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1636 1644 { 1637 - #line 217 "Prexonite.lex" 1645 + #line 219 "Prexonite.lex" 1638 1646 return tok(Parser._comma); 1639 1647 #line default 1640 1648 } 1641 1649 break; 1642 - case 47: 1650 + case 48: 1643 1651 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1644 1652 { 1645 1653 #line 82 "Prexonite.lex" ··· 1650 1658 case 38: 1651 1659 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1652 1660 { 1653 - #line 311 "Prexonite.lex" 1661 + #line 313 "Prexonite.lex" 1654 1662 buffer.Append("$"); 1655 1663 #line default 1656 1664 } ··· 1658 1666 case 14: 1659 1667 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1660 1668 { 1661 - #line 218 "Prexonite.lex" 1669 + #line 220 "Prexonite.lex" 1662 1670 Token dot = tok(Parser._dot); 1663 1671 string memberId = yytext(); 1664 1672 if(memberId.Length > 1) ··· 1671 1679 case 34: 1672 1680 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1673 1681 { 1674 - #line 301 "Prexonite.lex" 1682 + #line 303 "Prexonite.lex" 1675 1683 throw new PrexoniteException("Invalid smart string character '" + yytext() + "' (ASCII " + ((int)yytext()[0]) + ") in input on line " + yyline + "."); 1676 1684 #line default 1677 1685 } 1678 1686 break; 1679 - case 59: 1687 + case 60: 1680 1688 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1681 1689 { 1682 - #line 195 "Prexonite.lex" 1690 + #line 197 "Prexonite.lex" 1683 1691 return tok(Parser._deltaleft); 1684 1692 #line default 1685 1693 } ··· 1687 1695 case 44: 1688 1696 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1689 1697 { 1690 - #line 213 "Prexonite.lex" 1698 + #line 215 "Prexonite.lex" 1691 1699 return tok(Parser._pointer); 1692 1700 #line default 1693 1701 } 1694 1702 break; 1695 - case 52: 1703 + case 53: 1696 1704 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1697 1705 { 1698 - #line 197 "Prexonite.lex" 1706 + #line 199 "Prexonite.lex" 1699 1707 return tok(Parser._and); 1700 1708 #line default 1701 1709 } 1702 1710 break; 1703 - case 122: 1711 + case 123: 1704 1712 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1705 1713 { 1706 1714 #line 136 "Prexonite.lex" ··· 1708 1716 #line default 1709 1717 } 1710 1718 break; 1711 - case 121: 1719 + case 122: 1712 1720 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1713 1721 { 1714 1722 #line 134 "Prexonite.lex" ··· 1716 1724 #line default 1717 1725 } 1718 1726 break; 1719 - case 58: 1727 + case 59: 1720 1728 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1721 1729 { 1722 - #line 205 "Prexonite.lex" 1730 + #line 207 "Prexonite.lex" 1723 1731 return tok(Parser._le); 1724 1732 #line default 1725 1733 } 1726 1734 break; 1727 - case 48: 1735 + case 49: 1728 1736 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1729 1737 { 1730 1738 #line 92 "Prexonite.lex" ··· 1735 1743 case 37: 1736 1744 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1737 1745 { 1738 - #line 305 "Prexonite.lex" 1746 + #line 307 "Prexonite.lex" 1739 1747 PopState(); 1740 1748 ret(tok(Parser._string, buffer.ToString())); 1741 1749 buffer.Length = 0; ··· 1743 1751 #line default 1744 1752 } 1745 1753 break; 1746 - case 56: 1754 + case 57: 1747 1755 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1748 1756 { 1749 - #line 204 "Prexonite.lex" 1757 + #line 206 "Prexonite.lex" 1750 1758 return tok(Parser._ge); 1751 1759 #line default 1752 1760 } 1753 1761 break; 1754 - case 107: 1762 + case 108: 1755 1763 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1756 1764 { 1757 - #line 274 "Prexonite.lex" 1765 + #line 276 "Prexonite.lex" 1758 1766 buffer.Append(_unescapeChar(yytext())); 1759 1767 #line default 1760 1768 } ··· 1762 1770 case 36: 1763 1771 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1764 1772 { 1765 - #line 309 "Prexonite.lex" 1773 + #line 311 "Prexonite.lex" 1766 1774 buffer.Append(yytext()); 1767 1775 #line default 1768 1776 } 1769 1777 break; 1770 - case 117: 1778 + case 118: 1771 1779 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1772 1780 { 1773 - #line 171 "Prexonite.lex" 1781 + #line 173 "Prexonite.lex" 1774 1782 return tok(Parser._id,OperatorNames.Prexonite.Inequality); 1775 1783 #line default 1776 1784 } ··· 1778 1786 case 22: 1779 1787 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1780 1788 { 1781 - #line 206 "Prexonite.lex" 1789 + #line 208 "Prexonite.lex" 1782 1790 return tok(Parser._lt); 1783 1791 #line default 1784 1792 } 1785 1793 break; 1786 - case 66: 1794 + case 67: 1787 1795 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1788 1796 { 1789 - #line 245 "Prexonite.lex" 1797 + #line 247 "Prexonite.lex" 1790 1798 buffer.Append("\r"); 1791 1799 #line default 1792 1800 } ··· 1794 1802 case 27: 1795 1803 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1796 1804 { 1797 - #line 216 "Prexonite.lex" 1805 + #line 218 "Prexonite.lex" 1798 1806 return tok(Parser._semicolon); 1799 1807 #line default 1800 1808 } 1801 1809 break; 1802 - case 61: 1810 + case 62: 1803 1811 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1804 1812 { 1805 - #line 211 "Prexonite.lex" 1813 + #line 213 "Prexonite.lex" 1806 1814 return tok(Parser._coalescence); 1807 1815 #line default 1808 1816 } 1809 1817 break; 1810 - case 69: 1818 + case 70: 1811 1819 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1812 1820 { 1813 - #line 246 "Prexonite.lex" 1821 + #line 248 "Prexonite.lex" 1814 1822 buffer.Append("\v"); 1815 1823 #line default 1816 1824 } ··· 1818 1826 case 21: 1819 1827 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1820 1828 { 1821 - #line 203 "Prexonite.lex" 1829 + #line 205 "Prexonite.lex" 1822 1830 return tok(Parser._gt); 1823 1831 #line default 1824 1832 } 1825 1833 break; 1826 - case 64: 1834 + case 65: 1827 1835 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1828 1836 { 1829 - #line 247 "Prexonite.lex" 1837 + #line 249 "Prexonite.lex" 1830 1838 buffer.Append("\t"); 1831 1839 #line default 1832 1840 } 1833 1841 break; 1834 - case 115: 1842 + case 116: 1835 1843 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1836 1844 { 1837 - #line 170 "Prexonite.lex" 1845 + #line 172 "Prexonite.lex" 1838 1846 return tok(Parser._id,OperatorNames.Prexonite.Equality); 1839 1847 #line default 1840 1848 } 1841 1849 break; 1842 - case 126: 1850 + case 127: 1843 1851 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1844 1852 { 1845 - #line 165 "Prexonite.lex" 1853 + #line 167 "Prexonite.lex" 1846 1854 return tok(Parser._id,OperatorNames.Prexonite.Modulus); 1847 1855 #line default 1848 1856 } 1849 1857 break; 1850 - case 82: 1858 + case 83: 1851 1859 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1852 1860 { 1853 - #line 263 "Prexonite.lex" 1861 + #line 265 "Prexonite.lex" 1854 1862 /* nothing to do */ 1855 1863 #line default 1856 1864 } 1857 1865 break; 1858 - case 128: 1866 + case 129: 1859 1867 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1860 1868 { 1861 - #line 179 "Prexonite.lex" 1869 + #line 181 "Prexonite.lex" 1862 1870 return tok(Parser._id,OperatorNames.Prexonite.UnaryDeltaLeftPre); 1863 1871 #line default 1864 1872 } 1865 1873 break; 1866 - case 123: 1874 + case 124: 1867 1875 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1868 1876 { 1869 - #line 182 "Prexonite.lex" 1877 + #line 184 "Prexonite.lex" 1870 1878 return tok(Parser._id,OperatorNames.Prexonite.UnaryDeltaRightPost); 1871 1879 #line default 1872 1880 } 1873 1881 break; 1874 - case 71: 1882 + case 72: 1875 1883 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1876 1884 { 1877 - #line 242 "Prexonite.lex" 1885 + #line 244 "Prexonite.lex" 1878 1886 buffer.Append("\b"); 1879 1887 #line default 1880 1888 } ··· 1882 1890 case 1: 1883 1891 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1884 1892 { 1885 - #line 228 "Prexonite.lex" 1893 + #line 230 "Prexonite.lex" 1886 1894 Console.WriteLine("Rogue Character: \"{0}\"", yytext()); 1887 1895 #line default 1888 1896 } 1889 1897 break; 1890 - case 103: 1898 + case 104: 1891 1899 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1892 1900 { 1893 - #line 174 "Prexonite.lex" 1901 + #line 176 "Prexonite.lex" 1894 1902 return tok(Parser._id,OperatorNames.Prexonite.LessThan); 1895 1903 #line default 1896 1904 } 1897 1905 break; 1898 - case 68: 1906 + case 69: 1899 1907 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1900 1908 { 1901 - #line 241 "Prexonite.lex" 1909 + #line 243 "Prexonite.lex" 1902 1910 buffer.Append("\a"); 1903 1911 #line default 1904 1912 } 1905 1913 break; 1906 - case 67: 1914 + case 68: 1907 1915 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1908 1916 { 1909 - #line 243 "Prexonite.lex" 1917 + #line 245 "Prexonite.lex" 1910 1918 buffer.Append("\f"); 1911 1919 #line default 1912 1920 } 1913 1921 break; 1914 - case 101: 1922 + case 102: 1915 1923 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1916 1924 { 1917 - #line 168 "Prexonite.lex" 1925 + #line 170 "Prexonite.lex" 1918 1926 return tok(Parser._id,OperatorNames.Prexonite.BitwiseOr); 1919 1927 #line default 1920 1928 } 1921 1929 break; 1922 - case 96: 1930 + case 97: 1923 1931 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1924 1932 { 1925 - #line 163 "Prexonite.lex" 1933 + #line 165 "Prexonite.lex" 1926 1934 return tok(Parser._id,OperatorNames.Prexonite.Subtraction); 1927 1935 #line default 1928 1936 } 1929 1937 break; 1930 - case 55: 1938 + case 56: 1931 1939 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1932 1940 { 1933 - #line 202 "Prexonite.lex" 1941 + #line 204 "Prexonite.lex" 1934 1942 return tok(Parser._ne); 1935 1943 #line default 1936 1944 } 1937 1945 break; 1938 - case 116: 1946 + case 117: 1939 1947 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1940 1948 { 1941 - #line 184 "Prexonite.lex" 1949 + #line 186 "Prexonite.lex" 1942 1950 return tok(Parser._id,OperatorNames.Prexonite.BinaryDeltaRight); 1943 1951 #line default 1944 1952 } 1945 1953 break; 1946 - case 72: 1954 + case 73: 1947 1955 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1948 1956 { 1949 - #line 244 "Prexonite.lex" 1957 + #line 246 "Prexonite.lex" 1950 1958 buffer.Append("\n"); 1951 1959 #line default 1952 1960 } 1953 1961 break; 1954 - case 95: 1962 + case 96: 1955 1963 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1956 1964 { 1957 - #line 162 "Prexonite.lex" 1965 + #line 164 "Prexonite.lex" 1958 1966 return tok(Parser._id,OperatorNames.Prexonite.Addition); 1959 1967 #line default 1960 1968 } ··· 1967 1975 #line default 1968 1976 } 1969 1977 break; 1970 - case 50: 1978 + case 51: 1971 1979 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1972 1980 { 1973 - #line 214 "Prexonite.lex" 1981 + #line 216 "Prexonite.lex" 1974 1982 return tok(Parser._implementation); 1975 1983 #line default 1976 1984 } ··· 1978 1986 case 5: 1979 1987 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1980 1988 { 1981 - #line 190 "Prexonite.lex" 1989 + #line 192 "Prexonite.lex" 1982 1990 return tok(Parser._minus); 1983 1991 #line default 1984 1992 } ··· 1986 1994 case 3: 1987 1995 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1988 1996 { 1989 - #line 157 "Prexonite.lex" 1997 + #line 159 "Prexonite.lex" 1990 1998 return tok(checkKeyword(yytext()), yytext()); 1991 1999 #line default 1992 2000 } ··· 1994 2002 case 32: 1995 2003 if (ZZ_SPURIOUS_WARNINGS_SUCK) 1996 2004 { 1997 - #line 252 "Prexonite.lex" 2005 + #line 254 "Prexonite.lex" 1998 2006 buffer.Append("$"); 1999 2007 #line default 2000 2008 } ··· 2002 2010 case 18: 2003 2011 if (ZZ_SPURIOUS_WARNINGS_SUCK) 2004 2012 { 2005 - #line 193 "Prexonite.lex" 2013 + #line 195 "Prexonite.lex" 2006 2014 return tok(Parser._pow); 2007 2015 #line default 2008 2016 } ··· 2010 2018 case 35: 2011 2019 if (ZZ_SPURIOUS_WARNINGS_SUCK) 2012 2020 { 2013 - #line 256 "Prexonite.lex" 2021 + #line 258 "Prexonite.lex" 2014 2022 PopState(); 2015 2023 ret(tok(Parser._string, buffer.ToString())); 2016 2024 buffer.Length = 0; ··· 2018 2026 #line default 2019 2027 } 2020 2028 break; 2021 - case 114: 2029 + case 115: 2022 2030 if (ZZ_SPURIOUS_WARNINGS_SUCK) 2023 2031 { 2024 - #line 176 "Prexonite.lex" 2032 + #line 178 "Prexonite.lex" 2025 2033 return tok(Parser._id,OperatorNames.Prexonite.UnaryNegation); 2026 2034 #line default 2027 2035 } 2028 2036 break; 2029 - case 65: 2037 + case 78: 2030 2038 if (ZZ_SPURIOUS_WARNINGS_SUCK) 2031 2039 { 2032 - #line 240 "Prexonite.lex" 2040 + #line 266 "Prexonite.lex" 2033 2041 buffer.Append("\0"); 2034 2042 #line default 2035 2043 } 2036 2044 break; 2037 - case 73: 2045 + case 74: 2038 2046 if (ZZ_SPURIOUS_WARNINGS_SUCK) 2039 2047 { 2040 - #line 261 "Prexonite.lex" 2048 + #line 263 "Prexonite.lex" 2041 2049 buffer.Append("\\"); 2042 2050 #line default 2043 2051 } 2044 2052 break; 2045 - case 89: 2053 + case 90: 2046 2054 if (ZZ_SPURIOUS_WARNINGS_SUCK) 2047 2055 { 2048 - #line 323 "Prexonite.lex" 2056 + #line 325 "Prexonite.lex" 2049 2057 string clipped; 2050 2058 string id = _pruneSmartStringIdentifier(yytext(), out clipped); 2051 2059 string fragment = buffer.ToString(); ··· 2065 2073 case 19: 2066 2074 if (ZZ_SPURIOUS_WARNINGS_SUCK) 2067 2075 { 2068 - #line 200 "Prexonite.lex" 2076 + #line 202 "Prexonite.lex" 2069 2077 return tok(Parser._bitAnd); 2070 2078 #line default 2071 2079 } ··· 2073 2081 case 10: 2074 2082 if (ZZ_SPURIOUS_WARNINGS_SUCK) 2075 2083 { 2076 - #line 224 "Prexonite.lex" 2084 + #line 226 "Prexonite.lex" 2077 2085 return tok(Parser._at); 2078 2086 #line default 2079 2087 } 2080 2088 break; 2081 - case 74: 2089 + case 75: 2082 2090 if (ZZ_SPURIOUS_WARNINGS_SUCK) 2083 2091 { 2084 - #line 262 "Prexonite.lex" 2092 + #line 264 "Prexonite.lex" 2085 2093 buffer.Append("\""); 2086 2094 #line default 2087 2095 } 2088 2096 break; 2089 - case 112: 2097 + case 113: 2090 2098 if (ZZ_SPURIOUS_WARNINGS_SUCK) 2091 2099 { 2092 - #line 177 "Prexonite.lex" 2100 + #line 179 "Prexonite.lex" 2093 2101 return tok(Parser._id,OperatorNames.Prexonite.Increment); 2094 2102 #line default 2095 2103 } 2096 2104 break; 2097 - case 100: 2105 + case 101: 2098 2106 if (ZZ_SPURIOUS_WARNINGS_SUCK) 2099 2107 { 2100 - #line 167 "Prexonite.lex" 2108 + #line 169 "Prexonite.lex" 2101 2109 return tok(Parser._id,OperatorNames.Prexonite.BitwiseAnd); 2102 2110 #line default 2103 2111 } 2104 2112 break; 2105 - case 75: 2113 + case 76: 2106 2114 if (ZZ_SPURIOUS_WARNINGS_SUCK) 2107 2115 { 2108 - #line 275 "Prexonite.lex" 2116 + #line 277 "Prexonite.lex" 2109 2117 buffer.Append("$"); 2110 2118 #line default 2111 2119 } 2112 2120 break; 2113 - case 104: 2121 + case 105: 2114 2122 if (ZZ_SPURIOUS_WARNINGS_SUCK) 2115 2123 { 2116 2124 #line 144 "Prexonite.lex" ··· 2118 2126 #line default 2119 2127 } 2120 2128 break; 2121 - case 97: 2129 + case 98: 2122 2130 if (ZZ_SPURIOUS_WARNINGS_SUCK) 2123 2131 { 2124 - #line 164 "Prexonite.lex" 2132 + #line 166 "Prexonite.lex" 2125 2133 return tok(Parser._id,OperatorNames.Prexonite.Division); 2126 2134 #line default 2127 2135 } 2128 2136 break; 2129 - case 108: 2137 + case 109: 2130 2138 if (ZZ_SPURIOUS_WARNINGS_SUCK) 2131 2139 { 2132 2140 #line 109 "Prexonite.lex"
+1494 -1494
Prexonite/Compiler/Parser.Code.cs
··· 1 - // Prexonite 2 - // 3 - // Copyright (c) 2014, Christian Klauser 4 - // All rights reserved. 5 - // 6 - // Redistribution and use in source and binary forms, with or without modification, 7 - // are permitted provided that the following conditions are met: 8 - // 9 - // Redistributions of source code must retain the above copyright notice, 10 - // this list of conditions and the following disclaimer. 11 - // Redistributions in binary form must reproduce the above copyright notice, 12 - // this list of conditions and the following disclaimer in the 13 - // documentation and/or other materials provided with the distribution. 14 - // The names of the contributors may be used to endorse or 15 - // promote products derived from this software without specific prior written permission. 16 - // 17 - // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 - // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 - // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 - // IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 21 - // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 - // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 - // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 - // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 25 - // IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 - using System; 27 - using System.Collections.Generic; 28 - using System.Diagnostics; 29 - using System.Globalization; 30 - using System.Linq; 31 - using System.Runtime.InteropServices; 32 - using JetBrains.Annotations; 33 - using Prexonite.Commands.Core.Operators; 34 - using Prexonite.Compiler.Ast; 35 - using Prexonite.Compiler.Internal; 36 - using Prexonite.Compiler.Symbolic; 37 - using Prexonite.Compiler.Symbolic.Internal; 38 - using Prexonite.Internal; 39 - using Prexonite.Modular; 40 - using Prexonite.Properties; 41 - using Prexonite.Types; 42 - 43 - // ReSharper disable InconsistentNaming 44 - 45 - namespace Prexonite.Compiler 46 - { 47 - internal partial class Parser 48 - { 49 - [DebuggerStepThrough] 50 - internal Parser(IScanner scanner, Loader loader) 51 - : this(scanner) 52 - { 53 - if (loader == null) 54 - throw new ArgumentNullException(nameof(loader)); 55 - _loader = loader; 56 - _createTableOfInstructions(); 57 - Ast = new AstProxy(this); 58 - _astFactory = new ParserAstFactory(this); 59 - _referenceTransformer = new ReferenceTransformer(this); 60 - } 61 - 62 - #region Proxy interface 63 - 64 - private readonly Loader _loader; 65 - 66 - public Loader Loader 67 - { 68 - [DebuggerStepThrough] 69 - get { return _loader; } 70 - } 71 - 72 - /// <summary> 73 - /// Preflight mode causes the parser to abort at the 74 - /// first non-meta construct, giving the user the opportunity 75 - /// to inspect a file's "header" without fully compiling 76 - /// that file. 77 - /// </summary> 78 - public bool PreflightModeEnabled 79 - { 80 - get { return Loader.Options.PreflightModeEnabled; } 81 - } 82 - 83 - public Application TargetApplication 84 - { 85 - [DebuggerStepThrough] 86 - get { return _loader.Options.TargetApplication; } 87 - } 88 - 89 - public Module TargetModule 90 - { 91 - [DebuggerStepThrough] 92 - get { return TargetApplication.Module; } 93 - } 94 - 95 - public LoaderOptions Options 96 - { 97 - [DebuggerStepThrough] 98 - get { return _loader.Options; } 99 - } 100 - 101 - public Engine ParentEngine 102 - { 103 - [DebuggerStepThrough] 104 - get { return _loader.Options.ParentEngine; } 105 - } 106 - 107 - public SymbolStore Symbols 108 - { 109 - [DebuggerStepThrough] 110 - get { return target?.CurrentBlock.Symbols ?? _loader.Symbols; } 111 - } 112 - 113 - private DeclarationScopeBuilder _prepareDeclScope(QualifiedId relativeNsId, ISourcePosition idPosition) 114 - { 115 - if(relativeNsId.Count < 1) 116 - throw new ArgumentOutOfRangeException(nameof(relativeNsId),Resources.Parser_relativeNsId_empty); 117 - var outerScope = Loader.CurrentScope; 118 - QualifiedId prefix; 119 - SymbolStore declScopeStore; 120 - LocalNamespace surroundingNamespace; 121 - if (outerScope == null) 122 - { 123 - prefix = new QualifiedId(null); 124 - declScopeStore = Loader.TopLevelSymbols; 125 - surroundingNamespace = null; 126 - } 127 - else 128 - { 129 - prefix = outerScope.PathPrefix; 130 - declScopeStore = outerScope.Store; 131 - surroundingNamespace = outerScope._LocalNamespace; 132 - } 133 - 134 - var currentLookupScope = (ISymbolView<Symbol>) declScopeStore; 135 - var isOutermostNs = true; 136 - foreach (var nsId in relativeNsId) 137 - { 138 - var localNs = _tryGetLocalNamespace(currentLookupScope, nsId, idPosition); 139 - 140 - prefix = prefix + new QualifiedId(nsId); 141 - 142 - // Create namespace if necessary 143 - if (localNs == null) 144 - { 145 - localNs = ((ModuleLevelView) Loader.TopLevelSymbols).CreateLocalNamespace(new EmptySymbolView<Symbol>()); 146 - } 147 - 148 - // Make sure the namespace is exported from the current module and not just accessible via external declarations 149 - _declareNamespaceAsExported(surroundingNamespace, declScopeStore, nsId, isOutermostNs, idPosition, localNs, prefix); 150 - 151 - surroundingNamespace = localNs; 152 - currentLookupScope = localNs; 153 - if (isOutermostNs) 154 - isOutermostNs = false; 155 - } 156 - 157 - // This should never happen, check is here to convey this fact to null-analysis 158 - if(surroundingNamespace == null) 159 - throw new PrexoniteException("Failed to create the innermost namespace of " + relativeNsId + "."); 160 - 161 - // Create the local scope of this namespace *declaration* (the scope inside the braces) 162 - // Not that this is almost completely independent of the namespace itself 163 - // It is just used as one possible source for exports 164 - var builder = SymbolStoreBuilder.Create(declScopeStore); 165 - return new DeclarationScopeBuilder(builder, prefix, surroundingNamespace); 166 - } 167 - 168 - class DeclarationScopeBuilder 169 - { 170 - [NotNull] 171 - private readonly SymbolStoreBuilder _localScopeBuilder; 172 - 173 - private readonly QualifiedId _prefix; 174 - [NotNull] 175 - // ReSharper disable once MemberHidesStaticFromOuterClass 176 - private readonly LocalNamespace _namespace; 177 - 178 - public DeclarationScopeBuilder([NotNull]SymbolStoreBuilder localScopeBuilder, QualifiedId prefix, [NotNull]LocalNamespace ns) 179 - { 180 - if (localScopeBuilder == null) 181 - throw new ArgumentNullException(nameof(localScopeBuilder)); 182 - if (ns == null) 183 - throw new ArgumentNullException(nameof(ns)); 184 - if (prefix == null) 185 - throw new ArgumentNullException(nameof(prefix)); 186 - 187 - _localScopeBuilder = localScopeBuilder; 188 - _prefix = prefix; 189 - _namespace = ns; 190 - } 191 - 192 - [NotNull] 193 - public SymbolStoreBuilder LocalScopeBuilder 194 - { 195 - get { return _localScopeBuilder; } 196 - } 197 - 198 - public QualifiedId Prefix 199 - { 200 - get { return _prefix; } 201 - } 202 - 203 - [NotNull] 204 - public LocalNamespace Namespace 205 - { 206 - get { return _namespace; } 207 - } 208 - 209 - [NotNull] 210 - public DeclarationScope ToDeclarationScope() 211 - { 212 - return new DeclarationScope(Namespace, Prefix, LocalScopeBuilder.ToSymbolStore()); 213 - } 214 - } 215 - 216 - [CanBeNull] 217 - private LocalNamespace _tryGetLocalNamespace([NotNull] ISymbolView<Symbol> currentSurrounding, [NotNull] string superNsId, [NotNull] ISourcePosition idPosition) 218 - { 219 - Symbol sym; 220 - LocalNamespace localNs = null; 221 - if (currentSurrounding.TryGet(superNsId, out sym)) 222 - { 223 - var fakeExpr = Create.ExprFor(idPosition, sym); 224 - var nsUsage = fakeExpr as AstNamespaceUsage; 225 - if (nsUsage == null) 226 - Loader.ReportMessage(Message.Error( 227 - string.Format(Resources.Parser_NamespaceExpected, superNsId, sym), 228 - idPosition, MessageClasses.NamespaceExcepted)); 229 - else 230 - { 231 - // namespace already exists 232 - localNs = nsUsage.Namespace as LocalNamespace; 233 - if (localNs == null) 234 - { 235 - Loader.ReportMessage(Message.Error( 236 - string.Format(Resources.Parser_CannotExtendMergedNamespace, superNsId), 237 - idPosition, MessageClasses.CannotExtendMergedNamespace)); 238 - } 239 - } 240 - } 241 - return localNs; 242 - } 243 - 244 - /// <summary> 245 - /// Ensures the namespace is declared as an exported symbol (and not just available via external declarations) 246 - /// </summary> 247 - /// <param name="surroundingNamespace">Reference to the surrounding namespace, if any</param> 248 - /// <param name="outer">Reference to the top-level symbol store</param> 249 - /// <param name="superNsId">Name of the namespace to declare</param> 250 - /// <param name="isOutermostNs">True if the symbol should be added to the top-level scope; false if it should be declared in the surrounding namespace</param> 251 - /// <param name="idPosition">Position of the name that caused this declaration (position of the namespace name)</param> 252 - /// <param name="localNs">The namespace to declare</param> 253 - /// <param name="nextPrefix">Namespaces prefix to use for physical names in declared namespace. Or null if the namespace already has a prefix assigned.</param> 254 - private static void _declareNamespaceAsExported( 255 - LocalNamespace surroundingNamespace, 256 - SymbolStore outer, 257 - string superNsId, 258 - bool isOutermostNs, 259 - ISourcePosition idPosition, 260 - LocalNamespace localNs, 261 - QualifiedId nextPrefix) 262 - { 263 - var nsSym = Symbol.CreateNamespace(localNs, idPosition); 264 - Symbol existingSym; 265 - if (isOutermostNs) 266 - { 267 - // The outermost namespace (x in x.y.z) is declared as an ordinary symbol in the current scope 268 - if (!outer.IsDeclaredLocally(superNsId) || 269 - !(outer.TryGet(superNsId, out existingSym) && existingSym.Equals(nsSym))) 270 - { 271 - outer.Declare(superNsId, nsSym); 272 - } 273 - } 274 - else if (surroundingNamespace == null) 275 - throw new PrexoniteException( 276 - "Failed to create surrounding namespace (syntactic sugar for nested namespace)"); 277 - else 278 - { 279 - // Inner namespaces (z and y in x.y.z) are exported from their respective super-namespaces 280 - if (!surroundingNamespace.TryGetExported(superNsId, out existingSym) || !existingSym.Equals(nsSym)) 281 - { 282 - surroundingNamespace.DeclareExports( 283 - new KeyValuePair<string, Symbol>(superNsId, nsSym).Singleton()); 284 - } 285 - } 286 - 287 - if (localNs.Prefix == null) 288 - { 289 - localNs.Prefix = nextPrefix.ToString().Replace('.', '\\'); 290 - } 291 - } 292 - 293 - [CanBeNull] 294 - private ISymbolView<Symbol> _resolveNamespace(ISymbolView<Symbol> scope, [NotNull] ISourcePosition qualifiedIdPosition, QualifiedId qualifiedId) 295 - { 296 - while (qualifiedId.Count > 0) 297 - { 298 - Symbol sym; 299 - scope.TryGet(qualifiedId[0], out sym); 300 - var expr = Create.ExprFor(qualifiedIdPosition, sym); 301 - var nsUsage = expr as AstNamespaceUsage; 302 - if (nsUsage == null) 303 - { 304 - Create.ReportMessage( 305 - Message.Error(string.Format(Resources.Parser_NamespaceExpected, qualifiedId[0], sym == null ? "not defined" : sym.ToString()), 306 - qualifiedIdPosition, MessageClasses.NamespaceExcepted)); 307 - return null; 308 - } 309 - else 310 - { 311 - scope = nsUsage.Namespace; 312 - qualifiedId = qualifiedId.WithPrefixDropped(1); 313 - } 314 - } 315 - return scope; 316 - } 317 - 318 - private void _updateNamespace(DeclarationScope scope, SymbolStoreBuilder builder) 319 - { 320 - scope._LocalNamespace.DeclareExports(builder.ToSymbolStore()); 321 - } 322 - 323 - private SymbolOrigin _privateDeclarationOrigin(ISourcePosition position, DeclarationScope scope) 324 - { 325 - return new SymbolOrigin.NamespaceDeclarationScope(position, scope.PathPrefix); 326 - } 327 - 328 - private DeclarationScope _popDeclScope() 329 - { 330 - // The symbol for this namespace should already have been declared by the push operation 331 - return Loader.PopScope(); 332 - } 333 - 334 - /// <summary> 335 - /// When forwarding exported symbols from the declaration scope, 336 - /// we need to assemble a temporary symbol view that only contains 337 - /// the symbols declared locally. 338 - /// </summary> 339 - /// <param name="declStore">The store to extract the exported symbols from.</param> 340 - /// <returns>A static view (shallow copy) of the exported symbols of <paramref name="declStore"/>.</returns> 341 - private ISymbolView<Symbol> _indexExportedSymbols(SymbolStore declStore) 342 - { 343 - var index = SymbolStore.Create(); 344 - foreach (var symbol in declStore.LocalDeclarations) 345 - index.Declare(symbol.Key, symbol.Value); 346 - return index; 347 - } 348 - 349 - private String _assignPhysicalFunctionSlot([CanBeNull] String primaryId) 350 - { 351 - return _assignPhysicalSlot(primaryId ?? Engine.GenerateName("f")); 352 - } 353 - 354 - private string _assignPhysicalSlot(string id) 355 - { 356 - var scope = Loader.CurrentScope; 357 - return scope == null ? id : scope._LocalNamespace.DerivePhysicalName(id); 358 - } 359 - 360 - private String _assignPhysicalGlobalVariableSlot([CanBeNull] string primaryId) 361 - { 362 - return _assignPhysicalSlot(primaryId ?? Engine.GenerateName("v")); 363 - } 364 - 365 - public Loader.FunctionTargetsIterator FunctionTargets 366 - { 367 - [DebuggerStepThrough] 368 - get { return _loader.FunctionTargets; } 369 - } 370 - 371 - public AstProxy Ast { get; } 372 - 373 - [DebuggerStepThrough] 374 - public class AstProxy 375 - { 376 - private readonly Parser outer; 377 - 378 - internal AstProxy(Parser outer) 379 - { 380 - this.outer = outer; 381 - } 382 - 383 - public AstBlock this[PFunction func] => outer._loader.FunctionTargets[func].Ast; 384 - } 385 - 386 - private CompilerTarget _target; 387 - 388 - public CompilerTarget target 389 - { 390 - [DebuggerStepThrough] 391 - get { return _target; } 392 - } 393 - 394 - protected int LocalState 395 - { 396 - get 397 - { 398 - MetaEntry flagSwitch; 399 - bool flagLiteralsEnabled; 400 - if (target != null && target.Meta.TryGetValue(Shell.FlagLiteralsKey, out flagSwitch)) 401 - { 402 - flagLiteralsEnabled = flagSwitch.Switch; 403 - } 404 - else if (TargetApplication.Meta.TryGetValue(Shell.FlagLiteralsKey, out flagSwitch)) 405 - { 406 - flagLiteralsEnabled = flagSwitch.Switch; 407 - } 408 - else 409 - { 410 - flagLiteralsEnabled = _loader.Options.FlagLiteralsEnabled; 411 - } 412 - 413 - return flagLiteralsEnabled ? Lexer.LocalShell : Lexer.Local; 414 - } 415 - } 416 - 417 - public AstBlock CurrentBlock => target?.CurrentBlock; 418 - 419 - private readonly IAstFactory _astFactory; 420 - 421 - protected IAstFactory Create => _astFactory; 422 - 423 - #endregion 424 - 425 - #region String cache 426 - 427 - [DebuggerStepThrough] 428 - internal string cache(string toCache) 429 - { 430 - return _loader.CacheString(toCache); 431 - } 432 - 433 - #endregion 434 - 435 - public void ViolentlyAbortParse() 436 - { 437 - scanner.Abort(); 438 - } 439 - 440 - #region Helper 441 - 442 - #region General 443 - 444 - private static string _removeSingleQuotes(string s) 445 - { 446 - return s.Replace("'", ""); 447 - } 448 - 449 - public static bool TryParseInteger(string s, out int i) 450 - { 451 - return Int32.TryParse(_removeSingleQuotes(s), IntegerStyle, CultureInfo.InvariantCulture, 452 - out i); 453 - } 454 - 455 - public static bool TryParseReal(string s, out double d) 456 - { 457 - return Double.TryParse(_removeSingleQuotes(s), RealStyle, CultureInfo.InvariantCulture, 458 - out d); 459 - } 460 - 461 - public static bool TryParseVersion(string s, out Version version) 462 - { 463 - return System.Version.TryParse(s, out version); 464 - } 465 - 466 - public static NumberStyles RealStyle 467 - { 468 - get { return NumberStyles.AllowDecimalPoint | NumberStyles.AllowExponent; } 469 - } 470 - 471 - public static NumberStyles IntegerStyle 472 - { 473 - get { return NumberStyles.None; } 474 - } 475 - 476 - [DebuggerStepThrough, Obsolete("Use Loader.ReportMessage instead.")] 477 - public void SemErr(int line, int col, string message) 478 - { 479 - errors.SemErr(line, col, message); 480 - } 481 - 482 - [DebuggerStepThrough, Obsolete("Use Loader.ReportMessage instead.")] 483 - public void SemErr(Token tok, string s) 484 - { 485 - errors.SemErr(tok.line, tok.col, s); 486 - } 487 - 488 - private void _pushLexerState(int state) 489 - { 490 - var lex = scanner as Lexer; 491 - if (lex == null) 492 - throw new PrexoniteException("The prexonite grammar requires a *Lex-scanner."); 493 - lex.PushState(state); 494 - } 495 - 496 - private void _popLexerState() 497 - { 498 - var lex = scanner as Lexer; 499 - if (lex == null) 500 - throw new PrexoniteException("The prexonite grammar requires a *Lex-scanner."); 501 - lex.PopState(); 502 - //Might be id or keyword 503 - if ((la.kind > _BEGINKEYWORDS && la.kind < _ENDKEYWORDS) || la.kind == _id) 504 - la.kind = lex.checkKeyword(la.val); 505 - } 506 - 507 - private void _inject(Token c) 508 - { 509 - var lex = scanner as Lexer; 510 - if (lex == null) 511 - throw new PrexoniteException("The prexonite grammar requires a *Lex-scanner."); 512 - 513 - if (c == null) 514 - throw new ArgumentNullException(nameof(c)); 515 - 516 - lex._InjectToken(c); 517 - } 518 - 519 - private void _inject(int kind, string val) 520 - { 521 - if (val == null) 522 - throw new ArgumentNullException(nameof(val)); 523 - var c = new Token 524 - { 525 - kind = kind, 526 - val = val 527 - }; 528 - _inject(c); 529 - } 530 - 531 - private void _inject(int kind) 532 - { 533 - _inject(kind, System.String.Empty); 534 - } 535 - 536 - /// <summary> 537 - /// Defines a new global variable (or returns the existing declaration and instance) 538 - /// </summary> 539 - /// <param name="id">The physical name of the new global variable.</param> 540 - /// <param name="vari">The variable declaration for the new variable.</param> 541 - protected PVariable DefineGlobalVariable(string id, out VariableDeclaration vari) 542 - { 543 - if (TargetModule.Variables.TryGetVariable(id, out vari)) 544 - { 545 - return TargetApplication.Variables[vari.Id]; 546 - } 547 - else 548 - { 549 - vari = global::Prexonite.Modular.VariableDeclaration.Create(id); 550 - TargetModule.Variables.Add(vari); 551 - return TargetApplication.Variables[id] = new PVariable(vari); 552 - } 553 - } 554 - 555 - private void _compileAndExecuteBuildBlock(CompilerTarget buildBlockTarget) 556 - { 557 - if (errors.count > 0) 558 - { 559 - Loader.ReportMessage(Message.Error(Resources.Parser_ErrorsInBuildBlock,GetPosition(),MessageClasses.ErrorsInBuildBlock)); 560 - return; 561 - } 562 - 563 - //Emit code for top-level build block 564 - try 565 - { 566 - buildBlockTarget.Ast.EmitCode(buildBlockTarget, true, StackSemantics.Effect); 567 - 568 - buildBlockTarget.Function.Meta["File"] = scanner.File; 569 - buildBlockTarget.FinishTarget(); 570 - //Run the build block 571 - var fctx = buildBlockTarget.Function.CreateFunctionContext(ParentEngine, 572 - new PValue[] { }, 573 - new PVariable[] { }, true); 574 - object token = null; 575 - try 576 - { 577 - TargetApplication._SuppressInitialization = true; 578 - token = Loader.RequestBuildCommands(); 579 - ParentEngine.Process(fctx); 580 - } 581 - finally 582 - { 583 - if (token != null) 584 - Loader.ReleaseBuildCommands(token); 585 - TargetApplication._SuppressInitialization = false; 586 - } 587 - } 588 - catch (Exception e) 589 - { 590 - Loader.ReportMessage(Message.Error(string.Format(Resources.Parser_exception_in_build_block, e),GetPosition(),MessageClasses.ExceptionDuringCompilation)); 591 - } 592 - } 593 - 594 - private bool _suppressPrimarySymbol(IHasMetaTable ihmt) 595 - { 596 - return ihmt.Meta[Loader.SuppressPrimarySymbol].Switch; 597 - } 598 - 599 - #endregion //General 600 - 601 - #region Prexonite Script 602 - 603 - #region Symbol management 604 - 605 - internal static AstGetSet _NullNode(ISourcePosition position) 606 - { 607 - var n = new AstNull(position.File, position.Line, position.Column); 608 - return new AstIndirectCall(position, PCall.Get, n); 609 - } 610 - 611 - private readonly Stack<object> _scopeStack = new Stack<object>(); 612 - 613 - internal void _PushScope(AstScopedBlock block) 614 - { 615 - if (!ReferenceEquals(block.LexicalScope, CurrentBlock)) 616 - throw new PrexoniteException("Cannot push scope of unrelated block."); 617 - _scopeStack.Push(block); 618 - _target.BeginBlock(block); 619 - } 620 - 621 - internal void _PushScope(CompilerTarget ct) 622 - { 623 - if (!ReferenceEquals(ct.ParentTarget, _target)) 624 - throw new PrexoniteException("Cannot push scope of unrelated compiler target."); 625 - 626 - // SPECIAL CASE: Initialization code gets a separate environment every time 627 - // a block of code is added to it. 628 - if (ct.Function.Id == Application.InitializationId) 629 - { 630 - ct.Ast._ReplaceSymbols(SymbolStore.Create(Symbols)); 631 - } 632 - 633 - // Record scope 634 - _scopeStack.Push(ct); 635 - _target = ct; 636 - } 637 - 638 - internal void _PopScope(AstScopedBlock block) 639 - { 640 - if (!ReferenceEquals(_scopeStack.Peek(), block)) 641 - throw new PrexoniteException(string.Format("Tried to pop scope of block {0} but {1} was on top.", block, _scopeStack.Peek())); 642 - _scopeStack.Pop(); 643 - _target.EndBlock(); 644 - } 645 - 646 - internal void _PopScope(CompilerTarget ct) 647 - { 648 - if (!ReferenceEquals(_scopeStack.Peek(), ct)) 649 - throw new PrexoniteException(string.Format("Tried to pop scope of compiler target {0} but {1} was on top.", ct, _scopeStack.Peek())); 650 - _target = ct.ParentTarget; 651 - _scopeStack.Pop(); 652 - } 653 - 654 - #endregion 655 - 656 - [DebuggerStepThrough] 657 - public bool isLabel() //LL(2) 658 - { 659 - scanner.ResetPeek(); 660 - var c = la; 661 - var cla = scanner.Peek(); 662 - 663 - return c.kind == _lid || (isId(c) && cla.kind == _colon); 664 - } 665 - 666 - public bool isAssignmentOperator() //LL2 667 - { 668 - /* Applies to: 669 - * = 670 - * += 671 - * -= 672 - * *= 673 - * /= 674 - * ^= 675 - * |= 676 - * &= 677 - * ??= 678 - * ~= 679 - * <|= 680 - * |>= 681 - */ 682 - scanner.ResetPeek(); 683 - 684 - //current la = assign | plus | minus | times | div | pow | bitOr | bitAnd | coalesence | tilde 685 - 686 - switch (la.kind) 687 - { 688 - case _assign: 689 - return true; 690 - case _plus: 691 - case _minus: 692 - case _times: 693 - case _div: 694 - case _pow: 695 - case _bitOr: 696 - case _bitAnd: 697 - case _coalescence: 698 - case _tilde: 699 - case _deltaleft: 700 - case _deltaright: 701 - var c = scanner.Peek(); 702 - if (c.kind == _assign) 703 - return true; 704 - else 705 - return false; 706 - default: 707 - return false; 708 - } 709 - } 710 - 711 - public bool isSymbolDirective(string pattern) 712 - { 713 - scanner.ResetPeek(); 714 - return la.kind == _id 715 - && scanner.Peek().kind == _lpar 716 - && la.val.ToUpperInvariant() == pattern; 717 - 718 - } 719 - 720 - private bool isFollowedByStatementBlock() 721 - { 722 - scanner.ResetPeek(); 723 - return scanner.Peek().kind == _lbrace; 724 - } 725 - 726 - private bool isLambdaExpression() //LL(*) 727 - { 728 - scanner.ResetPeek(); 729 - 730 - var current = la; 731 - if (!(current.kind == _lpar || isId(current))) 732 - return false; 733 - var next = scanner.Peek(); 734 - 735 - var requirePar = false; 736 - if (current.kind == _lpar) 737 - { 738 - requirePar = true; 739 - current = next; 740 - next = scanner.Peek(); 741 - 742 - //Check for lambda expression without arguments 743 - if (current.kind == _rpar && next.kind == _implementation) 744 - return true; 745 - } 746 - 747 - if (isId(current)) 748 - { 749 - //break if lookahead is not valid to save tokens 750 - if ( 751 - !(next.kind == _comma || next.kind == _implementation || 752 - (next.kind == _rpar && requirePar))) 753 - return false; 754 - //Consume 1 755 - current = next; 756 - next = scanner.Peek(); 757 - } 758 - else if ((current.kind == _var || current.kind == _ref) && isId(next)) 759 - { 760 - //Consume 2 761 - current = scanner.Peek(); 762 - //break if lookahead is not valid to save tokens 763 - if ( 764 - !(current.kind == _comma || current.kind == _implementation || 765 - (current.kind == _rpar && requirePar))) 766 - return false; 767 - next = scanner.Peek(); 768 - } 769 - else 770 - { 771 - return false; 772 - } 773 - 774 - while (current.kind == _comma && requirePar) 775 - { 776 - //Consume comma 777 - current = next; 778 - next = scanner.Peek(); 779 - 780 - if (isId(current)) 781 - { 782 - //Consume 1 783 - current = next; 784 - next = scanner.Peek(); 785 - } 786 - else if ((current.kind == _var || current.kind == _ref) && isId(next)) 787 - { 788 - //Consume 2 789 - current = scanner.Peek(); 790 - next = scanner.Peek(); 791 - } 792 - else 793 - { 794 - return false; 795 - } 796 - } 797 - 798 - if (requirePar) 799 - if (current.kind == _rpar) 800 - { 801 - current = next; 802 - //cla = scanner.Peek(); 803 - } 804 - else 805 - { 806 - return false; 807 - } 808 - 809 - return current.kind == _implementation; 810 - } 811 - 812 - //LL(*) 813 - 814 - [DebuggerStepThrough] 815 - private bool isIndirectCall() //LL(2) 816 - { 817 - scanner.ResetPeek(); 818 - var c = la; 819 - var cla = scanner.Peek(); 820 - 821 - return c.kind == _dot && cla.kind == _lpar; 822 - } 823 - 824 - [DebuggerStepThrough] 825 - private bool isOuterVariable(string id) //context 826 - { 827 - return target._IsOuterVariable(id); 828 - } 829 - 830 - private string generateLocalId(string prefix = "") 831 - { 832 - return target.GenerateLocalId(prefix); 833 - } 834 - 835 - private Symbol _ensureDefinedLocal(string localAlias, string physicalId, bool isAutodereferenced, ISourcePosition declPos, bool isOverrideDecl) 836 - { 837 - var refSym = 838 - Symbol.CreateDereference(Symbol.CreateReference(EntityRef.Variable.Local.Create(physicalId), declPos), 839 - declPos); 840 - var sym = isAutodereferenced 841 - ? Symbol.CreateDereference(refSym, declPos) 842 - : refSym; 843 - 844 - target.Symbols.Declare(localAlias, sym); 845 - if (!isOverrideDecl && !target.Function.Variables.Contains(physicalId) && 846 - isOuterVariable(physicalId)) 847 - { 848 - target.RequireOuterVariable(physicalId); 849 - } 850 - else if(!target.Function.Variables.Contains(physicalId)) 851 - { 852 - target.Function.Variables.Add(physicalId); 853 - } 854 - return sym; 855 - } 856 - 857 - [NotNull] 858 - private AstGetSet _useSymbol([NotNull] ISymbolView<Symbol> scope, [NotNull] String id, [NotNull] ISourcePosition position) 859 - { 860 - Symbol sym; 861 - var expr = scope.TryGet(id, out sym) 862 - ? Create.ExprFor(position, sym) 863 - : new AstUnresolved(position, id); 864 - var complex = expr as AstGetSet; 865 - if (complex != null) 866 - { 867 - // If we have a namespace usage at hand, record the id used to access it 868 - // (namespaces are otherwise anonymous, they have no physical name) 869 - // Note: similar code is located in the GetSetExtension parser production 870 - // for subnamespaces 871 - var nsu = complex as AstNamespaceUsage; 872 - if (nsu != null && nsu.ReferencePath == null) 873 - { 874 - nsu.ReferencePath = new QualifiedId(id); 875 - } 876 - return complex; 877 - } 878 - Loader.ReportMessage(Message.Error(Resources.Parser_SymbolicUsageAsLValue, position, MessageClasses.ParserInternal)); 879 - complex = _NullNode(position); 880 - return complex; 881 - } 882 - 883 - private Symbol _parseSymbol(MExpr expr) 884 - { 885 - try 886 - { 887 - var parser = new SymbolMExprParser(Symbols,Loader,Loader.TopLevelSymbols); 888 - return parser.Parse(expr); 889 - } 890 - catch (ErrorMessageException e) 891 - { 892 - Loader.ReportMessage(e.CompilerMessage); 893 - return Symbol.CreateNil(e.CompilerMessage.Position); 894 - } 895 - } 896 - 897 - [DebuggerStepThrough] 898 - private static bool isId(Token c) 899 - { 900 - if (isGlobalId(c)) 901 - return true; 902 - switch (c.kind) 903 - { 904 - case _enabled: 905 - case _disabled: 906 - case _build: 907 - case _add: 908 - return true; 909 - default: 910 - return false; 911 - } 912 - } 913 - 914 - [DebuggerStepThrough] 915 - private static bool isGlobalId(Token c) 916 - { 917 - return c.kind == _id || c.kind == _anyId; 918 - } 919 - 920 - private bool _isNotNewDecl() 921 - { 922 - if (la.kind != _new) 923 - return false; 924 - 925 - scanner.ResetPeek(); 926 - var varTok = scanner.Peek(); 927 - 928 - return varTok.kind != _var && varTok.kind != _ref; 929 - } 930 - 931 - private static IEnumerable<string> let_bindings(CompilerTarget ft) 932 - { 933 - var lets = new HashSet<string>(Engine.DefaultStringComparer); 934 - for (var ct = ft; ct != null; ct = ct.ParentTarget) 935 - lets.UnionWith(ct.Function.Meta[PFunction.LetKey].List.Select(e => e.Text)); 936 - return lets; 937 - } 938 - 939 - private static void mark_as_let(PFunction f, string local) 940 - { 941 - f.Meta[PFunction.LetKey] = (MetaEntry) 942 - f.Meta[PFunction.LetKey].List 943 - .Union(new[] { (MetaEntry)local }) 944 - .ToArray(); 945 - } 946 - 947 - #region Assemble Invocation of Symbol 948 - 949 - private class ReferenceTransformer : SymbolHandler<int,Tuple<Symbol,bool>> 950 - { 951 - [NotNull] 952 - private readonly Parser _parser; 953 - 954 - public ReferenceTransformer([NotNull] Parser parser) 955 - { 956 - _parser = parser; 957 - } 958 - 959 - protected override Tuple<Symbol, bool> HandleWrappingSymbol(WrappingSymbol self, int argument) 960 - { 961 - if (argument == 0) 962 - return Tuple.Create<Symbol,bool>(self,false); 963 - else 964 - { 965 - var innerResult = self.InnerSymbol.HandleWith(this, argument); 966 - return Tuple.Create<Symbol,bool>(self.With(innerResult.Item1),innerResult.Item2); 967 - } 968 - } 969 - 970 - protected override Tuple<Symbol, bool> HandleLeafSymbol(Symbol self, int argument) 971 - { 972 - if (argument > 0) 973 - { 974 - throw new ErrorMessageException( 975 - Message.Error(Resources.ReferenceTransformer_CannotCreateReferenceToValue, 976 - _parser.GetPosition(), MessageClasses.CannotCreateReference)); 977 - } 978 - else 979 - { 980 - return Tuple.Create(self,false); 981 - } 982 - } 983 - 984 - public override Tuple<Symbol, bool> HandleDereference(DereferenceSymbol self, int argument) 985 - { 986 - if (argument > 0) 987 - { 988 - return self.InnerSymbol.HandleWith(this, argument - 1); 989 - } 990 - else 991 - { 992 - return base.HandleDereference(self, argument); 993 - } 994 - } 995 - 996 - public override Tuple<Symbol, bool> HandleExpand(ExpandSymbol self, int argument) 997 - { 998 - if (argument > 1) 999 - { 1000 - throw new ErrorMessageException( 1001 - Message.Error(Resources.ReferenceTransformer_HandleExpand_CannotCreateReferenceToDefinitionOfMacroOrPartialApplication, 1002 - _parser.GetPosition(), MessageClasses.CannotCreateReference)); 1003 - } 1004 - else if(argument == 1) 1005 - { 1006 - // Here, we don't actually remove the expansion, but rather switch the 1007 - // flag to true to indicate that the calling procedure should 1008 - // convert the resulting expansion node into a partial application. 1009 - return new Tuple<Symbol, bool>(base.HandleExpand(self,argument-1).Item1,true); 1010 - } 1011 - else 1012 - { 1013 - return base.HandleExpand(self, argument); 1014 - } 1015 - } 1016 - } 1017 - 1018 - [NotNull] 1019 - private readonly ReferenceTransformer _referenceTransformer; 1020 - 1021 - private AstExpr _assembleReference(string id, int ptrCount) 1022 - { 1023 - Debug.Assert(id != null); 1024 - Debug.Assert(ptrCount > 0); 1025 - 1026 - Symbol symbol; 1027 - var position = GetPosition(); 1028 - if (!Symbols.TryGet(id, out symbol)) 1029 - { 1030 - Loader.ReportMessage(Message.Error(string.Format(Resources.Parser__assembleReference_SymbolNotDefined, id),position,MessageClasses.SymbolNotResolved)); 1031 - return Create.Null(position); 1032 - } 1033 - else 1034 - { 1035 - try 1036 - { 1037 - var transformed = symbol.HandleWith(_referenceTransformer, ptrCount); 1038 - var invocation = Create.ExprFor(position, transformed.Item1); 1039 - if (transformed.Item2) 1040 - { 1041 - // If the reference transformer indicates that an Expand prefix was eliminated 1042 - // during the transformation, we need to convert the invocation into a partial application 1043 - var invocationCall = invocation as AstGetSet; 1044 - if (invocationCall == null) 1045 - { 1046 - Loader.ReportMessage( 1047 - Message.Error(Resources.Parser__assembleReference_MacroDefinitionNotLValue, position, 1048 - MessageClasses.ParserInternal)); 1049 - invocation = Create.Null(position); 1050 - } 1051 - else 1052 - { 1053 - invocationCall.Arguments.Add(Create.Placeholder(position)); 1054 - } 1055 - } 1056 - return invocation; 1057 - } 1058 - catch (ErrorMessageException e) 1059 - { 1060 - Loader.ReportMessage(e.CompilerMessage); 1061 - return Create.Null(position); 1062 - } 1063 - } 1064 - } 1065 - 1066 - private class EnsureInScopeHandler : TransformHandler<Parser> 1067 - { 1068 - public override Symbol HandleReference(ReferenceSymbol self, Parser argument) 1069 - { 1070 - EntityRef.Variable.Local local; 1071 - if(self.Entity.TryGetLocalVariable(out local) 1072 - && argument.isOuterVariable(local.Id)) 1073 - argument.target.RequireOuterVariable(local.Id); 1074 - return self; 1075 - } 1076 - } 1077 - private static readonly EnsureInScopeHandler _ensureInScope = new EnsureInScopeHandler(); 1078 - 1079 - public void EnsureInScope(Symbol symbol) 1080 - { 1081 - symbol.HandleWith(_ensureInScope, this); 1082 - } 1083 - 1084 - private void _fallbackObjectCreation(AstTypeExpr type, out AstExpr expr, 1085 - out ArgumentsProxy args) 1086 - { 1087 - var typeExpr = type as AstDynamicTypeExpression; 1088 - Symbol fallbackSymbol; 1089 - if ( 1090 - //is a type expression we understand (Parser currently only generates dynamic type expressions) 1091 - // constant type expressions are recognized during optimization 1092 - typeExpr != null 1093 - //happens in case of parse failure 1094 - && typeExpr.TypeId != null 1095 - //there is no such thing as a parametrized struct 1096 - && typeExpr.Arguments.Count == 0 1097 - //built-in types take precedence 1098 - && !ParentEngine.PTypeRegistry.Contains(typeExpr.TypeId) 1099 - //in case neither the built-in type nor the struct constructor exists, 1100 - // stay with built-in types for predictibility 1101 - && 1102 - target.Symbols.TryGet( 1103 - Loader.ObjectCreationFallbackPrefix + typeExpr.TypeId, 1104 - out fallbackSymbol)) 1105 - { 1106 - EnsureInScope(fallbackSymbol); 1107 - 1108 - var e = Create.ExprFor(type.Position,fallbackSymbol); 1109 - var call = e as AstGetSet; 1110 - if (call == null) 1111 - { 1112 - var pos = GetPosition(); 1113 - call = Create.IndirectCall(pos, Create.Null(pos)); 1114 - Loader.ReportMessage(Message.Create(MessageSeverity.Error, 1115 - string.Format(Resources.Parser__CannotUseExpressionAsAConstructor, 1116 - e), pos, 1117 - MessageClasses.CannotUseExpressionAsConstructor)); 1118 - } 1119 - expr = call; 1120 - args = call.Arguments; 1121 - } 1122 - else if (type != null) 1123 - { 1124 - var creation = new AstObjectCreation(this, type); 1125 - expr = creation; 1126 - args = creation.Arguments; 1127 - } 1128 - else 1129 - { 1130 - Loader.ReportMessage(Message.Error(Resources.Parser__fallbackObjectCreation_Failed,GetPosition(),MessageClasses.ObjectCreationSyntax)); 1131 - expr = new AstNull(this); 1132 - args = new ArgumentsProxy(new List<AstExpr>()); 1133 - } 1134 - } 1135 - 1136 - private AstExpr _createUnknownExpr() 1137 - { 1138 - return _createUnknownGetSet(); 1139 - } 1140 - 1141 - private AstGetSet _createUnknownGetSet() 1142 - { 1143 - return new AstIndirectCall(this, new AstNull(this)); 1144 - } 1145 - 1146 - private void _appendRight(AstExpr lhs, AstGetSet rhs) 1147 - { 1148 - _appendRight(lhs.Singleton(), rhs); 1149 - } 1150 - 1151 - private void _appendRight(IEnumerable<AstExpr> lhs, AstGetSet rhs) 1152 - { 1153 - rhs.Arguments.RightAppend(lhs); 1154 - rhs.Arguments.ReleaseRightAppend(); 1155 - AstIndirectCall indirectCallNode; 1156 - AstReference refNode; 1157 - EntityRef.Variable dummyVariable; 1158 - if ((indirectCallNode = rhs as AstIndirectCall) != null 1159 - && (refNode = indirectCallNode.Subject as AstReference) != null 1160 - && refNode.Entity.TryGetVariable(out dummyVariable)) 1161 - rhs.Call = PCall.Set; 1162 - } 1163 - 1164 - #endregion 1165 - 1166 - 1167 - #endregion 1168 - 1169 - #region Assembler 1170 - 1171 - [DebuggerStepThrough] 1172 - public void addInstruction(AstBlock block, Instruction ins) 1173 - { 1174 - block.Add(new AstAsmInstruction(this, ins)); 1175 - } 1176 - 1177 - public void addOpAlias(AstBlock block, string insBase, string detail) 1178 - { 1179 - int argc; 1180 - var alias = getOpAlias(insBase, detail, out argc); 1181 - if (alias == null) 1182 - { 1183 - Loader.ReportMessage( 1184 - Message.Error( 1185 - string.Format(Resources.Parser_addOpAlias_Unknown, insBase, detail), 1186 - GetPosition(), MessageClasses.UnknownAssemblyOperator)); 1187 - block.Add(new AstAsmInstruction(this, new Instruction(OpCode.nop))); 1188 - return; 1189 - } 1190 - 1191 - block.Add(new AstAsmInstruction(this, Instruction.CreateCommandCall(argc, alias))); 1192 - } 1193 - 1194 - [DebuggerStepThrough] 1195 - public void addLabel(AstBlock block, string label) 1196 - { 1197 - block.Statements.Add(new AstExplicitLabel(this, label)); 1198 - } 1199 - 1200 - [DebuggerStepThrough] 1201 - private bool isAsmInstruction(string insBase, string detail) //LL(4) 1202 - { 1203 - scanner.ResetPeek(); 1204 - var la1 = la.kind == _at ? scanner.Peek() : la; 1205 - var la2 = scanner.Peek(); 1206 - var la3 = scanner.Peek(); 1207 - return checkAsmInstruction(la1, la2, la3, insBase, detail); 1208 - } 1209 - 1210 - private static bool checkAsmInstruction( 1211 - Token la1, Token la2, Token la3, string insBase, string detail) 1212 - { 1213 - return 1214 - la1.kind != _string && Engine.StringsAreEqual(la1.val, insBase) && 1215 - (detail == null 1216 - ? (la2.kind != _dot || la3.kind == _integer) 1217 - : (la2.kind == _dot && la3.kind != _string && 1218 - Engine.StringsAreEqual(la3.val, detail)) 1219 - ); 1220 - } 1221 - 1222 - [DebuggerStepThrough] 1223 - private bool isInIntegerGroup() 1224 - { 1225 - return peekIsOneOf(asmIntegerGroup); 1226 - } 1227 - 1228 - [DebuggerStepThrough] 1229 - private bool isInJumpGroup() 1230 - { 1231 - return peekIsOneOf(asmJumpGroup); 1232 - } 1233 - 1234 - private bool isInOpAliasGroup() 1235 - { 1236 - return peekIsOneOf(asmOpAliasGroup); 1237 - } 1238 - 1239 - [DebuggerStepThrough] 1240 - private bool isInNullGroup() 1241 - { 1242 - return peekIsOneOf(asmNullGroup); 1243 - } 1244 - 1245 - [DebuggerStepThrough] 1246 - private bool isInIdGroup() 1247 - { 1248 - return peekIsOneOf(asmIdGroup); 1249 - } 1250 - 1251 - [DebuggerStepThrough] 1252 - private bool isInIdArgGroup() 1253 - { 1254 - return peekIsOneOf(asmIdArgGroup); 1255 - } 1256 - 1257 - [DebuggerStepThrough] 1258 - private bool isInArgGroup() 1259 - { 1260 - return peekIsOneOf(asmArgGroup); 1261 - } 1262 - 1263 - [DebuggerStepThrough] 1264 - private bool isInQualidArgGroup() 1265 - { 1266 - return peekIsOneOf(asmQualidArgGroup); 1267 - } 1268 - 1269 - //[NoDebug()] 1270 - private bool peekIsOneOf(string[,] table) 1271 - { 1272 - scanner.ResetPeek(); 1273 - var la1 = la.kind == _at ? scanner.Peek() : la; 1274 - var la2 = scanner.Peek(); 1275 - var la3 = scanner.Peek(); 1276 - for (var i = table.GetUpperBound(0); i >= 0; i--) 1277 - if (checkAsmInstruction(la1, la2, la3, table[i, 0], table[i, 1])) 1278 - return true; 1279 - return false; 1280 - } 1281 - 1282 - private readonly SymbolTable<OpCode> _instructionNameTable = new SymbolTable<OpCode>(60); 1283 - 1284 - private readonly SymbolTable<Tuple<string, int>> _opAliasTable = 1285 - new SymbolTable<Tuple<string, int>>(32); 1286 - 1287 - [DebuggerStepThrough] 1288 - private void _createTableOfInstructions() 1289 - { 1290 - var tab = _instructionNameTable; 1291 - //Add original names 1292 - foreach (var code in Enum.GetNames(typeof(OpCode))) 1293 - tab.Add(code.Replace('_', '.'), (OpCode)Enum.Parse(typeof(OpCode), code)); 1294 - 1295 - //Add instruction aliases -- NOTE: You'll also have to add them to the respective groups 1296 - tab.Add("new", OpCode.newobj); 1297 - tab.Add("check", OpCode.check_const); 1298 - tab.Add("cast", OpCode.cast_const); 1299 - tab.Add("ret", OpCode.ret_value); 1300 - tab.Add("ret.val", OpCode.ret_value); 1301 - tab.Add("yield", OpCode.ret_continue); 1302 - tab.Add("exit", OpCode.ret_exit); 1303 - tab.Add("break", OpCode.ret_break); 1304 - tab.Add("continue", OpCode.ret_continue); 1305 - tab.Add("jump.true", OpCode.jump_t); 1306 - tab.Add("jump.false", OpCode.jump_f); 1307 - tab.Add("inc", OpCode.incloc); 1308 - tab.Add("inci", OpCode.incloci); 1309 - tab.Add("dec", OpCode.decloc); 1310 - tab.Add("deci", OpCode.decloci); 1311 - tab.Add("inda", OpCode.indarg); 1312 - tab.Add("cor", OpCode.newcor); 1313 - tab.Add("exception", OpCode.exc); 1314 - tab.Add("ldnull", OpCode.ldc_null); 1315 - 1316 - //Add operator aliases 1317 - var ops = _opAliasTable; 1318 - ops.Add("neg", Tuple.Create(UnaryNegation.DefaultAlias, 1)); 1319 - ops.Add("not", Tuple.Create(LogicalNot.DefaultAlias, 1)); 1320 - ops.Add("add", Tuple.Create(Addition.DefaultAlias, 2)); 1321 - ops.Add("sub", Tuple.Create(Subtraction.DefaultAlias, 2)); 1322 - ops.Add("mul", Tuple.Create(Multiplication.DefaultAlias, 2)); 1323 - ops.Add("div", Tuple.Create(Division.DefaultAlias, 2)); 1324 - ops.Add("mod", Tuple.Create(Modulus.DefaultAlias, 2)); 1325 - ops.Add("pow", Tuple.Create(Power.DefaultAlias, 2)); 1326 - ops.Add("ceq", Tuple.Create(Equality.DefaultAlias, 2)); 1327 - ops.Add("cne", Tuple.Create(Inequality.DefaultAlias, 2)); 1328 - ops.Add("clt", Tuple.Create(LessThan.DefaultAlias, 2)); 1329 - ops.Add("cle", Tuple.Create(LessThanOrEqual.DefaultAlias, 2)); 1330 - ops.Add("cgt", Tuple.Create(GreaterThan.DefaultAlias, 2)); 1331 - ops.Add("cge", Tuple.Create(GreaterThanOrEqual.DefaultAlias, 2)); 1332 - ops.Add("or", Tuple.Create(BitwiseOr.DefaultAlias, 2)); 1333 - ops.Add("and", Tuple.Create(BitwiseAnd.DefaultAlias, 2)); 1334 - ops.Add("xor", Tuple.Create(ExclusiveOr.DefaultAlias, 2)); 1335 - } 1336 - 1337 - //[DebuggerStepThrough] 1338 - private string getOpAlias(string insBase, string detail, out int argc) 1339 - { 1340 - var combined = insBase + (detail == null ? "" : "." + detail); 1341 - var entry = _opAliasTable.GetDefault(combined, null); 1342 - if (entry == null) 1343 - { 1344 - argc = -1; 1345 - return null; 1346 - } 1347 - else 1348 - { 1349 - argc = entry.Item2; 1350 - return entry.Item1; 1351 - } 1352 - } 1353 - 1354 - //[DebuggerStepThrough] 1355 - private OpCode getOpCode(string insBase, string detail) 1356 - { 1357 - var combined = insBase + (detail == null ? "" : "." + detail); 1358 - return _instructionNameTable.GetDefault(combined, OpCode.invalid); 1359 - } 1360 - 1361 - #region Instruction tables 1362 - 1363 - private readonly string[,] asmIntegerGroup = 1364 - { 1365 - {"ldc", "int"}, 1366 - {"pop", null}, 1367 - {"dup", null}, 1368 - {"ldloci", null}, 1369 - {"stloci", null}, 1370 - {"incloci", null}, 1371 - {"inci", null}, 1372 - {"deci", null}, 1373 - {"ldr", "loci"} 1374 - }; 1375 - 1376 - private readonly string[,] asmJumpGroup = 1377 - { 1378 - {"jump", null}, 1379 - {"jump", "t"}, 1380 - {"jump", "f"}, 1381 - {"jump", "true"}, 1382 - {"jump", "false"}, 1383 - {"leave", null} 1384 - }; 1385 - 1386 - private readonly string[,] asmNullGroup = 1387 - { 1388 - {"ldc", "null"}, 1389 - {"ldnull", null}, 1390 - {"check", "arg"}, 1391 - {"check", "null"}, 1392 - {"cast", "arg"}, 1393 - {"ldr", "eng"}, 1394 - {"ldr", "app"}, 1395 - {"ret", null}, 1396 - {"ret", "set"}, 1397 - {"ret", "value"}, 1398 - {"ret", "val"}, 1399 - {"ret", "break"}, 1400 - {"ret", "continue"}, 1401 - {"ret", "exit"}, 1402 - {"break", null}, 1403 - {"continue", null}, 1404 - {"yield", null}, 1405 - {"exit", null}, 1406 - {"try", null}, 1407 - {"throw", null}, 1408 - {"exc", null}, 1409 - {"exception", null} 1410 - }; 1411 - 1412 - private readonly string[,] asmOpAliasGroup = 1413 - { 1414 - {"neg", null}, 1415 - {"not", null}, 1416 - {"add", null}, 1417 - {"sub", null}, 1418 - {"mul", null}, 1419 - {"div", null}, 1420 - {"mod", null}, 1421 - {"pow", null}, 1422 - {"ceq", null}, 1423 - {"cne", null}, 1424 - {"clt", null}, 1425 - {"cle", null}, 1426 - {"cgt", null}, 1427 - {"cge", null}, 1428 - {"or", null}, 1429 - {"and", null}, 1430 - {"xor", null} 1431 - }; 1432 - 1433 - private readonly string[,] asmIdGroup = 1434 - { 1435 - {"inc", null}, 1436 - {"incloc", null}, 1437 - {"incglob", null}, 1438 - {"dec", null}, 1439 - {"decloc", null}, 1440 - {"decglob", null}, 1441 - {"ldc", "string"}, 1442 - {"ldr", "func"}, 1443 - {"ldr", "cmd"}, 1444 - {"ldr", "glob"}, 1445 - {"ldr", "loc"}, 1446 - {"ldr", "type"}, 1447 - {"ldloc", null}, 1448 - {"stloc", null}, 1449 - {"ldglob", null}, 1450 - {"stglob", null}, 1451 - {"check", "const"}, 1452 - {"check", null}, 1453 - {"cast", "const"}, 1454 - {"cast", null}, 1455 - {"newclo", null} 1456 - }; 1457 - 1458 - private readonly string[,] asmIdArgGroup = 1459 - { 1460 - {"newtype", null}, 1461 - {"get", null}, 1462 - {"set", null}, 1463 - {"func", null}, 1464 - {"cmd", null}, 1465 - {"indloc", null}, 1466 - {"indglob", null} 1467 - }; 1468 - 1469 - private readonly string[,] asmArgGroup = 1470 - { 1471 - {"indarg", null}, 1472 - {"inda", null}, 1473 - {"newcor", null}, 1474 - {"cor", null}, 1475 - {"tail", null} 1476 - }; 1477 - 1478 - private readonly string[,] asmQualidArgGroup = 1479 - { 1480 - {"sget", null}, 1481 - {"sset", null}, 1482 - {"newobj", null}, 1483 - {"new", null} 1484 - }; 1485 - 1486 - #endregion 1487 - 1488 - #endregion 1489 - 1490 - #endregion 1491 - 1492 - } 1493 - } 1494 - 1 + // Prexonite 2 + // 3 + // Copyright (c) 2014, Christian Klauser 4 + // All rights reserved. 5 + // 6 + // Redistribution and use in source and binary forms, with or without modification, 7 + // are permitted provided that the following conditions are met: 8 + // 9 + // Redistributions of source code must retain the above copyright notice, 10 + // this list of conditions and the following disclaimer. 11 + // Redistributions in binary form must reproduce the above copyright notice, 12 + // this list of conditions and the following disclaimer in the 13 + // documentation and/or other materials provided with the distribution. 14 + // The names of the contributors may be used to endorse or 15 + // promote products derived from this software without specific prior written permission. 16 + // 17 + // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 + // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 + // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 + // IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 21 + // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 + // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 + // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 + // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 25 + // IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 + using System; 27 + using System.Collections.Generic; 28 + using System.Diagnostics; 29 + using System.Globalization; 30 + using System.Linq; 31 + using System.Runtime.InteropServices; 32 + using JetBrains.Annotations; 33 + using Prexonite.Commands.Core.Operators; 34 + using Prexonite.Compiler.Ast; 35 + using Prexonite.Compiler.Internal; 36 + using Prexonite.Compiler.Symbolic; 37 + using Prexonite.Compiler.Symbolic.Internal; 38 + using Prexonite.Internal; 39 + using Prexonite.Modular; 40 + using Prexonite.Properties; 41 + using Prexonite.Types; 42 + 43 + // ReSharper disable InconsistentNaming 44 + 45 + namespace Prexonite.Compiler 46 + { 47 + internal partial class Parser 48 + { 49 + [DebuggerStepThrough] 50 + internal Parser(IScanner scanner, Loader loader) 51 + : this(scanner) 52 + { 53 + if (loader == null) 54 + throw new ArgumentNullException(nameof(loader)); 55 + _loader = loader; 56 + _createTableOfInstructions(); 57 + Ast = new AstProxy(this); 58 + _astFactory = new ParserAstFactory(this); 59 + _referenceTransformer = new ReferenceTransformer(this); 60 + } 61 + 62 + #region Proxy interface 63 + 64 + private readonly Loader _loader; 65 + 66 + public Loader Loader 67 + { 68 + [DebuggerStepThrough] 69 + get { return _loader; } 70 + } 71 + 72 + /// <summary> 73 + /// Preflight mode causes the parser to abort at the 74 + /// first non-meta construct, giving the user the opportunity 75 + /// to inspect a file's "header" without fully compiling 76 + /// that file. 77 + /// </summary> 78 + public bool PreflightModeEnabled 79 + { 80 + get { return Loader.Options.PreflightModeEnabled; } 81 + } 82 + 83 + public Application TargetApplication 84 + { 85 + [DebuggerStepThrough] 86 + get { return _loader.Options.TargetApplication; } 87 + } 88 + 89 + public Module TargetModule 90 + { 91 + [DebuggerStepThrough] 92 + get { return TargetApplication.Module; } 93 + } 94 + 95 + public LoaderOptions Options 96 + { 97 + [DebuggerStepThrough] 98 + get { return _loader.Options; } 99 + } 100 + 101 + public Engine ParentEngine 102 + { 103 + [DebuggerStepThrough] 104 + get { return _loader.Options.ParentEngine; } 105 + } 106 + 107 + public SymbolStore Symbols 108 + { 109 + [DebuggerStepThrough] 110 + get { return target?.CurrentBlock.Symbols ?? _loader.Symbols; } 111 + } 112 + 113 + private DeclarationScopeBuilder _prepareDeclScope(QualifiedId relativeNsId, ISourcePosition idPosition) 114 + { 115 + if(relativeNsId.Count < 1) 116 + throw new ArgumentOutOfRangeException(nameof(relativeNsId),Resources.Parser_relativeNsId_empty); 117 + var outerScope = Loader.CurrentScope; 118 + QualifiedId prefix; 119 + SymbolStore declScopeStore; 120 + LocalNamespace surroundingNamespace; 121 + if (outerScope == null) 122 + { 123 + prefix = new QualifiedId(null); 124 + declScopeStore = Loader.TopLevelSymbols; 125 + surroundingNamespace = null; 126 + } 127 + else 128 + { 129 + prefix = outerScope.PathPrefix; 130 + declScopeStore = outerScope.Store; 131 + surroundingNamespace = outerScope._LocalNamespace; 132 + } 133 + 134 + var currentLookupScope = (ISymbolView<Symbol>) declScopeStore; 135 + var isOutermostNs = true; 136 + foreach (var nsId in relativeNsId) 137 + { 138 + var localNs = _tryGetLocalNamespace(currentLookupScope, nsId, idPosition); 139 + 140 + prefix = prefix + new QualifiedId(nsId); 141 + 142 + // Create namespace if necessary 143 + if (localNs == null) 144 + { 145 + localNs = ((ModuleLevelView) Loader.TopLevelSymbols).CreateLocalNamespace(new EmptySymbolView<Symbol>()); 146 + } 147 + 148 + // Make sure the namespace is exported from the current module and not just accessible via external declarations 149 + _declareNamespaceAsExported(surroundingNamespace, declScopeStore, nsId, isOutermostNs, idPosition, localNs, prefix); 150 + 151 + surroundingNamespace = localNs; 152 + currentLookupScope = localNs; 153 + if (isOutermostNs) 154 + isOutermostNs = false; 155 + } 156 + 157 + // This should never happen, check is here to convey this fact to null-analysis 158 + if(surroundingNamespace == null) 159 + throw new PrexoniteException("Failed to create the innermost namespace of " + relativeNsId + "."); 160 + 161 + // Create the local scope of this namespace *declaration* (the scope inside the braces) 162 + // Not that this is almost completely independent of the namespace itself 163 + // It is just used as one possible source for exports 164 + var builder = SymbolStoreBuilder.Create(declScopeStore); 165 + return new DeclarationScopeBuilder(builder, prefix, surroundingNamespace); 166 + } 167 + 168 + class DeclarationScopeBuilder 169 + { 170 + [NotNull] 171 + private readonly SymbolStoreBuilder _localScopeBuilder; 172 + 173 + private readonly QualifiedId _prefix; 174 + [NotNull] 175 + // ReSharper disable once MemberHidesStaticFromOuterClass 176 + private readonly LocalNamespace _namespace; 177 + 178 + public DeclarationScopeBuilder([NotNull]SymbolStoreBuilder localScopeBuilder, QualifiedId prefix, [NotNull]LocalNamespace ns) 179 + { 180 + if (localScopeBuilder == null) 181 + throw new ArgumentNullException(nameof(localScopeBuilder)); 182 + if (ns == null) 183 + throw new ArgumentNullException(nameof(ns)); 184 + if (prefix == null) 185 + throw new ArgumentNullException(nameof(prefix)); 186 + 187 + _localScopeBuilder = localScopeBuilder; 188 + _prefix = prefix; 189 + _namespace = ns; 190 + } 191 + 192 + [NotNull] 193 + public SymbolStoreBuilder LocalScopeBuilder 194 + { 195 + get { return _localScopeBuilder; } 196 + } 197 + 198 + public QualifiedId Prefix 199 + { 200 + get { return _prefix; } 201 + } 202 + 203 + [NotNull] 204 + public LocalNamespace Namespace 205 + { 206 + get { return _namespace; } 207 + } 208 + 209 + [NotNull] 210 + public DeclarationScope ToDeclarationScope() 211 + { 212 + return new DeclarationScope(Namespace, Prefix, LocalScopeBuilder.ToSymbolStore()); 213 + } 214 + } 215 + 216 + [CanBeNull] 217 + private LocalNamespace _tryGetLocalNamespace([NotNull] ISymbolView<Symbol> currentSurrounding, [NotNull] string superNsId, [NotNull] ISourcePosition idPosition) 218 + { 219 + Symbol sym; 220 + LocalNamespace localNs = null; 221 + if (currentSurrounding.TryGet(superNsId, out sym)) 222 + { 223 + var fakeExpr = Create.ExprFor(idPosition, sym); 224 + var nsUsage = fakeExpr as AstNamespaceUsage; 225 + if (nsUsage == null) 226 + Loader.ReportMessage(Message.Error( 227 + string.Format(Resources.Parser_NamespaceExpected, superNsId, sym), 228 + idPosition, MessageClasses.NamespaceExcepted)); 229 + else 230 + { 231 + // namespace already exists 232 + localNs = nsUsage.Namespace as LocalNamespace; 233 + if (localNs == null) 234 + { 235 + Loader.ReportMessage(Message.Error( 236 + string.Format(Resources.Parser_CannotExtendMergedNamespace, superNsId), 237 + idPosition, MessageClasses.CannotExtendMergedNamespace)); 238 + } 239 + } 240 + } 241 + return localNs; 242 + } 243 + 244 + /// <summary> 245 + /// Ensures the namespace is declared as an exported symbol (and not just available via external declarations) 246 + /// </summary> 247 + /// <param name="surroundingNamespace">Reference to the surrounding namespace, if any</param> 248 + /// <param name="outer">Reference to the top-level symbol store</param> 249 + /// <param name="superNsId">Name of the namespace to declare</param> 250 + /// <param name="isOutermostNs">True if the symbol should be added to the top-level scope; false if it should be declared in the surrounding namespace</param> 251 + /// <param name="idPosition">Position of the name that caused this declaration (position of the namespace name)</param> 252 + /// <param name="localNs">The namespace to declare</param> 253 + /// <param name="nextPrefix">Namespaces prefix to use for physical names in declared namespace. Or null if the namespace already has a prefix assigned.</param> 254 + private static void _declareNamespaceAsExported( 255 + LocalNamespace surroundingNamespace, 256 + SymbolStore outer, 257 + string superNsId, 258 + bool isOutermostNs, 259 + ISourcePosition idPosition, 260 + LocalNamespace localNs, 261 + QualifiedId nextPrefix) 262 + { 263 + var nsSym = Symbol.CreateNamespace(localNs, idPosition); 264 + Symbol existingSym; 265 + if (isOutermostNs) 266 + { 267 + // The outermost namespace (x in x.y.z) is declared as an ordinary symbol in the current scope 268 + if (!outer.IsDeclaredLocally(superNsId) || 269 + !(outer.TryGet(superNsId, out existingSym) && existingSym.Equals(nsSym))) 270 + { 271 + outer.Declare(superNsId, nsSym); 272 + } 273 + } 274 + else if (surroundingNamespace == null) 275 + throw new PrexoniteException( 276 + "Failed to create surrounding namespace (syntactic sugar for nested namespace)"); 277 + else 278 + { 279 + // Inner namespaces (z and y in x.y.z) are exported from their respective super-namespaces 280 + if (!surroundingNamespace.TryGetExported(superNsId, out existingSym) || !existingSym.Equals(nsSym)) 281 + { 282 + surroundingNamespace.DeclareExports( 283 + new KeyValuePair<string, Symbol>(superNsId, nsSym).Singleton()); 284 + } 285 + } 286 + 287 + if (localNs.Prefix == null) 288 + { 289 + localNs.Prefix = nextPrefix.ToString().Replace('.', '\\'); 290 + } 291 + } 292 + 293 + [CanBeNull] 294 + private ISymbolView<Symbol> _resolveNamespace(ISymbolView<Symbol> scope, [NotNull] ISourcePosition qualifiedIdPosition, QualifiedId qualifiedId) 295 + { 296 + while (qualifiedId.Count > 0) 297 + { 298 + Symbol sym; 299 + scope.TryGet(qualifiedId[0], out sym); 300 + var expr = Create.ExprFor(qualifiedIdPosition, sym); 301 + var nsUsage = expr as AstNamespaceUsage; 302 + if (nsUsage == null) 303 + { 304 + Create.ReportMessage( 305 + Message.Error(string.Format(Resources.Parser_NamespaceExpected, qualifiedId[0], sym == null ? "not defined" : sym.ToString()), 306 + qualifiedIdPosition, MessageClasses.NamespaceExcepted)); 307 + return null; 308 + } 309 + else 310 + { 311 + scope = nsUsage.Namespace; 312 + qualifiedId = qualifiedId.WithPrefixDropped(1); 313 + } 314 + } 315 + return scope; 316 + } 317 + 318 + private void _updateNamespace(DeclarationScope scope, SymbolStoreBuilder builder) 319 + { 320 + scope._LocalNamespace.DeclareExports(builder.ToSymbolStore()); 321 + } 322 + 323 + private SymbolOrigin _privateDeclarationOrigin(ISourcePosition position, DeclarationScope scope) 324 + { 325 + return new SymbolOrigin.NamespaceDeclarationScope(position, scope.PathPrefix); 326 + } 327 + 328 + private DeclarationScope _popDeclScope() 329 + { 330 + // The symbol for this namespace should already have been declared by the push operation 331 + return Loader.PopScope(); 332 + } 333 + 334 + /// <summary> 335 + /// When forwarding exported symbols from the declaration scope, 336 + /// we need to assemble a temporary symbol view that only contains 337 + /// the symbols declared locally. 338 + /// </summary> 339 + /// <param name="declStore">The store to extract the exported symbols from.</param> 340 + /// <returns>A static view (shallow copy) of the exported symbols of <paramref name="declStore"/>.</returns> 341 + private ISymbolView<Symbol> _indexExportedSymbols(SymbolStore declStore) 342 + { 343 + var index = SymbolStore.Create(); 344 + foreach (var symbol in declStore.LocalDeclarations) 345 + index.Declare(symbol.Key, symbol.Value); 346 + return index; 347 + } 348 + 349 + private String _assignPhysicalFunctionSlot([CanBeNull] String primaryId) 350 + { 351 + return _assignPhysicalSlot(primaryId ?? Engine.GenerateName("f")); 352 + } 353 + 354 + private string _assignPhysicalSlot(string id) 355 + { 356 + var scope = Loader.CurrentScope; 357 + return scope == null ? id : scope._LocalNamespace.DerivePhysicalName(id); 358 + } 359 + 360 + private String _assignPhysicalGlobalVariableSlot([CanBeNull] string primaryId) 361 + { 362 + return _assignPhysicalSlot(primaryId ?? Engine.GenerateName("v")); 363 + } 364 + 365 + public Loader.FunctionTargetsIterator FunctionTargets 366 + { 367 + [DebuggerStepThrough] 368 + get { return _loader.FunctionTargets; } 369 + } 370 + 371 + public AstProxy Ast { get; } 372 + 373 + [DebuggerStepThrough] 374 + public class AstProxy 375 + { 376 + private readonly Parser outer; 377 + 378 + internal AstProxy(Parser outer) 379 + { 380 + this.outer = outer; 381 + } 382 + 383 + public AstBlock this[PFunction func] => outer._loader.FunctionTargets[func].Ast; 384 + } 385 + 386 + private CompilerTarget _target; 387 + 388 + public CompilerTarget target 389 + { 390 + [DebuggerStepThrough] 391 + get { return _target; } 392 + } 393 + 394 + protected int LocalState 395 + { 396 + get 397 + { 398 + MetaEntry flagSwitch; 399 + bool flagLiteralsEnabled; 400 + if (target != null && target.Meta.TryGetValue(Shell.FlagLiteralsKey, out flagSwitch)) 401 + { 402 + flagLiteralsEnabled = flagSwitch.Switch; 403 + } 404 + else if (TargetApplication.Meta.TryGetValue(Shell.FlagLiteralsKey, out flagSwitch)) 405 + { 406 + flagLiteralsEnabled = flagSwitch.Switch; 407 + } 408 + else 409 + { 410 + flagLiteralsEnabled = _loader.Options.FlagLiteralsEnabled; 411 + } 412 + 413 + return flagLiteralsEnabled ? Lexer.LocalShell : Lexer.Local; 414 + } 415 + } 416 + 417 + public AstBlock CurrentBlock => target?.CurrentBlock; 418 + 419 + private readonly IAstFactory _astFactory; 420 + 421 + protected IAstFactory Create => _astFactory; 422 + 423 + #endregion 424 + 425 + #region String cache 426 + 427 + [DebuggerStepThrough] 428 + internal string cache(string toCache) 429 + { 430 + return _loader.CacheString(toCache); 431 + } 432 + 433 + #endregion 434 + 435 + public void ViolentlyAbortParse() 436 + { 437 + scanner.Abort(); 438 + } 439 + 440 + #region Helper 441 + 442 + #region General 443 + 444 + private static string _removeSingleQuotes(string s) 445 + { 446 + return s.Replace("'", ""); 447 + } 448 + 449 + public static bool TryParseInteger(string s, out int i) 450 + { 451 + return Int32.TryParse(_removeSingleQuotes(s), IntegerStyle, CultureInfo.InvariantCulture, 452 + out i); 453 + } 454 + 455 + public static bool TryParseReal(string s, out double d) 456 + { 457 + return Double.TryParse(_removeSingleQuotes(s), RealStyle, CultureInfo.InvariantCulture, 458 + out d); 459 + } 460 + 461 + public static bool TryParseVersion(string s, out Version version) 462 + { 463 + return System.Version.TryParse(s, out version); 464 + } 465 + 466 + public static NumberStyles RealStyle 467 + { 468 + get { return NumberStyles.AllowDecimalPoint | NumberStyles.AllowExponent; } 469 + } 470 + 471 + public static NumberStyles IntegerStyle 472 + { 473 + get { return NumberStyles.None; } 474 + } 475 + 476 + [DebuggerStepThrough, Obsolete("Use Loader.ReportMessage instead.")] 477 + public void SemErr(int line, int col, string message) 478 + { 479 + errors.SemErr(line, col, message); 480 + } 481 + 482 + [DebuggerStepThrough, Obsolete("Use Loader.ReportMessage instead.")] 483 + public void SemErr(Token tok, string s) 484 + { 485 + errors.SemErr(tok.line, tok.col, s); 486 + } 487 + 488 + private void _pushLexerState(int state) 489 + { 490 + var lex = scanner as Lexer; 491 + if (lex == null) 492 + throw new PrexoniteException("The prexonite grammar requires a *Lex-scanner."); 493 + lex.PushState(state); 494 + } 495 + 496 + private void _popLexerState() 497 + { 498 + var lex = scanner as Lexer; 499 + if (lex == null) 500 + throw new PrexoniteException("The prexonite grammar requires a *Lex-scanner."); 501 + lex.PopState(); 502 + //Might be id or keyword 503 + if ((la.kind > _BEGINKEYWORDS && la.kind < _ENDKEYWORDS) || la.kind == _id) 504 + la.kind = lex.checkKeyword(la.val); 505 + } 506 + 507 + private void _inject(Token c) 508 + { 509 + var lex = scanner as Lexer; 510 + if (lex == null) 511 + throw new PrexoniteException("The prexonite grammar requires a *Lex-scanner."); 512 + 513 + if (c == null) 514 + throw new ArgumentNullException(nameof(c)); 515 + 516 + lex._InjectToken(c); 517 + } 518 + 519 + private void _inject(int kind, string val) 520 + { 521 + if (val == null) 522 + throw new ArgumentNullException(nameof(val)); 523 + var c = new Token 524 + { 525 + kind = kind, 526 + val = val 527 + }; 528 + _inject(c); 529 + } 530 + 531 + private void _inject(int kind) 532 + { 533 + _inject(kind, System.String.Empty); 534 + } 535 + 536 + /// <summary> 537 + /// Defines a new global variable (or returns the existing declaration and instance) 538 + /// </summary> 539 + /// <param name="id">The physical name of the new global variable.</param> 540 + /// <param name="vari">The variable declaration for the new variable.</param> 541 + protected PVariable DefineGlobalVariable(string id, out VariableDeclaration vari) 542 + { 543 + if (TargetModule.Variables.TryGetVariable(id, out vari)) 544 + { 545 + return TargetApplication.Variables[vari.Id]; 546 + } 547 + else 548 + { 549 + vari = global::Prexonite.Modular.VariableDeclaration.Create(id); 550 + TargetModule.Variables.Add(vari); 551 + return TargetApplication.Variables[id] = new PVariable(vari); 552 + } 553 + } 554 + 555 + private void _compileAndExecuteBuildBlock(CompilerTarget buildBlockTarget) 556 + { 557 + if (errors.count > 0) 558 + { 559 + Loader.ReportMessage(Message.Error(Resources.Parser_ErrorsInBuildBlock,GetPosition(),MessageClasses.ErrorsInBuildBlock)); 560 + return; 561 + } 562 + 563 + //Emit code for top-level build block 564 + try 565 + { 566 + buildBlockTarget.Ast.EmitCode(buildBlockTarget, true, StackSemantics.Effect); 567 + 568 + buildBlockTarget.Function.Meta["File"] = scanner.File; 569 + buildBlockTarget.FinishTarget(); 570 + //Run the build block 571 + var fctx = buildBlockTarget.Function.CreateFunctionContext(ParentEngine, 572 + new PValue[] { }, 573 + new PVariable[] { }, true); 574 + object token = null; 575 + try 576 + { 577 + TargetApplication._SuppressInitialization = true; 578 + token = Loader.RequestBuildCommands(); 579 + ParentEngine.Process(fctx); 580 + } 581 + finally 582 + { 583 + if (token != null) 584 + Loader.ReleaseBuildCommands(token); 585 + TargetApplication._SuppressInitialization = false; 586 + } 587 + } 588 + catch (Exception e) 589 + { 590 + Loader.ReportMessage(Message.Error(string.Format(Resources.Parser_exception_in_build_block, e),GetPosition(),MessageClasses.ExceptionDuringCompilation)); 591 + } 592 + } 593 + 594 + private bool _suppressPrimarySymbol(IHasMetaTable ihmt) 595 + { 596 + return ihmt.Meta[Loader.SuppressPrimarySymbol].Switch; 597 + } 598 + 599 + #endregion //General 600 + 601 + #region Prexonite Script 602 + 603 + #region Symbol management 604 + 605 + internal static AstGetSet _NullNode(ISourcePosition position) 606 + { 607 + var n = new AstNull(position.File, position.Line, position.Column); 608 + return new AstIndirectCall(position, PCall.Get, n); 609 + } 610 + 611 + private readonly Stack<object> _scopeStack = new Stack<object>(); 612 + 613 + internal void _PushScope(AstScopedBlock block) 614 + { 615 + if (!ReferenceEquals(block.LexicalScope, CurrentBlock)) 616 + throw new PrexoniteException("Cannot push scope of unrelated block."); 617 + _scopeStack.Push(block); 618 + _target.BeginBlock(block); 619 + } 620 + 621 + internal void _PushScope(CompilerTarget ct) 622 + { 623 + if (!ReferenceEquals(ct.ParentTarget, _target)) 624 + throw new PrexoniteException("Cannot push scope of unrelated compiler target."); 625 + 626 + // SPECIAL CASE: Initialization code gets a separate environment every time 627 + // a block of code is added to it. 628 + if (ct.Function.Id == Application.InitializationId) 629 + { 630 + ct.Ast._ReplaceSymbols(SymbolStore.Create(Symbols)); 631 + } 632 + 633 + // Record scope 634 + _scopeStack.Push(ct); 635 + _target = ct; 636 + } 637 + 638 + internal void _PopScope(AstScopedBlock block) 639 + { 640 + if (!ReferenceEquals(_scopeStack.Peek(), block)) 641 + throw new PrexoniteException(string.Format("Tried to pop scope of block {0} but {1} was on top.", block, _scopeStack.Peek())); 642 + _scopeStack.Pop(); 643 + _target.EndBlock(); 644 + } 645 + 646 + internal void _PopScope(CompilerTarget ct) 647 + { 648 + if (!ReferenceEquals(_scopeStack.Peek(), ct)) 649 + throw new PrexoniteException(string.Format("Tried to pop scope of compiler target {0} but {1} was on top.", ct, _scopeStack.Peek())); 650 + _target = ct.ParentTarget; 651 + _scopeStack.Pop(); 652 + } 653 + 654 + #endregion 655 + 656 + [DebuggerStepThrough] 657 + public bool isLabel() //LL(2) 658 + { 659 + scanner.ResetPeek(); 660 + var c = la; 661 + var cla = scanner.Peek(); 662 + 663 + return c.kind == _lid || (isId(c) && cla.kind == _colon); 664 + } 665 + 666 + public bool isAssignmentOperator() //LL2 667 + { 668 + /* Applies to: 669 + * = 670 + * += 671 + * -= 672 + * *= 673 + * /= 674 + * ^= 675 + * |= 676 + * &= 677 + * ??= 678 + * ~= 679 + * <|= 680 + * |>= 681 + */ 682 + scanner.ResetPeek(); 683 + 684 + //current la = assign | plus | minus | times | div | pow | bitOr | bitAnd | coalesence | tilde 685 + 686 + switch (la.kind) 687 + { 688 + case _assign: 689 + return true; 690 + case _plus: 691 + case _minus: 692 + case _times: 693 + case _div: 694 + case _pow: 695 + case _bitOr: 696 + case _bitAnd: 697 + case _coalescence: 698 + case _tilde: 699 + case _deltaleft: 700 + case _deltaright: 701 + var c = scanner.Peek(); 702 + if (c.kind == _assign) 703 + return true; 704 + else 705 + return false; 706 + default: 707 + return false; 708 + } 709 + } 710 + 711 + public bool isSymbolDirective(string pattern) 712 + { 713 + scanner.ResetPeek(); 714 + return la.kind == _id 715 + && scanner.Peek().kind == _lpar 716 + && la.val.ToUpperInvariant() == pattern; 717 + 718 + } 719 + 720 + private bool isFollowedByStatementBlock() 721 + { 722 + scanner.ResetPeek(); 723 + return scanner.Peek().kind == _lbrace; 724 + } 725 + 726 + private bool isLambdaExpression() //LL(*) 727 + { 728 + scanner.ResetPeek(); 729 + 730 + var current = la; 731 + if (!(current.kind == _lpar || isId(current))) 732 + return false; 733 + var next = scanner.Peek(); 734 + 735 + var requirePar = false; 736 + if (current.kind == _lpar) 737 + { 738 + requirePar = true; 739 + current = next; 740 + next = scanner.Peek(); 741 + 742 + //Check for lambda expression without arguments 743 + if (current.kind == _rpar && next.kind == _implementation) 744 + return true; 745 + } 746 + 747 + if (isId(current)) 748 + { 749 + //break if lookahead is not valid to save tokens 750 + if ( 751 + !(next.kind == _comma || next.kind == _implementation || 752 + (next.kind == _rpar && requirePar))) 753 + return false; 754 + //Consume 1 755 + current = next; 756 + next = scanner.Peek(); 757 + } 758 + else if ((current.kind == _var || current.kind == _ref) && isId(next)) 759 + { 760 + //Consume 2 761 + current = scanner.Peek(); 762 + //break if lookahead is not valid to save tokens 763 + if ( 764 + !(current.kind == _comma || current.kind == _implementation || 765 + (current.kind == _rpar && requirePar))) 766 + return false; 767 + next = scanner.Peek(); 768 + } 769 + else 770 + { 771 + return false; 772 + } 773 + 774 + while (current.kind == _comma && requirePar) 775 + { 776 + //Consume comma 777 + current = next; 778 + next = scanner.Peek(); 779 + 780 + if (isId(current)) 781 + { 782 + //Consume 1 783 + current = next; 784 + next = scanner.Peek(); 785 + } 786 + else if ((current.kind == _var || current.kind == _ref) && isId(next)) 787 + { 788 + //Consume 2 789 + current = scanner.Peek(); 790 + next = scanner.Peek(); 791 + } 792 + else 793 + { 794 + return false; 795 + } 796 + } 797 + 798 + if (requirePar) 799 + if (current.kind == _rpar) 800 + { 801 + current = next; 802 + //cla = scanner.Peek(); 803 + } 804 + else 805 + { 806 + return false; 807 + } 808 + 809 + return current.kind == _implementation; 810 + } 811 + 812 + //LL(*) 813 + 814 + [DebuggerStepThrough] 815 + private bool isIndirectCall() //LL(2) 816 + { 817 + scanner.ResetPeek(); 818 + var c = la; 819 + var cla = scanner.Peek(); 820 + 821 + return c.kind == _dot && cla.kind == _lpar; 822 + } 823 + 824 + [DebuggerStepThrough] 825 + private bool isOuterVariable(string id) //context 826 + { 827 + return target._IsOuterVariable(id); 828 + } 829 + 830 + private string generateLocalId(string prefix = "") 831 + { 832 + return target.GenerateLocalId(prefix); 833 + } 834 + 835 + private Symbol _ensureDefinedLocal(string localAlias, string physicalId, bool isAutodereferenced, ISourcePosition declPos, bool isOverrideDecl) 836 + { 837 + var refSym = 838 + Symbol.CreateDereference(Symbol.CreateReference(EntityRef.Variable.Local.Create(physicalId), declPos), 839 + declPos); 840 + var sym = isAutodereferenced 841 + ? Symbol.CreateDereference(refSym, declPos) 842 + : refSym; 843 + 844 + target.Symbols.Declare(localAlias, sym); 845 + if (!isOverrideDecl && !target.Function.Variables.Contains(physicalId) && 846 + isOuterVariable(physicalId)) 847 + { 848 + target.RequireOuterVariable(physicalId); 849 + } 850 + else if(!target.Function.Variables.Contains(physicalId)) 851 + { 852 + target.Function.Variables.Add(physicalId); 853 + } 854 + return sym; 855 + } 856 + 857 + [NotNull] 858 + private AstGetSet _useSymbol([NotNull] ISymbolView<Symbol> scope, [NotNull] String id, [NotNull] ISourcePosition position) 859 + { 860 + Symbol sym; 861 + var expr = scope.TryGet(id, out sym) 862 + ? Create.ExprFor(position, sym) 863 + : new AstUnresolved(position, id); 864 + var complex = expr as AstGetSet; 865 + if (complex != null) 866 + { 867 + // If we have a namespace usage at hand, record the id used to access it 868 + // (namespaces are otherwise anonymous, they have no physical name) 869 + // Note: similar code is located in the GetSetExtension parser production 870 + // for subnamespaces 871 + var nsu = complex as AstNamespaceUsage; 872 + if (nsu != null && nsu.ReferencePath == null) 873 + { 874 + nsu.ReferencePath = new QualifiedId(id); 875 + } 876 + return complex; 877 + } 878 + Loader.ReportMessage(Message.Error(Resources.Parser_SymbolicUsageAsLValue, position, MessageClasses.ParserInternal)); 879 + complex = _NullNode(position); 880 + return complex; 881 + } 882 + 883 + private Symbol _parseSymbol(MExpr expr) 884 + { 885 + try 886 + { 887 + var parser = new SymbolMExprParser(Symbols,Loader,Loader.TopLevelSymbols); 888 + return parser.Parse(expr); 889 + } 890 + catch (ErrorMessageException e) 891 + { 892 + Loader.ReportMessage(e.CompilerMessage); 893 + return Symbol.CreateNil(e.CompilerMessage.Position); 894 + } 895 + } 896 + 897 + [DebuggerStepThrough] 898 + private static bool isId(Token c) 899 + { 900 + if (isGlobalId(c)) 901 + return true; 902 + switch (c.kind) 903 + { 904 + case _enabled: 905 + case _disabled: 906 + case _build: 907 + case _add: 908 + return true; 909 + default: 910 + return false; 911 + } 912 + } 913 + 914 + [DebuggerStepThrough] 915 + private static bool isGlobalId(Token c) 916 + { 917 + return c.kind == _id || c.kind == _anyId; 918 + } 919 + 920 + private bool _isNotNewDecl() 921 + { 922 + if (la.kind != _new) 923 + return false; 924 + 925 + scanner.ResetPeek(); 926 + var varTok = scanner.Peek(); 927 + 928 + return varTok.kind != _var && varTok.kind != _ref; 929 + } 930 + 931 + private static IEnumerable<string> let_bindings(CompilerTarget ft) 932 + { 933 + var lets = new HashSet<string>(Engine.DefaultStringComparer); 934 + for (var ct = ft; ct != null; ct = ct.ParentTarget) 935 + lets.UnionWith(ct.Function.Meta[PFunction.LetKey].List.Select(e => e.Text)); 936 + return lets; 937 + } 938 + 939 + private static void mark_as_let(PFunction f, string local) 940 + { 941 + f.Meta[PFunction.LetKey] = (MetaEntry) 942 + f.Meta[PFunction.LetKey].List 943 + .Union(new[] { (MetaEntry)local }) 944 + .ToArray(); 945 + } 946 + 947 + #region Assemble Invocation of Symbol 948 + 949 + private class ReferenceTransformer : SymbolHandler<int,Tuple<Symbol,bool>> 950 + { 951 + [NotNull] 952 + private readonly Parser _parser; 953 + 954 + public ReferenceTransformer([NotNull] Parser parser) 955 + { 956 + _parser = parser; 957 + } 958 + 959 + protected override Tuple<Symbol, bool> HandleWrappingSymbol(WrappingSymbol self, int argument) 960 + { 961 + if (argument == 0) 962 + return Tuple.Create<Symbol,bool>(self,false); 963 + else 964 + { 965 + var innerResult = self.InnerSymbol.HandleWith(this, argument); 966 + return Tuple.Create<Symbol,bool>(self.With(innerResult.Item1),innerResult.Item2); 967 + } 968 + } 969 + 970 + protected override Tuple<Symbol, bool> HandleLeafSymbol(Symbol self, int argument) 971 + { 972 + if (argument > 0) 973 + { 974 + throw new ErrorMessageException( 975 + Message.Error(Resources.ReferenceTransformer_CannotCreateReferenceToValue, 976 + _parser.GetPosition(), MessageClasses.CannotCreateReference)); 977 + } 978 + else 979 + { 980 + return Tuple.Create(self,false); 981 + } 982 + } 983 + 984 + public override Tuple<Symbol, bool> HandleDereference(DereferenceSymbol self, int argument) 985 + { 986 + if (argument > 0) 987 + { 988 + return self.InnerSymbol.HandleWith(this, argument - 1); 989 + } 990 + else 991 + { 992 + return base.HandleDereference(self, argument); 993 + } 994 + } 995 + 996 + public override Tuple<Symbol, bool> HandleExpand(ExpandSymbol self, int argument) 997 + { 998 + if (argument > 1) 999 + { 1000 + throw new ErrorMessageException( 1001 + Message.Error(Resources.ReferenceTransformer_HandleExpand_CannotCreateReferenceToDefinitionOfMacroOrPartialApplication, 1002 + _parser.GetPosition(), MessageClasses.CannotCreateReference)); 1003 + } 1004 + else if(argument == 1) 1005 + { 1006 + // Here, we don't actually remove the expansion, but rather switch the 1007 + // flag to true to indicate that the calling procedure should 1008 + // convert the resulting expansion node into a partial application. 1009 + return new Tuple<Symbol, bool>(base.HandleExpand(self,argument-1).Item1,true); 1010 + } 1011 + else 1012 + { 1013 + return base.HandleExpand(self, argument); 1014 + } 1015 + } 1016 + } 1017 + 1018 + [NotNull] 1019 + private readonly ReferenceTransformer _referenceTransformer; 1020 + 1021 + private AstExpr _assembleReference(string id, int ptrCount) 1022 + { 1023 + Debug.Assert(id != null); 1024 + Debug.Assert(ptrCount > 0); 1025 + 1026 + Symbol symbol; 1027 + var position = GetPosition(); 1028 + if (!Symbols.TryGet(id, out symbol)) 1029 + { 1030 + Loader.ReportMessage(Message.Error(string.Format(Resources.Parser__assembleReference_SymbolNotDefined, id),position,MessageClasses.SymbolNotResolved)); 1031 + return Create.Null(position); 1032 + } 1033 + else 1034 + { 1035 + try 1036 + { 1037 + var transformed = symbol.HandleWith(_referenceTransformer, ptrCount); 1038 + var invocation = Create.ExprFor(position, transformed.Item1); 1039 + if (transformed.Item2) 1040 + { 1041 + // If the reference transformer indicates that an Expand prefix was eliminated 1042 + // during the transformation, we need to convert the invocation into a partial application 1043 + var invocationCall = invocation as AstGetSet; 1044 + if (invocationCall == null) 1045 + { 1046 + Loader.ReportMessage( 1047 + Message.Error(Resources.Parser__assembleReference_MacroDefinitionNotLValue, position, 1048 + MessageClasses.ParserInternal)); 1049 + invocation = Create.Null(position); 1050 + } 1051 + else 1052 + { 1053 + invocationCall.Arguments.Add(Create.Placeholder(position)); 1054 + } 1055 + } 1056 + return invocation; 1057 + } 1058 + catch (ErrorMessageException e) 1059 + { 1060 + Loader.ReportMessage(e.CompilerMessage); 1061 + return Create.Null(position); 1062 + } 1063 + } 1064 + } 1065 + 1066 + private class EnsureInScopeHandler : TransformHandler<Parser> 1067 + { 1068 + public override Symbol HandleReference(ReferenceSymbol self, Parser argument) 1069 + { 1070 + EntityRef.Variable.Local local; 1071 + if(self.Entity.TryGetLocalVariable(out local) 1072 + && argument.isOuterVariable(local.Id)) 1073 + argument.target.RequireOuterVariable(local.Id); 1074 + return self; 1075 + } 1076 + } 1077 + private static readonly EnsureInScopeHandler _ensureInScope = new EnsureInScopeHandler(); 1078 + 1079 + public void EnsureInScope(Symbol symbol) 1080 + { 1081 + symbol.HandleWith(_ensureInScope, this); 1082 + } 1083 + 1084 + private void _fallbackObjectCreation(AstTypeExpr type, out AstExpr expr, 1085 + out ArgumentsProxy args) 1086 + { 1087 + var typeExpr = type as AstDynamicTypeExpression; 1088 + Symbol fallbackSymbol; 1089 + if ( 1090 + //is a type expression we understand (Parser currently only generates dynamic type expressions) 1091 + // constant type expressions are recognized during optimization 1092 + typeExpr != null 1093 + //happens in case of parse failure 1094 + && typeExpr.TypeId != null 1095 + //there is no such thing as a parametrized struct 1096 + && typeExpr.Arguments.Count == 0 1097 + //built-in types take precedence 1098 + && !ParentEngine.PTypeRegistry.Contains(typeExpr.TypeId) 1099 + //in case neither the built-in type nor the struct constructor exists, 1100 + // stay with built-in types for predictibility 1101 + && 1102 + target.Symbols.TryGet( 1103 + Loader.ObjectCreationFallbackPrefix + typeExpr.TypeId, 1104 + out fallbackSymbol)) 1105 + { 1106 + EnsureInScope(fallbackSymbol); 1107 + 1108 + var e = Create.ExprFor(type.Position,fallbackSymbol); 1109 + var call = e as AstGetSet; 1110 + if (call == null) 1111 + { 1112 + var pos = GetPosition(); 1113 + call = Create.IndirectCall(pos, Create.Null(pos)); 1114 + Loader.ReportMessage(Message.Create(MessageSeverity.Error, 1115 + string.Format(Resources.Parser__CannotUseExpressionAsAConstructor, 1116 + e), pos, 1117 + MessageClasses.CannotUseExpressionAsConstructor)); 1118 + } 1119 + expr = call; 1120 + args = call.Arguments; 1121 + } 1122 + else if (type != null) 1123 + { 1124 + var creation = new AstObjectCreation(this, type); 1125 + expr = creation; 1126 + args = creation.Arguments; 1127 + } 1128 + else 1129 + { 1130 + Loader.ReportMessage(Message.Error(Resources.Parser__fallbackObjectCreation_Failed,GetPosition(),MessageClasses.ObjectCreationSyntax)); 1131 + expr = new AstNull(this); 1132 + args = new ArgumentsProxy(new List<AstExpr>()); 1133 + } 1134 + } 1135 + 1136 + private AstExpr _createUnknownExpr() 1137 + { 1138 + return _createUnknownGetSet(); 1139 + } 1140 + 1141 + private AstGetSet _createUnknownGetSet() 1142 + { 1143 + return new AstIndirectCall(this, new AstNull(this)); 1144 + } 1145 + 1146 + private void _appendRight(AstExpr lhs, AstGetSet rhs) 1147 + { 1148 + _appendRight(lhs.Singleton(), rhs); 1149 + } 1150 + 1151 + private void _appendRight(IEnumerable<AstExpr> lhs, AstGetSet rhs) 1152 + { 1153 + rhs.Arguments.RightAppend(lhs); 1154 + rhs.Arguments.ReleaseRightAppend(); 1155 + AstIndirectCall indirectCallNode; 1156 + AstReference refNode; 1157 + EntityRef.Variable dummyVariable; 1158 + if ((indirectCallNode = rhs as AstIndirectCall) != null 1159 + && (refNode = indirectCallNode.Subject as AstReference) != null 1160 + && refNode.Entity.TryGetVariable(out dummyVariable)) 1161 + rhs.Call = PCall.Set; 1162 + } 1163 + 1164 + #endregion 1165 + 1166 + 1167 + #endregion 1168 + 1169 + #region Assembler 1170 + 1171 + [DebuggerStepThrough] 1172 + public void addInstruction(AstBlock block, Instruction ins) 1173 + { 1174 + block.Add(new AstAsmInstruction(this, ins)); 1175 + } 1176 + 1177 + public void addOpAlias(AstBlock block, string insBase, string detail) 1178 + { 1179 + int argc; 1180 + var alias = getOpAlias(insBase, detail, out argc); 1181 + if (alias == null) 1182 + { 1183 + Loader.ReportMessage( 1184 + Message.Error( 1185 + string.Format(Resources.Parser_addOpAlias_Unknown, insBase, detail), 1186 + GetPosition(), MessageClasses.UnknownAssemblyOperator)); 1187 + block.Add(new AstAsmInstruction(this, new Instruction(OpCode.nop))); 1188 + return; 1189 + } 1190 + 1191 + block.Add(new AstAsmInstruction(this, Instruction.CreateCommandCall(argc, alias))); 1192 + } 1193 + 1194 + [DebuggerStepThrough] 1195 + public void addLabel(AstBlock block, string label) 1196 + { 1197 + block.Statements.Add(new AstExplicitLabel(this, label)); 1198 + } 1199 + 1200 + [DebuggerStepThrough] 1201 + private bool isAsmInstruction(string insBase, string detail) //LL(4) 1202 + { 1203 + scanner.ResetPeek(); 1204 + var la1 = la.kind == _at ? scanner.Peek() : la; 1205 + var la2 = scanner.Peek(); 1206 + var la3 = scanner.Peek(); 1207 + return checkAsmInstruction(la1, la2, la3, insBase, detail); 1208 + } 1209 + 1210 + private static bool checkAsmInstruction( 1211 + Token la1, Token la2, Token la3, string insBase, string detail) 1212 + { 1213 + return 1214 + la1.kind != _string && Engine.StringsAreEqual(la1.val, insBase) && 1215 + (detail == null 1216 + ? (la2.kind != _dot || la3.kind == _integer) 1217 + : (la2.kind == _dot && la3.kind != _string && 1218 + Engine.StringsAreEqual(la3.val, detail)) 1219 + ); 1220 + } 1221 + 1222 + [DebuggerStepThrough] 1223 + private bool isInIntegerGroup() 1224 + { 1225 + return peekIsOneOf(asmIntegerGroup); 1226 + } 1227 + 1228 + [DebuggerStepThrough] 1229 + private bool isInJumpGroup() 1230 + { 1231 + return peekIsOneOf(asmJumpGroup); 1232 + } 1233 + 1234 + private bool isInOpAliasGroup() 1235 + { 1236 + return peekIsOneOf(asmOpAliasGroup); 1237 + } 1238 + 1239 + [DebuggerStepThrough] 1240 + private bool isInNullGroup() 1241 + { 1242 + return peekIsOneOf(asmNullGroup); 1243 + } 1244 + 1245 + [DebuggerStepThrough] 1246 + private bool isInIdGroup() 1247 + { 1248 + return peekIsOneOf(asmIdGroup); 1249 + } 1250 + 1251 + [DebuggerStepThrough] 1252 + private bool isInIdArgGroup() 1253 + { 1254 + return peekIsOneOf(asmIdArgGroup); 1255 + } 1256 + 1257 + [DebuggerStepThrough] 1258 + private bool isInArgGroup() 1259 + { 1260 + return peekIsOneOf(asmArgGroup); 1261 + } 1262 + 1263 + [DebuggerStepThrough] 1264 + private bool isInQualidArgGroup() 1265 + { 1266 + return peekIsOneOf(asmQualidArgGroup); 1267 + } 1268 + 1269 + //[NoDebug()] 1270 + private bool peekIsOneOf(string[,] table) 1271 + { 1272 + scanner.ResetPeek(); 1273 + var la1 = la.kind == _at ? scanner.Peek() : la; 1274 + var la2 = scanner.Peek(); 1275 + var la3 = scanner.Peek(); 1276 + for (var i = table.GetUpperBound(0); i >= 0; i--) 1277 + if (checkAsmInstruction(la1, la2, la3, table[i, 0], table[i, 1])) 1278 + return true; 1279 + return false; 1280 + } 1281 + 1282 + private readonly SymbolTable<OpCode> _instructionNameTable = new SymbolTable<OpCode>(60); 1283 + 1284 + private readonly SymbolTable<Tuple<string, int>> _opAliasTable = 1285 + new SymbolTable<Tuple<string, int>>(32); 1286 + 1287 + [DebuggerStepThrough] 1288 + private void _createTableOfInstructions() 1289 + { 1290 + var tab = _instructionNameTable; 1291 + //Add original names 1292 + foreach (var code in Enum.GetNames(typeof(OpCode))) 1293 + tab.Add(code.Replace('_', '.'), (OpCode)Enum.Parse(typeof(OpCode), code)); 1294 + 1295 + //Add instruction aliases -- NOTE: You'll also have to add them to the respective groups 1296 + tab.Add("new", OpCode.newobj); 1297 + tab.Add("check", OpCode.check_const); 1298 + tab.Add("cast", OpCode.cast_const); 1299 + tab.Add("ret", OpCode.ret_value); 1300 + tab.Add("ret.val", OpCode.ret_value); 1301 + tab.Add("yield", OpCode.ret_continue); 1302 + tab.Add("exit", OpCode.ret_exit); 1303 + tab.Add("break", OpCode.ret_break); 1304 + tab.Add("continue", OpCode.ret_continue); 1305 + tab.Add("jump.true", OpCode.jump_t); 1306 + tab.Add("jump.false", OpCode.jump_f); 1307 + tab.Add("inc", OpCode.incloc); 1308 + tab.Add("inci", OpCode.incloci); 1309 + tab.Add("dec", OpCode.decloc); 1310 + tab.Add("deci", OpCode.decloci); 1311 + tab.Add("inda", OpCode.indarg); 1312 + tab.Add("cor", OpCode.newcor); 1313 + tab.Add("exception", OpCode.exc); 1314 + tab.Add("ldnull", OpCode.ldc_null); 1315 + 1316 + //Add operator aliases 1317 + var ops = _opAliasTable; 1318 + ops.Add("neg", Tuple.Create(UnaryNegation.DefaultAlias, 1)); 1319 + ops.Add("not", Tuple.Create(LogicalNot.DefaultAlias, 1)); 1320 + ops.Add("add", Tuple.Create(Addition.DefaultAlias, 2)); 1321 + ops.Add("sub", Tuple.Create(Subtraction.DefaultAlias, 2)); 1322 + ops.Add("mul", Tuple.Create(Multiplication.DefaultAlias, 2)); 1323 + ops.Add("div", Tuple.Create(Division.DefaultAlias, 2)); 1324 + ops.Add("mod", Tuple.Create(Modulus.DefaultAlias, 2)); 1325 + ops.Add("pow", Tuple.Create(Power.DefaultAlias, 2)); 1326 + ops.Add("ceq", Tuple.Create(Equality.DefaultAlias, 2)); 1327 + ops.Add("cne", Tuple.Create(Inequality.DefaultAlias, 2)); 1328 + ops.Add("clt", Tuple.Create(LessThan.DefaultAlias, 2)); 1329 + ops.Add("cle", Tuple.Create(LessThanOrEqual.DefaultAlias, 2)); 1330 + ops.Add("cgt", Tuple.Create(GreaterThan.DefaultAlias, 2)); 1331 + ops.Add("cge", Tuple.Create(GreaterThanOrEqual.DefaultAlias, 2)); 1332 + ops.Add("or", Tuple.Create(BitwiseOr.DefaultAlias, 2)); 1333 + ops.Add("and", Tuple.Create(BitwiseAnd.DefaultAlias, 2)); 1334 + ops.Add("xor", Tuple.Create(ExclusiveOr.DefaultAlias, 2)); 1335 + } 1336 + 1337 + //[DebuggerStepThrough] 1338 + private string getOpAlias(string insBase, string detail, out int argc) 1339 + { 1340 + var combined = insBase + (detail == null ? "" : "." + detail); 1341 + var entry = _opAliasTable.GetDefault(combined, null); 1342 + if (entry == null) 1343 + { 1344 + argc = -1; 1345 + return null; 1346 + } 1347 + else 1348 + { 1349 + argc = entry.Item2; 1350 + return entry.Item1; 1351 + } 1352 + } 1353 + 1354 + //[DebuggerStepThrough] 1355 + private OpCode getOpCode(string insBase, string detail) 1356 + { 1357 + var combined = insBase + (detail == null ? "" : "." + detail); 1358 + return _instructionNameTable.GetDefault(combined, OpCode.invalid); 1359 + } 1360 + 1361 + #region Instruction tables 1362 + 1363 + private readonly string[,] asmIntegerGroup = 1364 + { 1365 + {"ldc", "int"}, 1366 + {"pop", null}, 1367 + {"dup", null}, 1368 + {"ldloci", null}, 1369 + {"stloci", null}, 1370 + {"incloci", null}, 1371 + {"inci", null}, 1372 + {"deci", null}, 1373 + {"ldr", "loci"} 1374 + }; 1375 + 1376 + private readonly string[,] asmJumpGroup = 1377 + { 1378 + {"jump", null}, 1379 + {"jump", "t"}, 1380 + {"jump", "f"}, 1381 + {"jump", "true"}, 1382 + {"jump", "false"}, 1383 + {"leave", null} 1384 + }; 1385 + 1386 + private readonly string[,] asmNullGroup = 1387 + { 1388 + {"ldc", "null"}, 1389 + {"ldnull", null}, 1390 + {"check", "arg"}, 1391 + {"check", "null"}, 1392 + {"cast", "arg"}, 1393 + {"ldr", "eng"}, 1394 + {"ldr", "app"}, 1395 + {"ret", null}, 1396 + {"ret", "set"}, 1397 + {"ret", "value"}, 1398 + {"ret", "val"}, 1399 + {"ret", "break"}, 1400 + {"ret", "continue"}, 1401 + {"ret", "exit"}, 1402 + {"break", null}, 1403 + {"continue", null}, 1404 + {"yield", null}, 1405 + {"exit", null}, 1406 + {"try", null}, 1407 + {"throw", null}, 1408 + {"exc", null}, 1409 + {"exception", null} 1410 + }; 1411 + 1412 + private readonly string[,] asmOpAliasGroup = 1413 + { 1414 + {"neg", null}, 1415 + {"not", null}, 1416 + {"add", null}, 1417 + {"sub", null}, 1418 + {"mul", null}, 1419 + {"div", null}, 1420 + {"mod", null}, 1421 + {"pow", null}, 1422 + {"ceq", null}, 1423 + {"cne", null}, 1424 + {"clt", null}, 1425 + {"cle", null}, 1426 + {"cgt", null}, 1427 + {"cge", null}, 1428 + {"or", null}, 1429 + {"and", null}, 1430 + {"xor", null} 1431 + }; 1432 + 1433 + private readonly string[,] asmIdGroup = 1434 + { 1435 + {"inc", null}, 1436 + {"incloc", null}, 1437 + {"incglob", null}, 1438 + {"dec", null}, 1439 + {"decloc", null}, 1440 + {"decglob", null}, 1441 + {"ldc", "string"}, 1442 + {"ldr", "func"}, 1443 + {"ldr", "cmd"}, 1444 + {"ldr", "glob"}, 1445 + {"ldr", "loc"}, 1446 + {"ldr", "type"}, 1447 + {"ldloc", null}, 1448 + {"stloc", null}, 1449 + {"ldglob", null}, 1450 + {"stglob", null}, 1451 + {"check", "const"}, 1452 + {"check", null}, 1453 + {"cast", "const"}, 1454 + {"cast", null}, 1455 + {"newclo", null} 1456 + }; 1457 + 1458 + private readonly string[,] asmIdArgGroup = 1459 + { 1460 + {"newtype", null}, 1461 + {"get", null}, 1462 + {"set", null}, 1463 + {"func", null}, 1464 + {"cmd", null}, 1465 + {"indloc", null}, 1466 + {"indglob", null} 1467 + }; 1468 + 1469 + private readonly string[,] asmArgGroup = 1470 + { 1471 + {"indarg", null}, 1472 + {"inda", null}, 1473 + {"newcor", null}, 1474 + {"cor", null}, 1475 + {"tail", null} 1476 + }; 1477 + 1478 + private readonly string[,] asmQualidArgGroup = 1479 + { 1480 + {"sget", null}, 1481 + {"sset", null}, 1482 + {"newobj", null}, 1483 + {"new", null} 1484 + }; 1485 + 1486 + #endregion 1487 + 1488 + #endregion 1489 + 1490 + #endregion 1491 + 1492 + } 1493 + } 1494 + 1495 1495 // ReSharper restore InconsistentNaming
+148 -138
Prexonite/Compiler/Parser.cs
··· 1145 1145 } 1146 1146 } 1147 1147 1148 - void TypeExpr(/*Parser.Expression.atg:511*/out AstTypeExpr type) { 1149 - /*Parser.Expression.atg:511*/type = null; 1148 + void TypeExpr(/*Parser.Expression.atg:517*/out AstTypeExpr type) { 1149 + /*Parser.Expression.atg:517*/type = null; 1150 1150 if (StartOf(12)) { 1151 - PrexoniteTypeExpr(/*Parser.Expression.atg:513*/out type); 1151 + PrexoniteTypeExpr(/*Parser.Expression.atg:519*/out type); 1152 1152 } else if (la.kind == _ns || la.kind == _doublecolon) { 1153 - ClrTypeExpr(/*Parser.Expression.atg:514*/out type); 1153 + ClrTypeExpr(/*Parser.Expression.atg:520*/out type); 1154 1154 } else SynErr(120); 1155 1155 } 1156 1156 1157 1157 void PrefixUnaryExpr(/*Parser.Expression.atg:264*/out AstExpr expr) { 1158 - /*Parser.Expression.atg:264*/var prefixes = new Stack<UnaryOperator>(); 1158 + /*Parser.Expression.atg:264*/var prefixes = new Stack<(bool IsSplice, UnaryOperator Op)>(); 1159 1159 /*Parser.Expression.atg:265*/var position = GetPosition(); 1160 1160 while (StartOf(13)) { 1161 1161 switch (la.kind) { ··· 1165 1165 } 1166 1166 case _minus: { 1167 1167 Get(); 1168 - /*Parser.Expression.atg:267*/prefixes.Push(UnaryOperator.UnaryNegation); 1168 + /*Parser.Expression.atg:267*/prefixes.Push((false, UnaryOperator.UnaryNegation)); 1169 + break; 1170 + } 1171 + case _times: { 1172 + Get(); 1173 + /*Parser.Expression.atg:268*/prefixes.Push((true, UnaryOperator.None)); 1169 1174 break; 1170 1175 } 1171 1176 case _inc: { 1172 1177 Get(); 1173 - /*Parser.Expression.atg:268*/prefixes.Push(UnaryOperator.PreIncrement); 1178 + /*Parser.Expression.atg:269*/prefixes.Push((false, UnaryOperator.PreIncrement)); 1174 1179 break; 1175 1180 } 1176 1181 case _dec: { 1177 1182 Get(); 1178 - /*Parser.Expression.atg:269*/prefixes.Push(UnaryOperator.PreDecrement); 1183 + /*Parser.Expression.atg:270*/prefixes.Push((false, UnaryOperator.PreDecrement)); 1179 1184 break; 1180 1185 } 1181 1186 case _deltaleft: { 1182 1187 Get(); 1183 - /*Parser.Expression.atg:270*/prefixes.Push(UnaryOperator.PreDeltaLeft); 1188 + /*Parser.Expression.atg:271*/prefixes.Push((false, UnaryOperator.PreDeltaLeft)); 1184 1189 break; 1185 1190 } 1186 1191 case _deltaright: { 1187 1192 Get(); 1188 - /*Parser.Expression.atg:271*/prefixes.Push(UnaryOperator.PreDeltaRight); 1193 + /*Parser.Expression.atg:272*/prefixes.Push((false, UnaryOperator.PreDeltaRight)); 1189 1194 break; 1190 1195 } 1191 1196 } 1192 1197 } 1193 - Primary(/*Parser.Expression.atg:273*/out expr); 1194 - /*Parser.Expression.atg:274*/while(prefixes.Count > 0) 1195 - expr = Create.UnaryOperation(position, prefixes.Pop(), expr); 1198 + Primary(/*Parser.Expression.atg:274*/out expr); 1199 + /*Parser.Expression.atg:275*/while(prefixes.Count > 0) { 1200 + var prefix = prefixes.Pop(); 1201 + if(prefix.IsSplice) 1202 + expr = Create.ArgumentSplice(position, expr); 1203 + else 1204 + expr = Create.UnaryOperation(position, prefix.Op, expr); 1205 + } 1196 1206 1197 1207 } 1198 1208 ··· 1247 1257 } else SynErr(121); 1248 1258 } 1249 1259 1250 - void Primary(/*Parser.Expression.atg:280*/out AstExpr expr) { 1251 - /*Parser.Expression.atg:280*/expr = null; 1260 + void Primary(/*Parser.Expression.atg:286*/out AstExpr expr) { 1261 + /*Parser.Expression.atg:286*/expr = null; 1252 1262 1253 1263 if (la.kind == _asm) { 1254 - /*Parser.Expression.atg:283*/_pushLexerState(Lexer.Asm); 1255 - /*Parser.Expression.atg:283*/var blockExpr = Create.Block(GetPosition()); 1264 + /*Parser.Expression.atg:289*/_pushLexerState(Lexer.Asm); 1265 + /*Parser.Expression.atg:289*/var blockExpr = Create.Block(GetPosition()); 1256 1266 _PushScope(blockExpr); 1257 1267 1258 1268 Get(); 1259 1269 Expect(_lpar); 1260 1270 while (StartOf(1)) { 1261 - AsmInstruction(/*Parser.Expression.atg:286*/blockExpr); 1271 + AsmInstruction(/*Parser.Expression.atg:292*/blockExpr); 1262 1272 } 1263 1273 Expect(_rpar); 1264 - /*Parser.Expression.atg:287*/_popLexerState(); 1265 - /*Parser.Expression.atg:287*/expr = blockExpr; 1274 + /*Parser.Expression.atg:293*/_popLexerState(); 1275 + /*Parser.Expression.atg:293*/expr = blockExpr; 1266 1276 _PopScope(blockExpr); 1267 1277 1268 1278 } else if (StartOf(16)) { 1269 - Constant(/*Parser.Expression.atg:290*/out expr); 1279 + Constant(/*Parser.Expression.atg:296*/out expr); 1270 1280 } else if (la.kind == _this) { 1271 - ThisExpression(/*Parser.Expression.atg:291*/out expr); 1281 + ThisExpression(/*Parser.Expression.atg:297*/out expr); 1272 1282 } else if (la.kind == _coroutine) { 1273 - CoroutineCreation(/*Parser.Expression.atg:292*/out expr); 1283 + CoroutineCreation(/*Parser.Expression.atg:298*/out expr); 1274 1284 } else if (la.kind == _lbrack) { 1275 - ListLiteral(/*Parser.Expression.atg:293*/out expr); 1285 + ListLiteral(/*Parser.Expression.atg:299*/out expr); 1276 1286 } else if (la.kind == _lbrace) { 1277 - HashLiteral(/*Parser.Expression.atg:294*/out expr); 1287 + HashLiteral(/*Parser.Expression.atg:300*/out expr); 1278 1288 } else if (StartOf(17)) { 1279 - LoopExpr(/*Parser.Expression.atg:295*/out expr); 1289 + LoopExpr(/*Parser.Expression.atg:301*/out expr); 1280 1290 } else if (la.kind == _throw) { 1281 - /*Parser.Expression.atg:296*/AstThrow th; 1282 - ThrowExpression(/*Parser.Expression.atg:297*/out th); 1283 - /*Parser.Expression.atg:297*/expr = th; 1284 - } else if (/*Parser.Expression.atg:299*/isLambdaExpression()) { 1285 - LambdaExpression(/*Parser.Expression.atg:299*/out expr); 1291 + /*Parser.Expression.atg:302*/AstThrow th; 1292 + ThrowExpression(/*Parser.Expression.atg:303*/out th); 1293 + /*Parser.Expression.atg:303*/expr = th; 1294 + } else if (/*Parser.Expression.atg:305*/isLambdaExpression()) { 1295 + LambdaExpression(/*Parser.Expression.atg:305*/out expr); 1286 1296 } else if (la.kind == _lazy) { 1287 - LazyExpression(/*Parser.Expression.atg:300*/out expr); 1297 + LazyExpression(/*Parser.Expression.atg:306*/out expr); 1288 1298 } else if (la.kind == _lpar) { 1289 1299 Get(); 1290 - Expr(/*Parser.Expression.atg:301*/out expr); 1300 + Expr(/*Parser.Expression.atg:307*/out expr); 1291 1301 Expect(_rpar); 1292 - } else if (/*Parser.Expression.atg:302*/_isNotNewDecl()) { 1293 - ObjectCreation(/*Parser.Expression.atg:302*/out expr); 1302 + } else if (/*Parser.Expression.atg:308*/_isNotNewDecl()) { 1303 + ObjectCreation(/*Parser.Expression.atg:308*/out expr); 1294 1304 } else if (StartOf(18)) { 1295 - GetInitiator(/*Parser.Expression.atg:303*/out expr); 1305 + GetInitiator(/*Parser.Expression.atg:309*/out expr); 1296 1306 } else if (la.kind == _LPopExpr) { 1297 1307 Get(); 1298 1308 Expect(_lpar); 1299 - Expr(/*Parser.Expression.atg:304*/out expr); 1300 - /*Parser.Expression.atg:309*/_popLexerState(); _inject(_plus); 1309 + Expr(/*Parser.Expression.atg:310*/out expr); 1310 + /*Parser.Expression.atg:315*/_popLexerState(); _inject(_plus); 1301 1311 Expect(_rpar); 1302 1312 } else SynErr(122); 1303 1313 } 1304 1314 1305 - void Constant(/*Parser.Expression.atg:314*/out AstExpr expr) { 1306 - /*Parser.Expression.atg:314*/expr = null; int vi; double vr; bool vb; string vs; 1315 + void Constant(/*Parser.Expression.atg:320*/out AstExpr expr) { 1316 + /*Parser.Expression.atg:320*/expr = null; int vi; double vr; bool vb; string vs; 1307 1317 if (la.kind == _integer) { 1308 - Integer(/*Parser.Expression.atg:316*/out vi); 1309 - /*Parser.Expression.atg:316*/expr = new AstConstant(this, vi); 1318 + Integer(/*Parser.Expression.atg:322*/out vi); 1319 + /*Parser.Expression.atg:322*/expr = new AstConstant(this, vi); 1310 1320 } else if (la.kind == _real || la.kind == _realLike) { 1311 - Real(/*Parser.Expression.atg:317*/out vr); 1312 - /*Parser.Expression.atg:317*/expr = new AstConstant(this, vr); 1321 + Real(/*Parser.Expression.atg:323*/out vr); 1322 + /*Parser.Expression.atg:323*/expr = new AstConstant(this, vr); 1313 1323 } else if (la.kind == _true || la.kind == _false) { 1314 - Boolean(/*Parser.Expression.atg:318*/out vb); 1315 - /*Parser.Expression.atg:318*/expr = new AstConstant(this, vb); 1324 + Boolean(/*Parser.Expression.atg:324*/out vb); 1325 + /*Parser.Expression.atg:324*/expr = new AstConstant(this, vb); 1316 1326 } else if (la.kind == _string) { 1317 - String(/*Parser.Expression.atg:319*/out vs); 1318 - /*Parser.Expression.atg:319*/expr = new AstConstant(this, vs); 1327 + String(/*Parser.Expression.atg:325*/out vs); 1328 + /*Parser.Expression.atg:325*/expr = new AstConstant(this, vs); 1319 1329 } else if (la.kind == _null) { 1320 1330 Null(); 1321 - /*Parser.Expression.atg:320*/expr = new AstConstant(this, null); 1331 + /*Parser.Expression.atg:326*/expr = new AstConstant(this, null); 1322 1332 } else SynErr(123); 1323 1333 } 1324 1334 1325 - void ThisExpression(/*Parser.Expression.atg:498*/out AstExpr expr) { 1326 - /*Parser.Expression.atg:498*/var position = GetPosition(); 1335 + void ThisExpression(/*Parser.Expression.atg:504*/out AstExpr expr) { 1336 + /*Parser.Expression.atg:504*/var position = GetPosition(); 1327 1337 expr = Create.IndirectCall(position,Create.Null(position)); 1328 1338 1329 1339 Expect(_this); 1330 - /*Parser.Expression.atg:502*/Loader.ReportMessage(Message.Error("Illegal use of reserved keyword `this`.",position,MessageClasses.ThisReserved)); 1340 + /*Parser.Expression.atg:508*/Loader.ReportMessage(Message.Error("Illegal use of reserved keyword `this`.",position,MessageClasses.ThisReserved)); 1331 1341 } 1332 1342 1333 - void CoroutineCreation(/*Parser.Expression.atg:392*/out AstExpr expr) { 1334 - /*Parser.Expression.atg:393*/AstCreateCoroutine cor = new AstCreateCoroutine(this); 1343 + void CoroutineCreation(/*Parser.Expression.atg:398*/out AstExpr expr) { 1344 + /*Parser.Expression.atg:399*/AstCreateCoroutine cor = new AstCreateCoroutine(this); 1335 1345 AstExpr iexpr; 1336 1346 expr = cor; 1337 1347 1338 1348 Expect(_coroutine); 1339 - Expr(/*Parser.Expression.atg:398*/out iexpr); 1340 - /*Parser.Expression.atg:398*/cor.Expression = iexpr; 1349 + Expr(/*Parser.Expression.atg:404*/out iexpr); 1350 + /*Parser.Expression.atg:404*/cor.Expression = iexpr; 1341 1351 if (la.kind == _for) { 1342 1352 Get(); 1343 - Arguments(/*Parser.Expression.atg:399*/cor.Arguments); 1353 + Arguments(/*Parser.Expression.atg:405*/cor.Arguments); 1344 1354 } 1345 1355 } 1346 1356 1347 - void ListLiteral(/*Parser.Expression.atg:324*/out AstExpr expr) { 1348 - /*Parser.Expression.atg:324*/AstExpr iexpr; 1357 + void ListLiteral(/*Parser.Expression.atg:330*/out AstExpr expr) { 1358 + /*Parser.Expression.atg:330*/AstExpr iexpr; 1349 1359 AstListLiteral lst = new AstListLiteral(this); 1350 1360 expr = lst; 1351 1361 bool missingExpr = false; 1352 1362 1353 1363 Expect(_lbrack); 1354 1364 if (StartOf(14)) { 1355 - Expr(/*Parser.Expression.atg:331*/out iexpr); 1356 - /*Parser.Expression.atg:331*/lst.Elements.Add(iexpr); 1365 + Expr(/*Parser.Expression.atg:337*/out iexpr); 1366 + /*Parser.Expression.atg:337*/lst.Elements.Add(iexpr); 1357 1367 while (la.kind == _comma) { 1358 1368 Get(); 1359 - /*Parser.Expression.atg:332*/if(missingExpr) 1369 + /*Parser.Expression.atg:338*/if(missingExpr) 1360 1370 SemErr("Missing expression in list literal (two consecutive commas)."); 1361 1371 1362 1372 if (StartOf(14)) { 1363 - Expr(/*Parser.Expression.atg:335*/out iexpr); 1364 - /*Parser.Expression.atg:335*/lst.Elements.Add(iexpr); 1373 + Expr(/*Parser.Expression.atg:341*/out iexpr); 1374 + /*Parser.Expression.atg:341*/lst.Elements.Add(iexpr); 1365 1375 missingExpr = false; 1366 1376 1367 1377 } else if (la.kind == _comma || la.kind == _rbrack) { 1368 - /*Parser.Expression.atg:338*/missingExpr = true; 1378 + /*Parser.Expression.atg:344*/missingExpr = true; 1369 1379 } else SynErr(124); 1370 1380 } 1371 1381 } 1372 1382 Expect(_rbrack); 1373 1383 } 1374 1384 1375 - void HashLiteral(/*Parser.Expression.atg:346*/out AstExpr expr) { 1376 - /*Parser.Expression.atg:346*/AstExpr iexpr; 1385 + void HashLiteral(/*Parser.Expression.atg:352*/out AstExpr expr) { 1386 + /*Parser.Expression.atg:352*/AstExpr iexpr; 1377 1387 AstHashLiteral hash = new AstHashLiteral(this); 1378 1388 expr = hash; 1379 1389 bool missingExpr = false; 1380 1390 1381 1391 Expect(_lbrace); 1382 1392 if (StartOf(14)) { 1383 - Expr(/*Parser.Expression.atg:353*/out iexpr); 1384 - /*Parser.Expression.atg:353*/hash.Elements.Add(iexpr); 1393 + Expr(/*Parser.Expression.atg:359*/out iexpr); 1394 + /*Parser.Expression.atg:359*/hash.Elements.Add(iexpr); 1385 1395 while (la.kind == _comma) { 1386 1396 Get(); 1387 - /*Parser.Expression.atg:354*/if(missingExpr) 1397 + /*Parser.Expression.atg:360*/if(missingExpr) 1388 1398 SemErr("Missing expression in list literal (two consecutive commas)."); 1389 1399 1390 1400 if (StartOf(14)) { 1391 - Expr(/*Parser.Expression.atg:357*/out iexpr); 1392 - /*Parser.Expression.atg:357*/hash.Elements.Add(iexpr); 1401 + Expr(/*Parser.Expression.atg:363*/out iexpr); 1402 + /*Parser.Expression.atg:363*/hash.Elements.Add(iexpr); 1393 1403 missingExpr = false; 1394 1404 1395 1405 } else if (la.kind == _comma || la.kind == _rbrace) { 1396 - /*Parser.Expression.atg:360*/missingExpr = true; 1406 + /*Parser.Expression.atg:366*/missingExpr = true; 1397 1407 } else SynErr(125); 1398 1408 } 1399 1409 } 1400 1410 Expect(_rbrace); 1401 1411 } 1402 1412 1403 - void LoopExpr(/*Parser.Expression.atg:368*/out AstExpr expr) { 1404 - /*Parser.Expression.atg:368*/var dummyBlock = Create.Block(GetPosition()); 1413 + void LoopExpr(/*Parser.Expression.atg:374*/out AstExpr expr) { 1414 + /*Parser.Expression.atg:374*/var dummyBlock = Create.Block(GetPosition()); 1405 1415 _PushScope(dummyBlock); 1406 1416 expr = _NullNode(GetPosition()); 1407 1417 1408 1418 if (la.kind == _do || la.kind == _while || la.kind == _until) { 1409 - WhileLoop(/*Parser.Expression.atg:373*/dummyBlock); 1419 + WhileLoop(/*Parser.Expression.atg:379*/dummyBlock); 1410 1420 } else if (la.kind == _for) { 1411 - ForLoop(/*Parser.Expression.atg:374*/dummyBlock); 1421 + ForLoop(/*Parser.Expression.atg:380*/dummyBlock); 1412 1422 } else if (la.kind == _foreach) { 1413 - ForeachLoop(/*Parser.Expression.atg:375*/dummyBlock); 1423 + ForeachLoop(/*Parser.Expression.atg:381*/dummyBlock); 1414 1424 } else SynErr(126); 1415 - /*Parser.Expression.atg:376*/_PopScope(dummyBlock); 1425 + /*Parser.Expression.atg:382*/_PopScope(dummyBlock); 1416 1426 SemErr("Loop expressions are no longer supported."); 1417 1427 1418 1428 } 1419 1429 1420 - void ThrowExpression(/*Parser.Expression.atg:492*/out AstThrow th) { 1421 - /*Parser.Expression.atg:492*/th = new AstThrow(this); 1430 + void ThrowExpression(/*Parser.Expression.atg:498*/out AstThrow th) { 1431 + /*Parser.Expression.atg:498*/th = new AstThrow(this); 1422 1432 Expect(_throw); 1423 - Expr(/*Parser.Expression.atg:495*/out th.Expression); 1433 + Expr(/*Parser.Expression.atg:501*/out th.Expression); 1424 1434 } 1425 1435 1426 - void LambdaExpression(/*Parser.Expression.atg:403*/out AstExpr expr) { 1427 - /*Parser.Expression.atg:403*/PFunction func = TargetApplication.CreateFunction(generateLocalId()); 1436 + void LambdaExpression(/*Parser.Expression.atg:409*/out AstExpr expr) { 1437 + /*Parser.Expression.atg:409*/PFunction func = TargetApplication.CreateFunction(generateLocalId()); 1428 1438 func.Meta[Application.ImportKey] = target.Function.Meta[Application.ImportKey]; 1429 1439 func.Meta[PFunction.ParentFunctionKey] = target.Function.Id; 1430 1440 Loader.CreateFunctionTarget(func, target, GetPosition()); 1431 1441 CompilerTarget ft = FunctionTargets[func]; 1432 1442 ISourcePosition position; 1433 1443 1434 - /*Parser.Expression.atg:411*/position = GetPosition(); 1444 + /*Parser.Expression.atg:417*/position = GetPosition(); 1435 1445 if (StartOf(19)) { 1436 - FormalArg(/*Parser.Expression.atg:412*/ft); 1446 + FormalArg(/*Parser.Expression.atg:418*/ft); 1437 1447 } else if (la.kind == _lpar) { 1438 1448 Get(); 1439 1449 if (StartOf(19)) { 1440 - FormalArg(/*Parser.Expression.atg:414*/ft); 1450 + FormalArg(/*Parser.Expression.atg:420*/ft); 1441 1451 while (la.kind == _comma) { 1442 1452 Get(); 1443 - FormalArg(/*Parser.Expression.atg:416*/ft); 1453 + FormalArg(/*Parser.Expression.atg:422*/ft); 1444 1454 } 1445 1455 } 1446 1456 Expect(_rpar); 1447 1457 } else SynErr(127); 1448 - /*Parser.Expression.atg:421*/_PushScope(ft); 1458 + /*Parser.Expression.atg:427*/_PushScope(ft); 1449 1459 Expect(_implementation); 1450 1460 if (la.kind == _lbrace) { 1451 1461 Get(); 1452 1462 while (StartOf(20)) { 1453 - Statement(/*Parser.Expression.atg:424*/ft.Ast); 1463 + Statement(/*Parser.Expression.atg:430*/ft.Ast); 1454 1464 } 1455 1465 Expect(_rbrace); 1456 1466 } else if (StartOf(14)) { 1457 - /*Parser.Expression.atg:426*/AstReturn ret = new AstReturn(this, ReturnVariant.Exit); 1458 - Expr(/*Parser.Expression.atg:427*/out ret.Expression); 1459 - /*Parser.Expression.atg:427*/ft.Ast.Add(ret); 1467 + /*Parser.Expression.atg:432*/AstReturn ret = new AstReturn(this, ReturnVariant.Exit); 1468 + Expr(/*Parser.Expression.atg:433*/out ret.Expression); 1469 + /*Parser.Expression.atg:433*/ft.Ast.Add(ret); 1460 1470 } else SynErr(128); 1461 - /*Parser.Expression.atg:430*/_PopScope(ft); 1471 + /*Parser.Expression.atg:436*/_PopScope(ft); 1462 1472 if(errors.count == 0) 1463 1473 { 1464 1474 try { ··· 1474 1484 1475 1485 } 1476 1486 1477 - void LazyExpression(/*Parser.Expression.atg:447*/out AstExpr expr) { 1478 - /*Parser.Expression.atg:447*/PFunction func = TargetApplication.CreateFunction(generateLocalId()); 1487 + void LazyExpression(/*Parser.Expression.atg:453*/out AstExpr expr) { 1488 + /*Parser.Expression.atg:453*/PFunction func = TargetApplication.CreateFunction(generateLocalId()); 1479 1489 func.Meta[Application.ImportKey] = target.Function.Meta[Application.ImportKey]; 1480 1490 func.Meta[PFunction.ParentFunctionKey] = target.Function.Id; 1481 1491 Loader.CreateFunctionTarget(func, target, GetPosition()); ··· 1486 1496 _PushScope(ft); 1487 1497 1488 1498 Expect(_lazy); 1489 - /*Parser.Expression.atg:458*/position = GetPosition(); 1499 + /*Parser.Expression.atg:464*/position = GetPosition(); 1490 1500 if (la.kind == _lbrace) { 1491 1501 Get(); 1492 1502 while (StartOf(20)) { 1493 - Statement(/*Parser.Expression.atg:460*/ft.Ast); 1503 + Statement(/*Parser.Expression.atg:466*/ft.Ast); 1494 1504 } 1495 1505 Expect(_rbrace); 1496 1506 } else if (StartOf(14)) { 1497 - /*Parser.Expression.atg:462*/AstReturn ret = new AstReturn(this, ReturnVariant.Exit); 1498 - Expr(/*Parser.Expression.atg:463*/out ret.Expression); 1499 - /*Parser.Expression.atg:463*/ft.Ast.Add(ret); 1507 + /*Parser.Expression.atg:468*/AstReturn ret = new AstReturn(this, ReturnVariant.Exit); 1508 + Expr(/*Parser.Expression.atg:469*/out ret.Expression); 1509 + /*Parser.Expression.atg:469*/ft.Ast.Add(ret); 1500 1510 } else SynErr(129); 1501 - /*Parser.Expression.atg:467*/var cap = ft._ToCaptureByValue(let_bindings(ft)); 1511 + /*Parser.Expression.atg:473*/var cap = ft._ToCaptureByValue(let_bindings(ft)); 1502 1512 1503 1513 //Restore parent target 1504 1514 _PopScope(ft); ··· 1523 1533 1524 1534 } 1525 1535 1526 - void ObjectCreation(/*Parser.Expression.atg:383*/out AstExpr expr) { 1527 - /*Parser.Expression.atg:383*/AstTypeExpr type; 1536 + void ObjectCreation(/*Parser.Expression.atg:389*/out AstExpr expr) { 1537 + /*Parser.Expression.atg:389*/AstTypeExpr type; 1528 1538 ArgumentsProxy args; 1529 1539 1530 1540 Expect(_new); 1531 - TypeExpr(/*Parser.Expression.atg:387*/out type); 1532 - /*Parser.Expression.atg:387*/_fallbackObjectCreation(type, out expr, out args); 1533 - Arguments(/*Parser.Expression.atg:388*/args); 1541 + TypeExpr(/*Parser.Expression.atg:393*/out type); 1542 + /*Parser.Expression.atg:393*/_fallbackObjectCreation(type, out expr, out args); 1543 + Arguments(/*Parser.Expression.atg:394*/args); 1534 1544 } 1535 1545 1536 1546 void GetInitiator(/*Parser.Statement.atg:172*/out AstExpr complex) { ··· 1808 1818 } 1809 1819 } 1810 1820 1811 - void ExplicitTypeExpr(/*Parser.Expression.atg:505*/out AstTypeExpr type) { 1812 - /*Parser.Expression.atg:505*/type = null; 1821 + void ExplicitTypeExpr(/*Parser.Expression.atg:511*/out AstTypeExpr type) { 1822 + /*Parser.Expression.atg:511*/type = null; 1813 1823 if (la.kind == _tilde) { 1814 1824 Get(); 1815 - PrexoniteTypeExpr(/*Parser.Expression.atg:507*/out type); 1825 + PrexoniteTypeExpr(/*Parser.Expression.atg:513*/out type); 1816 1826 } else if (la.kind == _ns || la.kind == _doublecolon) { 1817 - ClrTypeExpr(/*Parser.Expression.atg:508*/out type); 1827 + ClrTypeExpr(/*Parser.Expression.atg:514*/out type); 1818 1828 } else SynErr(140); 1819 1829 } 1820 1830 1821 - void PrexoniteTypeExpr(/*Parser.Expression.atg:533*/out AstTypeExpr type) { 1822 - /*Parser.Expression.atg:533*/string id = null; 1831 + void PrexoniteTypeExpr(/*Parser.Expression.atg:539*/out AstTypeExpr type) { 1832 + /*Parser.Expression.atg:539*/string id = null; 1823 1833 if (StartOf(4)) { 1824 - Id(/*Parser.Expression.atg:535*/out id); 1834 + Id(/*Parser.Expression.atg:541*/out id); 1825 1835 } else if (la.kind == _null) { 1826 1836 Get(); 1827 - /*Parser.Expression.atg:535*/id = NullPType.Literal; 1837 + /*Parser.Expression.atg:541*/id = NullPType.Literal; 1828 1838 } else SynErr(141); 1829 - /*Parser.Expression.atg:537*/AstDynamicTypeExpression dType = new AstDynamicTypeExpression(this, id); 1839 + /*Parser.Expression.atg:543*/AstDynamicTypeExpression dType = new AstDynamicTypeExpression(this, id); 1830 1840 if (la.kind == _lt) { 1831 1841 Get(); 1832 1842 if (StartOf(26)) { 1833 - TypeExprElement(/*Parser.Expression.atg:539*/dType.Arguments); 1843 + TypeExprElement(/*Parser.Expression.atg:545*/dType.Arguments); 1834 1844 while (la.kind == _comma) { 1835 1845 Get(); 1836 - TypeExprElement(/*Parser.Expression.atg:540*/dType.Arguments); 1846 + TypeExprElement(/*Parser.Expression.atg:546*/dType.Arguments); 1837 1847 } 1838 1848 } 1839 1849 Expect(_gt); 1840 1850 } 1841 - /*Parser.Expression.atg:544*/type = dType; 1851 + /*Parser.Expression.atg:550*/type = dType; 1842 1852 } 1843 1853 1844 - void ClrTypeExpr(/*Parser.Expression.atg:518*/out AstTypeExpr type) { 1845 - /*Parser.Expression.atg:518*/string id; 1846 - /*Parser.Expression.atg:520*/StringBuilder typeId = new StringBuilder(); 1854 + void ClrTypeExpr(/*Parser.Expression.atg:524*/out AstTypeExpr type) { 1855 + /*Parser.Expression.atg:524*/string id; 1856 + /*Parser.Expression.atg:526*/StringBuilder typeId = new StringBuilder(); 1847 1857 if (la.kind == _doublecolon) { 1848 1858 Get(); 1849 1859 } else if (la.kind == _ns) { 1850 1860 Get(); 1851 - /*Parser.Expression.atg:522*/typeId.Append(t.val); typeId.Append('.'); 1861 + /*Parser.Expression.atg:528*/typeId.Append(t.val); typeId.Append('.'); 1852 1862 } else SynErr(142); 1853 1863 while (la.kind == _ns) { 1854 1864 Get(); 1855 - /*Parser.Expression.atg:524*/typeId.Append(t.val); typeId.Append('.'); 1865 + /*Parser.Expression.atg:530*/typeId.Append(t.val); typeId.Append('.'); 1856 1866 } 1857 - Id(/*Parser.Expression.atg:526*/out id); 1858 - /*Parser.Expression.atg:526*/typeId.Append(id); 1867 + Id(/*Parser.Expression.atg:532*/out id); 1868 + /*Parser.Expression.atg:532*/typeId.Append(id); 1859 1869 type = new AstConstantTypeExpression(this, 1860 1870 "Object(\"" + StringPType.Escape(typeId.ToString()) + "\")"); 1861 1871 1862 1872 } 1863 1873 1864 - void TypeExprElement(/*Parser.Expression.atg:548*/List<AstExpr> args ) { 1865 - /*Parser.Expression.atg:548*/AstExpr expr; AstTypeExpr type; 1874 + void TypeExprElement(/*Parser.Expression.atg:554*/List<AstExpr> args ) { 1875 + /*Parser.Expression.atg:554*/AstExpr expr; AstTypeExpr type; 1866 1876 if (StartOf(16)) { 1867 - Constant(/*Parser.Expression.atg:550*/out expr); 1868 - /*Parser.Expression.atg:550*/args.Add(expr); 1877 + Constant(/*Parser.Expression.atg:556*/out expr); 1878 + /*Parser.Expression.atg:556*/args.Add(expr); 1869 1879 } else if (la.kind == _ns || la.kind == _tilde || la.kind == _doublecolon) { 1870 - ExplicitTypeExpr(/*Parser.Expression.atg:551*/out type); 1871 - /*Parser.Expression.atg:551*/args.Add(type); 1880 + ExplicitTypeExpr(/*Parser.Expression.atg:557*/out type); 1881 + /*Parser.Expression.atg:557*/args.Add(type); 1872 1882 } else if (la.kind == _lpar) { 1873 1883 Get(); 1874 - Expr(/*Parser.Expression.atg:552*/out expr); 1884 + Expr(/*Parser.Expression.atg:558*/out expr); 1875 1885 Expect(_rpar); 1876 - /*Parser.Expression.atg:552*/args.Add(expr); 1886 + /*Parser.Expression.atg:558*/args.Add(expr); 1877 1887 } else SynErr(143); 1878 1888 } 1879 1889 ··· 4143 4153 {x,T,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,T,x, x,x,x,T, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x}, 4144 4154 {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,T,T, T,x,x,x, T,x,x,x, T,T,T,x, T,T,x,T, T,T,x,T, x,T,T,T, T,T,x,x, x,x,T,T, T,T,T,x, x,T,x,x, x,x,x,x, x,x,x,x, x,x,x}, 4145 4155 {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,T,x, x,x,x,T, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x}, 4146 - {x,T,T,x, T,x,T,T, T,T,x,x, x,T,x,x, x,x,x,T, T,T,T,x, x,T,x,x, T,x,x,x, x,T,x,x, x,x,T,x, T,T,x,x, x,x,T,T, T,T,T,T, x,x,x,x, T,T,T,x, x,T,x,T, x,x,x,T, x,x,x,x, x,x,x,x, T,T,x,x, x,T,T,x, T,x,T,T, T,T,x,x, x,T,x,x, x,T,x,x, T,x,x,x, T,x,x}, 4156 + {x,T,T,x, T,x,T,T, T,T,x,x, x,T,x,x, x,x,x,T, T,T,T,x, x,T,x,x, T,x,x,x, x,T,T,x, x,x,T,x, T,T,x,x, x,x,T,T, T,T,T,T, x,x,x,x, T,T,T,x, x,T,x,T, x,x,x,T, x,x,x,x, x,x,x,x, T,T,x,x, x,T,T,x, T,x,T,T, T,T,x,x, x,T,x,x, x,T,x,x, T,x,x,x, T,x,x}, 4147 4157 {x,x,x,x, x,x,x,x, x,x,T,T, T,T,T,T, T,T,T,T, x,T,x,T, T,T,T,T, T,T,T,T, T,T,T,x, T,T,x,T, x,x,x,x, x,T,T,T, x,x,x,x, x,T,T,x, x,x,x,x, x,x,x,x, x,T,x,x, x,x,x,T, T,T,x,x, x,x,x,x, T,x,x,x, x,x,x,x, T,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x}, 4148 4158 {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,T,x, x,x,x,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x}, 4149 4159 {x,x,x,x, x,x,x,x, x,x,T,T, x,x,T,x, x,x,x,x, x,x,x,x, x,T,x,T, T,x,x,x, x,x,T,x, x,x,x,T, x,x,x,x, x,x,T,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x}, 4150 4160 {x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,T, x,x,x,T, x,T,x,x, x,x,x,x, x,x,x,x, x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x}, 4151 4161 {x,T,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,T,x, x,x,x,T, x,x,x,T, x,x,x,x, x,x,x,x, x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x}, 4152 - {x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,x, x,x,x,T, x,x,x,x, x,T,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x}, 4153 - {x,T,T,x, T,x,T,T, T,T,x,x, x,T,x,x, x,x,x,T, T,T,T,x, x,T,x,x, T,x,x,x, x,T,x,x, x,x,T,x, T,T,x,x, x,x,T,T, T,T,T,T, x,x,x,x, T,T,T,x, x,T,x,T, x,x,x,T, x,x,x,x, x,x,x,x, T,T,T,T, x,T,T,x, T,x,T,T, T,T,x,x, x,T,x,x, x,T,x,x, T,x,x,x, T,x,x}, 4162 + {x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,x, x,x,x,T, x,x,x,x, x,T,x,x, T,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,T,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x}, 4163 + {x,T,T,x, T,x,T,T, T,T,x,x, x,T,x,x, x,x,x,T, T,T,T,x, x,T,x,x, T,x,x,x, x,T,T,x, x,x,T,x, T,T,x,x, x,x,T,T, T,T,T,T, x,x,x,x, T,T,T,x, x,T,x,T, x,x,x,T, x,x,x,x, x,x,x,x, T,T,T,T, x,T,T,x, T,x,T,T, T,T,x,x, x,T,x,x, x,T,x,x, T,x,x,x, T,x,x}, 4154 4164 {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x}, 4155 4165 {x,x,x,x, x,x,T,T, T,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x}, 4156 4166 {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,T,T, T,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x}, ··· 4186 4196 {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,x, T,T,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x}, 4187 4197 {x,x,x,x, x,x,x,x, x,x,T,T, x,T,T,x, x,x,x,T, x,x,x,x, x,T,x,T, T,x,x,x, x,T,T,x, x,x,x,T, x,x,x,x, x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x}, 4188 4198 {x,x,x,x, x,x,x,x, x,x,T,T, x,x,T,x, x,x,x,x, x,x,x,x, x,T,x,T, T,x,x,x, x,T,T,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x}, 4189 - {x,T,T,x, T,x,T,T, T,T,x,T, x,T,x,x, x,x,x,T, T,T,T,x, x,T,x,x, T,x,x,x, x,T,x,x, x,x,T,x, T,T,x,x, x,x,T,T, T,T,T,T, x,x,x,x, T,T,T,x, x,T,x,T, x,x,x,T, x,x,x,x, x,x,x,x, T,T,T,T, x,T,T,x, T,x,T,T, T,T,x,x, x,T,x,x, x,T,x,x, T,x,x,x, T,x,x}, 4199 + {x,T,T,x, T,x,T,T, T,T,x,T, x,T,x,x, x,x,x,T, T,T,T,x, x,T,x,x, T,x,x,x, x,T,T,x, x,x,T,x, T,T,x,x, x,x,T,T, T,T,T,T, x,x,x,x, T,T,T,x, x,T,x,T, x,x,x,T, x,x,x,x, x,x,x,x, T,T,T,T, x,T,T,x, T,x,T,T, T,T,x,x, x,T,x,x, x,T,x,x, T,x,x,x, T,x,x}, 4190 4200 {x,x,x,x, x,x,x,x, x,x,T,T, x,x,T,x, x,x,x,x, x,x,x,x, x,T,x,T, T,x,x,x, x,x,T,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x} 4191 4201 4192 4202 #line 144 "C:\Users\chris\Documents\GitHub\prx\Tools\Parser.frame" //FRAME
+353 -351
Prexonite/Compiler/Prexonite.lex
··· 1 - /* 2 - * Prexonite, a scripting engine (Scripting Language -> Bytecode -> Virtual Machine) 3 - * Copyright (C) 2007 Christian "SealedSun" Klauser 4 - * E-mail sealedsun a.t gmail d.ot com 5 - * Web http://www.sealedsun.ch/ 6 - * 7 - * This program is free software; you can redistribute it and/or modify 8 - * it under the terms of the GNU General Public License as published by 9 - * the Free Software Foundation; either version 2 of the License, or 10 - * (at your option) any later version. 11 - * 12 - * Please contact me (sealedsun a.t gmail do.t com) if you need a different license. 13 - * 14 - * This program is distributed in the hope that it will be useful, 15 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 - * GNU General Public License for more details. 18 - * 19 - * You should have received a copy of the GNU General Public License along 20 - * with this program; if not, write to the Free Software Foundation, Inc., 21 - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 22 - */ 23 - 24 - //Prexonite Scanner file. 25 - 26 - using System; 27 - using System.Text; 28 - using System.IO; 29 - using Prexonite; 30 - using Prexonite.Types; 31 - using Prexonite.Commands; 32 - using Prexonite.Compiler; 33 - using Prexonite.Compiler.Ast; 34 - 35 - partial 36 - %% 37 - 38 - %class Lexer 39 - %function Scan 40 - %type Token 41 - %line 42 - %column 43 - %char 44 - %unicode 45 - %ignorecase 46 - %implements Prexonite.Internal.IScanner 47 - 48 - %eofval{ 49 - return tok(Parser._EOF); 50 - %eofval} 51 - 52 - Digit = [0-9] 53 - HexDigit = [0-9ABCDEFabcdef] 54 - Integer = {Digit} ("'" | {Digit})* 55 - Exponent = e("+"|"-")?{Integer} 56 - //Identifier = {Letter} ( {Letter} | {Digit} )* 57 - Identifier = ([:jletter:] | [\\]) ([:jletterdigit:] | [\\] | "'")* 58 - //For reference, a line break would be defined like this, but apart 59 - // from line comments, Prexonite Script does not care about line breaks 60 - //LineBreak = \r\n|\r|\n|\u2028|\u2029|\u000B|\u000C|\u0085 61 - NotLineBreak = [^\r\n\u2028\u2029\u000B\u000C\u0085] 62 - WhiteSpace = [ \t\r\n\u2028\u2029\u000B\u000C\u0085] 63 - RegularStringChar = [^$\"\\\r\n\u2028\u2029\u000B\u000C\u0085] 64 - RegularVerbatimStringChar = [^$\"] 65 - Noise = "/*" ~"*/" | "//" {NotLineBreak}* | {WhiteSpace}+ 66 - 67 - // String: a constant string with C-style escape sequences 68 - // SmartString: a string with C-style escape sequences and $-interpolation (needs support from Parser) 69 - // VerbatimString: a constant string where only "" escapes to ". 70 - // SmartVerbatimString: a string with $-interpolation where only "" escapes to " (needs support from Parser) 71 - // Local: code body (function body, RHS of global variable, etc.) 72 - // LocalShell: like code body, but accepts flag literals (-q, --long, --option=EXPR) 73 - // Asm: assembler code (resembles global scope) 74 - // Transfer: Body of a symbol transfer expression (namespace declaration), mostly like global scope 75 - // YYINITIAL: the global scope 76 - %state String, SmartString, VerbatimString, SmartVerbatimString, VerbatimBlock, Local, LocalShell, Asm, Transfer 77 - 78 - %% 79 - 80 - //Only global code 81 - <YYINITIAL> { 82 - "to" { return tok(Parser._to); } 83 - } 84 - 85 - <YYINITIAL,Local,LocalShell> { 86 - "does" { return tok(Parser._does); } 87 - } 88 - 89 - //Not local code 90 - <YYINITIAL,Asm, Transfer> { 91 - "\"" { buffer.Length = 0; PushState(String); } 92 - "@\"" { buffer.Length = 0; PushState(VerbatimString); } 93 - } 94 - 95 - //Only local code 96 - <Local,LocalShell> { 97 - "\"" { buffer.Length = 0; PushState(SmartString); } 98 - "@\"" { buffer.Length = 0; PushState(SmartVerbatimString); } 99 - 100 - } 101 - 102 - // Everywhere in code except in symbol transfer specifications 103 - // this is a hack to get around an ambiguity of (*) 104 - <YYINITIAL,Local,LocalShell,Asm> { 105 - "(*)" { return tok(Parser._id,OperatorNames.Prexonite.Multiplication); } 106 - } 107 - 108 - <Transfer> { 109 - "(*)" { return tok(Parser._timessym); } 110 - } 111 - 112 - // When flag literals are enabled, GNU-style flags (-f, -vf, --long, --opt=EXPR) are recognized. 113 - // This mode is of course not compatible with Prexonite code unaware of shell extensions 114 - <LocalShell> { 115 - "-" "-"? [:jletterdigit:] ([:jletterdigit:]|"-")* "="? { 116 - String flag = yytext(); 117 - if(flag.EndsWith("=")) { 118 - return multiple( 119 - tok(Parser._string, flag), 120 - tok(Parser._plus, "+") 121 - ); 122 - } 123 - else { 124 - return tok(Parser._string, flag); 125 - } 126 - } 127 - } 128 - 129 - //Everywhere in code 130 - <YYINITIAL,Local,LocalShell,Asm,Transfer> { 131 - 132 - {Noise} { /* Comment/Whitespace: ignore */ } 133 - 134 - {Integer} "." {Integer} {Exponent} { return tok(Parser._real, yytext()); } //definite real 135 - {Integer} "." {Integer} { return tok(Parser._realLike, yytext()); } //could also be version literal 136 - {Integer} "." {Integer} "." {Integer} ("." {Integer})? { return tok(Parser._version, yytext()); } 137 - 138 - {Integer} | 139 - 0x{HexDigit}+ { return tok(Parser._integer, yytext()); } 140 - 141 - "true" { return tok(Parser._true); } 142 - "false" { return tok(Parser._false); } 143 - "var" { return tok(Parser._var); } 144 - "ref" { return tok(Parser._ref); } 145 - 146 - "$" {Identifier} "::" { string ns = yytext(); 147 - return tok(Parser._ns, ns.Substring(1,ns.Length-3)); } 148 - 149 - {Identifier} "::" { string ns = yytext(); 150 - return tok(Parser._ns, ns.Substring(0, ns.Length-2)); } 151 - 152 - //any identifier 153 - 154 - "$" {Identifier} { return tok(Parser._id, yytext().Substring(1)); } 155 - "$\"" { buffer.Length = 0; PushState(String); return tok(Parser._anyId); } 156 - 157 - {Identifier} { return tok(checkKeyword(yytext()), yytext()); } 158 - 159 - 160 - "{" { return tok(Parser._lbrace); } 161 - "[" { return tok(Parser._lbrack); } 162 - "(+)" { return tok(Parser._id,OperatorNames.Prexonite.Addition); } 163 - "(-)" { return tok(Parser._id,OperatorNames.Prexonite.Subtraction); } 164 - "(/)" { return tok(Parser._id,OperatorNames.Prexonite.Division); } 165 - "(" [mM][oO][dD] ")" { return tok(Parser._id,OperatorNames.Prexonite.Modulus); } 166 - "(^)" { return tok(Parser._id,OperatorNames.Prexonite.Power); } 167 - "(&)" { return tok(Parser._id,OperatorNames.Prexonite.BitwiseAnd); } 168 - "(|)" { return tok(Parser._id,OperatorNames.Prexonite.BitwiseOr); } 169 - "(" [xX][oO][rR] ")" { return tok(Parser._id,OperatorNames.Prexonite.ExclusiveOr); } 170 - "(==)" { return tok(Parser._id,OperatorNames.Prexonite.Equality); } 171 - "(!=)" { return tok(Parser._id,OperatorNames.Prexonite.Inequality); } 172 - "(>)" { return tok(Parser._id,OperatorNames.Prexonite.GreaterThan); } 173 - "(>=)" { return tok(Parser._id,OperatorNames.Prexonite.GreaterThanOrEqual); } 174 - "(<)" { return tok(Parser._id,OperatorNames.Prexonite.LessThan); } 175 - "(<=)" { return tok(Parser._id,OperatorNames.Prexonite.LessThanOrEqual); } 176 - "(-.)" { return tok(Parser._id,OperatorNames.Prexonite.UnaryNegation); } 177 - "(++)" { return tok(Parser._id,OperatorNames.Prexonite.Increment); } 178 - "(--)" { return tok(Parser._id,OperatorNames.Prexonite.Decrement); } 179 - "(<|.)" { return tok(Parser._id,OperatorNames.Prexonite.UnaryDeltaLeftPre); } 180 - "(.<|)" { return tok(Parser._id,OperatorNames.Prexonite.UnaryDeltaLeftPost); } 181 - "(|>.)" { return tok(Parser._id,OperatorNames.Prexonite.UnaryDeltaRightPre); } 182 - "(.|>)" { return tok(Parser._id,OperatorNames.Prexonite.UnaryDeltaRightPost); } 183 - "(<|)" { return tok(Parser._id,OperatorNames.Prexonite.BinaryDeltaLeft); } 184 - "(|>)" { return tok(Parser._id,OperatorNames.Prexonite.BinaryDeltaRight); } 185 - "(" { return tok(Parser._lpar); } 186 - ")" { return tok(Parser._rpar); } 187 - "]" { return tok(Parser._rbrack); } 188 - "}" { return tok(Parser._rbrace); } 189 - "+" { return tok(Parser._plus); } 190 - "-" { return tok(Parser._minus); } 191 - "*" { return tok(Parser._times); } 192 - "/" { return tok(Parser._div); } 193 - "^" { return tok(Parser._pow); } 194 - "=" { return tok(Parser._assign); } 195 - "<|" { return tok(Parser._deltaleft); } 196 - "|>" { return tok(Parser._deltaright); } 197 - "&&" { return tok(Parser._and); } 198 - "||" { return tok(Parser._or); } 199 - "|" { return tok(Parser._bitOr); } 200 - "&" { return tok(Parser._bitAnd); } 201 - "==" { return tok(Parser._eq); } 202 - "!=" { return tok(Parser._ne); } 203 - ">" { return tok(Parser._gt); } 204 - ">=" { return tok(Parser._ge); } 205 - "<=" { return tok(Parser._le); } 206 - "<" { return tok(Parser._lt); } 207 - "++" { return tok(Parser._inc); } 208 - "--" { return tok(Parser._dec); } 209 - "~" { return tok(Parser._tilde); } 210 - "::" { return tok(Parser._doublecolon); } 211 - "??" { return tok(Parser._coalescence); } 212 - "?" { return tok(Parser._question); } 213 - "->" { return tok(Parser._pointer); } 214 - "=>" { return tok(Parser._implementation); } 215 - ":" { return tok(Parser._colon); } 216 - ";" { return tok(Parser._semicolon); } 217 - "," { return tok(Parser._comma); } 218 - "." ({Identifier})? { Token dot = tok(Parser._dot); 219 - string memberId = yytext(); 220 - if(memberId.Length > 1) 221 - return multiple(dot,tok(Parser._id,memberId.Substring(memberId.StartsWith(".$") ? 2 : 1))); 222 - else 223 - return dot; } 224 - "@" { return tok(Parser._at); } 225 - ">>" { return tok(Parser._appendright); } 226 - "<<" { return tok(Parser._appendleft); } 227 - 228 - .|\n { Console.WriteLine("Rogue Character: \"{0}\"", yytext()); } 229 - } 230 - 231 - <String> { 232 - "\"" { PopState(); 233 - ret(tok(Parser._string, buffer.ToString())); 234 - buffer.Length = 0; 235 - } 236 - {RegularStringChar}+ { buffer.Append(yytext()); } 237 - "\\\\" { buffer.Append("\\"); } 238 - "\\\"" { buffer.Append("\""); } 239 - "\\"& { /* nothing to do */ } 240 - "\\"0 { buffer.Append("\0"); } 241 - "\\"a { buffer.Append("\a"); } 242 - "\\"b { buffer.Append("\b"); } 243 - "\\"f { buffer.Append("\f"); } 244 - "\\"n { buffer.Append("\n"); } 245 - "\\"r { buffer.Append("\r"); } 246 - "\\"v { buffer.Append("\v"); } 247 - "\\"t { buffer.Append("\t"); } 248 - "\\"x {HexDigit} {HexDigit}? {HexDigit}? {HexDigit}? | 249 - "\\"u {HexDigit} {HexDigit} {HexDigit} {HexDigit} | 250 - "\\"U {HexDigit} {HexDigit} {HexDigit} {HexDigit} {HexDigit} {HexDigit} {HexDigit} {HexDigit} { buffer.Append(_unescapeChar(yytext())); } 251 - //No need to escape $, but possible. 252 - "$" | "\\$" { buffer.Append("$"); } 253 - } 254 - 255 - <SmartString> { 256 - "\"" { PopState(); 257 - ret(tok(Parser._string, buffer.ToString())); 258 - buffer.Length = 0; 259 - } 260 - {RegularStringChar}+ { buffer.Append(yytext()); } 261 - "\\\\" { buffer.Append("\\"); } 262 - "\\\"" { buffer.Append("\""); } 263 - "\\"& { /* nothing to do */ } 264 - "\\"0 { buffer.Append("\0"); } 265 - "\\"a { buffer.Append("\a"); } 266 - "\\"b { buffer.Append("\b"); } 267 - "\\"f { buffer.Append("\f"); } 268 - "\\"n { buffer.Append("\n"); } 269 - "\\"r { buffer.Append("\r"); } 270 - "\\"v { buffer.Append("\v"); } 271 - "\\"t { buffer.Append("\t"); } 272 - "\\"x {HexDigit} {HexDigit}? {HexDigit}? {HexDigit}? | 273 - "\\"u {HexDigit} {HexDigit} {HexDigit} {HexDigit} | 274 - "\\"U {HexDigit} {HexDigit} {HexDigit} {HexDigit} {HexDigit} {HexDigit} {HexDigit} {HexDigit} { buffer.Append(_unescapeChar(yytext())); } 275 - "\\$" { buffer.Append("$"); } 276 - "$" {Identifier} &? 277 - { string clipped; 278 - string id = _pruneSmartStringIdentifier(yytext(), out clipped); 279 - string fragment = buffer.ToString(); 280 - buffer.Length = 0; 281 - return multiple( 282 - tok(Parser._string, fragment), 283 - tok(Parser._plus), 284 - tok(Parser._id, id), 285 - clipped != null ? tok(Parser._plus) : null, 286 - clipped != null ? tok(Parser._string, clipped) : null, 287 - tok(Parser._plus) 288 - ); 289 - } 290 - "$(" { string fragment = buffer.ToString(); 291 - buffer.Length = 0; 292 - PushState(_surroundingLocalState); 293 - return multiple( 294 - tok(Parser._string, fragment), 295 - tok(Parser._plus), 296 - tok(Parser._LPopExpr), 297 - tok(Parser._lpar) 298 - //2nd plus is injected by the parser 299 - ); 300 - } 301 - .|\n { throw new PrexoniteException("Invalid smart string character '" + yytext() + "' (ASCII " + ((int)yytext()[0]) + ") in input on line " + yyline + "."); } 302 - } 303 - 304 - <VerbatimString> { 305 - "\"" { PopState(); 306 - ret(tok(Parser._string, buffer.ToString())); 307 - buffer.Length = 0; 308 - } 309 - {RegularVerbatimStringChar} { buffer.Append(yytext()); } 310 - "\"\"" { buffer.Append("\""); } 311 - "$" { buffer.Append("$"); } 312 - 313 - } 314 - 315 - <SmartVerbatimString> { 316 - "\"" { PopState(); 317 - ret(tok(Parser._string, buffer.ToString())); 318 - buffer.Length = 0; 319 - } 320 - {RegularVerbatimStringChar} { buffer.Append(yytext()); } 321 - "\"\"" { buffer.Append("\""); } 322 - "$" {Identifier} &? 323 - { string clipped; 324 - string id = _pruneSmartStringIdentifier(yytext(), out clipped); 325 - string fragment = buffer.ToString(); 326 - buffer.Length = 0; 327 - return multiple( 328 - tok(Parser._string, fragment), 329 - tok(Parser._plus), 330 - tok(Parser._id, id), 331 - clipped != null ? tok(Parser._plus) : null, 332 - clipped != null ? tok(Parser._string, clipped) : null, 333 - tok(Parser._plus) 334 - ); 335 - } 336 - "$(" { string fragment = buffer.ToString(); 337 - buffer.Length = 0; 338 - PushState(_surroundingLocalState); 339 - return multiple( 340 - tok(Parser._string, fragment), 341 - tok(Parser._plus), 342 - tok(Parser._LPopExpr), 343 - tok(Parser._lpar) 344 - //2nd plus is injected by the parser 345 - ); 346 - } 347 - 348 - } 349 - 350 - //Error symbol 351 - .|\n { throw new PrexoniteException(System.String.Format("Invalid character \"{0}\" detected on line {1} in {2}.", yytext(), yyline, File)); } 1 + /* 2 + * Prexonite, a scripting engine (Scripting Language -> Bytecode -> Virtual Machine) 3 + * Copyright (C) 2007 Christian "SealedSun" Klauser 4 + * E-mail sealedsun a.t gmail d.ot com 5 + * Web http://www.sealedsun.ch/ 6 + * 7 + * This program is free software; you can redistribute it and/or modify 8 + * it under the terms of the GNU General Public License as published by 9 + * the Free Software Foundation; either version 2 of the License, or 10 + * (at your option) any later version. 11 + * 12 + * Please contact me (sealedsun a.t gmail do.t com) if you need a different license. 13 + * 14 + * This program is distributed in the hope that it will be useful, 15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 + * GNU General Public License for more details. 18 + * 19 + * You should have received a copy of the GNU General Public License along 20 + * with this program; if not, write to the Free Software Foundation, Inc., 21 + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 22 + */ 23 + 24 + //Prexonite Scanner file. 25 + 26 + using System; 27 + using System.Text; 28 + using System.IO; 29 + using Prexonite; 30 + using Prexonite.Types; 31 + using Prexonite.Commands; 32 + using Prexonite.Compiler; 33 + using Prexonite.Compiler.Ast; 34 + 35 + partial 36 + %% 37 + 38 + %class Lexer 39 + %function Scan 40 + %type Token 41 + %line 42 + %column 43 + %char 44 + %unicode 45 + %ignorecase 46 + %implements Prexonite.Internal.IScanner 47 + 48 + %eofval{ 49 + return tok(Parser._EOF); 50 + %eofval} 51 + 52 + Digit = [0-9] 53 + HexDigit = [0-9ABCDEFabcdef] 54 + Integer = {Digit} ("'" | {Digit})* 55 + Exponent = e("+"|"-")?{Integer} 56 + //Identifier = {Letter} ( {Letter} | {Digit} )* 57 + Identifier = ([:jletter:] | [\\]) ([:jletterdigit:] | [\\] | "'")* 58 + //For reference, a line break would be defined like this, but apart 59 + // from line comments, Prexonite Script does not care about line breaks 60 + //LineBreak = \r\n|\r|\n|\u2028|\u2029|\u000B|\u000C|\u0085 61 + NotLineBreak = [^\r\n\u2028\u2029\u000B\u000C\u0085] 62 + WhiteSpace = [ \t\r\n\u2028\u2029\u000B\u000C\u0085] 63 + RegularStringChar = [^$\"\\\r\n\u2028\u2029\u000B\u000C\u0085] 64 + RegularVerbatimStringChar = [^$\"] 65 + Noise = "/*" ~"*/" | "//" {NotLineBreak}* | {WhiteSpace}+ 66 + 67 + // String: a constant string with C-style escape sequences 68 + // SmartString: a string with C-style escape sequences and $-interpolation (needs support from Parser) 69 + // VerbatimString: a constant string where only "" escapes to ". 70 + // SmartVerbatimString: a string with $-interpolation where only "" escapes to " (needs support from Parser) 71 + // Local: code body (function body, RHS of global variable, etc.) 72 + // LocalShell: like code body, but accepts flag literals (-q, --long, --option=EXPR) 73 + // Asm: assembler code (resembles global scope) 74 + // Transfer: Body of a symbol transfer expression (namespace declaration), mostly like global scope 75 + // YYINITIAL: the global scope 76 + %state String, SmartString, VerbatimString, SmartVerbatimString, VerbatimBlock, Local, LocalShell, Asm, Transfer 77 + 78 + %% 79 + 80 + //Only global code 81 + <YYINITIAL> { 82 + "to" { return tok(Parser._to); } 83 + } 84 + 85 + <YYINITIAL,Local,LocalShell> { 86 + "does" { return tok(Parser._does); } 87 + } 88 + 89 + //Not local code 90 + <YYINITIAL,Asm, Transfer> { 91 + "\"" { buffer.Length = 0; PushState(String); } 92 + "@\"" { buffer.Length = 0; PushState(VerbatimString); } 93 + } 94 + 95 + //Only local code 96 + <Local,LocalShell> { 97 + "\"" { buffer.Length = 0; PushState(SmartString); } 98 + "@\"" { buffer.Length = 0; PushState(SmartVerbatimString); } 99 + 100 + } 101 + 102 + // Everywhere in code except in symbol transfer specifications 103 + // this is a hack to get around an ambiguity of (*) 104 + <YYINITIAL,Local,LocalShell,Asm> { 105 + "(*)" { return tok(Parser._id,OperatorNames.Prexonite.Multiplication); } 106 + } 107 + 108 + <Transfer> { 109 + "(*)" { return tok(Parser._timessym); } 110 + } 111 + 112 + // When flag literals are enabled, GNU-style flags (-f, -vf, --long, --opt=EXPR) are recognized. 113 + // This mode is of course not compatible with Prexonite code unaware of shell extensions 114 + <LocalShell> { 115 + "-" "-"? [:jletterdigit:] ([:jletterdigit:]|"-")* "="? { 116 + String flag = yytext(); 117 + if(flag.EndsWith("=")) { 118 + return multiple( 119 + tok(Parser._string, flag), 120 + tok(Parser._plus, "+") 121 + ); 122 + } 123 + else { 124 + return tok(Parser._string, flag); 125 + } 126 + } 127 + } 128 + 129 + //Everywhere in code 130 + <YYINITIAL,Local,LocalShell,Asm,Transfer> { 131 + 132 + {Noise} { /* Comment/Whitespace: ignore */ } 133 + 134 + {Integer} "." {Integer} {Exponent} { return tok(Parser._real, yytext()); } //definite real 135 + {Integer} "." {Integer} { return tok(Parser._realLike, yytext()); } //could also be version literal 136 + {Integer} "." {Integer} "." {Integer} ("." {Integer})? { return tok(Parser._version, yytext()); } 137 + 138 + {Integer} | 139 + 0x{HexDigit}+ { return tok(Parser._integer, yytext()); } 140 + 141 + "true" { return tok(Parser._true); } 142 + "false" { return tok(Parser._false); } 143 + "var" { return tok(Parser._var); } 144 + "ref" { return tok(Parser._ref); } 145 + 146 + "$" {Identifier} "::" { string ns = yytext(); 147 + return tok(Parser._ns, ns.Substring(1,ns.Length-3)); } 148 + 149 + {Identifier} "::" { string ns = yytext(); 150 + return tok(Parser._ns, ns.Substring(0, ns.Length-2)); } 151 + 152 + //any identifier 153 + 154 + "$" {Identifier} { return tok(Parser._id, yytext().Substring(1)); } 155 + "$\"" { buffer.Length = 0; PushState(String); return tok(Parser._anyId); } 156 + // Support $@ to mean "var args". Emulated $@ from bash. 157 + "$@" { return multiple(tok(Parser._var), tok(Parser._id, PFunction.ArgumentListId)); } 158 + 159 + {Identifier} { return tok(checkKeyword(yytext()), yytext()); } 160 + 161 + 162 + "{" { return tok(Parser._lbrace); } 163 + "[" { return tok(Parser._lbrack); } 164 + "(+)" { return tok(Parser._id,OperatorNames.Prexonite.Addition); } 165 + "(-)" { return tok(Parser._id,OperatorNames.Prexonite.Subtraction); } 166 + "(/)" { return tok(Parser._id,OperatorNames.Prexonite.Division); } 167 + "(" [mM][oO][dD] ")" { return tok(Parser._id,OperatorNames.Prexonite.Modulus); } 168 + "(^)" { return tok(Parser._id,OperatorNames.Prexonite.Power); } 169 + "(&)" { return tok(Parser._id,OperatorNames.Prexonite.BitwiseAnd); } 170 + "(|)" { return tok(Parser._id,OperatorNames.Prexonite.BitwiseOr); } 171 + "(" [xX][oO][rR] ")" { return tok(Parser._id,OperatorNames.Prexonite.ExclusiveOr); } 172 + "(==)" { return tok(Parser._id,OperatorNames.Prexonite.Equality); } 173 + "(!=)" { return tok(Parser._id,OperatorNames.Prexonite.Inequality); } 174 + "(>)" { return tok(Parser._id,OperatorNames.Prexonite.GreaterThan); } 175 + "(>=)" { return tok(Parser._id,OperatorNames.Prexonite.GreaterThanOrEqual); } 176 + "(<)" { return tok(Parser._id,OperatorNames.Prexonite.LessThan); } 177 + "(<=)" { return tok(Parser._id,OperatorNames.Prexonite.LessThanOrEqual); } 178 + "(-.)" { return tok(Parser._id,OperatorNames.Prexonite.UnaryNegation); } 179 + "(++)" { return tok(Parser._id,OperatorNames.Prexonite.Increment); } 180 + "(--)" { return tok(Parser._id,OperatorNames.Prexonite.Decrement); } 181 + "(<|.)" { return tok(Parser._id,OperatorNames.Prexonite.UnaryDeltaLeftPre); } 182 + "(.<|)" { return tok(Parser._id,OperatorNames.Prexonite.UnaryDeltaLeftPost); } 183 + "(|>.)" { return tok(Parser._id,OperatorNames.Prexonite.UnaryDeltaRightPre); } 184 + "(.|>)" { return tok(Parser._id,OperatorNames.Prexonite.UnaryDeltaRightPost); } 185 + "(<|)" { return tok(Parser._id,OperatorNames.Prexonite.BinaryDeltaLeft); } 186 + "(|>)" { return tok(Parser._id,OperatorNames.Prexonite.BinaryDeltaRight); } 187 + "(" { return tok(Parser._lpar); } 188 + ")" { return tok(Parser._rpar); } 189 + "]" { return tok(Parser._rbrack); } 190 + "}" { return tok(Parser._rbrace); } 191 + "+" { return tok(Parser._plus); } 192 + "-" { return tok(Parser._minus); } 193 + "*" { return tok(Parser._times); } 194 + "/" { return tok(Parser._div); } 195 + "^" { return tok(Parser._pow); } 196 + "=" { return tok(Parser._assign); } 197 + "<|" { return tok(Parser._deltaleft); } 198 + "|>" { return tok(Parser._deltaright); } 199 + "&&" { return tok(Parser._and); } 200 + "||" { return tok(Parser._or); } 201 + "|" { return tok(Parser._bitOr); } 202 + "&" { return tok(Parser._bitAnd); } 203 + "==" { return tok(Parser._eq); } 204 + "!=" { return tok(Parser._ne); } 205 + ">" { return tok(Parser._gt); } 206 + ">=" { return tok(Parser._ge); } 207 + "<=" { return tok(Parser._le); } 208 + "<" { return tok(Parser._lt); } 209 + "++" { return tok(Parser._inc); } 210 + "--" { return tok(Parser._dec); } 211 + "~" { return tok(Parser._tilde); } 212 + "::" { return tok(Parser._doublecolon); } 213 + "??" { return tok(Parser._coalescence); } 214 + "?" { return tok(Parser._question); } 215 + "->" { return tok(Parser._pointer); } 216 + "=>" { return tok(Parser._implementation); } 217 + ":" { return tok(Parser._colon); } 218 + ";" { return tok(Parser._semicolon); } 219 + "," { return tok(Parser._comma); } 220 + "." ({Identifier})? { Token dot = tok(Parser._dot); 221 + string memberId = yytext(); 222 + if(memberId.Length > 1) 223 + return multiple(dot,tok(Parser._id,memberId.Substring(memberId.StartsWith(".$") ? 2 : 1))); 224 + else 225 + return dot; } 226 + "@" { return tok(Parser._at); } 227 + ">>" { return tok(Parser._appendright); } 228 + "<<" { return tok(Parser._appendleft); } 229 + 230 + .|\n { Console.WriteLine("Rogue Character: \"{0}\"", yytext()); } 231 + } 232 + 233 + <String> { 234 + "\"" { PopState(); 235 + ret(tok(Parser._string, buffer.ToString())); 236 + buffer.Length = 0; 237 + } 238 + {RegularStringChar}+ { buffer.Append(yytext()); } 239 + "\\\\" { buffer.Append("\\"); } 240 + "\\\"" { buffer.Append("\""); } 241 + "\\"& { /* nothing to do */ } 242 + "\\"0 { buffer.Append("\0"); } 243 + "\\"a { buffer.Append("\a"); } 244 + "\\"b { buffer.Append("\b"); } 245 + "\\"f { buffer.Append("\f"); } 246 + "\\"n { buffer.Append("\n"); } 247 + "\\"r { buffer.Append("\r"); } 248 + "\\"v { buffer.Append("\v"); } 249 + "\\"t { buffer.Append("\t"); } 250 + "\\"x {HexDigit} {HexDigit}? {HexDigit}? {HexDigit}? | 251 + "\\"u {HexDigit} {HexDigit} {HexDigit} {HexDigit} | 252 + "\\"U {HexDigit} {HexDigit} {HexDigit} {HexDigit} {HexDigit} {HexDigit} {HexDigit} {HexDigit} { buffer.Append(_unescapeChar(yytext())); } 253 + //No need to escape $, but possible. 254 + "$" | "\\$" { buffer.Append("$"); } 255 + } 256 + 257 + <SmartString> { 258 + "\"" { PopState(); 259 + ret(tok(Parser._string, buffer.ToString())); 260 + buffer.Length = 0; 261 + } 262 + {RegularStringChar}+ { buffer.Append(yytext()); } 263 + "\\\\" { buffer.Append("\\"); } 264 + "\\\"" { buffer.Append("\""); } 265 + "\\"& { /* nothing to do */ } 266 + "\\"0 { buffer.Append("\0"); } 267 + "\\"a { buffer.Append("\a"); } 268 + "\\"b { buffer.Append("\b"); } 269 + "\\"f { buffer.Append("\f"); } 270 + "\\"n { buffer.Append("\n"); } 271 + "\\"r { buffer.Append("\r"); } 272 + "\\"v { buffer.Append("\v"); } 273 + "\\"t { buffer.Append("\t"); } 274 + "\\"x {HexDigit} {HexDigit}? {HexDigit}? {HexDigit}? | 275 + "\\"u {HexDigit} {HexDigit} {HexDigit} {HexDigit} | 276 + "\\"U {HexDigit} {HexDigit} {HexDigit} {HexDigit} {HexDigit} {HexDigit} {HexDigit} {HexDigit} { buffer.Append(_unescapeChar(yytext())); } 277 + "\\$" { buffer.Append("$"); } 278 + "$" {Identifier} &? 279 + { string clipped; 280 + string id = _pruneSmartStringIdentifier(yytext(), out clipped); 281 + string fragment = buffer.ToString(); 282 + buffer.Length = 0; 283 + return multiple( 284 + tok(Parser._string, fragment), 285 + tok(Parser._plus), 286 + tok(Parser._id, id), 287 + clipped != null ? tok(Parser._plus) : null, 288 + clipped != null ? tok(Parser._string, clipped) : null, 289 + tok(Parser._plus) 290 + ); 291 + } 292 + "$(" { string fragment = buffer.ToString(); 293 + buffer.Length = 0; 294 + PushState(_surroundingLocalState); 295 + return multiple( 296 + tok(Parser._string, fragment), 297 + tok(Parser._plus), 298 + tok(Parser._LPopExpr), 299 + tok(Parser._lpar) 300 + //2nd plus is injected by the parser 301 + ); 302 + } 303 + .|\n { throw new PrexoniteException("Invalid smart string character '" + yytext() + "' (ASCII " + ((int)yytext()[0]) + ") in input on line " + yyline + "."); } 304 + } 305 + 306 + <VerbatimString> { 307 + "\"" { PopState(); 308 + ret(tok(Parser._string, buffer.ToString())); 309 + buffer.Length = 0; 310 + } 311 + {RegularVerbatimStringChar} { buffer.Append(yytext()); } 312 + "\"\"" { buffer.Append("\""); } 313 + "$" { buffer.Append("$"); } 314 + 315 + } 316 + 317 + <SmartVerbatimString> { 318 + "\"" { PopState(); 319 + ret(tok(Parser._string, buffer.ToString())); 320 + buffer.Length = 0; 321 + } 322 + {RegularVerbatimStringChar} { buffer.Append(yytext()); } 323 + "\"\"" { buffer.Append("\""); } 324 + "$" {Identifier} &? 325 + { string clipped; 326 + string id = _pruneSmartStringIdentifier(yytext(), out clipped); 327 + string fragment = buffer.ToString(); 328 + buffer.Length = 0; 329 + return multiple( 330 + tok(Parser._string, fragment), 331 + tok(Parser._plus), 332 + tok(Parser._id, id), 333 + clipped != null ? tok(Parser._plus) : null, 334 + clipped != null ? tok(Parser._string, clipped) : null, 335 + tok(Parser._plus) 336 + ); 337 + } 338 + "$(" { string fragment = buffer.ToString(); 339 + buffer.Length = 0; 340 + PushState(_surroundingLocalState); 341 + return multiple( 342 + tok(Parser._string, fragment), 343 + tok(Parser._plus), 344 + tok(Parser._LPopExpr), 345 + tok(Parser._lpar) 346 + //2nd plus is injected by the parser 347 + ); 348 + } 349 + 350 + } 351 + 352 + //Error symbol 353 + .|\n { throw new PrexoniteException(System.String.Format("Invalid character \"{0}\" detected on line {1} in {2}.", yytext(), yyline, File)); }
+4
Prexonite/Prexonite.csproj
··· 98 98 <Reference Include="System.Core"> 99 99 <RequiredTargetFramework>3.5</RequiredTargetFramework> 100 100 </Reference> 101 + <Reference Include="System.ValueTuple, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51"> 102 + <HintPath>..\packages\System.ValueTuple.4.4.0-preview1-25305-02\lib\net461\System.ValueTuple.dll</HintPath> 103 + </Reference> 101 104 </ItemGroup> 102 105 <ItemGroup> 103 106 <Compile Include="ApplicationCompound.cs" /> ··· 490 493 <Compile Include="Types\StructurePType.cs" /> 491 494 <Compile Include="VM.cs" /> 492 495 <Content Include="Compiler\Prexonite.lex" /> 496 + <None Include="packages.config" /> 493 497 <None Include="prxlib\sh.pxs" /> 494 498 <None Include="Commands\Core\Operators\Operators.tt"> 495 499 <Generator>TextTemplatingFileGenerator</Generator>
+15 -9
Prexonite/Prexonite__gen.atg
··· 712 712 . 713 713 714 714 PrefixUnaryExpr<out AstExpr expr> 715 - (. var prefixes = new Stack<UnaryOperator>(); .) 715 + (. var prefixes = new Stack<(bool IsSplice, UnaryOperator Op)>(); .) 716 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); .) 717 + { plus // don't need to do anything for '+expr' 718 + | minus (. prefixes.Push((false, UnaryOperator.UnaryNegation)); .) 719 + | times (. prefixes.Push((true, UnaryOperator.None)); .) 720 + | inc (. prefixes.Push((false, UnaryOperator.PreIncrement)); .) 721 + | dec (. prefixes.Push((false, UnaryOperator.PreDecrement)); .) 722 + | deltaleft (. prefixes.Push((false, UnaryOperator.PreDeltaLeft)); .) 723 + | deltaright (. prefixes.Push((false, UnaryOperator.PreDeltaRight)); .) 723 724 } 724 725 Primary<out expr> 725 - (. while(prefixes.Count > 0) 726 - expr = Create.UnaryOperation(position, prefixes.Pop(), expr); 726 + (. while(prefixes.Count > 0) { 727 + var prefix = prefixes.Pop(); 728 + if(prefix.IsSplice) 729 + expr = Create.ArgumentSplice(position, expr); 730 + else 731 + expr = Create.UnaryOperation(position, prefix.Op, expr); 732 + } 727 733 .) 728 734 . 729 735
+452 -449
Prexonite/Types/NullPType.cs
··· 1 - // Prexonite 2 - // 3 - // Copyright (c) 2014, Christian Klauser 4 - // All rights reserved. 5 - // 6 - // Redistribution and use in source and binary forms, with or without modification, 7 - // are permitted provided that the following conditions are met: 8 - // 9 - // Redistributions of source code must retain the above copyright notice, 10 - // this list of conditions and the following disclaimer. 11 - // Redistributions in binary form must reproduce the above copyright notice, 12 - // this list of conditions and the following disclaimer in the 13 - // documentation and/or other materials provided with the distribution. 14 - // The names of the contributors may be used to endorse or 15 - // promote products derived from this software without specific prior written permission. 16 - // 17 - // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 - // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 - // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 - // IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 21 - // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 - // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 - // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 - // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 25 - // IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 - #define SINGLE_NULL 27 - 28 - #region 29 - 30 - using System.Diagnostics; 31 - using Prexonite.Compiler.Cil; 32 - 33 - #endregion 34 - 35 - namespace Prexonite.Types 36 - { 37 - [PTypeLiteral("Null")] 38 - public class NullPType : PType, ICilCompilerAware 39 - { 40 - #region Singleton 41 - 42 - private NullPType() 43 - { 44 - } 45 - 46 - private static readonly NullPType instance = new NullPType(); 47 - 48 - /// <summary> 49 - /// The one and only instance of <see cref = "NullPType" />. 50 - /// </summary> 51 - public static NullPType Instance 52 - { 53 - get { return instance; } 54 - } 55 - 56 - #endregion 57 - 58 - #region Static 59 - 60 - #if SINGLE_NULL 61 - private static readonly PValue _single_null = new PValue(null, instance); 62 - #endif 63 - 64 - /// <summary> 65 - /// Returns a PValue(null). 66 - /// </summary> 67 - /// <returns>PValue(null)</returns> 68 - public static PValue CreateValue() 69 - { 70 - #if SINGLE_NULL 71 - return _single_null; 72 - #else 73 - return new PValue(null, Instance); 74 - #endif 75 - } 76 - 77 - #endregion 78 - 79 - /// <summary> 80 - /// Returns a PValue(null). 81 - /// </summary> 82 - /// <returns>PValue(null)</returns> 83 - [DebuggerStepThrough] 84 - public PValue CreatePValue() 85 - { 86 - #if SINGLE_NULL 87 - return _single_null; 88 - #else 89 - return new PValue(null, this); 90 - #endif 91 - } 92 - 93 - #region Access interface implementation 94 - 95 - public override PValue Construct(StackContext sctx, PValue[] args) 96 - { 97 - return Null.CreatePValue(); 98 - } 99 - 100 - public override bool TryConstruct(StackContext sctx, PValue[] args, out PValue result) 101 - { 102 - result = Null.CreatePValue(); 103 - return true; 104 - } 105 - 106 - public override bool TryDynamicCall( 107 - StackContext sctx, 108 - PValue subject, 109 - PValue[] args, 110 - PCall call, 111 - string id, 112 - out PValue result) 113 - { 114 - result = null; 115 - if (Engine.StringsAreEqual(id, "tostring")) 116 - result = String.CreatePValue(""); 117 - else if (Engine.StringsAreEqual(id, @"\boxed")) 118 - result = sctx.CreateNativePValue(CreatePValue()); 119 - return result != null; 120 - } 121 - 122 - public override bool TryStaticCall( 123 - StackContext sctx, PValue[] args, PCall call, string id, out PValue result) 124 - { 125 - result = null; 126 - return false; 127 - } 128 - 129 - protected override bool InternalConvertTo( 130 - StackContext sctx, 131 - PValue subject, 132 - PType target, 133 - bool useExplicit, 134 - out PValue result) 135 - { 136 - result = null; 137 - switch (target.ToBuiltIn()) 138 - { 139 - case BuiltIn.Real: 140 - result = Real.CreatePValue(0.0); 141 - break; 142 - case BuiltIn.Int: 143 - result = Int.CreatePValue(0); 144 - break; 145 - case BuiltIn.String: 146 - result = String.CreatePValue(""); 147 - break; 148 - case BuiltIn.Bool: 149 - result = Bool.CreatePValue(false); 150 - break; 151 - } 152 - 153 - return result != null; 154 - } 155 - 156 - protected override bool InternalConvertFrom( 157 - StackContext sctx, 158 - PValue subject, 159 - bool useExplicit, 160 - out PValue result) 161 - { 162 - result = Null.CreatePValue(); 163 - return true; 164 - } 165 - 166 - protected override bool InternalIsEqual(PType otherType) 167 - { 168 - return otherType is NullPType; 169 - } 170 - 171 - private const int _code = 1357155649; 172 - 173 - public override int GetHashCode() 174 - { 175 - return _code; 176 - } 177 - 178 - #region Operators (no action) 179 - 180 - //UNARY 181 - public override bool Increment(StackContext sctx, PValue operand, out PValue result) 182 - { 183 - result = operand; 184 - return true; 185 - } 186 - 187 - public override bool Decrement(StackContext sctx, PValue operand, out PValue result) 188 - { 189 - result = operand; 190 - return true; 191 - } 192 - 193 - public override bool LogicalNot(StackContext sctx, PValue operand, out PValue result) 194 - { 195 - result = operand; 196 - return true; 197 - } 198 - 199 - public override bool OnesComplement(StackContext sctx, PValue operand, out PValue result) 200 - { 201 - result = operand; 202 - return true; 203 - } 204 - 205 - public override bool UnaryNegation(StackContext sctx, PValue operand, out PValue result) 206 - { 207 - result = operand; 208 - return true; 209 - } 210 - 211 - //BINARY 212 - 213 - private static bool _coalesce(PValue leftOperand, PValue rightOperand, out PValue result) 214 - { 215 - result = null; 216 - var leftIsNull = leftOperand.Value == null; 217 - var rightIsNull = rightOperand.Value == null; 218 - 219 - if (leftIsNull && rightIsNull) 220 - result = Null.CreatePValue(); 221 - else if (leftIsNull) 222 - result = rightOperand; 223 - else if (rightIsNull) 224 - result = leftOperand; 225 - 226 - return result != null; 227 - } 228 - 229 - public override bool Addition( 230 - StackContext sctx, PValue leftOperand, PValue rightOperand, out PValue result) 231 - { 232 - return _coalesce(leftOperand, rightOperand, out result); 233 - } 234 - 235 - public override bool Subtraction( 236 - StackContext sctx, PValue leftOperand, PValue rightOperand, out PValue result) 237 - { 238 - return _coalesce(leftOperand, rightOperand, out result); 239 - } 240 - 241 - public override bool Multiply( 242 - StackContext sctx, PValue leftOperand, PValue rightOperand, out PValue result) 243 - { 244 - return _coalesce(leftOperand, rightOperand, out result); 245 - } 246 - 247 - public override bool Division( 248 - StackContext sctx, PValue leftOperand, PValue rightOperand, out PValue result) 249 - { 250 - return _coalesce(leftOperand, rightOperand, out result); 251 - } 252 - 253 - public override bool Modulus( 254 - StackContext sctx, PValue leftOperand, PValue rightOperand, out PValue result) 255 - { 256 - return _coalesce(leftOperand, rightOperand, out result); 257 - } 258 - 259 - public override bool BitwiseAnd( 260 - StackContext sctx, PValue leftOperand, PValue rightOperand, out PValue result) 261 - { 262 - return _coalesce(leftOperand, rightOperand, out result); 263 - } 264 - 265 - public override bool BitwiseOr( 266 - StackContext sctx, PValue leftOperand, PValue rightOperand, out PValue result) 267 - { 268 - return _coalesce(leftOperand, rightOperand, out result); 269 - } 270 - 271 - public override bool ExclusiveOr( 272 - StackContext sctx, PValue leftOperand, PValue rightOperand, out PValue result) 273 - { 274 - return _coalesce(leftOperand, rightOperand, out result); 275 - } 276 - 277 - public override bool Equality( 278 - StackContext sctx, PValue leftOperand, PValue rightOperand, out PValue result) 279 - { 280 - var leftIsNull = leftOperand.Value == null; 281 - var rightIsNull = rightOperand.Value == null; 282 - 283 - if (leftIsNull && rightIsNull) 284 - result = Bool.CreatePValue(true); 285 - else if (leftIsNull ^ rightIsNull) 286 - result = Bool.CreatePValue(false); 287 - else 288 - result = null; //unknown 289 - 290 - return result != null; 291 - } 292 - 293 - public override bool Inequality( 294 - StackContext sctx, PValue leftOperand, PValue rightOperand, out PValue result) 295 - { 296 - var leftIsNull = leftOperand.Value == null; 297 - var rightIsNull = rightOperand.Value == null; 298 - 299 - if (leftIsNull && rightIsNull) 300 - result = Bool.CreatePValue(false); 301 - else if (leftIsNull ^ rightIsNull) 302 - result = Bool.CreatePValue(true); 303 - else 304 - result = null; //unknown 305 - 306 - return result != null; 307 - } 308 - 309 - public override bool GreaterThan( 310 - StackContext sctx, PValue leftOperand, PValue rightOperand, out PValue result) 311 - { 312 - result = null; 313 - var leftIsNull = leftOperand.Value == null; 314 - var rightIsNull = rightOperand.Value == null; 315 - 316 - if (leftIsNull && rightIsNull) 317 - result = Bool.CreatePValue(false); 318 - else if (leftIsNull) 319 - result = Bool.CreatePValue(false); //everything else is greater than null 320 - else if (rightIsNull) 321 - result = Bool.CreatePValue(true); 322 - 323 - return result != null; 324 - } 325 - 326 - public override bool GreaterThanOrEqual( 327 - StackContext sctx, 328 - PValue leftOperand, 329 - PValue rightOperand, 330 - out PValue result) 331 - { 332 - result = null; 333 - var leftIsNull = leftOperand.Value == null; 334 - var rightIsNull = rightOperand.Value == null; 335 - 336 - if (leftIsNull && rightIsNull) 337 - result = Bool.CreatePValue(true); 338 - else if (leftIsNull) 339 - result = Bool.CreatePValue(false); //everything else is greater than null 340 - else if (rightIsNull) 341 - result = Bool.CreatePValue(true); 342 - 343 - return result != null; 344 - } 345 - 346 - public override bool LessThan( 347 - StackContext sctx, PValue leftOperand, PValue rightOperand, out PValue result) 348 - { 349 - result = null; 350 - var leftIsNull = leftOperand.Value == null; 351 - var rightIsNull = rightOperand.Value == null; 352 - 353 - if (leftIsNull && rightIsNull) 354 - result = Bool.CreatePValue(false); 355 - else if (leftIsNull) 356 - result = Bool.CreatePValue(true); //everything else is greater than null 357 - else if (rightIsNull) 358 - result = Bool.CreatePValue(false); 359 - 360 - return result != null; 361 - } 362 - 363 - public override bool LessThanOrEqual( 364 - StackContext sctx, 365 - PValue leftOperand, 366 - PValue rightOperand, 367 - out PValue result) 368 - { 369 - result = null; 370 - var leftIsNull = leftOperand.Value == null; 371 - var rightIsNull = rightOperand.Value == null; 372 - 373 - if (leftIsNull && rightIsNull) 374 - result = Bool.CreatePValue(true); 375 - else if (leftIsNull) 376 - result = Bool.CreatePValue(true); //everything else is greater than null 377 - else if (rightIsNull) 378 - result = Bool.CreatePValue(false); 379 - 380 - return result != null; 381 - } 382 - 383 - #endregion 384 - 385 - #endregion 386 - 387 - /// <summary> 388 - /// The indirect call implementation of null values: Do nothing. 389 - /// </summary> 390 - /// <param name = "sctx">The context in which to do nothing. (ignored).</param> 391 - /// <param name = "subject">The subject on which to do nothing (ignored).</param> 392 - /// <param name = "args">The list of arguments (ignored).</param> 393 - /// <param name = "result">The result of doing nothing. Always PValue(null).</param> 394 - /// <returns>Always true (doing nothing can't possibly fail...)</returns> 395 - [DebuggerStepThrough] 396 - public override bool IndirectCall( 397 - StackContext sctx, PValue subject, PValue[] args, out PValue result) 398 - { 399 - //Does nothing 400 - result = CreatePValue(); 401 - return true; 402 - } 403 - 404 - public const string Literal = "Null"; 405 - 406 - /// <summary> 407 - /// Returns the Null <see cref = "Literal" />. 408 - /// </summary> 409 - /// <returns>The Null <see cref = "Literal" />.</returns> 410 - [DebuggerStepThrough] 411 - public override string ToString() 412 - { 413 - return Literal; 414 - } 415 - 416 - [DebuggerStepThrough] 417 - public static implicit operator PValue(NullPType T) 418 - { 419 - #if SINGLE_NULL 420 - return _single_null; 421 - #else 422 - return new PValue(null, this); 423 - #endif 424 - } 425 - 426 - #region ICilCompilerAware Members 427 - 428 - /// <summary> 429 - /// Asses qualification and preferences for a certain instruction. 430 - /// </summary> 431 - /// <param name = "ins">The instruction that is about to be compiled.</param> 432 - /// <returns>A set of <see cref = "CompilationFlags" />.</returns> 433 - CompilationFlags ICilCompilerAware.CheckQualification(Instruction ins) 434 - { 435 - return CompilationFlags.PrefersCustomImplementation; 436 - } 437 - 438 - /// <summary> 439 - /// Provides a custom compiler routine for emitting CIL byte code for a specific instruction. 440 - /// </summary> 441 - /// <param name = "state">The compiler state.</param> 442 - /// <param name = "ins">The instruction to compile.</param> 443 - void ICilCompilerAware.ImplementInCil(CompilerState state, Instruction ins) 444 - { 445 - state.EmitCall(Compiler.Cil.Compiler.GetNullPType); 446 - } 447 - 448 - #endregion 449 - } 1 + // Prexonite 2 + // 3 + // Copyright (c) 2014, Christian Klauser 4 + // All rights reserved. 5 + // 6 + // Redistribution and use in source and binary forms, with or without modification, 7 + // are permitted provided that the following conditions are met: 8 + // 9 + // Redistributions of source code must retain the above copyright notice, 10 + // this list of conditions and the following disclaimer. 11 + // Redistributions in binary form must reproduce the above copyright notice, 12 + // this list of conditions and the following disclaimer in the 13 + // documentation and/or other materials provided with the distribution. 14 + // The names of the contributors may be used to endorse or 15 + // promote products derived from this software without specific prior written permission. 16 + // 17 + // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 + // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 + // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 + // IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 21 + // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 + // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 + // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 + // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 25 + // IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 + #define SINGLE_NULL 27 + 28 + #region 29 + 30 + using System.Diagnostics; 31 + using System.Linq; 32 + using Prexonite.Compiler.Cil; 33 + 34 + #endregion 35 + 36 + namespace Prexonite.Types 37 + { 38 + [PTypeLiteral("Null")] 39 + public class NullPType : PType, ICilCompilerAware 40 + { 41 + #region Singleton 42 + 43 + private NullPType() 44 + { 45 + } 46 + 47 + private static readonly NullPType instance = new NullPType(); 48 + 49 + /// <summary> 50 + /// The one and only instance of <see cref = "NullPType" />. 51 + /// </summary> 52 + public static NullPType Instance 53 + { 54 + get { return instance; } 55 + } 56 + 57 + #endregion 58 + 59 + #region Static 60 + 61 + #if SINGLE_NULL 62 + private static readonly PValue _single_null = new PValue(null, instance); 63 + #endif 64 + 65 + /// <summary> 66 + /// Returns a PValue(null). 67 + /// </summary> 68 + /// <returns>PValue(null)</returns> 69 + public static PValue CreateValue() 70 + { 71 + #if SINGLE_NULL 72 + return _single_null; 73 + #else 74 + return new PValue(null, Instance); 75 + #endif 76 + } 77 + 78 + #endregion 79 + 80 + /// <summary> 81 + /// Returns a PValue(null). 82 + /// </summary> 83 + /// <returns>PValue(null)</returns> 84 + [DebuggerStepThrough] 85 + public PValue CreatePValue() 86 + { 87 + #if SINGLE_NULL 88 + return _single_null; 89 + #else 90 + return new PValue(null, this); 91 + #endif 92 + } 93 + 94 + #region Access interface implementation 95 + 96 + public override PValue Construct(StackContext sctx, PValue[] args) 97 + { 98 + return Null.CreatePValue(); 99 + } 100 + 101 + public override bool TryConstruct(StackContext sctx, PValue[] args, out PValue result) 102 + { 103 + result = Null.CreatePValue(); 104 + return true; 105 + } 106 + 107 + public override bool TryDynamicCall( 108 + StackContext sctx, 109 + PValue subject, 110 + PValue[] args, 111 + PCall call, 112 + string id, 113 + out PValue result) 114 + { 115 + result = null; 116 + if (Engine.StringsAreEqual(id, "tostring")) 117 + result = String.CreatePValue(""); 118 + else if (Engine.StringsAreEqual(id, @"\boxed")) 119 + result = sctx.CreateNativePValue(CreatePValue()); 120 + else if (Engine.StringsAreEqual(id, "GetEnumerator")) 121 + result = sctx.CreateNativePValue(Enumerable.Empty<PValue>().GetEnumerator()); 122 + return result != null; 123 + } 124 + 125 + public override bool TryStaticCall( 126 + StackContext sctx, PValue[] args, PCall call, string id, out PValue result) 127 + { 128 + result = null; 129 + return false; 130 + } 131 + 132 + protected override bool InternalConvertTo( 133 + StackContext sctx, 134 + PValue subject, 135 + PType target, 136 + bool useExplicit, 137 + out PValue result) 138 + { 139 + result = null; 140 + switch (target.ToBuiltIn()) 141 + { 142 + case BuiltIn.Real: 143 + result = Real.CreatePValue(0.0); 144 + break; 145 + case BuiltIn.Int: 146 + result = Int.CreatePValue(0); 147 + break; 148 + case BuiltIn.String: 149 + result = String.CreatePValue(""); 150 + break; 151 + case BuiltIn.Bool: 152 + result = Bool.CreatePValue(false); 153 + break; 154 + } 155 + 156 + return result != null; 157 + } 158 + 159 + protected override bool InternalConvertFrom( 160 + StackContext sctx, 161 + PValue subject, 162 + bool useExplicit, 163 + out PValue result) 164 + { 165 + result = Null.CreatePValue(); 166 + return true; 167 + } 168 + 169 + protected override bool InternalIsEqual(PType otherType) 170 + { 171 + return otherType is NullPType; 172 + } 173 + 174 + private const int _code = 1357155649; 175 + 176 + public override int GetHashCode() 177 + { 178 + return _code; 179 + } 180 + 181 + #region Operators (no action) 182 + 183 + //UNARY 184 + public override bool Increment(StackContext sctx, PValue operand, out PValue result) 185 + { 186 + result = operand; 187 + return true; 188 + } 189 + 190 + public override bool Decrement(StackContext sctx, PValue operand, out PValue result) 191 + { 192 + result = operand; 193 + return true; 194 + } 195 + 196 + public override bool LogicalNot(StackContext sctx, PValue operand, out PValue result) 197 + { 198 + result = operand; 199 + return true; 200 + } 201 + 202 + public override bool OnesComplement(StackContext sctx, PValue operand, out PValue result) 203 + { 204 + result = operand; 205 + return true; 206 + } 207 + 208 + public override bool UnaryNegation(StackContext sctx, PValue operand, out PValue result) 209 + { 210 + result = operand; 211 + return true; 212 + } 213 + 214 + //BINARY 215 + 216 + private static bool _coalesce(PValue leftOperand, PValue rightOperand, out PValue result) 217 + { 218 + result = null; 219 + var leftIsNull = leftOperand.Value == null; 220 + var rightIsNull = rightOperand.Value == null; 221 + 222 + if (leftIsNull && rightIsNull) 223 + result = Null.CreatePValue(); 224 + else if (leftIsNull) 225 + result = rightOperand; 226 + else if (rightIsNull) 227 + result = leftOperand; 228 + 229 + return result != null; 230 + } 231 + 232 + public override bool Addition( 233 + StackContext sctx, PValue leftOperand, PValue rightOperand, out PValue result) 234 + { 235 + return _coalesce(leftOperand, rightOperand, out result); 236 + } 237 + 238 + public override bool Subtraction( 239 + StackContext sctx, PValue leftOperand, PValue rightOperand, out PValue result) 240 + { 241 + return _coalesce(leftOperand, rightOperand, out result); 242 + } 243 + 244 + public override bool Multiply( 245 + StackContext sctx, PValue leftOperand, PValue rightOperand, out PValue result) 246 + { 247 + return _coalesce(leftOperand, rightOperand, out result); 248 + } 249 + 250 + public override bool Division( 251 + StackContext sctx, PValue leftOperand, PValue rightOperand, out PValue result) 252 + { 253 + return _coalesce(leftOperand, rightOperand, out result); 254 + } 255 + 256 + public override bool Modulus( 257 + StackContext sctx, PValue leftOperand, PValue rightOperand, out PValue result) 258 + { 259 + return _coalesce(leftOperand, rightOperand, out result); 260 + } 261 + 262 + public override bool BitwiseAnd( 263 + StackContext sctx, PValue leftOperand, PValue rightOperand, out PValue result) 264 + { 265 + return _coalesce(leftOperand, rightOperand, out result); 266 + } 267 + 268 + public override bool BitwiseOr( 269 + StackContext sctx, PValue leftOperand, PValue rightOperand, out PValue result) 270 + { 271 + return _coalesce(leftOperand, rightOperand, out result); 272 + } 273 + 274 + public override bool ExclusiveOr( 275 + StackContext sctx, PValue leftOperand, PValue rightOperand, out PValue result) 276 + { 277 + return _coalesce(leftOperand, rightOperand, out result); 278 + } 279 + 280 + public override bool Equality( 281 + StackContext sctx, PValue leftOperand, PValue rightOperand, out PValue result) 282 + { 283 + var leftIsNull = leftOperand.Value == null; 284 + var rightIsNull = rightOperand.Value == null; 285 + 286 + if (leftIsNull && rightIsNull) 287 + result = Bool.CreatePValue(true); 288 + else if (leftIsNull ^ rightIsNull) 289 + result = Bool.CreatePValue(false); 290 + else 291 + result = null; //unknown 292 + 293 + return result != null; 294 + } 295 + 296 + public override bool Inequality( 297 + StackContext sctx, PValue leftOperand, PValue rightOperand, out PValue result) 298 + { 299 + var leftIsNull = leftOperand.Value == null; 300 + var rightIsNull = rightOperand.Value == null; 301 + 302 + if (leftIsNull && rightIsNull) 303 + result = Bool.CreatePValue(false); 304 + else if (leftIsNull ^ rightIsNull) 305 + result = Bool.CreatePValue(true); 306 + else 307 + result = null; //unknown 308 + 309 + return result != null; 310 + } 311 + 312 + public override bool GreaterThan( 313 + StackContext sctx, PValue leftOperand, PValue rightOperand, out PValue result) 314 + { 315 + result = null; 316 + var leftIsNull = leftOperand.Value == null; 317 + var rightIsNull = rightOperand.Value == null; 318 + 319 + if (leftIsNull && rightIsNull) 320 + result = Bool.CreatePValue(false); 321 + else if (leftIsNull) 322 + result = Bool.CreatePValue(false); //everything else is greater than null 323 + else if (rightIsNull) 324 + result = Bool.CreatePValue(true); 325 + 326 + return result != null; 327 + } 328 + 329 + public override bool GreaterThanOrEqual( 330 + StackContext sctx, 331 + PValue leftOperand, 332 + PValue rightOperand, 333 + out PValue result) 334 + { 335 + result = null; 336 + var leftIsNull = leftOperand.Value == null; 337 + var rightIsNull = rightOperand.Value == null; 338 + 339 + if (leftIsNull && rightIsNull) 340 + result = Bool.CreatePValue(true); 341 + else if (leftIsNull) 342 + result = Bool.CreatePValue(false); //everything else is greater than null 343 + else if (rightIsNull) 344 + result = Bool.CreatePValue(true); 345 + 346 + return result != null; 347 + } 348 + 349 + public override bool LessThan( 350 + StackContext sctx, PValue leftOperand, PValue rightOperand, out PValue result) 351 + { 352 + result = null; 353 + var leftIsNull = leftOperand.Value == null; 354 + var rightIsNull = rightOperand.Value == null; 355 + 356 + if (leftIsNull && rightIsNull) 357 + result = Bool.CreatePValue(false); 358 + else if (leftIsNull) 359 + result = Bool.CreatePValue(true); //everything else is greater than null 360 + else if (rightIsNull) 361 + result = Bool.CreatePValue(false); 362 + 363 + return result != null; 364 + } 365 + 366 + public override bool LessThanOrEqual( 367 + StackContext sctx, 368 + PValue leftOperand, 369 + PValue rightOperand, 370 + out PValue result) 371 + { 372 + result = null; 373 + var leftIsNull = leftOperand.Value == null; 374 + var rightIsNull = rightOperand.Value == null; 375 + 376 + if (leftIsNull && rightIsNull) 377 + result = Bool.CreatePValue(true); 378 + else if (leftIsNull) 379 + result = Bool.CreatePValue(true); //everything else is greater than null 380 + else if (rightIsNull) 381 + result = Bool.CreatePValue(false); 382 + 383 + return result != null; 384 + } 385 + 386 + #endregion 387 + 388 + #endregion 389 + 390 + /// <summary> 391 + /// The indirect call implementation of null values: Do nothing. 392 + /// </summary> 393 + /// <param name = "sctx">The context in which to do nothing. (ignored).</param> 394 + /// <param name = "subject">The subject on which to do nothing (ignored).</param> 395 + /// <param name = "args">The list of arguments (ignored).</param> 396 + /// <param name = "result">The result of doing nothing. Always PValue(null).</param> 397 + /// <returns>Always true (doing nothing can't possibly fail...)</returns> 398 + [DebuggerStepThrough] 399 + public override bool IndirectCall( 400 + StackContext sctx, PValue subject, PValue[] args, out PValue result) 401 + { 402 + //Does nothing 403 + result = CreatePValue(); 404 + return true; 405 + } 406 + 407 + public const string Literal = "Null"; 408 + 409 + /// <summary> 410 + /// Returns the Null <see cref = "Literal" />. 411 + /// </summary> 412 + /// <returns>The Null <see cref = "Literal" />.</returns> 413 + [DebuggerStepThrough] 414 + public override string ToString() 415 + { 416 + return Literal; 417 + } 418 + 419 + [DebuggerStepThrough] 420 + public static implicit operator PValue(NullPType T) 421 + { 422 + #if SINGLE_NULL 423 + return _single_null; 424 + #else 425 + return new PValue(null, this); 426 + #endif 427 + } 428 + 429 + #region ICilCompilerAware Members 430 + 431 + /// <summary> 432 + /// Asses qualification and preferences for a certain instruction. 433 + /// </summary> 434 + /// <param name = "ins">The instruction that is about to be compiled.</param> 435 + /// <returns>A set of <see cref = "CompilationFlags" />.</returns> 436 + CompilationFlags ICilCompilerAware.CheckQualification(Instruction ins) 437 + { 438 + return CompilationFlags.PrefersCustomImplementation; 439 + } 440 + 441 + /// <summary> 442 + /// Provides a custom compiler routine for emitting CIL byte code for a specific instruction. 443 + /// </summary> 444 + /// <param name = "state">The compiler state.</param> 445 + /// <param name = "ins">The instruction to compile.</param> 446 + void ICilCompilerAware.ImplementInCil(CompilerState state, Instruction ins) 447 + { 448 + state.EmitCall(Compiler.Cil.Compiler.GetNullPType); 449 + } 450 + 451 + #endregion 452 + } 450 453 }
+1 -1
PrexoniteTests/PrexoniteTests.csproj.DotSettings
··· 1 1 <wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> 2 2 <s:String x:Key="/Default/CodeEditing/Localization/Localizable/@EntryValue">No</s:String> 3 - <s:String x:Key="/Default/CodeInspection/CSharpLanguageProject/LanguageLevel/@EntryValue">CSharp60</s:String></wpf:ResourceDictionary> 3 + <s:String x:Key="/Default/CodeInspection/CSharpLanguageProject/LanguageLevel/@EntryValue">CSharp70</s:String></wpf:ResourceDictionary>
+78 -7
PrexoniteTests/Tests/ShellExtensions.cs
··· 31 31 using System.Net; 32 32 using NUnit.Framework; 33 33 using Prexonite; 34 + using Prexonite.Commands.Math; 35 + using Prexonite.Types; 34 36 35 37 namespace PrexoniteTests.Tests 36 38 { ··· 334 336 } 335 337 336 338 [Test] 339 + public void NullSupportsForeach() 340 + { 341 + Compile(@" 342 + function main(a){ 343 + var z = a; 344 + foreach(var x in null){ 345 + z += x; 346 + } 347 + return z; 348 + } 349 + "); 350 + Expect(16, 16); 351 + } 352 + 353 + [Test] 337 354 public void SpliceFunctionCall() 338 355 { 339 356 Compile(@" ··· 341 358 return call(string_concat(?), ["":""], var args >> map(x => ""<$x>"")); 342 359 } 343 360 344 - macro splice(xs){ 345 - context.Block.Expression = context.Factory.ArgumentSplice(context.Invocation.Position, xs); 346 - } 347 - 348 361 function main(a, xs, b, ys, c){ 349 - return ->f.(a, splice(xs), b, splice(ys), c); 362 + return ->f.(a, *xs, b, *ys, c); 350 363 } 351 364 352 365 function main2(xs) { 353 - return f(splice(xs)); 366 + return f(*xs); 354 367 } 355 368 356 369 function main3(xs, ys){ 357 - return f(splice(xs), splice(ys)); 370 + return f(*xs, *ys); 371 + } 372 + 373 + function main4(a, b, c, xs) { 374 + return f(a, b, c, *xs); 375 + } 376 + 377 + function main5(xs, a, b, c) { 378 + return f(*xs, a, b, c); 358 379 } 359 380 "); 360 381 ··· 375 396 _list("x1", "x2", "x3"), _list()); 376 397 ExpectNamed("main3", ":<x1>", 377 398 _list("x1"), _list()); 399 + 400 + ExpectNamed("main4", ":<a><b><c><x1><x2><x3>", "a", "b", "c", _list("x1", "x2", "x3")); 401 + ExpectNamed("main4", ":<a><b><c><x1>", "a", "b", "c", _list("x1")); 402 + ExpectNamed("main4", ":<a><b><c>", "a", "b", "c", _list()); 403 + ExpectNamed("main5", ":<x1><x2><x3><a><b><c>", _list("x1", "x2", "x3"), "a", "b", "c"); 404 + ExpectNamed("main5", ":<x1><a><b><c>", _list("x1"), "a", "b", "c"); 405 + ExpectNamed("main5", ":<a><b><c>", _list(), "a", "b", "c"); 406 + ExpectNamed("main4", ":<a><b><c>", "a", "b", "c", PType.Null); 407 + ExpectNamed("main5", ":<a><b><c>", PType.Null, "a", "b", "c"); 408 + ExpectNamed("main3", ":<x1>", 409 + _list("x1"), PType.Null); 410 + ExpectNamed("main2", ":", PType.Null); 411 + } 412 + 413 + /// <summary> 414 + /// Verify that <code>$@</code> is equivalent to 'var args' 415 + /// </summary> 416 + [Test] 417 + public void VarArgsSigil() 418 + { 419 + Compile(@" 420 + function main(){ 421 + return call(string_concat(?), ["":""], $@ >> map(x => ""<$x>"")); 422 + } 423 + "); 424 + Expect(":<a><b><c>", "a", "b", "c"); 425 + Expect(":"); 426 + } 427 + 428 + [Test] 429 + public void VarArgsSigilSplice() 430 + { 431 + Compile(@" 432 + function main(){ 433 + return string_concat("":"", *$@); 434 + } 435 + "); 436 + Expect(":abc", "a", "b", "c"); 437 + } 438 + 439 + [Test] 440 + public void FlowSplice() 441 + { 442 + Compile(@" 443 + function main(){ 444 + var xs = var args; 445 + return *xs >> foldl(->(+), "":""); 446 + } 447 + "); 448 + Expect(":abc", "a", "b", "c"); 378 449 } 379 450 380 451 private PValue _list(params object[] elements)