[JEDI.NET-commits] main/run Jedi.Math.Evaluation.Base.pas,NONE,1.1 Jedi.Math.Evaluation.BinaryNodes.
Status: Pre-Alpha
Brought to you by:
jedi_mbe
Update of /cvsroot/jedidotnet/main/run In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4816/main/run Added Files: Jedi.Math.Evaluation.Base.pas Jedi.Math.Evaluation.BinaryNodes.pas Jedi.Math.Evaluation.CompilingProcessor.pas Jedi.Math.Evaluation.EvalProcessor.pas Jedi.Math.Evaluation.Namespaces.Generic.pas Jedi.Math.Evaluation.TenaryNodes.pas Jedi.Math.Evaluation.Tokenization.pas Jedi.Math.Evaluation.Tokens.pas Jedi.Math.Evaluation.UnaryNodes.pas Jedi.Math.Evaluation.ValueNodes.pas Jedi.Math.Resources.pas Log Message: Expression parsing and evaluating --- NEW FILE: Jedi.Math.Evaluation.Tokenization.pas --- {--------------------------------------------------------------------------------------------------- The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.mozilla.org/MPL/MPL-1.1.html Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for the specific language governing rights and limitations under the License. The Original Code is: Jedi.Math.Evaluation.Tokenization.pas, released on --. The Initial Developer of the Original Code is Marcel Bestebroer Portions created by Marcel Bestebroer are Copyright (C) 2004 Marcel Bestebroer All Rights Reserved. Contributor(s): You may retrieve the latest version of this file at the JEDI.NET home page, located at http://sf.net/projects/jedidotnet Known Issues: ---------------------------------------------------------------------------------------------------} // $Id: Jedi.Math.Evaluation.Tokenization.pas,v 1.1 2005/08/22 17:27:08 jedi_mbe Exp $ unit Jedi.Math.Evaluation.Tokenization; interface {$REGION 'uses'} uses Jedi.System.SourceVersioning, Jedi.System.Strings, Jedi.Text.Tokenization.Base, System.Globalization, System.IO; {$ENDREGION} {$REGION 'Math lexer'} type [JediSourceInfo( '$Source: /cvsroot/jedidotnet/main/run/Jedi.Math.Evaluation.Tokenization.pas,v $', '$Revision: 1.1 $', '$Date: 2005/08/22 17:27:08 $')] MathLexer = class (&Object, ITokenProvider) {$REGION 'Constructors'} strict protected constructor Create(tokenizer: ITokenizer); {$ENDREGION} {$REGION 'Data'} strict private FFromStack: Boolean; FList: ITokenProvider; FTokenizer: ITokenizer; {$ENDREGION} {$REGION 'ITokenProvider methods'} strict protected function get_Current: IToken; function Next: Boolean; procedure RestorePointer; procedure SavePointer; {$ENDREGION} {$REGION 'Static methods'} public class function Tokenize(s: string): ITokenProvider; overload; static; class function Tokenize(s: string; formatProvider: IFormatProvider): ITokenProvider; overload; static; class function Tokenize(reader: TextReader): ITokenProvider; overload; static; class function Tokenize(reader: TextReader; formatProvider: IFormatProvider): ITokenProvider; overload; static; class function Tokenize(reader: TextReader; ownsReader: Boolean): ITokenProvider; overload; static; class function Tokenize(reader: TextReader; ownsReader: Boolean; formatProvider: IFormatProvider): ITokenProvider; overload; static; {$ENDREGION} end; {$ENDREGION} {$REGION 'Math tokenizer'} type [JediSourceInfo( '$Source: /cvsroot/jedidotnet/main/run/Jedi.Math.Evaluation.Tokenization.pas,v $', '$Revision: 1.1 $', '$Date: 2005/08/22 17:27:08 $')] MathTokenizer = class (TextTokenizer) {$REGION 'Constructors'} protected constructor Create(reader: TextReader; ownsReader: Boolean; formatProvider: IFormatProvider); {$ENDREGION} {$REGION 'Property accessors'} public function get_FormatProvider: IFormatProvider; {$ENDREGION} {$REGION 'Properties'} public property FormatProvider: IFormatProvider read get_FormatProvider; {$ENDREGION} end; {$ENDREGION} implementation {$REGION 'internal uses'} uses Jedi.Math.Evaluation.Tokens; {$ENDREGION} {$REGION 'MathLexer'} constructor MathLexer.Create(tokenizer: ITokenizer); begin inherited Create; FTokenizer := tokenizer; Next; // make sure we're properly intialized end; function MathLexer.get_Current: IToken; begin if FFromStack then Result := FList.Current else Result := ITokenProvider(FTokenizer).Current; end; function MathLexer.Next: Boolean; begin if FFromStack then Result := FList.Next else Result := False; if not Result then begin FFromStack := False; Result := TokenProviderUtils.Next(ITokenProvider(FTokenizer), [TypeOf(WhiteSpaceToken), TypeOf(ControlToken)]); end; if (FList <> nil) and not FFromStack and Result then TokenList(FList).AddToken(ITokenProvider(FTokenizer).Current); end; procedure MathLexer.RestorePointer; begin if (FList <> nil) and (TokenList(FList).CanRestorePointer) then begin FList.RestorePointer; FFromStack := True; end; end; procedure MathLexer.SavePointer; begin if FList = nil then FList := TokenList.Create; FList.SavePointer; end; class function MathLexer.Tokenize(s: string): ITokenProvider; begin Result := Tokenize(StringReader.Create(s), True, NumberFormatInfo.InvariantInfo); end; class function MathLexer.Tokenize(s: string; formatProvider: IFormatProvider): ITokenProvider; begin Result := Tokenize(StringReader.Create(s), True, formatProvider); end; class function MathLexer.Tokenize(reader: TextReader): ITokenProvider; begin Result := Tokenize(reader, True, NumberFormatInfo.InvariantInfo); end; class function MathLexer.Tokenize(reader: TextReader; formatProvider: IFormatProvider): ITokenProvider; begin Result := Tokenize(reader, True, formatProvider); end; class function MathLexer.Tokenize(reader: TextReader; ownsReader: Boolean): ITokenProvider; begin Result := Tokenize(reader, ownsReader, NumberFormatInfo.InvariantInfo); end; class function MathLexer.Tokenize(reader: TextReader; ownsReader: Boolean; formatProvider: IFormatProvider): ITokenProvider; begin Result := MathLexer.Create(MathTokenizer.Create(reader, ownsReader, formatProvider)); end; {$ENDREGION} {$REGION 'MathTokenizer'} constructor MathTokenizer.Create(reader: TextReader; ownsReader: Boolean; formatProvider: IFormatProvider); begin inherited Create(reader, ownsReader, MathTokenSet.Default, StringUtils.TabSet.Create(2), formatProvider); end; function MathTokenizer.get_FormatProvider: IFormatProvider; begin Result := IFormatProvider(Context); end; {$ENDREGION} end. --- NEW FILE: Jedi.Math.Evaluation.ValueNodes.pas --- {--------------------------------------------------------------------------------------------------- The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.mozilla.org/MPL/MPL-1.1.html Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for the specific language governing rights and limitations under the License. The Original Code is: Jedi.Math.Evaluation.ValueNodes.pas, released on --. The Initial Developer of the Original Code is Marcel Bestebroer Portions created by Marcel Bestebroer are Copyright (C) 2004 Marcel Bestebroer All Rights Reserved. Contributor(s): You may retrieve the latest version of this file at the JEDI.NET home page, located at http://sf.net/projects/jedidotnet Known Issues: ---------------------------------------------------------------------------------------------------} // $Id: Jedi.Math.Evaluation.ValueNodes.pas,v 1.1 2005/08/22 17:27:08 jedi_mbe Exp $ unit Jedi.Math.Evaluation.ValueNodes; interface {$REGION 'uses'} uses Jedi.Math.Evaluation.Base, Jedi.Math.Evaluation.CompilingProcessor, Jedi.System.SourceVersioning, System.Collections; {$ENDREGION} {$REGION 'Symbol expression node'} type [JediSourceInfo( '$Source: /cvsroot/jedidotnet/main/run/Jedi.Math.Evaluation.ValueNodes.pas,v $', '$Revision: 1.1 $', '$Date: 2005/08/22 17:27:08 $')] SymbolExpressionNode = class abstract (ExpressionNode) {$REGION 'Constructors'} strict protected constructor Create(symbol: Symbol); {$ENDREGION} {$REGION 'Data'} strict private FSymbol: Symbol; {$ENDREGION} {$REGION 'Overrides'} public function get_Literal: string; override; function get_Precedence: Integer; override; {$ENDREGION} {$REGION 'Properties'} strict protected property Symbol: Symbol read FSymbol; {$ENDREGION} end; {$ENDREGION} {$REGION 'Immediate expression node'} type [JediSourceInfo( '$Source: /cvsroot/jedidotnet/main/run/Jedi.Math.Evaluation.ValueNodes.pas,v $', '$Revision: 1.1 $', '$Date: 2005/08/22 17:27:08 $')] ImmediateExpressionNode = class (ExpressionNode) {$REGION 'Constructors'} public constructor Create(value: Double); {$ENDREGION} {$REGION 'Data'} strict private FValue: Double; {$ENDREGION} {$REGION 'Overrides'} public function Execute: Double; override; function get_Literal: string; override; function get_Precedence: Integer; override; {$ENDREGION} end; {$ENDREGION} {$REGION 'Constant expression node'} type [JediSourceInfo( '$Source: /cvsroot/jedidotnet/main/run/Jedi.Math.Evaluation.ValueNodes.pas,v $', '$Revision: 1.1 $', '$Date: 2005/08/22 17:27:08 $')] ConstantExpressionNode = class (SymbolExpressionNode) {$REGION 'Constructors'} public constructor Create(constant: Constant); {$ENDREGION} {$REGION 'Overrides'} public function Execute: Double; override; {$ENDREGION} {$REGION 'Property accessors'} public function get_Constant: Constant; {$ENDREGION} {$REGION 'Properties'} public property Constant: Constant read get_Constant; {$ENDREGION} end; {$ENDREGION} {$REGION 'Function expression node'} type [JediSourceInfo( '$Source: /cvsroot/jedidotnet/main/run/Jedi.Math.Evaluation.ValueNodes.pas,v $', '$Revision: 1.1 $', '$Date: 2005/08/22 17:27:08 $')] FunctionExpressionNode = class (SymbolExpressionNode) {$REGION 'Constructors'} public constructor Create(&function: &Function; args: array of ExpressionNode); {$ENDREGION} {$REGION 'Overrides'} public function Execute: Double; override; {$ENDREGION} {$REGION 'Property accessors'} public function get_Function: &Function; {$ENDREGION} {$REGION 'Properties'} public property &Function: &Function read get_Function; {$ENDREGION} end; {$ENDREGION} {$REGION 'Variable expression node'} type [JediSourceInfo( '$Source: /cvsroot/jedidotnet/main/run/Jedi.Math.Evaluation.ValueNodes.pas,v $', '$Revision: 1.1 $', '$Date: 2005/08/22 17:27:08 $')] VariableExpressionNode = class (SymbolExpressionNode) {$REGION 'Constructors'} public constructor Create(variable: Variable); {$ENDREGION} {$REGION 'Overrides'} public function Execute: Double; override; {$ENDREGION} {$REGION 'Property accessors'} public function get_Variable: Variable; {$ENDREGION} {$REGION 'Properties'} public property Variable: Variable read get_Variable; {$ENDREGION} end; {$ENDREGION} implementation {$AUTOBOX ON} {$REGION 'ConstantExpressionNode'} constructor ConstantExpressionNode.Create(constant: Constant); begin inherited Create(constant); end; function ConstantExpressionNode.Execute: Double; begin Result := Jedi.Math.Evaluation.Base.Constant(Symbol).Value; end; function ConstantExpressionNode.get_Constant: Constant; begin Result := Jedi.Math.Evaluation.Base.Constant(Symbol); end; {$ENDREGION} {$REGION 'FunctionExpressionNode'} constructor FunctionExpressionNode.Create(&function: &Function; args: array of ExpressionNode); var node: ExpressionNode; begin inherited Create(&function); for node in args do Add(node); end; function FunctionExpressionNode.Execute: Double; var evaluatedArgs: ArrayList; node: &Object; begin evaluatedArgs := ArrayList.Create(ChildNodes.Count); for node in ChildNodes do evaluatedArgs.Add(ExpressionNode(node).Execute); Result := Jedi.Math.Evaluation.Base.Function(Symbol).Evaluate(evaluatedArgs.ToArray); end; function FunctionExpressionNode.get_Function: &Function; begin Result := Jedi.Math.Evaluation.Base.Function(Symbol); end; {$ENDREGION} {$REGION 'ImmediateExpressionNode'} constructor ImmediateExpressionNode.Create(value: Double); begin inherited Create(ExpressionNodeArray.Create()); FValue := value; end; function ImmediateExpressionNode.Execute: Double; begin Result := FValue; end; function ImmediateExpressionNode.get_Literal: string; begin Result := FValue.ToString; end; function ImmediateExpressionNode.get_Precedence: Integer; begin Result := 0; end; {$ENDREGION} {$REGION 'SymbolExpressionNode'} constructor SymbolExpressionNode.Create(symbol: Symbol); begin inherited Create(ExpressionNodeArray.Create()); FSymbol := symbol; end; function SymbolExpressionNode.get_Literal: string; begin Result := FSymbol.Name; end; function SymbolExpressionNode.get_Precedence: Integer; begin Result := 0; end; {$ENDREGION} {$REGION 'VariableExpressionNode'} constructor VariableExpressionNode.Create(variable: Variable); begin inherited Create(variable); end; function VariableExpressionNode.Execute: Double; begin Result := Jedi.Math.Evaluation.Base.Variable(Symbol).Value; end; function VariableExpressionNode.get_Variable: Variable; begin Result := Jedi.Math.Evaluation.Base.Variable(Symbol); end; {$ENDREGION} end. --- NEW FILE: Jedi.Math.Resources.pas --- {--------------------------------------------------------------------------------------------------- The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.mozilla.org/MPL/MPL-1.1.html Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for the specific language governing rights and limitations under the License. The Original Code is: Jedi.Math.Resources.pas, released on --. The Initial Developer of the Original Code is Marcel Bestebroer Portions created by Marcel Bestebroer are Copyright (C) 2004 Marcel Bestebroer All Rights Reserved. Contributor(s): You may retrieve the latest version of this file at the JEDI.NET home page, located at http://sf.net/projects/jedidotnet Known Issues: ---------------------------------------------------------------------------------------------------} // $Id: Jedi.Math.Resources.pas,v 1.1 2005/08/22 17:27:08 jedi_mbe Exp $ unit Jedi.Math.Resources; interface {$REGION 'uses'} uses Jedi.System.SourceVersioning, Jedi.Text.Tokenization.Base, System.Globalization, System.Resources; {$ENDREGION} {$REGION 'Helper types'} type ObjectArray = array of &Object; {$ENDREGION} {$REGION 'Jedi.Math resources'} type [JediSourceInfo( '$Source: /cvsroot/jedidotnet/main/run/Jedi.Math.Resources.pas,v $', '$Revision: 1.1 $', '$Date: 2005/08/22 17:27:08 $')] Resources = class abstract (&Object) {$REGION 'Constructors'} strict private class constructor Create; strict protected constructor Create; {$ENDREGION} {$REGION 'Data'} strict private class var rm: ResourceManager; {$ENDREGION} {$REGION 'Basic string retrieval'} public class function GetResourceString(id: string): string; overload; static; class function GetResourceString(culture: CultureInfo; id: string): string; overload; static; class function GetResourceString(id: string; arg0: &Object): string; overload; static; class function GetResourceString(culture: CultureInfo; id: string; arg0: &Object): string; overload; static; class function GetResourceString(id: string; arg0, arg1: &Object): string; overload; static; class function GetResourceString(culture: CultureInfo; id: string; arg0, arg1: &Object): string; overload; static; class function GetResourceString(id: string; arg0, arg1, arg2: &Object): string; overload; static; class function GetResourceString(culture: CultureInfo; id: string; arg0, arg1, arg2: &Object): string; overload; static; class function GetResourceString(id: string; args: ObjectArray): string; overload; static; class function GetResourceString(culture: CultureInfo; id: string; args: ObjectArray): string; overload; static; {$ENDREGION} {$REGION 'Helper methods'} strict protected class function ParserExpectedMsg(culture: CultureInfo; currentToken: IToken; expectedId: string; args: ObjectArray): string; static; {$ENDREGION} {$REGION 'Parser exception messages'} public class function ParserExpectedClosingParenthesis(currentToken, openParenthesis: IToken): string; overload; static; class function ParserExpectedClosingParenthesis(culture: CultureInfo; currentToken, openParenthesis: IToken): string; overload; static; class function ParserExpectedConditionalValueSeparator(currentToken: IToken): string; overload; static; class function ParserExpectedConditionalValueSeparator(culture: CultureInfo; currentToken: IToken): string; overload; static; class function ParserExpectedArgumentSeparator(currentToken: IToken): string; overload; static; class function ParserExpectedArgumentSeparator(culture: CultureInfo; currentToken: IToken): string; overload; static; class function ParserExpectedPrimary(currentToken: IToken): string; overload; static; class function ParserExpectedPrimary(culture: CultureInfo; currentToken: IToken): string; overload; static; class function ParserUnknownIdentifier(currentToken: IToken): string; overload; static; class function ParserUnknownIdentifier(culture: CultureInfo; currentToken: IToken): string; overload; static; {$ENDREGION} end; {$ENDREGION} implementation {$AUTOBOX ON} {$REGION 'Resources'} class constructor Resources.Create; begin rm := ResourceManager.Create('Jedi.Math', TypeOf(Resources).Assembly); end; constructor Resources.Create; begin inherited Create; end; class function Resources.GetResourceString(id: string): string; begin Result := GetResourceString(CultureInfo.CurrentCulture, id); end; class function Resources.GetResourceString(culture: CultureInfo; id: string): string; begin Result := rm.GetString(id, culture); end; class function Resources.GetResourceString(id: string; arg0: &Object): string; begin Result := System.String.Format(GetResourceString(CultureInfo.CurrentCulture, id), arg0); end; class function Resources.GetResourceString(culture: CultureInfo; id: string; arg0: &Object): string; begin Result := System.String.Format(GetResourceString(culture, id), arg0); end; class function Resources.GetResourceString(id: string; arg0, arg1: &Object): string; begin Result := System.String.Format(GetResourceString(CultureInfo.CurrentCulture, id), arg0, arg1); end; class function Resources.GetResourceString(culture: CultureInfo; id: string; arg0, arg1: &Object): string; begin Result := System.String.Format(GetResourceString(culture, id), arg0, arg1); end; class function Resources.GetResourceString(id: string; arg0, arg1, arg2: &Object): string; begin Result := System.String.Format(GetResourceString(CultureInfo.CurrentCulture, id), arg0, arg1, arg2); end; class function Resources.GetResourceString(culture: CultureInfo; id: string; arg0, arg1, arg2: &Object): string; begin Result := System.String.Format(GetResourceString(culture, id), arg0, arg1, arg2); end; class function Resources.GetResourceString(id: string; args: array of &Object): string; begin Result := System.String.Format(GetResourceString(CultureInfo.CurrentCulture, id), args); end; class function Resources.GetResourceString(culture: CultureInfo; id: string; args: array of &Object): string; begin Result := System.String.Format(GetResourceString(culture, id), args); end; class function Resources.ParserExpectedClosingParenthesis(currentToken, openParenthesis: IToken): string; begin Result := ParserExpectedClosingParenthesis(CultureInfo.CurrentCulture, currentToken, openParenthesis); end; class function Resources.ParserExpectedClosingParenthesis(culture: CultureInfo; currentToken, openParenthesis: IToken): string; begin Result := GetResourceString(culture, 'ParserExpBase', GetResourceString(culture, 'ParserExpClosePar', openParenthesis.Line, openParenthesis.Column), currentToken.Line, currentToken.Column) end; class function Resources.ParserExpectedConditionalValueSeparator(currentToken: IToken): string; begin Result := ParserExpectedConditionalValueSeparator(CultureInfo.CurrentCulture, currentToken); end; class function Resources.ParserExpectedConditionalValueSeparator(culture: CultureInfo; currentToken: IToken): string; begin Result := ParserExpectedMsg(culture, currentToken, 'ParserExpCondValueSep', nil); end; class function Resources.ParserExpectedArgumentSeparator(currentToken: IToken): string; begin Result := ParserExpectedArgumentSeparator(CultureInfo.CurrentCulture, currentToken); end; class function Resources.ParserExpectedArgumentSeparator(culture: CultureInfo; currentToken: IToken): string; begin Result := ParserExpectedMsg(culture, currentToken, 'parserExpArgSep', nil); end; class function Resources.ParserExpectedMsg(culture: CultureInfo; currentToken: IToken; expectedId: string; args: ObjectArray): string; begin if currentToken <> nil then Result := GetResourceString(culture, 'ParserExpBase', GetResourceString(culture, expectedId, args), currentToken.Line, currentToken.Column) else Result := GetResourceString(culture, 'ParserExpBase', GetResourceString(culture, expectedId, args), '?', '?'); end; class function Resources.ParserExpectedPrimary(currentToken: IToken): string; begin Result := ParserExpectedPrimary(CultureInfo.CurrentCulture, currentToken); end; class function Resources.ParserExpectedPrimary(culture: CultureInfo; currentToken: IToken): string; begin Result := ParserExpectedMsg(culture, currentToken, 'ParserExpPrimary', nil); end; class function Resources.ParserUnknownIdentifier(currentToken: IToken): string; begin Result := ParserUnknownIdentifier(CultureInfo.InvariantCulture, currentToken); end; class function Resources.ParserUnknownIdentifier(culture: CultureInfo; currentToken: IToken): string; begin Result := GetResourceString(culture, 'ParserUnknownIdent', currentToken.Literal, currentToken.Line, currentToken.Column); end; {$ENDREGION} end. --- NEW FILE: Jedi.Math.Evaluation.BinaryNodes.pas --- {--------------------------------------------------------------------------------------------------- The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.mozilla.org/MPL/MPL-1.1.html Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for the specific language governing rights and limitations under the License. The Original Code is: Jedi.Math.Evaluation.BinaryNodes.pas, released on --. The Initial Developer of the Original Code is Marcel Bestebroer Portions created by Marcel Bestebroer are Copyright (C) 2004 Marcel Bestebroer All Rights Reserved. Contributor(s): You may retrieve the latest version of this file at the JEDI.NET home page, located at http://sf.net/projects/jedidotnet [...979 lines suppressed...] end; function XorExpressionNode.get_Literal: string; begin Result := '^'; end; function XorExpressionNode.Execute: Double; var boolState: Boolean; node: ExpressionNode; begin boolState := False; for node in ChildNodes do boolState := boolState xor (node.Execute <> 0); Result := LogicalExpressionNode.MakeLogical(boolState); end; {$ENDREGION} end. --- NEW FILE: Jedi.Math.Evaluation.TenaryNodes.pas --- {--------------------------------------------------------------------------------------------------- The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.mozilla.org/MPL/MPL-1.1.html Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for the specific language governing rights and limitations under the License. The Original Code is: Jedi.Math.Evaluation.TenaryNodes.pas, released on --. The Initial Developer of the Original Code is Marcel Bestebroer Portions created by Marcel Bestebroer are Copyright (C) 2004 Marcel Bestebroer All Rights Reserved. Contributor(s): You may retrieve the latest version of this file at the JEDI.NET home page, located at http://sf.net/projects/jedidotnet Known Issues: ---------------------------------------------------------------------------------------------------} // $Id: Jedi.Math.Evaluation.TenaryNodes.pas,v 1.1 2005/08/22 17:27:08 jedi_mbe Exp $ unit Jedi.Math.Evaluation.TenaryNodes; interface {$REGION 'uses'} uses Jedi.Math.Evaluation.Base, Jedi.Math.Evaluation.CompilingProcessor, Jedi.System.SourceVersioning; {$ENDREGION} {$REGION 'Condition expression node'} type [JediSourceInfo( '$Source: /cvsroot/jedidotnet/main/run/Jedi.Math.Evaluation.TenaryNodes.pas,v $', '$Revision: 1.1 $', '$Date: 2005/08/22 17:27:08 $')] ConditionExpressionNode = class (ExpressionNode) {$REGION 'Constructors'} public constructor Create(condition: ExpressionNode); {$ENDREGION} {$REGION 'Overrides'} public function get_IsLeftAssociative: Boolean; override; function get_Literal: string; override; function get_Precedence: Integer; override; function Execute: Double; override; {$ENDREGION} {$REGION 'Property accessors'} public function get_Condition: ExpressionNode; function get_False: ExpressionNode; function get_True: ExpressionNode; {$ENDREGION} {$REGION 'Properties'} public property Condition: ExpressionNode read get_Condition; property &False: ExpressionNode read get_False; property &True: ExpressionNode read get_True; {$ENDREGION} end; {$ENDREGION} implementation {$REGION 'ConditionExpressionNode'} constructor ConditionExpressionNode.Create(condition: ExpressionNode); begin inherited Create(ExpressionNodeArray.Create(condition)); end; function ConditionExpressionNode.Execute: Double; begin if Condition.Execute <> 0 then Result := True.Execute else Result := False.Execute; end; function ConditionExpressionNode.get_Condition: ExpressionNode; begin Result := ExpressionNode(ChildNodes[0]); end; function ConditionExpressionNode.get_False: ExpressionNode; begin Result := ExpressionNode(ChildNodes[2]); end; function ConditionExpressionNode.get_IsLeftAssociative: Boolean; begin Result := Borland.Delphi.System.False; end; function ConditionExpressionNode.get_Literal: string; begin Result := '?'; end; function ConditionExpressionNode.get_Precedence: Integer; begin Result := 8; end; function ConditionExpressionNode.get_True: ExpressionNode; begin Result := ExpressionNode(ChildNodes[1]); end; {$ENDREGION} end. --- NEW FILE: Jedi.Math.Evaluation.Namespaces.Generic.pas --- (This appears to be a binary file; contents omitted.) --- NEW FILE: Jedi.Math.Evaluation.UnaryNodes.pas --- {--------------------------------------------------------------------------------------------------- The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.mozilla.org/MPL/MPL-1.1.html Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for the specific language governing rights and limitations under the License. The Original Code is: Jedi.Math.Evaluation.UnaryNodes.pas, released on --. The Initial Developer of the Original Code is Marcel Bestebroer Portions created by Marcel Bestebroer are Copyright (C) 2004 Marcel Bestebroer All Rights Reserved. Contributor(s): You may retrieve the latest version of this file at the JEDI.NET home page, located at http://sf.net/projects/jedidotnet Known Issues: ---------------------------------------------------------------------------------------------------} // $Id: Jedi.Math.Evaluation.UnaryNodes.pas,v 1.1 2005/08/22 17:27:08 jedi_mbe Exp $ unit Jedi.Math.Evaluation.UnaryNodes; interface {$REGION 'uses'} uses Jedi.Math.Evaluation.Base, Jedi.Math.Evaluation.BinaryNodes, Jedi.Math.Evaluation.CompilingProcessor, Jedi.System.SourceVersioning; {$ENDREGION} {$REGION 'Unary expression node'} type [JediSourceInfo( '$Source: /cvsroot/jedidotnet/main/run/Jedi.Math.Evaluation.UnaryNodes.pas,v $', '$Revision: 1.1 $', '$Date: 2005/08/22 17:27:08 $')] UnaryExpressionNode = class abstract (ExpressionNode) {$REGION 'Constructors'} strict protected constructor Create(operand: ExpressionNode); {$ENDREGION} end; {$ENDREGION} {$REGION 'Logical negate expression node'} type [JediSourceInfo( '$Source: /cvsroot/jedidotnet/main/run/Jedi.Math.Evaluation.UnaryNodes.pas,v $', '$Revision: 1.1 $', '$Date: 2005/08/22 17:27:08 $')] LogicalNegateExpressionNode = class (UnaryExpressionNode) {$REGION 'Constructors'} public constructor Create(operand: ExpressionNode); {$ENDREGION} {$REGION 'Overrides'} public function Execute: Double; override; function get_Literal: string; override; function get_Precedence: Integer; override; {$ENDREGION} end; {$ENDREGION} {$REGION 'Negate expression node'} type [JediSourceInfo( '$Source: /cvsroot/jedidotnet/main/run/Jedi.Math.Evaluation.UnaryNodes.pas,v $', '$Revision: 1.1 $', '$Date: 2005/08/22 17:27:08 $')] NegateExpressionNode = class (UnaryExpressionNode) {$REGION 'Constructors'} public constructor Create(operand: ExpressionNode); {$ENDREGION} {$REGION 'Overrides'} public function Execute: Double; override; function get_Literal: string; override; function get_Precedence: Integer; override; {$ENDREGION} end; {$ENDREGION} implementation {$REGION 'LogicalNegateExpressionNode'} constructor LogicalNegateExpressionNode.Create(operand: ExpressionNode); begin inherited Create(operand); end; function LogicalNegateExpressionNode.Execute: Double; begin Result := LogicalExpressionNode.MakeLogical(ExpressionNode(ChildNodes[0]).Execute = 0); end; function LogicalNegateExpressionNode.get_Literal: string; begin Result := '!'; end; function LogicalNegateExpressionNode.get_Precedence: Integer; begin Result := 1; end; {$ENDREGION} {$REGION 'NegateExpressionNode'} constructor NegateExpressionNode.Create(operand: ExpressionNode); begin inherited Create(operand); end; function NegateExpressionNode.Execute: Double; begin Result := -ExpressionNode(ChildNodes[0]).Execute; end; function NegateExpressionNode.get_Literal: string; begin Result := '-'; end; function NegateExpressionNode.get_Precedence: Integer; begin Result := 1; end; {$ENDREGION} {$REGION 'UnaryExpressionNode'} constructor UnaryExpressionNode.Create(operand: ExpressionNode); begin inherited Create(ExpressionNodeArray.Create(operand)); end; {$ENDREGION} end. --- NEW FILE: Jedi.Math.Evaluation.Base.pas --- {--------------------------------------------------------------------------------------------------- The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.mozilla.org/MPL/MPL-1.1.html Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for the specific language governing rights and limitations under the License. The Original Code is: Jedi.Math.Evaluation.Base.pas, released on --. The Initial Developer of the Original Code is Marcel Bestebroer Portions created by Marcel Bestebroer are Copyright (C) 2004 Marcel Bestebroer All Rights Reserved. Contributor(s): You may retrieve the latest version of this file at the JEDI.NET home page, located at http://sf.net/projects/jedidotnet [...1330 lines suppressed...] FName := name; end; function Variable.get_Name: string; begin Result := FName; end; function Variable.get_Namespace: Namespace; begin Result := FNamespace; end; procedure Variable.SetNamespace(ns: Namespace); begin FNamespace := ns; end; {$ENDREGION} end. --- NEW FILE: Jedi.Math.Evaluation.Tokens.pas --- {--------------------------------------------------------------------------------------------------- The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.mozilla.org/MPL/MPL-1.1.html Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for the specific language governing rights and limitations under the License. The Original Code is: Jedi.Math.Evaluation.Tokens.pas, released on --. The Initial Developer of the Original Code is Marcel Bestebroer Portions created by Marcel Bestebroer are Copyright (C) 2004 Marcel Bestebroer All Rights Reserved. Contributor(s): You may retrieve the latest version of this file at the JEDI.NET home page, located at http://sf.net/projects/jedidotnet [...1549 lines suppressed...] end; class function XorToken.CheckAndCreate(tokenizer: ITokenizer; out usedLength: Integer): IToken; begin if tokenizer.CurrentLine.StartsWith('^') then begin usedLength := 1; Result := XorToken.Create(tokenizer); end else Result := nil; end; function XorToken.Literal: string; begin Result := '^'; end; {$ENDREGION} end. --- NEW FILE: Jedi.Math.Evaluation.EvalProcessor.pas --- {--------------------------------------------------------------------------------------------------- The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.mozilla.org/MPL/MPL-1.1.html Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for the specific language governing rights and limitations under the License. The Original Code is: Jedi.Math.Evaluation.EvalProcessor.pas, released on --. The Initial Developer of the Original Code is Marcel Bestebroer Portions created by Marcel Bestebroer are Copyright (C) 2004 Marcel Bestebroer All Rights Reserved. Contributor(s): You may retrieve the latest version of this file at the JEDI.NET home page, located at http://sf.net/projects/jedidotnet Known Issues: ---------------------------------------------------------------------------------------------------} // $Id: Jedi.Math.Evaluation.EvalProcessor.pas,v 1.1 2005/08/22 17:27:08 jedi_mbe Exp $ unit Jedi.Math.Evaluation.EvalProcessor; interface {$REGION 'uses'} uses Jedi.Math.Evaluation.Base, Jedi.System.SourceVersioning; {$ENDREGION} {$REGION 'Evaluating processor'} type [JediSourceInfo( '$Source: /cvsroot/jedidotnet/main/run/Jedi.Math.Evaluation.EvalProcessor.pas,v $', '$Revision: 1.1 $', '$Date: 2005/08/22 17:27:08 $')] EvaluatingProcessor = class (ExpressionProcessor) {$REGION 'Constructors'} strict protected constructor Create; {$ENDREGION} {$REGION 'Data'} strict private class var FDefault: EvaluatingProcessor; {$ENDREGION} {$REGION 'Overrides'} protected function Add(left, right: &Object): &Object; override; function CallFunction(func: &Function; args: ObjectArray): &Object; override; function Divide(left, right: &Object): &Object; override; function Equal(left, right: &Object): &Object; override; function GreaterThan(left, right: &Object): &Object; override; function GreaterThanOrEqual(left, right: &Object): &Object; override; function LeftShift(left, right: &Object): &Object; override; function LessThan(left, right: &Object): &Object; override; function LessThanOrEqual(left, right: &Object): &Object; override; function LoadConstant(&const: Constant): &Object; override; function LoadImmediate(value: Double): &Object; override; function LoadVariable(&var: Variable): &Object; override; function LogicalAnd(left, right: &Object; conditional: Boolean): &Object; override; function LogicalNot(operand: &Object): &Object; override; function LogicalOr(left, right: &Object; conditional: Boolean): &Object; override; function LogicalXor(left, right: &Object): &Object; override; function Multiply(left, right: &Object): &Object; override; function Negate(operand: &Object): &Object; override; function NotEqual(left, right: &Object): &Object; override; function ProcessConditional(condition: &Object; out skipTrue, skipFalse: Boolean): &Object; override; function ProcessConditionalFalseValue(conditional: &Object; value: &Object): &Object; override; function ProcessConditionalTrueValue(conditional: &Object; value: &Object): &Object; override; function RightShift(left, right: &Object): &Object; override; function SkipLogicalAnd(current: &Object): Boolean; override; function SkipLogicalOr(current: &Object): Boolean; override; function Subtract(left, right: &Object): &Object; override; {$ENDREGION} {$REGION 'Static methods'} public class function Default: ExpressionProcessor; static; {$ENDREGION} end; {$ENDREGION} implementation {$AUTOBOX ON} {$REGION 'EvaluatingProcessor'} constructor EvaluatingProcessor.Create; begin inherited Create; end; function EvaluatingProcessor.Add(left, right: &Object): &Object; begin Result := Double(left) + Double(right); end; function EvaluatingProcessor.CallFunction(func: &Function; args: ObjectArray): &Object; begin Result := func.Evaluate(args); end; class function EvaluatingProcessor.Default: ExpressionProcessor; begin if FDefault = nil then FDefault := EvaluatingProcessor.Create; Result := FDefault; end; function EvaluatingProcessor.Divide(left, right: &Object): &Object; begin Result := Double(left) / Double(right); end; function EvaluatingProcessor.Equal(left, right: &Object): &Object; begin if Double(left) = Double(right) then Result := 1.0 else Result := 0.0; end; function EvaluatingProcessor.GreaterThan(left, right: &Object): &Object; begin if Double(left) > Double(right) then Result := 1.0 else Result := 0.0; end; function EvaluatingProcessor.GreaterThanOrEqual(left, right: &Object): &Object; begin if Double(left) >= Double(right) then Result := 1.0 else Result := 0.0; end; function EvaluatingProcessor.LeftShift(left, right: &Object): &Object; begin Result := System.Convert.ToDouble(Trunc(Double(left)) shl Trunc(Double(right))); end; function EvaluatingProcessor.LessThan(left, right: &Object): &Object; begin if Double(left) < Double(right) then Result := 1.0 else Result := 0.0; end; function EvaluatingProcessor.LessThanOrEqual(left, right: &Object): &Object; begin if Double(left) <= Double(right) then Result := 1.0 else Result := 0.0; end; function EvaluatingProcessor.LoadConstant(&const: Constant): &Object; begin Result := Double(&const.Value); end; function EvaluatingProcessor.LoadImmediate(value: Double): &Object; begin Result := value; end; function EvaluatingProcessor.LoadVariable(&var: Variable): &Object; begin Result := &Double(&var.Value); end; function EvaluatingProcessor.LogicalAnd(left, right: &Object; conditional: Boolean): &Object; begin if (Double(left) <> 0) and (Double(right) <> 0) then Result := 1.0 else Result := 0.0; end; function EvaluatingProcessor.LogicalNot(operand: &Object): &Object; begin if Double(operand) = 0 then Result := 1.0 else Result := 0.0; end; function EvaluatingProcessor.LogicalOr(left, right: &Object; conditional: Boolean): &Object; begin if (Double(left) <> 0) or (Double(right) <> 0) then Result := 1.0 else Result := 0.0; end; function EvaluatingProcessor.LogicalXor(left, right: &Object): &Object; begin if (Double(left) <> 0) xor (Double(right) <> 0) then Result := 1.0 else Result := 0.0; end; function EvaluatingProcessor.Multiply(left, right: &Object): &Object; begin Result := Double(left) * Double(right); end; function EvaluatingProcessor.Negate(operand: &Object): &Object; begin Result := -Double(operand); end; function EvaluatingProcessor.NotEqual(left, right: &Object): &Object; begin if Double(left) <> Double(right) then Result := 1.0 else Result := 0.0; end; function EvaluatingProcessor.ProcessConditional(condition: &Object; out skipTrue, skipFalse: Boolean): &Object; begin skipTrue := Double(condition) = 0; skipFalse := not skipTrue; Result := condition; end; function EvaluatingProcessor.ProcessConditionalFalseValue(conditional: &Object; value: &Object): &Object; begin Result := value; end; function EvaluatingProcessor.ProcessConditionalTrueValue(conditional: &Object; value: &Object): &Object; begin Result := value; end; function EvaluatingProcessor.RightShift(left, right: &Object): &Object; begin Result := System.Convert.ToDouble(Trunc(Double(left)) shr Trunc(Double(right))); end; function EvaluatingProcessor.SkipLogicalAnd(current: &Object): Boolean; begin Result := Double(current) = 0; end; function EvaluatingProcessor.SkipLogicalOr(current: &Object): Boolean; begin Result := Double(current) <> 0; end; function EvaluatingProcessor.Subtract(left, right: &Object): &Object; begin Result := Double(left) - Double(right); end; {$ENDREGION} end. --- NEW FILE: Jedi.Math.Evaluation.CompilingProcessor.pas --- {--------------------------------------------------------------------------------------------------- The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.mozilla.org/MPL/MPL-1.1.html Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for the specific language governing rights and limitations under the License. The Original Code is: Jedi.Math.Evaluation.CompilingProcessor.pas, released on --. The Initial Developer of the Original Code is Marcel Bestebroer Portions created by Marcel Bestebroer are Copyright (C) 2004 Marcel Bestebroer All Rights Reserved. Contributor(s): You may retrieve the latest version of this file at the JEDI.NET home page, located at http://sf.net/projects/jedidotnet Known Issues: ---------------------------------------------------------------------------------------------------} // $Id: Jedi.Math.Evaluation.CompilingProcessor.pas,v 1.1 2005/08/22 17:27:08 jedi_mbe Exp $ unit Jedi.Math.Evaluation.CompilingProcessor; interface {$REGION 'uses'} uses Jedi.Math.Evaluation.Base, Jedi.System.SourceVersioning, System.Collections; {$ENDREGION} {$REGION 'Compiling processor'} type [JediSourceInfo( '$Source: /cvsroot/jedidotnet/main/run/Jedi.Math.Evaluation.CompilingProcessor.pas,v $', '$Revision: 1.1 $', '$Date: 2005/08/22 17:27:08 $')] CompilingProcessor = class (ExpressionProcessor) {$REGION 'Constructors'} strict protected constructor Create; {$ENDREGION} {$REGION 'Data'} strict private class var FDefault: CompilingProcessor; {$ENDREGION} {$REGION 'Overrides'} protected function Add(left, right: &Object): &Object; override; function CallFunction(func: &Function; args: ObjectArray): &Object; override; function Divide(left, right: &Object): &Object; override; function Equal(left, right: &Object): &Object; override; function GreaterThan(left, right: &Object): &Object; override; function GreaterThanOrEqual(left, right: &Object): &Object; override; function LeftShift(left, right: &Object): &Object; override; function LessThan(left, right: &Object): &Object; override; function LessThanOrEqual(left, right: &Object): &Object; override; function LoadConstant(&const: Constant): &Object; override; function LoadImmediate(value: Double): &Object; override; function LoadVariable(&var: Variable): &Object; override; function LogicalAnd(left, right: &Object; conditional: Boolean): &Object; override; function LogicalNot(operand: &Object): &Object; override; function LogicalOr(left, right: &Object; conditional: Boolean): &Object; override; function LogicalXor(left, right: &Object): &Object; override; function Multiply(left, right: &Object): &Object; override; function Negate(operand: &Object): &Object; override; function NotEqual(left, right: &Object): &Object; override; function ProcessConditional(condition: &Object; out skipTrue, skipFalse: Boolean): &Object; override; function ProcessConditionalFalseValue(conditional: &Object; value: &Object): &Object; override; function ProcessConditionalTrueValue(conditional: &Object; value: &Object): &Object; override; function RightShift(left, right: &Object): &Object; override; function SkipLogicalAnd(current: &Object): Boolean; override; function SkipLogicalOr(current: &Object): Boolean; override; function Subtract(left, right: &Object): &Object; override; {$ENDREGION} {$REGION 'Static methods'} public class function Default: ExpressionProcessor; static; {$ENDREGION} end; {$ENDREGION} {$REGION 'Expression node'} type ExpressionNode = class; ExpressionNodeArray = array of ExpressionNode; [JediSourceInfo( '$Source: /cvsroot/jedidotnet/main/run/Jedi.Math.Evaluation.CompilingProcessor.pas,v $', '$Revision: 1.1 $', '$Date: 2005/08/22 17:27:08 $')] ExpressionNode = class abstract (&Object) {$REGION 'Constructors'} strict protected constructor Create(nodes: ExpressionNodeArray); {$ENDREGION} {$REGION 'Data'} strict private FChildNodes: IList; {$ENDREGION} {$REGION 'Public methods'} public procedure Add(value: ExpressionNode); function Execute: Double; virtual; abstract; procedure Remove(value: ExpressionNode); procedure RemoveAt(index: Integer); {$ENDREGION} {$REGION 'Property accessors'} public function get_Count: Integer; function get_IsLeftAssociative: Boolean; virtual; function get_Literal: string; virtual; abstract; function get_Nodes(index: Integer): ExpressionNode; function get_Precedence: Integer; virtual; abstract; {$ENDREGION} {$REGION 'Properties'} strict protected property ChildNodes: IList read FChildNodes write FChildNodes; public property Count: Integer read get_Count; property IsLeftAssociative: Boolean read get_IsLeftAssociative; property Literal: string read get_Literal; property Nodes[&index: Integer]: ExpressionNode read get_Nodes; default; property Precedence: Integer read get_Precedence; {$ENDREGION} end; {$ENDREGION} implementation {$AUTOBOX ON} {$REGION 'internal uses'} uses Jedi.Math.Evaluation.BinaryNodes, Jedi.Math.Evaluation.TenaryNodes, Jedi.Math.Evaluation.UnaryNodes, Jedi.Math.Evaluation.ValueNodes; {$ENDREGION} {$REGION 'CompilingProcessor'} constructor CompilingProcessor.Create; begin inherited Create; end; function CompilingProcessor.Add(left, right: &Object): &Object; begin Result := AddExpressionNode.Create(ExpressionNode(left), ExpressionNode(right)); end; function CompilingProcessor.CallFunction(func: &Function; args: ObjectArray): &Object; var nodes: array of ExpressionNode; begin nodes := new (ExpressionNodeArray, Length(args)); &Array.Copy(args, nodes, Length(args)); Result := FunctionExpressionNode.Create(func, nodes); end; class function CompilingProcessor.Default: ExpressionProcessor; begin if FDefault = nil then FDefault := CompilingProcessor.Create; Result := FDefault; end; function CompilingProcessor.Divide(left, right: &Object): &Object; begin Result := DivideExpressionNode.Create(ExpressionNode(left), ExpressionNode(right)); end; function CompilingProcessor.Equal(left, right: &Object): &Object; begin Result := EqualExpressionNode.Create(ExpressionNode(left), ExpressionNode(right)); end; function CompilingProcessor.GreaterThan(left, right: &Object): &Object; begin Result := GreaterThanExpressionNode.Create(ExpressionNode(left), ExpressionNode(right)); end; function CompilingProcessor.GreaterThanOrEqual(left, right: &Object): &Object; begin Result := GreaterThanOrEqualExpressionNode.Create(ExpressionNode(left), ExpressionNode(right)); end; function CompilingProcessor.LeftShift(left, right: &Object): &Object; begin Result := LeftShiftExpressionNode.Create(ExpressionNode(left), ExpressionNode(right)); end; function CompilingProcessor.LessThan(left, right: &Object): &Object; begin Result := LessThanExpressionNode.Create(ExpressionNode(left), ExpressionNode(right)); end; function CompilingProcessor.LessThanOrEqual(left, right: &Object): &Object; begin Result := LessThanOrEqualExpressionNode.Create(ExpressionNode(left), ExpressionNode(right)); end; function CompilingProcessor.LoadConstant(&const: Constant): &Object; begin Result := ConstantExpressionNode.Create(&const); end; function CompilingProcessor.LoadImmediate(value: Double): &Object; begin Result := ImmediateExpressionNode.Create(value); end; function CompilingProcessor.LoadVariable(&var: Variable): &Object; begin Result := VariableExpressionNode.Create(&var); end; function CompilingProcessor.LogicalAnd(left, right: &Object; conditional: Boolean): &Object; begin if not conditional then Result := AndExpressionNode.Create(ExpressionNode(left), ExpressionNode(right)) else Result := ConditionalAndExpressionNode.Create(ExpressionNode(left), ExpressionNode(right)); end; function CompilingProcessor.LogicalNot(operand: &Object): &Object; begin Result := LogicalNegateExpressionNode.Create(ExpressionNode(operand)); end; function CompilingProcessor.LogicalOr(left, right: &Object; conditional: Boolean): &Object; begin if not conditional then Result := OrExpressionNode.Create(ExpressionNode(left), ExpressionNode(right)) else Result := ConditionalOrExpressionNode.Create(ExpressionNode(left), ExpressionNode(right)); end; function CompilingProcessor.LogicalXor(left, right: &Object): &Object; begin Result := XorExpressionNode.Create(ExpressionNode(left), ExpressionNode(right)); end; function CompilingProcessor.Multiply(left, right: &Object): &Object; begin Result := MultiplyExpressionNode.Create(ExpressionNode(left), ExpressionNode(right)); end; function CompilingProcessor.Negate(operand: &Object): &Object; begin Result := NegateExpressionNode.Create(ExpressionNode(operand)); end; function CompilingProcessor.NotEqual(left, right: &Object): &Object; begin Result := NotEqualExpressionNode.Create(ExpressionNode(left), ExpressionNode(right)); end; function CompilingProcessor.ProcessConditional(condition: &Object; out skipTrue, skipFalse: Boolean): &Object; begin Result := ConditionExpressionNode.Create(ExpressionNode(condition)); skipTrue := False; skipFalse := False; end; function CompilingProcessor.ProcessConditionalFalseValue(conditional: &Object; value: &Object): &Object; begin Result := conditional; ExpressionNode(Result).Add(ExpressionNode(value)); end; function CompilingProcessor.ProcessConditionalTrueValue(conditional: &Object; value: &Object): &Object; begin Result := conditional; ExpressionNode(Result).Add(ExpressionNode(value)); end; function CompilingProcessor.RightShift(left, right: &Object): &Object; begin Result := RightShiftExpressionNode.Create(ExpressionNode(left), ExpressionNode(right)); end; function CompilingProcessor.SkipLogicalAnd(current: &Object): Boolean; begin Result := False; end; function CompilingProcessor.SkipLogicalOr(current: &Object): Boolean; begin Result := False; end; function CompilingProcessor.Subtract(left, right: &Object): &Object; begin Result := SubtractExpressionNode.Create(ExpressionNode(left), ExpressionNode(right)); end; {$ENDREGION} {$REGION 'ExpressionNode'} constructor ExpressionNode.Create(nodes: ExpressionNodeArray); begin inherited Create; FChildNodes := ArrayList.Create(&Array(nodes)); end; procedure ExpressionNode.Add(value: ExpressionNode); begin FChildNodes.Add(value); end; function ExpressionNode.get_Count: Integer; begin Result := FChildNodes.Count; end; function ExpressionNode.get_IsLeftAssociative: Boolean; begin Result := True; end; function ExpressionNode.get_Nodes(index: Integer): ExpressionNode; begin Result := ExpressionNode(FChildNodes[index]); end; procedure ExpressionNode.Remove(value: ExpressionNode); begin FChildNodes.Remove(value); end; procedure ExpressionNode.RemoveAt(index: Integer); begin FChildNodes.RemoveAt(index); end; {$ENDREGION} end. |