2007-02-28 08:10 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl)

* harbour/include/hbpp.h
  * harbour/source/compiler/complex.c
  * harbour/source/compiler/harbour.y
  * harbour/source/compiler/harbour.yyc
  * harbour/source/pp/ppcore.c
    * updated lexer to recognize IF(<exp1>,<exp2>,<exp3>) in expressions like
      IF(<exp,...>) - it allow to make some grammar rules much more simple.
This commit is contained in:
Przemyslaw Czerpak
2007-02-28 07:11:17 +00:00
parent d4f042a2a5
commit 1cba971155
6 changed files with 2542 additions and 2615 deletions

View File

@@ -8,6 +8,15 @@
2002-12-01 13:30 UTC+0100 Foo Bar <foo.bar@foobar.org>
*/
2007-02-28 08:10 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl)
* harbour/include/hbpp.h
* harbour/source/compiler/complex.c
* harbour/source/compiler/harbour.y
* harbour/source/compiler/harbour.yyc
* harbour/source/pp/ppcore.c
* updated lexer to recognize IF(<exp1>,<exp2>,<exp3>) in expressions like
IF(<exp,...>) - it allow to make some grammar rules much more simple.
2007-02-27 12:10 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl)
* harbour/include/hbcomp.h
* harbour/include/hbexpra.c

View File

@@ -649,6 +649,7 @@ extern char * hb_pp_tokenBlockString( PHB_PP_STATE pState, PHB_PP_TOKEN pToken,
extern PHB_PP_STATE hb_pp_lexNew( char * pString, ULONG ulLen );
extern PHB_PP_TOKEN hb_pp_lexGet( PHB_PP_STATE pState );
extern PHB_PP_TOKEN hb_pp_tokenGet( PHB_PP_STATE pState );
extern BOOL hb_pp_tokenNextExp( PHB_PP_TOKEN * pTokenPtr );
HB_EXTERN_END

View File

@@ -981,7 +981,24 @@ int hb_complex( YYSTYPE *yylval_ptr, HB_COMP_DECL )
HB_COMP_ERR_SYNTAX, "IF", NULL );
else if( HB_PP_TOKEN_TYPE( pToken->pNext->type ) == HB_PP_TOKEN_LEFT_PB )
{
pLex->iState = pLex->iState == LOOKUP ? IF : IIF;
if( pLex->iState == LOOKUP )
{
PHB_PP_TOKEN pNext = pToken->pNext->pNext; /* COND EXP */
pLex->iState = IF;
if( hb_pp_tokenNextExp( &pNext ) ) /* TRUE EXP */
{
if( hb_pp_tokenNextExp( &pNext ) ) /* FALSE EXP */
{
if( !hb_pp_tokenNextExp( &pNext ) && pNext &&
HB_PP_TOKEN_TYPE( pNext->type ) == HB_PP_TOKEN_RIGHT_PB )
pLex->iState = IIF;
}
}
}
else
pLex->iState = IIF;
return pLex->iState;
}
else if( HB_PP_LEX_NEEDLEFT( pToken->pNext ) || pLex->iState != LOOKUP )

View File

@@ -212,8 +212,6 @@ extern void yyerror( HB_COMP_DECL, char * ); /* parsing error management fun
%type <asExpr> Argument ExtArgument RefArgument ArgList ElemList
%type <asExpr> BlockExpList BlockVars BlockVarList
%type <asExpr> DoName DoProc DoArgs DoArgument DoArgList
%type <asExpr> PareExpList1 PareExpList2 PareExpList3 PareExpListN
%type <asExpr> ExpList ExpList1 ExpList2 ExpList3
%type <asExpr> NumValue NumAlias
%type <asExpr> NilValue NilAlias
%type <asExpr> LiteralValue LiteralAlias
@@ -231,8 +229,8 @@ extern void yyerror( HB_COMP_DECL, char * ); /* parsing error management fun
%type <asExpr> FunIdentCall FunCall FunCallAlias FunRef
%type <asExpr> ObjectData ObjectDataAlias ObjectRef
%type <asExpr> ObjectMethod ObjectMethodAlias
%type <asExpr> IfInline IfInlineAlias IfExpression
%type <asExpr> PareExpList PareExpListAlias
%type <asExpr> IfInline IfInlineAlias
%type <asExpr> PareExpList PareExpListAlias ExpList
%type <asExpr> Expression ExtExpression SimpleExpression LValue LeftExpression
%type <asExpr> EmptyExpression
%type <asExpr> ExprAssign ExprOperEq ExprPreOp ExprPostOp
@@ -969,7 +967,7 @@ ArrayIndex : IndexList ']'
*/
IndexList : '[' ExtExpression { $$ = hb_compExprNewArrayAt( $<asExpr>0, $2, HB_COMP_PARAM ); }
| IndexList ',' ExtExpression { $$ = hb_compExprNewArrayAt( $1, $3, HB_COMP_PARAM ); }
| IndexList ']' '[' ExtExpression { $$ = hb_compExprNewArrayAt( $1, $4, HB_COMP_PARAM ); }
| IndexList ']' '[' ExtExpression { $$ = hb_compExprNewArrayAt( $1, $4, HB_COMP_PARAM ); }
;
ElemList : ExtArgument { $$ = hb_compExprNewList( $1, HB_COMP_PARAM ); }
@@ -977,7 +975,7 @@ ElemList : ExtArgument { $$ = hb_compExprNewList( $1, HB_COMP_PA
;
CodeBlock : CBSTART { $<asExpr>$ = hb_compExprNewCodeBlock( $1.string, $1.length, $1.flags, HB_COMP_PARAM ); $1.string = NULL; }
BlockVars '|' BlockExpList '}' { $$ = $<asExpr>2; }
BlockVars '|' BlockExpList '}' { $$ = $<asExpr>2; }
;
/* NOTE: This uses $-2 then don't use BlockExpList in other context
@@ -998,84 +996,46 @@ BlockVarList : IdentName AsType { HB_COMP_PARAM->iVarScope =
| BlockVarList ',' IdentName AsType { HB_COMP_PARAM->iVarScope = VS_LOCAL; $$ = hb_compExprCBVarAdd( $<asExpr>0, $3, HB_COMP_PARAM->cVarType, HB_COMP_PARAM ); HB_COMP_PARAM->cVarType = ' '; }
;
/* There is a conflict between the use of IF( Expr1, Expr2, Expr3 )
* and parenthesized expression ( Expr1, Expr2, Expr3 )
* To solve this conflict we have to split the definitions into more
* atomic ones.
* Also the generation of pcodes have to be delayed and moved to the
* end of whole parenthesized expression.
*/
PareExpList1: ExpList1 ')'
;
ExpList : Expression { $$ = hb_compExprNewList( $1, HB_COMP_PARAM ); }
| ExpList ',' Expression { $$ = hb_compExprAddListExpr( $1, $3 ); }
PareExpList2: ExpList2 ')'
;
PareExpList3: ExpList3 ')'
;
PareExpListN: ExpList ')'
;
PareExpList : PareExpList1
| PareExpList2
| PareExpList3
| PareExpListN
PareExpList : '(' ExpList ')' { $$ = $2 };
;
PareExpListAlias : PareExpList ALIASOP
;
/* NOTE: Clipper allows to pass variable by reference only as
* function argument, IIF() 2-nd and 3-rd argument and as
* explicit array item {...@var...}
* function arguments, IIF() 2-nd and 3-rd arguments and as
* explicit array items {...@var...}
* AFAIK these are also the only one places where empty expressions in
* the parenthesis expressions list are accepted
*/
ExpList1 : '(' Expression { $$ = hb_compExprNewList( $2, HB_COMP_PARAM ); }
;
ExpList2 : ExpList1 ',' Expression { $$ = hb_compExprAddListExpr( $1, $3 ); }
;
ExpList3 : ExpList2 ',' Expression { $$ = hb_compExprAddListExpr( $1, $3 ); }
;
ExpList : ExpList3 ',' Expression { $$ = hb_compExprAddListExpr( $1, $3 ); }
| ExpList ',' Expression { $$ = hb_compExprAddListExpr( $1, $3 ); }
;
IfInline : IIF '(' Expression ',' Argument ',' Argument ')'
{ $$ = hb_compExprNewIIF( hb_compExprAddListExpr( hb_compExprAddListExpr( hb_compExprNewList( $3, HB_COMP_PARAM ), $5 ), $7 ) ); }
| IF ExpList1 ',' Expression ',' Argument ')'
{ $$ = hb_compExprNewIIF( hb_compExprAddListExpr( hb_compExprAddListExpr( hb_compExprNewList( $2, HB_COMP_PARAM ), $4 ), $6 ) ); }
| IF ExpList1 ',' RefArgument ',' Argument ')'
{ $$ = hb_compExprNewIIF( hb_compExprAddListExpr( hb_compExprAddListExpr( hb_compExprNewList( $2, HB_COMP_PARAM ), $4 ), $6 ) ); }
| IF ExpList1 ',' ',' Argument ')'
{ $$ = hb_compExprNewIIF( hb_compExprAddListExpr( hb_compExprAddListExpr( hb_compExprNewList( $2, HB_COMP_PARAM ), hb_compExprNewEmpty( HB_COMP_PARAM ) ), $5 ) ); }
;
IfInline : IIF '(' Expression ',' Argument ',' Argument ')'
{ $$ = hb_compExprNewIIF( hb_compExprAddListExpr( hb_compExprAddListExpr( hb_compExprNewList( $3, HB_COMP_PARAM ), $5 ), $7 ) ); }
;
IfInlineAlias : IfInline ALIASOP
;
VarDefs : LOCAL { HB_COMP_PARAM->iVarScope = VS_LOCAL; hb_compLinePush( HB_COMP_PARAM ); }
VarList Crlf { HB_COMP_PARAM->cVarType = ' '; }
| STATIC { HB_COMP_PARAM->iVarScope = VS_STATIC; hb_compLinePush( HB_COMP_PARAM ); }
VarList Crlf { HB_COMP_PARAM->cVarType = ' '; }
| PARAMETERS { if( HB_COMP_PARAM->functions.pLast->bFlags & FUN_USES_LOCAL_PARAMS )
hb_compGenError( HB_COMP_PARAM, hb_comp_szErrors, 'E', HB_COMP_ERR_PARAMETERS_NOT_ALLOWED, NULL, NULL );
else
HB_COMP_PARAM->functions.pLast->wParamNum=0; HB_COMP_PARAM->iVarScope = ( VS_PRIVATE | VS_PARAMETER ); }
MemvarList Crlf { HB_COMP_PARAM->iVarScope = VS_NONE; }
;
VarDefs : LOCAL { HB_COMP_PARAM->iVarScope = VS_LOCAL; hb_compLinePush( HB_COMP_PARAM ); }
VarList Crlf { HB_COMP_PARAM->cVarType = ' '; }
| STATIC { HB_COMP_PARAM->iVarScope = VS_STATIC; hb_compLinePush( HB_COMP_PARAM ); }
VarList Crlf { HB_COMP_PARAM->cVarType = ' '; }
| PARAMETERS { if( HB_COMP_PARAM->functions.pLast->bFlags & FUN_USES_LOCAL_PARAMS )
hb_compGenError( HB_COMP_PARAM, hb_comp_szErrors, 'E', HB_COMP_ERR_PARAMETERS_NOT_ALLOWED, NULL, NULL );
else
HB_COMP_PARAM->functions.pLast->wParamNum=0; HB_COMP_PARAM->iVarScope = ( VS_PRIVATE | VS_PARAMETER ); }
MemvarList Crlf { HB_COMP_PARAM->iVarScope = VS_NONE; }
;
VarList : VarDef { $$ = 1; }
| VarList ',' VarDef { $$++; }
;
VarList : VarDef { $$ = 1; }
| VarList ',' VarDef { $$++; }
;
ExtVarList : ExtVarDef { $$ = 1; }
| ExtVarList ',' ExtVarDef { $$++; }
;
ExtVarList : ExtVarDef { $$ = 1; }
| ExtVarList ',' ExtVarDef { $$++; }
;
/* NOTE: if STATIC or LOCAL variables are declared and initialized then we can
* assign a value immediately - however for PRIVATE and PUBLIC variables
@@ -1305,7 +1265,7 @@ DummyArgList : DummyArgument
| DummyArgList ',' DummyArgument
;
DummyArgument : EmptyExpression { hb_compExprDelete( $1, HB_COMP_PARAM ); }
DummyArgument : EmptyExpression { hb_compExprDelete( $1, HB_COMP_PARAM ); }
;
FormalList : IdentName AsType { hb_compDeclaredParameterAdd( HB_COMP_PARAM, $1, HB_COMP_PARAM->cVarType ); }
@@ -1340,7 +1300,7 @@ IfEndif : IfBegin EndIf { hb_compGenJumpHere( $1, HB_COMP_
| IfBegin IfElseIf IfElse EndIf { hb_compGenJumpHere( $1, HB_COMP_PARAM ); hb_compElseIfFix( HB_COMP_PARAM, $2 ); }
;
IfBegin : IF IfExpression
IfBegin : IF Expression
{ ++HB_COMP_PARAM->wIfCounter; hb_compLinePushIfInside( HB_COMP_PARAM ); }
Crlf
{ hb_compExprDelete( hb_compExprGenPush( $2, HB_COMP_PARAM ), HB_COMP_PARAM ); $$ = hb_compGenJumpFalse( 0, HB_COMP_PARAM ); }
@@ -1348,13 +1308,6 @@ IfBegin : IF IfExpression
{ $$ = hb_compGenJump( 0, HB_COMP_PARAM ); hb_compGenJumpHere( $<iNumber>5, HB_COMP_PARAM ); }
;
IfExpression: SimpleExpression
| Variable
| PareExpList1
| PareExpList2
| PareExpListN
;
IfElse : ELSE Crlf { HB_COMP_PARAM->functions.pLast->bFlags &= ~ FUN_BREAK_CODE; }
EmptyStats
;

File diff suppressed because it is too large Load Diff

View File

@@ -5065,6 +5065,18 @@ PHB_PP_TOKEN hb_pp_lexGet( PHB_PP_STATE pState )
return pToken;
}
BOOL hb_pp_tokenNextExp( PHB_PP_TOKEN * pTokenPtr )
{
if( hb_pp_tokenCanStartExp( * pTokenPtr ) )
{
BOOL fStop = FALSE;
if( hb_pp_tokenSkipExp( pTokenPtr, NULL, HB_PP_CMP_STD, &fStop ) && !fStop )
return TRUE;
}
return FALSE;
}
/*
* convert token letters to upper cases
* strip leading '&' and trailing '.' (if any) from macrovar token