diff --git a/.gitattributes b/.gitattributes index 041e9ee738..88c2ab7de3 100644 --- a/.gitattributes +++ b/.gitattributes @@ -494,6 +494,8 @@ components/codetools/examples/scanexamples/unusedunits1.pas svneol=native#text/p components/codetools/examples/scanexamples/wrongforwarddefinitions.pas svneol=native#text/plain components/codetools/examples/setincludepath.lpi svneol=native#text/plain components/codetools/examples/setincludepath.pas svneol=native#text/plain +components/codetools/examples/testexpreval.lpi svneol=native#text/plain +components/codetools/examples/testexpreval.pas svneol=native#text/plain components/codetools/examples/testscompleteblock/beginwithoutindent1.inc svneol=native#text/plain components/codetools/examples/testscompleteblock/beginwithoutindent1_result1.inc svneol=native#text/plain components/codetools/examples/testscompleteblock/beginwithoutindent1_result2.inc svneol=native#text/plain diff --git a/components/codetools/examples/testexpreval.lpi b/components/codetools/examples/testexpreval.lpi new file mode 100644 index 0000000000..9c74a89bc8 --- /dev/null +++ b/components/codetools/examples/testexpreval.lpi @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + </General> + <PublishOptions> + <Version Value="2"/> + <IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/> + <ExcludeFileFilter Value="*.(bak|ppu|ppw|o|so);*~;backup"/> + </PublishOptions> + <RunParams> + <local> + <FormatVersion Value="1"/> + <LaunchingApplication PathPlusParams="/usr/X11R6/bin/xterm -T 'Lazarus Run Output' -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/> + </local> + </RunParams> + <RequiredPackages Count="2"> + <Item1> + <PackageName Value="LCL"/> + </Item1> + <Item2> + <PackageName Value="CodeTools"/> + </Item2> + </RequiredPackages> + <Units Count="1"> + <Unit0> + <Filename Value="testexpreval.pas"/> + <IsPartOfProject Value="True"/> + <UnitName Value="TestExprEval"/> + </Unit0> + </Units> + </ProjectOptions> + <CompilerOptions> + <Version Value="8"/> + <SearchPaths> + <OtherUnitFiles Value="scanexamples/"/> + </SearchPaths> + <Other> + <CompilerPath Value="$(CompPath)"/> + </Other> + </CompilerOptions> +</CONFIG> diff --git a/components/codetools/examples/testexpreval.pas b/components/codetools/examples/testexpreval.pas new file mode 100644 index 0000000000..5eb2318926 --- /dev/null +++ b/components/codetools/examples/testexpreval.pas @@ -0,0 +1,71 @@ +{ + *************************************************************************** + * * + * This source is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This code is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * General Public License for more details. * + * * + * A copy of the GNU General Public License is available on the World * + * Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also * + * obtain it by writing to the Free Software Foundation, * + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + * * + *************************************************************************** + + Author: Mattias Gaertner + + Abstract: + Demonstrating, how to add a method to a class and extending the uses section. +} +program TestExprEval; + +{$mode objfpc}{$H+} + +uses + Classes, SysUtils, FileProcs, ExprEval; + +var + e: TExpressionEvaluator; + +procedure Test(Expr, ExpectedResult: string); +var + OldResult, NewResult: String; +begin + DebugLn(['Test Expression="',expr,'"']); + OldResult:=e.Eval(Expr); + NewResult:=e.Eval2(Expr); + DebugLn(['Test eval2 OldResult="',OldResult,'" NewResult="',NewResult,'"']); + if NewResult<>ExpectedResult then + DebugLn(['FATAL: Expression="',expr,'" ExpectedResult="',ExpectedResult,'" <> NewResult="',NewResult,'"']); +end; + +begin + e:=TExpressionEvaluator.Create; + e.Variables['A']:='123'; + //Test('defined A','1'); + //Test('defined(A)','1'); + //Test('undefined(A)','0'); + //Test('not undefined(A)','1'); + //Test('not defined A','0'); + //Test('A or B','123'); + //Test('defined(B)','0'); + //Test('B or A','1'); + //Test('defined(B) or defined(A)','1'); + //Test('defined(B) or not defined(A)','0'); + //Test('not defined(B) or not defined(A)','1'); + //Test('not defined(B) or defined(A)','1'); + //Test('1 << 2','4'); + //Test('4 >> 1','2'); + //Test('4 = ''4''','1'); + //Test('(1+1)=2','1'); + //Test('(1+(2+4))=7','1'); + Test('(1+2*3)=7','1'); + e.Free; +end. +