Files
harbour-core/harbour/source/macro/macro.y
Przemyslaw Czerpak 26a11bd859 2009-03-21 16:07 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl)
* harbour/bin/hb-func.sh
    ! restored default optimization flag (-O3) in hb* scripts

  * harbour/harbour.spec
    ! fixed recent modification

  * harbour/contrib/rddads/ads1.c
  * harbour/contrib/rddads/adsfunc.c
  * harbour/contrib/hbmisc/strfmt.c
  * harbour/contrib/hbcrypt/sha1.c
    ! fixed wrongly used C reference operator

  * harbour/contrib/hbwin/win_prn2.c
  * harbour/contrib/hbwin/wapi_commctrl.c
  * harbour/source/vm/maindllp.c
    ! fixes for unicode builds

  * harbour/include/std.ch
    + added SET TIME FORMAT [TO] <f>

  * harbour/include/set.ch
  * harbour/include/hbset.h
  * harbour/source/vm/set.c
    + added _SET_TIMEFORMAT
      The folowing modifiers are supported:
         hh - hours
         mm - minutes
         ss - seconds
         fff - fraction part of seconds
         p - 1-st letter from PM / AM signature. When used time is shown
             in 12 hour format otherwise 24 hour format is used
      ex: Set( __SET_TIMEFORMAT, "hh:mm pm" )
      default _SET_TIMEFORMAT value is "hh:mm:ss:fff"
    + added C function: char * hb_setGetTimeFormat( void );

  * harbour/include/hbpp.h
  * harbour/source/pp/ppcore.c
    + added support for timestamp constant values in the form:
         t"YYYY-MM-DD HH:MM:SS.fff"
      The exact accepted timestamp pattern is is:
         YYYY-MM-DD [H[H][:M[M][:S[S][.f[f[f[f]]]]]]] [PM|AM]
      i.e.:
         tValue := t"2009-03-21 5:31:45.437 PM"
      or:
         YYYY-MM-DDT[H[H][:M[M][:S[S][.f[f[f[f]]]]]]] [PM|AM]
      with literal "T" as date and time part delimiters (XML timestamp
      format), i.e.:
         tValue := t"2009-03-21T17:31:45.437"
      The folowing characters can be used as date delimiters: "-", "/", "."
      if PM or AM is used HH is in range < 1 : 12 > otherwise
      in range < 0 : 23 >

  * harbour/source/compiler/complex.c
  * harbour/source/compiler/harbour.y
  * harbour/source/compiler/harbour.yyc
  * harbour/source/compiler/harbour.yyh
    + added support for t"YYYY-MM-DD HH:MM:SS.fff" time stamp constant
      to compiler
    + added support for VFP datetime constant values:
         { ^ [ YYYY-MM-DD [,] ] [ HH[:MM[:SS][.FFF]] [AM|PM] ] }
      The following characters can be used as date delimiters: "-", "/".
      Dot "." as date delimiter is not supported.
      There is no limit on number of characters in YYYY, MM, DD, HH, MM,
      SS, FFF parts. Important is only their value. This is the format
      in semi PP notation:
         { ^ <YEAR> <sep:/-> <MONTH> <sep:/-> <DAY> [[<sep2:,>]
           [ <HOUR> [ : <MIN> [ : <SEC> [ . <FRAQ> ] ] ] [AM|PP] ] }
      In practice it allows to also parse xHarbour datetime constant
      values with compatible conditions though xHarbour support onlu "/"
      as date delimiter.
      NOTE: there is one important difference to VFP and xHarbour in
      decoding above format. In VFP and xHarbour when date part is
      missing then it's set by default to: 1899-12-30 so this code:
         { ^ 12:00 }
      gived the same results as:
         { ^ 1899/12/30 12:00 }
      Harbour does not set any default date value when timestamp
      constant value contains only time part.
      If you want we can change it for strict VFP compatiblity.
      Now this extension is enabled by default for testing. In the future
      it will be probably covered by HB_COMPAT_FOXPRO macro.

  * harbour/source/macro/macro.yyc
  * harbour/source/macro/macro.y
  * harbour/source/macro/macro.yyh
  * harbour/source/macro/macrolex.c
    + added support for t"YYYY-MM-DD HH:MM:SS.fff" time stamp constant
      to macro compiler

  * harbour/include/hbmacro.h
  * harbour/source/vm/macro.c
    + added new function:
      void hb_macroGenPushTimeStamp( LONG lDate, LONG lTime, HB_COMP_DECL );

  * harbour/include/hberrors.h
  * harbour/source/compiler/hbgenerr.c
    + added new compile time error: "Invalid timestamp constant '%s'"

  * harbour/source/compiler/cmdcheck.c
    * use Harbour API timestamp functions instead of calling system
      functions

  * harbour/include/hbpcode.h
  * harbour/source/compiler/hbfix.c
  * harbour/source/compiler/hbpcode.c
  * harbour/source/compiler/hbdead.c
  * harbour/source/compiler/genc.c
  * harbour/source/compiler/gencc.c
  * harbour/source/compiler/hblbl.c
  * harbour/source/compiler/hbstripl.c
  * harbour/source/compiler/hbopt.c
    + added new PCODE HB_P_PUSHTIMESTAMP (replaced one unused PCODE value)
      to store timestamp constant values in the PCODE

  * harbour/include/hbcomp.h
  * harbour/source/compiler/hbmain.c
    + added new function:
      void hb_compGenPushTimeStamp( LONG lDate, LONG lTime, HB_COMP_DECL );

  * harbour/include/hbexprop.h
  * harbour/source/common/expropt1.c
    + added new C functions:
      HB_EXPR_PTR hb_compExprNewTimeStamp( LONG, LONG, HB_COMP_DECL );

  * harbour/include/hbexprb.c
  * harbour/include/hbcompdf.h
  * harbour/source/common/expropt2.c
    + added timestamp expressions support
    + added compile time optimization for timestamp expressions
    * updated function optimization for timestamp expressions

  * harbour/include/hbdate.h
  * harbour/source/common/hbdate.c
    * changed hb_dateMilliSeconds() to return UTC julian timestamp in
      milliseconds
    * changed existing seconds, time and timestamp functions to operate
      on common OS specific functions to eliminate possible problems
      with different OS time counters
    + added new functions to operates on time and timestamp values.
      See source code for details.

  + harbour/source/rtl/cputime.c
    * moved double hb_secondsCPU( int n ) function to separate file

  * harbour/source/rtl/seconds.c
    - removed old version of date/seconds functions

  * harbour/source/vm/hashes.c
  * harbour/source/vm/arrays.c
    + added support for timestamp values as hash item indexes

  * harbour/source/vm/hashfunc.c
    + added support for find timestamp values in hash and array items
      by simple date value in AScan(), hb_HScan(), hb_AScan() and hb_RAScan()
      functions when exact comparison is not used.

  * harbour/source/vm/asort.c
    + added support for sorting timestamp values

  * harbour/source/vm/classes.c
    + added support for timestamp scallar classes
    + added support for timestamp typed instance variables

  * harbour/source/vm/memvars.c
    + added support for timestamp values in .mem files

  * harbour/source/vm/estack.c
    + show timestamp values in stack dump

  * harbour/include/hbapi.h
  * harbour/source/vm/arrays.c
    + added new C functions:
      double hb_arrayGetTD( PHB_ITEM pArray, ULONG ulIndex );
      BOOL hb_arraySetTD( PHB_ITEM pArray, ULONG ulIndex, double dTimeStamp )
      BOOL hb_arrayGetTDT( PHB_ITEM pArray, ULONG ulIndex,
                           LONG * plJulian, LONG * plMilliSec );
      BOOL hb_arraySetTDT( PHB_ITEM pArray, ULONG ulIndex,
                           LONG lJulian, LONG lMilliSec );

  * harbour/include/hbapi.h
  * harbour/source/vm/extend.c
    + accept timestamp items in date functions - use only date part of
      timestamp value
    + added new C functions:
      double hb_partd( int iParam, ... );
      BOOL hb_partdt( LONG * plJulian, LONG * plMilliSec , int iParam, ... );
      void hb_rettd( double dTimeStamp );
      void hb_rettdt( LONG lJulian, LONG lMilliSec );
      int hb_stortd( double dTimeStamp, int iParam, ... );
      int hb_stortdt( LONG lJulian, LONG lMilliSec, int iParam, ... );

  * harbour/include/hbapiitm.h
  * harbour/source/vm/itemapi.c
    + accept timestamp items in date functions - use only date part of
      timestamp value
    + added new C functions:
      char * hb_itemGetTS( PHB_ITEM pItem, char * szDateTime );
      PHB_ITEM hb_itemPutTS( PHB_ITEM pItem, const char * szDateTime );
      double hb_itemGetTD( PHB_ITEM pItem );
      PHB_ITEM hb_itemPutTD( PHB_ITEM pItem, double dTimeStamp )
      BOOL hb_itemGetTDT( PHB_ITEM pItem, LONG * plJulian, LONG * plMilliSec );
      PHB_ITEM hb_itemPutTDT( PHB_ITEM pItem, LONG lJulian, LONG lMilliSec );
    + support for timestamp items in hb_itemString(), hb_itemPadConv() and
      hb_itemTypeStr() functions

  * harbour/include/hbvm.h
  * harbour/include/hbxvm.h
  * harbour/include/hbapi.h
  * harbour/source/vm/hvm.c
    + added HB_IT_TIMESTAMP items
    * modified HB_IT_DATE internal item structure to use common structure
      with HB_IT_TIMESTAMP - it  simplifies HVM code and eliminates additional
      RT conditions.
    + added HB_IS_TIMESTAMP() and ISTIMESTAMP() macros
    + added HB_IS_DATETIME() and ISDATETIME() macros - they return true
      if item/parameter is DATE or TIMESTAMP type.
    + added void hb_vmPushTimeStamp( long lJulian, long lMilliSec );
      and xhb_vmPushTimeStamp()
    + added support for timestamp values in relational operators:
         <, <=, >, >=, =, ==
      When two timestamp values are compared then VM compares date and
      time parts in both values.
      When date and timestamp values are used in <, <=, >, >=, = operations
      then VM compares only date part in both values.
      When date and timestamp values are used in == operation then VM
      compares date part in both values and then check if time part
      of timestamp value is 0.
    + added support for timestamp values in + and - math operations.
      The following rules are used in timestamp arithmetic:
         <t> + <t> => <t>
         <t> - <t> => <n>
         <t> + <n> => <t>
         <n> + <t> => <t>
         <t> - <n> => <t>
         <d> + <t> => <t>
         <t> + <d> => <t>
         <d> - <t> => <n>
         <t> - <d> => <n>
      When number is result or argument of timestamp operation then the
      its integer part is a number of day and fractional part is the time.

  * harbour/source/rtl/dateshb.c
    + added new .prg functions to mange date and timestamp values:
      HB_DATETIME() -> <tTimeStamp>
      HB_CTOD( <cDate> [, <cDateFormat> ] ) -> <dDate>
      HB_DTOC( <dDate> [, <cDateFormat> ] ) -> <cDate>
      HB_NTOT( <nValue> ) -> <tTimeStamp>
      HB_TTON( <tTimeStamp> ) -> <nValue>
      HB_TTOC( <tTimeStamp>, [ <cDateFormat> ] [, <cTimeFormat> ] ) ->
                                                            <cTimeStamp>
      HB_CTOT( <cTimeStamp>, [ <cDateFormat> ] [, <cTimeFormat> ] ) ->
                                                            <tTimeStamp>
      HB_TTOS( <tTimeStamp> ) -> <cYYYYMMDDHHMMSSFFF>
      HB_STOT( <cDateTime> ) -> <tTimeStamp>
         <cDateTime> should be in one of the above form:
            - "YYYYMMDDHHMMSSFFF"
            - "YYYYMMDDHHMMSSFF"
            - "YYYYMMDDHHMMSSF"
            - "YYYYMMDDHHMMSS"
            - "YYYYMMDDHHMM"
            - "YYYYMMDDHH"
            - "YYYYMMDD"
            - "HHMMSSFFF"
            - "HHMMSSF"
            - "HHMMSS"
            - "HHMM"
            - "HH"
         Important is number of digits.
      HB_TSTOSTR( <tTimeStamp> ) -> <cTimeStamp> // YYYY-MM-DD HH:MM:SS.fff
      HB_STRTOTS( <cTimeStamp> ) -> <tTimeStamp>
         <cTimeStamp> should be in one of the above form:
            YYYY-MM-DD [H[H][:M[M][:S[S][.f[f[f[f]]]]]]] [PM|AM]
            YYYY-MM-DDT[H[H][:M[M][:S[S][.f[f[f[f]]]]]]] [PM|AM]
         The folowing characters can be used as date delimiters: "-", "/", "."
         T - is literal "T" - it's for XML timestamp format
         if PM or AM is used HH is in range < 1 : 12 > otherwise
         in range < 0 : 23 >
      HB_HOUR( <tTimeStamp> ) -> <nHour>
      HB_MINUTE( <tTimeStamp> ) -> <nMinute>
      HB_SEC( <tTimeStamp> ) -> <nSeconds>   // with milliseconds

  * harbour/source/rtl/datec.c
    + accept timestamp parameters in CMONTH() and CDOW() functions

  * harbour/source/rtl/empty.c
    + added support for timestamp items

  * harbour/source/rtl/itemseri.c
    + added support for timestamp items serialization

  * harbour/source/rtl/minmax.c
    + added support for timestamp values to MIN() and MAX() functions.
      when only one of given parameters is timestamp value and other
      is date value and date parts are equal then always date item
      is returned as both MIN() or MAX() value.

  * harbour/source/rtl/dates.c
    + added new C functions: hb_timeFormat(), hb_timeUnformat(),
      hb_timeStampFormat(), hb_timeStampUnformat()

  * harbour/source/rtl/valtype.c
    + added .prg functions: HB_ISDATETIME(), HB_ISTIMESTAMP()

  * harbour/source/rtl/transfrm.c
    + added support for timestamp items formatting.
    + added new function modifier @T.
      When @T is used without @D then only time part of timestamp value
      is formatted and return.
      When @D is used without @T then only date part of timestamp value
      is formatted and return.

  * harbour/source/rtl/tbrowse.prg
    + display timestamp values

  * harbour/source/rtl/philes.c
    + accept timestamp value as second parameter of HB_FSETDATETIME()
      function
    + store file data and time in second parameter of HB_FGETDATETIME()
      as timestamp value.
    Old parameters (2-dDate, 3-cTime) are still supported but please think
    about removing them - they are redundant.

  * harbour/source/rtl/filesys.c
    * updated function names


  * harbour/source/rdd/dbf1.c
    + added native support for time and timestamp fields

  * harbour/include/hbrddcdx.h
  * harbour/include/hbrddnsx.h
  * harbour/source/rdd/dbfntx/dbfntx1.c
  * harbour/source/rdd/dbfcdx/dbfcdx1.c
  * harbour/source/rdd/dbfnsx/dbfnsx1.c
  * harbour/source/rdd/dbffpt/dbffpt1.c
    + added support for indexing timestamp fields
    + added support for using DATE values with timestamp fields
      which replicate HVM behavior.
      SEEK and SEEKLAST with date value when active index is on
      timestamp positions to 1-st or last record where date part
      of indexed timesamp value is equal.
      Settings scopes to date values when active index is on timestamp
      value reduce the visible record range to these ones which have
      date part of timestamp value in the range of dates values used
      for scopes. It possible to mix date and timestamp values in scope
      and set one scope to date value and the second to timesamp.

  * harbour/source/rdd/sdf1.c
  * harbour/source/rdd/delim1.c
    + added support for exporting timestamp fields

  * harbour/source/rdd/dbsql.c
    ! fixed typo in logical value export
    + export timestamp fields.
      Please update the format to given SQL syntax.


  * harbour/contrib/hbct/files.c
    + changed SETFDATI() to optionally accept timestamp parameter
      instead of two parameters dDate and cTime

  * harbour/contrib/hbct/misc1.c
    + added timestamp support to XTOC() function

  * harbour/contrib/hbct/misc2.c
    + added timestamp support to COMPLEMENT() function

  * harbour/contrib/hbct/dattime2.c
    + accept timestamp values in ADDMONTH(), DOY(), ISLEAP(), QUARTER()
      LASTDAYOM(), WEEK() functions

  * harbour/contrib/hbmzip/hbmzip.c
    + updated HB_ZipFileCreate( hZip, cZipName, tDateTime, cTime, ... )
      functions to optionaly accept timestamp value in 3-rd parameter
      instead od dDate, and cTime in 3-rd and 4-th parameters.
    + updated HB_UnzipFileInfo( hUnzip, @cZipName, @tDateTime, @cTime, ... )
      to return timestamp value in 3-rd parameter instead of date value.
      TODO: Please think about removing 4-th parameter from:
               HB_ZipFileCreate( hZip, cZipName, tDateTime, cTime, ... )
               HB_UnzipFileInfo( hUnzip, @cZipName, @tDateTime, @cTime, ... )
            Now it's redundant.
  * harbour/contrib/hbmzip/readme.txt
    * updated parameters description for above functions

  * harbour/contrib/hbnf/descendn.c
    + added timestamp support to FT_DESCEND() function

  * harbour/contrib/hbclipsm/date.c
    + accept timestamp values in DATEASAGE(), DATEASARRAY() and DATEISLEAP()
      functions

  * harbour/contrib/hbmisc/dates2.c
    + accept timestamp values in ISLEAPYEAR(), DAYSINMONTH(), EOM(), BOM(),
      WOM(), WOY(), EOY() and BOY() functions


   The following contrib files should be updated but I'm leaving it to
   other developers who want to keep this code alive:
         contrib/hbtip/utils.c
         contrib/hbvpdf/hbvpdf.prg
         contrib/hbvpdf/hbvpdft.prg
         contrib/hbwin/win_dll.c
            some minor cleanups if necessary and authors will find
            timestamp values usable

         contrib/hbole/ole2.c
         contrib/hbwin/win_ole.c
            add support for timestamp values in OLE

         contrib/rddado/adordd.prg
         contrib/rddads/ads1.c
         contrib/rddads/adsx.c
         contrib/rddsql/...
            add support for timestamp values in RDDs

   Warning: this implementation is not xHarbour compatible. There are many
   important differences. Mostly on C level and used API. Please be careful
   in porting xHarbour source code to Harbour.
2009-03-21 15:04:43 +00:00

1095 lines
39 KiB
Plaintext

%pure-parser
%parse-param { HB_MACRO_PTR pMacro }
%lex-param { HB_MACRO_PTR pMacro }
%name-prefix = "hb_macro"
%{
/*
* $Id$
*/
/*
* Harbour Project source code:
* Macro compiler YACC rules and actions
*
* Copyright 1999 Antonio Linares <alinares@fivetech.com>
* www - http://www.harbour-project.org
*
* This program 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, or (at your option)
* any later version.
*
* This program 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.
*
* You should have received a copy of the GNU General Public License
* along with this software; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/).
*
* As a special exception, the Harbour Project gives permission for
* additional uses of the text contained in its release of Harbour.
*
* The exception is that, if you link the Harbour libraries with other
* files to produce an executable, this does not by itself cause the
* resulting executable to be covered by the GNU General Public License.
* Your use of that executable is in no way restricted on account of
* linking the Harbour library code into it.
*
* This exception does not however invalidate any other reasons why
* the executable file might be covered by the GNU General Public License.
*
* This exception applies only to the code released by the Harbour
* Project under the name Harbour. If you copy code from other
* Harbour Project or Free Software Foundation releases into a copy of
* Harbour, as the General Public License permits, the exception does
* not apply to the code that you add in this way. To avoid misleading
* anyone as to the status of such modified files, you must delete
* this exception notice from them.
*
* If you write modifications of your own for Harbour, it is your choice
* whether to permit this exception to apply to your modifications.
* If you do not wish that, delete this exception notice.
*
*/
/* TODO list
* 1) Change the pcode generated by ::cVar from Self:cVar to QSELF():cVar
* The major problem to solve is how to support QSELF() inside a codeblock.
*/
/* this #define HAVE TO be placed before all #include directives
*/
#define HB_MACRO_SUPPORT
#include "hbmacro.h"
#include "hbcomp.h"
#include "hbdate.h"
#include "hbpp.h"
/* Compile using: bison -d -p hb_comp macro.y */
/* to pacify some warnings in BCC */
#if defined( __BORLANDC__ ) && !defined( __STDC__ )
# define __STDC__
#endif
#undef alloca
#define alloca hb_xgrab
#undef malloc
#define malloc hb_xgrab
#undef realloc
#define realloc hb_xrealloc
#undef free
#define free hb_xfree
/* NOTE: these symbols are used internally in bison.simple
*/
#undef YYFREE
#define YYFREE hb_xfree
#undef YYMALLOC
#define YYMALLOC hb_xgrab
#define NO_YYERROR
/* yacc/lex related definitions
*/
/* Standard checking for valid expression creation
*/
#define HB_MACRO_CHECK( pExpr ) \
if( ! ( HB_MACRO_DATA->status & HB_MACRO_CONT ) ) \
{ \
YYABORT; \
}
#define HB_MACRO_IFENABLED( pSet, pExpr, flag ) \
if( HB_MACRO_DATA->supported & (flag) ) \
{ \
pSet = (pExpr); \
}\
else \
{ \
YYABORT; \
}
#if defined( __BORLANDC__ ) || defined( __WATCOMC__ )
/* The if() inside this macro is always TRUE but it's used to hide BCC warning */
#define HB_MACRO_ABORT if( !( HB_MACRO_DATA->status & HB_MACRO_CONT ) ) { YYABORT; }
#else
#define HB_MACRO_ABORT { YYABORT; }
#endif
%}
%union /* special structure used by lex and yacc to share info */
{
const char * string; /* to hold a string returned by lex */
int iNumber; /* to hold a temporary integer number */
HB_LONG lNumber; /* to hold a temporary long number */
void * pVoid; /* to hold any memory structure we may need */
HB_EXPR_PTR asExpr;
struct
{
const char * string;
int length;
} valChar;
struct
{
int iNumber; /* to hold a number returned by lex */
} valInteger;
struct
{
HB_LONG lNumber; /* to hold a long number returned by lex */
UCHAR bWidth; /* to hold the width of the value */
} valLong;
struct
{
double dNumber; /* to hold a double number returned by lex */
UCHAR bWidth; /* to hold the width of the value */
UCHAR bDec; /* to hold the number of decimal points in the value */
} valDouble;
struct
{
long date; /* to hold julian date */
long time; /* to hold milliseconds */
} valTimeStamp;
};
%{
/* This must be placed after the above union - the union is
* typedef-ined to YYSTYPE
*/
extern int yylex( YYSTYPE *, HB_MACRO_PTR ); /* main lex token function, called by yyparse() */
extern int yyparse( HB_MACRO_PTR ); /* main yacc parsing function */
extern void yyerror( HB_MACRO_PTR, const char * ); /* parsing error management function */
static void hb_macroIdentNew( HB_COMP_DECL, char * );
%}
%token IDENTIFIER NIL NUM_DOUBLE INASSIGN NUM_LONG NUM_DATE TIMESTAMP
%token IIF LITERAL TRUEVALUE FALSEVALUE
%token AND OR NOT EQ NE1 NE2 INC DEC ALIASOP HASHOP SELF
%token LE GE FIELD MACROVAR MACROTEXT
%token PLUSEQ MINUSEQ MULTEQ DIVEQ POWER EXPEQ MODEQ
%token EPSILON
/*the lowest precedence*/
/*postincrement and postdecrement*/
%left POST
/*assigment - from right to left*/
%right INASSIGN
%right PLUSEQ MINUSEQ
%right MULTEQ DIVEQ MODEQ
%right EXPEQ
/*logical operators*/
%right OR
%right AND
%right NOT
/*relational operators*/
%right '=' EQ NE1 NE2
%right '<' '>' LE GE '$'
/*mathematical operators*/
%right '+' '-'
%right '*' '/' '%'
%right POWER
%right UNARY
/*preincrement and predecrement*/
%right PRE
/*special operators*/
%right ALIASOP '&' '@'
%right ','
/*the highest precedence*/
%type <string> IDENTIFIER MACROVAR MACROTEXT
%type <valChar> LITERAL
%type <valDouble> NUM_DOUBLE
%type <valLong> NUM_LONG
%type <valLong> NUM_DATE
%type <valTimeStamp> TIMESTAMP
%type <asExpr> Argument ExtArgument RefArgument ArgList ElemList
%type <asExpr> BlockExpList BlockVarList BlockVars
%type <asExpr> NumValue NumAlias
%type <asExpr> NilValue
%type <asExpr> LiteralValue
%type <asExpr> CodeBlock
%type <asExpr> Logical
%type <asExpr> SelfValue
%type <asExpr> Array
%type <asExpr> ArrayAt
%type <asExpr> Hash HashList
%type <asExpr> Variable VarAlias
%type <asExpr> MacroVar MacroVarAlias
%type <asExpr> MacroExpr MacroExprAlias
%type <asExpr> AliasId AliasVar AliasExpr
%type <asExpr> VariableAt
%type <asExpr> FunCall FunRef
%type <asExpr> ObjectData
%type <asExpr> ObjectMethod
%type <asExpr> IfInline
%type <asExpr> ExpList PareExpList PareExpListAlias AsParamList RootParamList
%type <asExpr> Expression ExtExpression SimpleExpression LeftExpression
%type <asExpr> EmptyExpression
%type <asExpr> ExprAssign ExprOperEq ExprPreOp ExprPostOp
%type <asExpr> ExprMath ExprBool ExprRelation ExprUnary
%type <asExpr> ExprPlusEq ExprMinusEq ExprMultEq ExprDivEq ExprModEq ExprExpEq
%type <asExpr> ArrayIndex IndexList
%type <asExpr> FieldAlias FieldVarAlias
%type <asExpr> PostOp
%type <asExpr> DateValue TimeStampValue
%%
Main : Expression '\n' {
HB_MACRO_DATA->exprType = hb_compExprType( $1 );
if( HB_MACRO_DATA->Flags & HB_MACRO_GEN_PUSH )
hb_macroExprGenPush( $1, HB_COMP_PARAM );
else
hb_macroExprGenPop( $1, HB_COMP_PARAM );
hb_macroGenPCode1( HB_P_ENDPROC, HB_COMP_PARAM );
}
| Expression {
HB_MACRO_DATA->exprType = hb_compExprType( $1 );
if( HB_MACRO_DATA->Flags & HB_MACRO_GEN_PUSH )
hb_macroExprGenPush( $1, HB_COMP_PARAM );
else
hb_macroExprGenPop( $1, HB_COMP_PARAM );
hb_macroGenPCode1( HB_P_ENDPROC, HB_COMP_PARAM );
}
| AsParamList {
HB_MACRO_DATA->exprType = hb_compExprType( $1 );
if( HB_MACRO_DATA->Flags & HB_MACRO_GEN_PUSH )
hb_macroExprGenPush( $1, HB_COMP_PARAM );
else
hb_macroExprGenPop( $1, HB_COMP_PARAM );
hb_macroGenPCode1( HB_P_ENDPROC, HB_COMP_PARAM );
}
| Expression error {
HB_TRACE(HB_TR_DEBUG, ("macro -> invalid expression: %s", HB_MACRO_DATA->string));
hb_macroError( EG_SYNTAX, HB_COMP_PARAM );
HB_MACRO_ABORT;
}
| error {
HB_TRACE(HB_TR_DEBUG, ("macro -> invalid syntax: %s", HB_MACRO_DATA->string));
hb_macroError( EG_SYNTAX, HB_COMP_PARAM );
HB_MACRO_ABORT;
}
;
/* Numeric values
*/
NumValue : NUM_DOUBLE { $$ = hb_compExprNewDouble( $1.dNumber, $1.bWidth, $1.bDec, HB_COMP_PARAM ); }
| NUM_LONG { $$ = hb_compExprNewLong( $1.lNumber, HB_COMP_PARAM ); }
;
DateValue : NUM_DATE { $$ = hb_compExprNewDate( $1.lNumber, HB_COMP_PARAM ); }
;
TimeStampValue : TIMESTAMP { $$ = hb_compExprNewTimeStamp( $1.date, $1.time, HB_COMP_PARAM ); }
;
NumAlias : NUM_LONG ALIASOP { $$ = hb_compExprNewLong( $1.lNumber, HB_COMP_PARAM ); }
;
/* NIL value
*/
NilValue : NIL { $$ = hb_compExprNewNil( HB_COMP_PARAM ); }
;
/* Literal string value
*/
LiteralValue : LITERAL { $$ = hb_compExprNewString( $1.string, $1.length, FALSE, HB_COMP_PARAM ); }
;
/* Logical value
*/
Logical : TRUEVALUE { $$ = hb_compExprNewLogical( TRUE, HB_COMP_PARAM ); }
| FALSEVALUE { $$ = hb_compExprNewLogical( FALSE, HB_COMP_PARAM ); }
;
/* SELF value and expressions
*/
SelfValue : SELF { $$ = hb_compExprNewSelf( HB_COMP_PARAM ); }
;
/* Literal array
*/
Array : '{' ElemList '}' { $$ = hb_compExprNewArray( $2, HB_COMP_PARAM ); }
;
/* Literal array access
*/
ArrayAt : Array ArrayIndex { $$ = $2; }
;
/* Literal hash
*/
Hash : '{' HASHOP '}' { $$ = hb_compExprNewHash( NULL, HB_COMP_PARAM ); }
| '{' HashList '}' { $$ = hb_compExprNewHash( $2, HB_COMP_PARAM ); }
;
HashList : Expression HASHOP EmptyExpression { $$ = hb_compExprAddListExpr( hb_compExprNewList( $1, HB_COMP_PARAM ), $3 ); }
| HashList ',' Expression HASHOP EmptyExpression { $$ = hb_compExprAddListExpr( hb_compExprAddListExpr( $1, $3 ), $5 ); }
;
/* Variables
*/
Variable : IDENTIFIER { $$ = hb_compExprNewVar( $1, HB_COMP_PARAM ); }
;
VarAlias : IDENTIFIER ALIASOP { $$ = hb_compExprNewAlias( $1, HB_COMP_PARAM ); }
;
/* Macro variables - this can signal compilation errors
*/
MacroVar : MACROVAR { $$ = hb_compExprNewMacro( NULL, '&', $1, HB_COMP_PARAM );
HB_MACRO_CHECK( $$ );
}
| MACROTEXT { BOOL fNewString;
char * szVarName = hb_macroTextSymbol( $1, strlen( $1 ), &fNewString );
if( szVarName )
{
if( fNewString )
hb_macroIdentNew( HB_COMP_PARAM, szVarName );
$$ = hb_compExprNewVar( szVarName, HB_COMP_PARAM );
HB_MACRO_CHECK( $$ );
}
else
{
/* invalid variable name
*/
HB_TRACE(HB_TR_DEBUG, ("macro -> invalid variable name: %s", $1));
YYABORT;
}
}
;
MacroVarAlias : MacroVar ALIASOP { hb_compExprMacroAsAlias( $1 ); }
;
/* Macro expressions
*/
MacroExpr : '&' PareExpList { $$ = hb_compExprNewMacro( $2, 0, NULL, HB_COMP_PARAM ); }
;
MacroExprAlias : MacroExpr ALIASOP
;
/* Aliased variables
*/
/* special case: _FIELD-> and FIELD-> can be nested
*/
FieldAlias : FIELD ALIASOP { $$ = hb_compExprNewAlias( "FIELD", HB_COMP_PARAM ); }
| FIELD ALIASOP FieldAlias { $$ = $3; }
;
/* ignore _FIELD-> or FIELD-> if a real alias is specified
*/
FieldVarAlias : FieldAlias VarAlias { $$ = $2; }
| FieldAlias NumAlias { $$ = $2; }
| FieldAlias PareExpListAlias { $$ = $2; }
| FieldAlias MacroVarAlias { $$ = $2; }
| FieldAlias MacroExprAlias { $$ = $2; }
;
AliasId : IDENTIFIER { $$ = hb_compExprNewVar( $1, HB_COMP_PARAM ); }
| MacroVar
;
AliasVar : NumAlias AliasId { $$ = hb_compExprNewAliasVar( $1, $2, HB_COMP_PARAM ); }
| MacroVarAlias AliasId { $$ = hb_compExprNewAliasVar( $1, $2, HB_COMP_PARAM ); }
| MacroExprAlias AliasId { $$ = hb_compExprNewAliasVar( $1, $2, HB_COMP_PARAM ); }
| PareExpListAlias AliasId { $$ = hb_compExprNewAliasVar( $1, $2, HB_COMP_PARAM ); }
| VarAlias AliasId { $$ = hb_compExprNewAliasVar( $1, $2, HB_COMP_PARAM ); }
| FieldAlias AliasId { $$ = hb_compExprNewAliasVar( $1, $2, HB_COMP_PARAM ); }
| FieldVarAlias AliasId { $$ = hb_compExprNewAliasVar( $1, $2, HB_COMP_PARAM ); }
;
/* Aliased expressions
*/
/* NOTE: In the case:
* alias->( Expression )
* alias always selects a workarea at runtime
*/
AliasExpr : NumAlias PareExpList { $$ = hb_compExprNewAliasExpr( $1, $2, HB_COMP_PARAM ); }
| VarAlias PareExpList { $$ = hb_compExprNewAliasExpr( $1, $2, HB_COMP_PARAM ); }
| MacroVarAlias PareExpList { $$ = hb_compExprNewAliasExpr( $1, $2, HB_COMP_PARAM ); }
| MacroExprAlias PareExpList { $$ = hb_compExprNewAliasExpr( $1, $2, HB_COMP_PARAM ); }
| PareExpListAlias PareExpList { $$ = hb_compExprNewAliasExpr( $1, $2, HB_COMP_PARAM ); }
;
/* Array expressions access
*/
VariableAt : NumValue ArrayIndex { $$ = $2; }
| NilValue ArrayIndex { $$ = $2; }
| DateValue ArrayIndex { $$ = $2; }
| TimeStampValue ArrayIndex { $$ = $2; }
| LiteralValue ArrayIndex { $$ = $2; }
| CodeBlock ArrayIndex { $$ = $2; }
| Logical ArrayIndex { $$ = $2; }
| Hash ArrayIndex { $$ = $2; }
| SelfValue ArrayIndex { $$ = $2; }
| Variable ArrayIndex { $$ = $2; }
| AliasVar ArrayIndex { $$ = $2; }
| AliasExpr ArrayIndex { $$ = $2; }
| MacroVar ArrayIndex { $$ = $2; }
| MacroExpr ArrayIndex { $$ = $2; }
| ObjectData ArrayIndex { $$ = $2; }
| ObjectMethod ArrayIndex { $$ = $2; }
| FunCall ArrayIndex { $$ = $2; }
| IfInline ArrayIndex { $$ = $2; }
| PareExpList ArrayIndex { $$ = $2; }
;
/* Function call
*/
FunCall : IDENTIFIER '(' ArgList ')' { $$ = hb_macroExprNewFunCall( hb_compExprNewFunName( $1, HB_COMP_PARAM ), $3, HB_COMP_PARAM );
HB_MACRO_CHECK( $$ );
}
| MacroVar '(' ArgList ')' { $$ = hb_macroExprNewFunCall( $1, $3, HB_COMP_PARAM );
HB_MACRO_CHECK( $$ );
}
;
FunRef : '@' IDENTIFIER '(' ArgList ')' { if( hb_compExprParamListLen( $4 ) != 0 )
{
hb_macroError( EG_SYNTAX, HB_COMP_PARAM );
YYABORT;
}
else
$$ = hb_compExprNewFunRef( $2, HB_COMP_PARAM );
}
;
ArgList : ExtArgument { $$ = hb_compExprNewArgList( $1, HB_COMP_PARAM ); }
| ArgList ',' ExtArgument { $$ = hb_compExprAddListExpr( $1, $3 ); }
;
Argument : EmptyExpression
| RefArgument
;
RefArgument : '@' IDENTIFIER { $$ = hb_compExprNewVarRef( $2, HB_COMP_PARAM ); }
| '@' MacroVar { $$ = hb_compExprNewRef( $2, HB_COMP_PARAM ); }
| '@' AliasVar { $$ = hb_compExprNewRef( $2, HB_COMP_PARAM ); }
| '@' ObjectData { $$ = hb_compExprNewRef( $2, HB_COMP_PARAM ); }
| '@' VariableAt { $$ = $2; $$->value.asList.reference = TRUE; }
;
ExtArgument : EPSILON { $$ = hb_compExprNewArgRef( HB_COMP_PARAM ); }
| Argument
;
/* Object's instance variable
*/
ObjectData : LeftExpression ':' IDENTIFIER { $$ = hb_macroExprNewSend( $1, $3, NULL, HB_COMP_PARAM ); }
| LeftExpression ':' MacroVar { $$ = hb_macroExprNewSend( $1, NULL, $3, HB_COMP_PARAM ); }
| LeftExpression ':' MacroExpr { $$ = hb_macroExprNewSend( $1, NULL, $3, HB_COMP_PARAM ); }
;
/* Object's method
*/
ObjectMethod : ObjectData '(' ArgList ')' { $$ = hb_compExprNewMethodCall( $1, $3 ); }
;
SimpleExpression :
NumValue
| NilValue
| DateValue
| TimeStampValue
| LiteralValue
| CodeBlock
| Logical
| SelfValue
| Array
| ArrayAt
| Hash
| AliasVar
| AliasExpr
| MacroVar
| MacroExpr
| Variable
| VariableAt
| FunCall
| IfInline
| ObjectData
| ObjectMethod
| ExprAssign
| ExprOperEq { HB_MACRO_IFENABLED( $$, $1, HB_SM_HARBOUR ); }
| ExprPostOp { HB_MACRO_IFENABLED( $$, $1, HB_SM_HARBOUR ); }
| ExprPreOp { HB_MACRO_IFENABLED( $$, $1, HB_SM_HARBOUR ); }
| ExprUnary
| ExprMath
| ExprBool
| ExprRelation
| FunRef
;
Expression : SimpleExpression { $$ = $1; HB_MACRO_CHECK( $$ ); }
| PareExpList { $$ = $1; HB_MACRO_CHECK( $$ ); }
;
ExtExpression : EPSILON { $$ = hb_compExprNewArgRef( HB_COMP_PARAM ); }
| Expression
;
RootParamList : EmptyExpression ',' {
if( !(HB_MACRO_DATA->Flags & HB_MACRO_GEN_LIST) )
{
HB_TRACE(HB_TR_DEBUG, ("macro -> invalid expression: %s", HB_MACRO_DATA->string));
hb_macroError( EG_SYNTAX, HB_COMP_PARAM );
YYABORT;
}
}
EmptyExpression {
HB_MACRO_DATA->uiListElements = 1;
$$ = hb_compExprAddListExpr( ( HB_MACRO_DATA->Flags & HB_MACRO_GEN_PARE ) ? hb_compExprNewList( $1, HB_COMP_PARAM ) : hb_compExprNewArgList( $1, HB_COMP_PARAM ), $4 );
}
;
AsParamList : RootParamList
| AsParamList ',' EmptyExpression { HB_MACRO_DATA->uiListElements++;
$$ = hb_compExprAddListExpr( $1, $3 ); }
;
EmptyExpression: /* nothing => nil */ { $$ = hb_compExprNewEmpty( HB_COMP_PARAM ); }
| Expression
;
LeftExpression : NumValue
| NilValue
| DateValue
| TimeStampValue
| LiteralValue
| CodeBlock
| Logical
| SelfValue
| Array
| ArrayAt
| Hash
| AliasVar
| AliasExpr
| MacroVar
| MacroExpr
| Variable
| VariableAt
| PareExpList
| FunCall
| IfInline
| ObjectData
| ObjectMethod
;
/* NOTE: PostOp can be used in one context only - it uses $0 rule
* (the rule that stands before PostOp)
*/
PostOp : INC { $$ = hb_compExprNewPostInc( $<asExpr>0, HB_COMP_PARAM ); }
| DEC { $$ = hb_compExprNewPostDec( $<asExpr>0, HB_COMP_PARAM ); }
;
/* NOTE: We cannot use 'Expression PostOp' because it caused
* shift/reduce conflicts
*/
ExprPostOp : LeftExpression PostOp %prec POST { $$ = $2; }
;
ExprPreOp : INC Expression %prec PRE { $$ = hb_compExprNewPreInc( $2, HB_COMP_PARAM ); }
| DEC Expression %prec PRE { $$ = hb_compExprNewPreDec( $2, HB_COMP_PARAM ); }
;
ExprUnary : NOT Expression { $$ = hb_compExprNewNot( $2, HB_COMP_PARAM ); }
| '-' Expression %prec UNARY { $$ = hb_compExprNewNegate( $2, HB_COMP_PARAM ); }
| '+' Expression %prec UNARY { $$ = $2; }
;
ExprAssign : NumValue INASSIGN Expression { $$ = hb_compExprAssign( $1, $3, HB_COMP_PARAM ); }
| NilValue INASSIGN Expression { $$ = hb_compExprAssign( $1, $3, HB_COMP_PARAM ); }
| DateValue INASSIGN Expression { $$ = hb_compExprAssign( $1, $3, HB_COMP_PARAM ); }
| TimeStampValue INASSIGN Expression { $$ = hb_compExprAssign( $1, $3, HB_COMP_PARAM ); }
| LiteralValue INASSIGN Expression { $$ = hb_compExprAssign( $1, $3, HB_COMP_PARAM ); }
| CodeBlock INASSIGN Expression { $$ = hb_compExprAssign( $1, $3, HB_COMP_PARAM ); }
| Logical INASSIGN Expression { $$ = hb_compExprAssign( $1, $3, HB_COMP_PARAM ); }
| SelfValue INASSIGN Expression { $$ = hb_compExprAssign( $1, $3, HB_COMP_PARAM ); }
| Array INASSIGN Expression { $$ = hb_compExprAssign( $1, $3, HB_COMP_PARAM ); }
| ArrayAt INASSIGN Expression { $$ = hb_compExprAssign( $1, $3, HB_COMP_PARAM ); }
| Hash INASSIGN Expression { $$ = hb_compExprAssign( $1, $3, HB_COMP_PARAM ); }
| AliasVar INASSIGN Expression { $$ = hb_compExprAssign( $1, $3, HB_COMP_PARAM ); }
| AliasExpr INASSIGN Expression { $$ = hb_compExprAssign( $1, $3, HB_COMP_PARAM ); }
| MacroVar INASSIGN Expression { $$ = hb_compExprAssign( $1, $3, HB_COMP_PARAM ); }
| MacroExpr INASSIGN Expression { $$ = hb_compExprAssign( $1, $3, HB_COMP_PARAM ); }
| Variable INASSIGN Expression { $$ = hb_compExprAssign( $1, $3, HB_COMP_PARAM ); }
| VariableAt INASSIGN Expression { $$ = hb_compExprAssign( $1, $3, HB_COMP_PARAM ); }
| PareExpList INASSIGN Expression { $$ = hb_compExprAssign( $1, $3, HB_COMP_PARAM ); }
| FunCall INASSIGN Expression { $$ = hb_compExprAssign( $1, $3, HB_COMP_PARAM ); }
| IfInline INASSIGN Expression { $$ = hb_compExprAssign( $1, $3, HB_COMP_PARAM ); }
| ObjectData INASSIGN Expression { HB_MACRO_IFENABLED( $$, hb_compExprAssign( $1, $3, HB_COMP_PARAM ), HB_SM_HARBOUR ); }
| ObjectMethod INASSIGN Expression { $$ = hb_compExprAssign( $1, $3, HB_COMP_PARAM ); }
;
ExprPlusEq : LeftExpression PLUSEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewPlusEq( $1, HB_COMP_PARAM ), $3, HB_COMP_PARAM ); }
;
ExprMinusEq : LeftExpression MINUSEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewMinusEq( $1, HB_COMP_PARAM ), $3, HB_COMP_PARAM ); }
;
ExprMultEq : LeftExpression MULTEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewMultEq( $1, HB_COMP_PARAM ), $3, HB_COMP_PARAM ); }
;
ExprDivEq : LeftExpression DIVEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewDivEq( $1, HB_COMP_PARAM ), $3, HB_COMP_PARAM ); }
;
ExprModEq : LeftExpression MODEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewModEq( $1, HB_COMP_PARAM ), $3, HB_COMP_PARAM ); }
;
ExprExpEq : LeftExpression EXPEQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewExpEq( $1, HB_COMP_PARAM ), $3, HB_COMP_PARAM ); }
;
ExprOperEq : ExprPlusEq
| ExprMinusEq
| ExprMultEq
| ExprDivEq
| ExprModEq
| ExprExpEq
;
ExprMath : Expression '+' Expression { $$ = hb_compExprSetOperand( hb_compExprNewPlus( $1, HB_COMP_PARAM ), $3, HB_COMP_PARAM ); }
| Expression '-' Expression { $$ = hb_compExprSetOperand( hb_compExprNewMinus( $1, HB_COMP_PARAM ), $3, HB_COMP_PARAM ); }
| Expression '*' Expression { $$ = hb_compExprSetOperand( hb_compExprNewMult( $1, HB_COMP_PARAM ), $3, HB_COMP_PARAM ); }
| Expression '/' Expression { $$ = hb_compExprSetOperand( hb_compExprNewDiv( $1, HB_COMP_PARAM ), $3, HB_COMP_PARAM ); }
| Expression '%' Expression { $$ = hb_compExprSetOperand( hb_compExprNewMod( $1, HB_COMP_PARAM ), $3, HB_COMP_PARAM ); }
| Expression POWER Expression { $$ = hb_compExprSetOperand( hb_compExprNewPower( $1, HB_COMP_PARAM ), $3, HB_COMP_PARAM ); }
;
ExprBool : Expression AND Expression { $$ = hb_compExprSetOperand( hb_compExprNewAnd( $1, HB_COMP_PARAM ), $3, HB_COMP_PARAM ); }
| Expression OR Expression { $$ = hb_compExprSetOperand( hb_compExprNewOr( $1, HB_COMP_PARAM ), $3, HB_COMP_PARAM ); }
;
ExprRelation: Expression EQ Expression { $$ = hb_compExprSetOperand( hb_compExprNewEQ( $1, HB_COMP_PARAM ), $3, HB_COMP_PARAM ); }
| Expression '<' Expression { $$ = hb_compExprSetOperand( hb_compExprNewLT( $1, HB_COMP_PARAM ), $3, HB_COMP_PARAM ); }
| Expression '>' Expression { $$ = hb_compExprSetOperand( hb_compExprNewGT( $1, HB_COMP_PARAM ), $3, HB_COMP_PARAM ); }
| Expression LE Expression { $$ = hb_compExprSetOperand( hb_compExprNewLE( $1, HB_COMP_PARAM ), $3, HB_COMP_PARAM ); }
| Expression GE Expression { $$ = hb_compExprSetOperand( hb_compExprNewGE( $1, HB_COMP_PARAM ), $3, HB_COMP_PARAM ); }
| Expression NE1 Expression { $$ = hb_compExprSetOperand( hb_compExprNewNE( $1, HB_COMP_PARAM ), $3, HB_COMP_PARAM ); }
| Expression NE2 Expression { $$ = hb_compExprSetOperand( hb_compExprNewNE( $1, HB_COMP_PARAM ), $3, HB_COMP_PARAM ); }
| Expression '$' Expression { $$ = hb_compExprSetOperand( hb_compExprNewIN( $1, HB_COMP_PARAM ), $3, HB_COMP_PARAM ); }
| Expression '=' Expression { $$ = hb_compExprSetOperand( hb_compExprNewEqual( $1, HB_COMP_PARAM ), $3, HB_COMP_PARAM ); }
;
ArrayIndex : IndexList ']'
;
/* NOTE: $0 represents the expression before ArrayIndex
* Don't use ArrayIndex in other context than as an array index!
*/
IndexList : '[' ExtExpression { $$ = hb_macroExprNewArrayAt( $<asExpr>0, $2, HB_COMP_PARAM ); }
| IndexList ',' ExtExpression { $$ = hb_macroExprNewArrayAt( $1, $3, HB_COMP_PARAM ); }
| IndexList ']' '[' ExtExpression { $$ = hb_macroExprNewArrayAt( $1, $4, HB_COMP_PARAM ); }
;
ElemList : ExtArgument { $$ = hb_compExprNewList( $1, HB_COMP_PARAM ); }
| ElemList ',' ExtArgument { $$ = hb_compExprAddListExpr( $1, $3 ); }
;
CodeBlock : '{' '|'
{ $<asExpr>$ = hb_compExprNewCodeBlock( NULL, 0, 0, HB_COMP_PARAM ); }
BlockVars '|' BlockExpList '}'
{ $$ = $<asExpr>3; }
;
/* NOTE: This uses $-2 then don't use BlockExpList in other context
*/
BlockExpList: Expression { $$ = hb_compExprAddCodeblockExpr( $<asExpr>-2, $1 ); }
| BlockExpList ',' Expression { $$ = hb_compExprAddCodeblockExpr( $<asExpr>-2, $3 ); }
;
/* NOTE: This uses $0 then don't use BlockVars and BlockVarList in other context
*/
BlockVars : /* empty list */ { $$ = NULL; }
| EPSILON { $$ = NULL; $<asExpr>0->value.asCodeblock.flags |= HB_BLOCK_VPARAMS; }
| BlockVarList { $$ = $1; }
| BlockVarList ',' EPSILON { $$ = $1; $<asExpr>0->value.asCodeblock.flags |= HB_BLOCK_VPARAMS; }
;
BlockVarList: IDENTIFIER { $$ = hb_compExprCBVarAdd( $<asExpr>0, $1, ' ', HB_COMP_PARAM ); }
| BlockVarList ',' IDENTIFIER { $$ = hb_compExprCBVarAdd( $<asExpr>0, $3, ' ', HB_COMP_PARAM ); HB_MACRO_CHECK( $$ ); }
;
ExpList : '(' EmptyExpression { $$ = hb_compExprNewList( $2, HB_COMP_PARAM ); }
| ExpList ',' EmptyExpression { $$ = hb_compExprAddListExpr( $1, $3 ); }
;
PareExpList : ExpList ')'
;
PareExpListAlias : PareExpList ALIASOP
;
/* Lexer should return IIF for "if" symbol */
IfInline : IIF '(' Expression ',' Argument ',' Argument ')'
{ $$ = hb_compExprNewIIF( hb_compExprAddListExpr( hb_compExprAddListExpr( hb_compExprNewList( $3, HB_COMP_PARAM ), $5 ), $7 ) ); }
;
%%
/*
** ------------------------------------------------------------------------ **
*/
void yyerror( HB_MACRO_PTR pMacro, const char * s )
{
HB_SYMBOL_UNUSED( pMacro );
HB_SYMBOL_UNUSED( s );
}
/* ************************************************************************* */
typedef struct HB_MEXPR_
{
HB_EXPR Expression;
struct HB_MEXPR_ *pPrev;
}
HB_MEXPR, * HB_MEXPR_PTR;
typedef struct HB_MIDENT_
{
char * Identifier;
struct HB_MIDENT_ *pPrev;
}
HB_MIDENT, * HB_MIDENT_PTR;
/* Allocates memory for Expression holder structure and stores it
* on the linked list
*/
static HB_EXPR_PTR hb_macroExprAlloc( HB_COMP_DECL )
{
HB_MEXPR_PTR pMExpr = ( HB_MEXPR_PTR ) hb_xgrab( sizeof( HB_MEXPR ) );
pMExpr->pPrev = ( HB_MEXPR_PTR ) HB_MACRO_DATA->pExprLst;
HB_MACRO_DATA->pExprLst = ( void * ) pMExpr;
return &pMExpr->Expression;
}
static void hb_macroIdentNew( HB_COMP_DECL, char * szIdent )
{
HB_MIDENT_PTR pMIdent = ( HB_MIDENT_PTR ) hb_xgrab( sizeof( HB_MIDENT ) );
pMIdent->Identifier = szIdent;
pMIdent->pPrev = ( HB_MIDENT_PTR ) HB_MACRO_DATA->pIdentLst;
HB_MACRO_DATA->pIdentLst = ( void * ) pMIdent;
}
static HB_EXPR_PTR hb_macroExprNew( HB_COMP_DECL, HB_EXPRTYPE iType )
{
HB_EXPR_PTR pExpr;
HB_TRACE(HB_TR_DEBUG, ("hb_macroExprNew(%p,%i)", HB_COMP_PARAM, iType));
pExpr = hb_macroExprAlloc( HB_COMP_PARAM );
pExpr->ExprType = iType;
pExpr->pNext = NULL;
pExpr->ValType = HB_EV_UNKNOWN;
pExpr->Counter = 1;
return pExpr;
}
/* Delete self - all components will be deleted somewhere else
*/
static void hb_macroExprClear( HB_COMP_DECL, HB_EXPR_PTR pExpr )
{
HB_SYMBOL_UNUSED( HB_COMP_PARAM );
if( --pExpr->Counter == 0 )
pExpr->ExprType = HB_ET_NONE;
}
/* Delete all components and delete self
*/
static void hb_macroExprDelete( HB_COMP_DECL, HB_EXPR_PTR pExpr )
{
HB_TRACE(HB_TR_DEBUG, ("hb_macroExprDelete(%p,%p)", HB_COMP_PARAM, pExpr));
if( pExpr && --pExpr->Counter == 0 )
{
HB_EXPR_USE( pExpr, HB_EA_DELETE );
pExpr->ExprType = HB_ET_NONE;
}
}
/* Delete all components and delete self
*/
static void hb_macroExprFree( HB_COMP_DECL, HB_EXPR_PTR pExpr )
{
HB_TRACE(HB_TR_DEBUG, ("hb_macroExprFree()"));
if( --pExpr->Counter == 0 )
{
HB_EXPR_USE( pExpr, HB_EA_DELETE );
pExpr->ExprType = HB_ET_NONE;
}
}
/* Deallocate all memory used by expression optimizer */
static void hb_macroLstFree( HB_MACRO_PTR pMacro )
{
if( pMacro->pExprLst )
{
HB_MEXPR_PTR pMExpr = ( HB_MEXPR_PTR ) pMacro->pExprLst;
do
{
hb_macroExprDelete( pMacro, &pMExpr->Expression );
pMExpr = pMExpr->pPrev;
}
while( pMExpr );
do
{
pMExpr = ( HB_MEXPR_PTR ) pMacro->pExprLst;
pMacro->pExprLst = ( void * ) pMExpr->pPrev;
hb_xfree( pMExpr );
}
while( pMacro->pExprLst );
}
while( pMacro->pIdentLst )
{
HB_MIDENT_PTR pMIdent = ( HB_MIDENT_PTR ) HB_MACRO_DATA->pIdentLst;
HB_MACRO_DATA->pIdentLst = ( void * ) pMIdent->pPrev;
hb_xfree( pMIdent->Identifier );
hb_xfree( pMIdent );
}
}
static HB_EXPR_PTR hb_macroErrorType( HB_COMP_DECL, HB_EXPR_PTR pExpr )
{
hb_macroError( EG_ARG, HB_COMP_PARAM );
return pExpr;
}
static HB_EXPR_PTR hb_macroErrorSyntax( HB_COMP_DECL, HB_EXPR_PTR pExpr )
{
hb_macroError( EG_SYNTAX, HB_COMP_PARAM );
return pExpr;
}
static void hb_macroErrorDuplVar( HB_COMP_DECL, const char * szVarName )
{
HB_SYMBOL_UNUSED( szVarName );
hb_macroError( EG_SYNTAX, HB_COMP_PARAM );
}
static const HB_COMP_FUNCS s_macro_funcs =
{
hb_macroExprNew,
hb_macroExprClear,
hb_macroExprFree,
hb_macroExprDelete,
hb_macroErrorType,
hb_macroErrorSyntax,
hb_macroErrorDuplVar,
};
int hb_macroYYParse( HB_MACRO_PTR pMacro )
{
int iResult;
pMacro->funcs = &s_macro_funcs;
if( hb_macroLexNew( pMacro ) )
{
pMacro->status = HB_MACRO_CONT;
pMacro->pExprLst = NULL;
pMacro->pIdentLst = NULL;
iResult = yyparse( pMacro );
hb_macroLstFree( pMacro );
hb_macroLexDelete( pMacro );
}
else
iResult = HB_MACRO_FAILURE;
return iResult;
}
#if defined( HB_MACRO_PPLEX )
/* it's an example of PP token translator which change tokens generated by
PP into terminal symbols used by our grammar parser generated by Bison */
BOOL hb_macroLexNew( HB_MACRO_PTR pMacro )
{
pMacro->pLex = ( void * ) hb_pp_lexNew( pMacro->string, pMacro->length );
return pMacro->pLex != NULL;
}
void hb_macroLexDelete( HB_MACRO_PTR pMacro )
{
if( pMacro->pLex )
{
hb_pp_free( ( PHB_PP_STATE ) pMacro->pLex );
pMacro->pLex = NULL;
}
}
int hb_macrolex( YYSTYPE *yylval_ptr, HB_MACRO_PTR pMacro )
{
PHB_PP_TOKEN pToken = hb_pp_lexGet( ( PHB_PP_STATE ) pMacro->pLex );
if( !pToken )
return 0;
switch( HB_PP_TOKEN_TYPE( pToken->type ) )
{
case HB_PP_TOKEN_KEYWORD:
if( pToken->len >= 4 && pToken->len <= 6 && pToken->pNext &&
HB_PP_TOKEN_TYPE( pToken->pNext->type ) == HB_PP_TOKEN_ALIAS &&
( hb_strnicmp( "_FIELD", pToken->value, pToken->len ) == 0 ||
hb_strnicmp( "FIELD", pToken->value, pToken->len ) == 0 ) )
{
return FIELD;
}
else if( pToken->len == 3 && pToken->pNext &&
HB_PP_TOKEN_TYPE( pToken->pNext->type ) == HB_PP_TOKEN_LEFT_PB &&
hb_stricmp( "IIF", pToken->value ) == 0 )
{
return IIF;
}
else if( pToken->len == 2 && pToken->pNext &&
HB_PP_TOKEN_TYPE( pToken->pNext->type ) == HB_PP_TOKEN_LEFT_PB &&
hb_stricmp( "IF", pToken->value ) == 0 )
return IIF;
else if( pToken->len == 3 && hb_stricmp( "NIL", pToken->value ) == 0 )
return NIL;
hb_pp_tokenUpper( pToken );
yylval_ptr->string = pToken->value;
return IDENTIFIER;
case HB_PP_TOKEN_MACROVAR:
hb_pp_tokenUpper( pToken );
yylval_ptr->string = pToken->value;
return MACROVAR;
case HB_PP_TOKEN_MACROTEXT:
hb_pp_tokenUpper( pToken );
yylval_ptr->string = pToken->value;
return MACROTEXT;
case HB_PP_TOKEN_NUMBER:
{
HB_LONG lNumber;
double dNumber;
int iDec, iWidth;
if( hb_compStrToNum( pToken->value, pToken->len, &lNumber, &dNumber, &iDec, &iWidth ) )
{
yylval_ptr->valDouble.dNumber = dNumber;
yylval_ptr->valDouble.bDec = ( UCHAR ) iDec;
yylval_ptr->valDouble.bWidth = ( UCHAR ) iWidth;
return NUM_DOUBLE;
}
else
{
yylval_ptr->valLong.lNumber = lNumber;
yylval_ptr->valLong.bWidth = ( UCHAR ) iWidth;
return NUM_LONG;
}
}
case HB_PP_TOKEN_DATE:
if( pToken->len == 10 )
{
int year, month, day;
hb_dateStrGet( pToken->value + 2, &year, &month, &day );
yylval_ptr->valLong.lNumber = hb_dateEncode( year, month, day );
}
else
yylval_ptr->valLong.lNumber = 0;
return NUM_DATE;
case HB_PP_TOKEN_TIMESTAMP:
if( !hb_timeStampStrGetDT( pToken->value,
&yylval_ptr->valTimeStamp.date,
&yylval_ptr->valTimeStamp.time ) )
{
hb_macroError( EG_SYNTAX, pMacro );
}
return TIMESTAMP;
case HB_PP_TOKEN_STRING:
yylval_ptr->valChar.string = pToken->value;
yylval_ptr->valChar.length = pToken->len;
return LITERAL;
case HB_PP_TOKEN_LOGICAL:
return pToken->value[ 1 ] == 'T' ? TRUEVALUE : FALSEVALUE;
case HB_PP_TOKEN_HASH:
case HB_PP_TOKEN_DIRECTIVE:
return NE1;
case HB_PP_TOKEN_NE:
return NE2;
case HB_PP_TOKEN_ASSIGN:
return INASSIGN;
case HB_PP_TOKEN_EQUAL:
return EQ;
case HB_PP_TOKEN_INC:
return INC;
case HB_PP_TOKEN_DEC:
return DEC;
case HB_PP_TOKEN_ALIAS:
return ALIASOP;
case HB_PP_TOKEN_LE:
return LE;
case HB_PP_TOKEN_GE:
return GE;
case HB_PP_TOKEN_PLUSEQ:
return PLUSEQ;
case HB_PP_TOKEN_MINUSEQ:
return MINUSEQ;
case HB_PP_TOKEN_MULTEQ:
return MULTEQ;
case HB_PP_TOKEN_DIVEQ:
return DIVEQ;
case HB_PP_TOKEN_MODEQ:
return MODEQ;
case HB_PP_TOKEN_EXPEQ:
return EXPEQ;
case HB_PP_TOKEN_POWER:
return POWER;
case HB_PP_TOKEN_AND:
return AND;
case HB_PP_TOKEN_OR:
return OR;
case HB_PP_TOKEN_NOT:
return NOT;
default:
return pToken->value[ 0 ];
}
}
#endif /* HB_MACRO_PPLEX */