Updating compiler files

This commit is contained in:
Alexander S.Kresin
1999-07-07 08:55:23 +00:00
parent d1855d9474
commit 99d012f435
4 changed files with 66 additions and 67 deletions

View File

@@ -1,3 +1,10 @@
19990707-11:10 Alexander Kresin
* source\compiler\harbour.l
* source\compiler\harbour.y
* include\hberrors.h
* changed calls of genError() function for implementing it to preprocessor
* from harbour.y removed some lines related to #include implementation
19990706-23:35 EDT David G. Holm <dholm@jsd-llc.com>
* source/rtl/set.c
+ Added header template and filled in

View File

@@ -17,18 +17,17 @@
#define ERR_STRING_TERMINATOR 7
#define ERR_FUNC_RESERVED 8
#define ERR_ILLEGAL_INIT 9
#define ERR_CANT_OPEN_INCLUDE 10
#define ERR_ENDIF 11
#define ERR_ENDDO 12
#define ERR_ENDCASE 13
#define ERR_NEXTFOR 14
#define ERR_UNMATCHED_ELSE 15
#define ERR_UNMATCHED_ELSEIF 16
#define ERR_SYNTAX 17
#define ERR_UNCLOSED_STRU 18
#define ERR_UNMATCHED_EXIT 19
#define ERR_SYNTAX2 20
#define ERR_INCOMPLETE_STMT 21
#define ERR_ENDIF 10
#define ERR_ENDDO 11
#define ERR_ENDCASE 12
#define ERR_NEXTFOR 13
#define ERR_UNMATCHED_ELSE 14
#define ERR_UNMATCHED_ELSEIF 15
#define ERR_SYNTAX 16
#define ERR_UNCLOSED_STRU 17
#define ERR_UNMATCHED_EXIT 18
#define ERR_SYNTAX2 19
#define ERR_INCOMPLETE_STMT 20
#define WARN_AMBIGUOUS_VAR 1
#define WARN_VAR_NOT_USED 2
@@ -42,7 +41,7 @@
#define WARN_LOGICAL_SUSPECT 10
#define WARN_NUMERIC_SUSPECT 11
void GenError( int, char*, char * ); /* generic parsing error management function */
void GenError( char* _szErrors[], char, int, char*, char * ); /* generic parsing error management function */
void GenWarning( int, char*, char * ); /* generic parsing warning management function */
#endif /* HB_ERROR_H_ */

View File

@@ -51,6 +51,7 @@ extern WORD _wForCounter;
extern WORD _wIfCounter;
extern WORD _wWhileCounter;
extern WORD _wCaseCounter;
extern char * _szCErrors[];
int iLine = 1;
long lNumber = 0;
@@ -131,9 +132,9 @@ Separator {SpaceTab}
<INITIAL>\[ BEGIN STRING3;
<STRING1>[^'^\n]* { GenError( ERR_STRING_TERMINATOR, yytext, NULL ); BEGIN 0; }
<STRING2>[^\"^\n]* { GenError( ERR_STRING_TERMINATOR, yytext, NULL ); BEGIN 0; }
<STRING3>[^\]]*\n { GenError( ERR_STRING_TERMINATOR, yytext, NULL ); BEGIN 0; }
<STRING1>[^'^\n]* { GenError( _szCErrors, 'E', ERR_STRING_TERMINATOR, yytext, NULL ); BEGIN 0; }
<STRING2>[^\"^\n]* { GenError( _szCErrors, 'E', ERR_STRING_TERMINATOR, yytext, NULL ); BEGIN 0; }
<STRING3>[^\]]*\n { GenError( _szCErrors, 'E', ERR_STRING_TERMINATOR, yytext, NULL ); BEGIN 0; }
<STRING1>[^']*' { if( i_INDEX_STATE )
BEGIN INDEX;
@@ -203,7 +204,7 @@ Separator {SpaceTab}
return ';';
}
<LINECONT_>{Separator}*("("|")") {
GenError( ERR_INCOMPLETE_STMT, yytext, NULL );
GenError( _szCErrors, 'E', ERR_INCOMPLETE_STMT, yytext, NULL );
}
<LINECONT_>";" ; /*Ignore any repeated ';' */
<LINECONT_>{Separator}*. {
@@ -240,7 +241,7 @@ Separator {SpaceTab}
<BREAK_>{Separator}*[\[] { /* array */
if( i_INDEX_STATE ) BEGIN INDEX; else BEGIN 0;
/* Clipper does not like break[] at all */
GenError( ERR_SYNTAX, yytext, NULL );
GenError( _szCErrors, 'E', ERR_SYNTAX, yytext, NULL );
}
<BREAK_>{Separator}*[^_a-zA-Z\[] { /* there is no identifier after "break" */
if( i_INDEX_STATE ) BEGIN INDEX; else BEGIN 0;
@@ -278,7 +279,7 @@ Separator {SpaceTab}
<CASE_>{Separator}*[\[] { /* array */
if( i_INDEX_STATE ) BEGIN INDEX; else BEGIN 0;
/* Clipper does not like case[] at all */
GenError( ERR_SYNTAX, yytext, NULL );
GenError( _szCErrors, 'E', ERR_SYNTAX, yytext, NULL );
}
<CASE_>{Separator}*("+="|"-="|"->") { /* operators */
if( i_INDEX_STATE ) BEGIN INDEX; else BEGIN 0;
@@ -347,19 +348,19 @@ Separator {SpaceTab}
%}
"else" { /* ELSE can be used in one context only */
if( _wIfCounter == 0 )
GenError( ERR_UNMATCHED_ELSE, NULL, NULL );
GenError( _szCErrors, 'E', ERR_UNMATCHED_ELSE, NULL, NULL );
_iState =ELSE;
return ELSE;
}
"elseif" { /* ELSEIF can be used in one context only */
if( _wIfCounter == 0 )
GenError( ERR_UNMATCHED_ELSEIF, NULL, NULL );
GenError( _szCErrors, 'E', ERR_UNMATCHED_ELSEIF, NULL, NULL );
_iState =ELSEIF;
return ELSEIF;
}
"end"{Separator}+"sequ"("ence"|"enc"|"en"|"e")? {
if( _wSeqCounter == 0 )
GenError( ERR_ENDIF, NULL, NULL );
GenError( _szCErrors, 'E', ERR_ENDIF, NULL, NULL );
return END;
}
%{
@@ -368,17 +369,17 @@ Separator {SpaceTab}
"endif"|"endi" { /* ENDIF can be used in one context only */
if( _wIfCounter == 0 )
GenError( ERR_ENDIF, NULL, NULL );
GenError( _szCErrors, 'E', ERR_ENDIF, NULL, NULL );
return ENDIF;
}
"endc"("ase"|"as"|"a")? { /* ENDCASE can be used in one context only */
if( _wCaseCounter == 0 )
GenError( ERR_ENDCASE, NULL, NULL );
GenError( _szCErrors, 'E', ERR_ENDCASE, NULL, NULL );
return ENDCASE;
}
"enddo"|"endd" { /* ENDDO can be used in one context only */
if( _wWhileCounter == 0 )
GenError( ERR_ENDDO, NULL, NULL );
GenError( _szCErrors, 'E', ERR_ENDDO, NULL, NULL );
return ENDDO;
}
%{
@@ -389,7 +390,7 @@ Separator {SpaceTab}
if( i_INDEX_STATE ) BEGIN INDEX; else BEGIN 0;
if( _iState == LOOKUP )
{ /* Clipper does not like end[] & end() at the begining of line */
GenError( ERR_ENDIF, NULL, NULL );
GenError( _szCErrors, 'E', ERR_ENDIF, NULL, NULL );
}
yylval.string = yy_strdup( "END" );
_iState =IDENTIFIER;
@@ -400,7 +401,7 @@ Separator {SpaceTab}
if( i_INDEX_STATE ) BEGIN INDEX; else BEGIN 0;
if( _iState == LOOKUP )
{ /* Clipper does not like end-> & end++ at the begining of line */
GenError( ERR_ENDIF, NULL, NULL );
GenError( _szCErrors, 'E', ERR_ENDIF, NULL, NULL );
}
yylval.string = yy_strdup( "END" );
_iState =IDENTIFIER;
@@ -443,7 +444,7 @@ Separator {SpaceTab}
if( _iState == LOOKUP )
{ /* it is first item in the line */
if( _wForCounter == 0 && _wWhileCounter == 0 )
GenError( ERR_UNMATCHED_EXIT, "EXIT", NULL );
GenError( _szCErrors, 'E', ERR_UNMATCHED_EXIT, "EXIT", NULL );
_iState =EXITLOOP;
return EXITLOOP;
}
@@ -555,7 +556,7 @@ Separator {SpaceTab}
if( i_INDEX_STATE ) BEGIN INDEX; else BEGIN 0;
if( _iState == LOOKUP )
{ /* Clipper does not like FOR() at the begining of line */
GenError( ERR_SYNTAX, yytext, NULL );
GenError( _szCErrors, 'E', ERR_SYNTAX, yytext, NULL );
}
yylval.string = yy_strdup( "FOR" );
_iState =IDENTIFIER;
@@ -580,14 +581,14 @@ Separator {SpaceTab}
return FUNCTION;
}
<FUNCTION_>{Separator}*[^_a-zA-Z] { /* Clipper needs FUNCTION in one context only */
GenError( ERR_SYNTAX, ((yytext[ yyleng-1 ]=='\n')?"FUNCTION":yytext), NULL );
GenError( _szCErrors, 'E', ERR_SYNTAX, ((yytext[ yyleng-1 ]=='\n')?"FUNCTION":yytext), NULL );
}
%{
/* ************************************************************************ */
%}
"iif" {
if( _iState == FUNCTION || _iState == PROCEDURE )
GenError( ERR_SYNTAX, "IIF", NULL );
GenError( _szCErrors, 'E', ERR_SYNTAX, "IIF", NULL );
else
BEGIN IIF_;
/* Note: In Clipper:
@@ -604,14 +605,14 @@ Separator {SpaceTab}
return IIF;
}
<IIF_>{Separator}*[^\(] {
GenError( ERR_SYNTAX, ((yytext[ yyleng-1 ]=='\n')?"IIF":yytext), NULL );
GenError( _szCErrors, 'E', ERR_SYNTAX, ((yytext[ yyleng-1 ]=='\n')?"IIF":yytext), NULL );
}
%{
/* ************************************************************************ */
%}
"if" {
if( _iState == FUNCTION || _iState == PROCEDURE )
GenError( ERR_SYNTAX, "IF", NULL );
GenError( _szCErrors, 'E', ERR_SYNTAX, "IF", NULL );
else
BEGIN IF_;
}
@@ -625,16 +626,16 @@ Separator {SpaceTab}
return _iState;
}
<IF_>{Separator}*[\)\[\]\/\^\*\%\=\$\@] {
GenError( ERR_SYNTAX2, yytext, "IF" );
GenError( _szCErrors, 'E', ERR_SYNTAX2, yytext, "IF" );
}
<IF_>{Separator}*"->" {
GenError( ERR_SYNTAX2, yytext, "IF" );
GenError( _szCErrors, 'E', ERR_SYNTAX2, yytext, "IF" );
}
<IF_>{Separator}*[\n] {
GenError( ERR_SYNTAX, "IF", NULL );
GenError( _szCErrors, 'E', ERR_SYNTAX, "IF", NULL );
}
<IF_>{Separator}*("++"|"--")/[\n] {
GenError( ERR_SYNTAX2, yytext, "IF" );
GenError( _szCErrors, 'E', ERR_SYNTAX2, yytext, "IF" );
}
<IF_>{Separator}*. {
if( i_INDEX_STATE ) BEGIN INDEX; else BEGIN 0;
@@ -666,7 +667,7 @@ Separator {SpaceTab}
return IDENTIFIER;
}
<IN_>{Separator}*[0-9] {
GenError( ERR_SYNTAX, yytext, NULL );
GenError( _szCErrors, 'E', ERR_SYNTAX, yytext, NULL );
}
<IN_>{Separator}*. {
if( i_INDEX_STATE ) BEGIN INDEX; else BEGIN 0;
@@ -737,7 +738,7 @@ Separator {SpaceTab}
if( _iState == LOOKUP )
{ /* it is first item in the line */
if( _wWhileCounter == 0 && _wForCounter == 0 )
GenError( ERR_UNMATCHED_EXIT, "LOOP", NULL );
GenError( _szCErrors, 'E', ERR_UNMATCHED_EXIT, "LOOP", NULL );
_iState =LOOP;
return LOOP;
}
@@ -769,7 +770,7 @@ Separator {SpaceTab}
if( _iState == LOOKUP )
{ /* it is first item in the line */
if( _wForCounter == 0 )
GenError( ERR_NEXTFOR, NULL, NULL );
GenError( _szCErrors, 'E', ERR_NEXTFOR, NULL, NULL );
_iState =NEXT;
return NEXT;
}
@@ -785,7 +786,7 @@ Separator {SpaceTab}
if( i_INDEX_STATE ) BEGIN INDEX; else BEGIN 0;
if( _iState == LOOKUP )
{ /* Clipper does not like NEXT[] & NEXT() at the begining of line */
GenError( ERR_NEXTFOR, NULL, NULL );
GenError( _szCErrors, 'E', ERR_NEXTFOR, NULL, NULL );
}
yylval.string = yy_strdup( "NEXT" );
_iState =IDENTIFIER;
@@ -796,7 +797,7 @@ Separator {SpaceTab}
if( i_INDEX_STATE ) BEGIN INDEX; else BEGIN 0;
if( _iState == LOOKUP )
{ /* Clipper does not like next-> & next++ at the begining of line */
GenError( ERR_NEXTFOR, NULL, NULL );
GenError( _szCErrors, 'E', ERR_NEXTFOR, NULL, NULL );
}
yylval.string = yy_strdup( "NEXT" );
_iState =IDENTIFIER;
@@ -816,7 +817,7 @@ Separator {SpaceTab}
if( _iState == LOOKUP )
{
if( _wForCounter == 0 )
GenError( ERR_NEXTFOR, NULL, NULL );
GenError( _szCErrors, 'E', ERR_NEXTFOR, NULL, NULL );
_iState =NEXT;
return NEXT;
}
@@ -860,7 +861,7 @@ Separator {SpaceTab}
<WHILE_>{Separator}*[\[] { /* array */
if( i_INDEX_STATE ) BEGIN INDEX; else BEGIN 0;
/* Clipper does not like while[] at all */
GenError( ERR_SYNTAX, yytext, NULL );
GenError( _szCErrors, 'E', ERR_SYNTAX, yytext, NULL );
}
<WHILE_>{Separator}*[\:\=\|\$\%\*\,\/\]\)\}\^] { /* there is an operator after "case" */
if( i_INDEX_STATE ) BEGIN INDEX; else BEGIN 0;
@@ -917,7 +918,7 @@ Separator {SpaceTab}
}
<WITH_>{Separator}*[\[] { /* array */
/* Clipper does not like with[] at all */
GenError( ERR_SYNTAX, yytext, NULL );
GenError( _szCErrors, 'E', ERR_SYNTAX, yytext, NULL );
}
<WITH_>{Separator}*. {
if( i_INDEX_STATE ) BEGIN INDEX; else BEGIN 0;
@@ -980,7 +981,7 @@ Separator {SpaceTab}
[\(] ++_iOpenBracket; _iState =SEPARATOR; return yytext[ 0 ];
[\)] --_iOpenBracket; _iState =SEPARATOR; return yytext[ 0 ];
{InvalidNumber} GenError( ERR_NUMERIC_FORMAT, NULL, NULL );
{InvalidNumber} GenError( _szCErrors, 'E', ERR_NUMERIC_FORMAT, NULL, NULL );
{Number} { char * ptr;
yylval.dNum.dNumber = atof( yytext );

View File

@@ -252,7 +252,7 @@ int iVarScope = VS_LOCAL; /* holds the scope for next variables to be defined
/* different values for iVarScope */
/* Table with parse errors */
char * _szErrors[] = { "Statement not allowed outside of procedure or function",
char * _szCErrors[] = { "Statement not allowed outside of procedure or function",
"Redefinition of procedure or function: \'%s\'",
"Duplicate variable declaration: \'%s\'",
"%s declaration follows executable statement",
@@ -261,7 +261,6 @@ char * _szErrors[] = { "Statement not allowed outside of procedure or function",
"Unterminated string: \'%s\'",
"Redefinition of predefined function %s: \'%s\'",
"Illegal initializer: \'%s\'",
"Can\'t open #include file: \'%s\'",
"ENDIF does not match IF",
"ENDDO does not match WHILE",
"ENDCASE does not match DO CASE",
@@ -435,7 +434,7 @@ extern int _iState; /* current parser state (defined in harbour.l */
%token FUNCTION PROCEDURE IDENTIFIER RETURN NIL DOUBLE INASSIGN INTEGER INTLONG
%token LOCAL STATIC IIF IF ELSE ELSEIF END ENDIF LITERAL TRUEVALUE FALSEVALUE
%token INCLUDE EXTERN INIT EXIT AND OR NOT PUBLIC EQ NE1 NE2
%token EXTERN INIT EXIT AND OR NOT PUBLIC EQ NE1 NE2
%token INC DEC ALIAS DOCASE CASE OTHERWISE ENDCASE ENDDO MEMVAR
%token WHILE EXIT LOOP END FOR NEXT TO STEP LE GE FIELD IN PARAMETERS
%token PLUSEQ MINUSEQ MULTEQ DIVEQ POWER EXPEQ MODEQ EXITLOOP
@@ -485,7 +484,6 @@ Main : { Line(); } Source {
Source : Crlf
| Extern
| Include
| VarDefs
| FieldsDef
| MemvarDef
@@ -493,7 +491,6 @@ Source : Crlf
| Statement
| Source Crlf
| Source Extern
| Source Include
| Source Function
| Source { LineBody(); } Statement
| Source VarDefs
@@ -501,11 +498,6 @@ Source : Crlf
| Source MemvarDef
;
Include : NE1 INCLUDE LITERAL { if( ! Include( $3, _pIncludePath ) )
GenError( ERR_CANT_OPEN_INCLUDE, $3, NULL );
_iState =LOOKUP;
} Crlf
;
Extern : EXTERN ExtList { _iState =LOOKUP; } Crlf
;
@@ -1112,11 +1104,11 @@ void * GenElseIf( void * pFirst, WORD wOffset )
return pFirst;
}
void GenError( int iError, char * szError1, char * szError2 )
void GenError( char* _szErrors[], char cPrefix, int iError, char * szError1, char * szError2 )
{
char * szLine = ( char * ) OurMalloc( 160 ); /*2 lines of text */
printf( "\r%s(%i) ", files.pLast->szFileName, iLine );
printf( "Error E%i ", iError );
printf( "Error %c%i ", cPrefix, iError );
sprintf( szLine, _szErrors[ iError - 1 ], szError1, szError2 );
printf( "%s\n\n", szLine );
exit( 1 );
@@ -1673,7 +1665,7 @@ void AddVar( char * szVarName )
/* Variable declaration is outside of function/procedure body.
In this case only STATIC and PARAMETERS variables are allowed. */
--iLine;
GenError( ERR_OUTSIDE, NULL, NULL );
GenError( _szCErrors, 'E', ERR_OUTSIDE, NULL, NULL );
}
/* check if we are declaring local/static variable after some
@@ -1683,7 +1675,7 @@ void AddVar( char * szVarName )
if( (functions.pLast->bFlags & FUN_STATEMENTS) && !(iVarScope == VS_FIELD || iVarScope == VS_MEMVAR) )
{
--iLine;
GenError( ERR_FOLLOWS_EXEC, (iVarScope==VS_LOCAL?"LOCAL":"STATIC"), NULL );
GenError( _szCErrors, 'E', ERR_FOLLOWS_EXEC, (iVarScope==VS_LOCAL?"LOCAL":"STATIC"), NULL );
}
/* When static variable is added then functions.pLast points to function
@@ -1697,7 +1689,7 @@ void AddVar( char * szVarName )
* value initialization
*/
if( _pInitFunc->bFlags & FUN_ILLEGAL_INIT )
GenError( ERR_ILLEGAL_INIT, szVarName, pFunc->szName );
GenError( _szCErrors, 'E', ERR_ILLEGAL_INIT, szVarName, pFunc->szName );
}
/* Check if a declaration of duplicated variable name is requested */
@@ -1957,7 +1949,7 @@ void FunDef( char * szFunName, char cScope, int iType )
/* The name of a function/procedure is already defined */
if( ( pFunc != functions.pFirst ) || _iStartProc )
/* it is not a starting procedure that was automatically created */
GenError( ERR_FUNC_DUPL, szFunName, NULL );
GenError( _szCErrors, 'E', ERR_FUNC_DUPL, szFunName, NULL );
}
pFunction = (char * *)RESERVED_FUNC( szFunName );
@@ -1966,7 +1958,7 @@ void FunDef( char * szFunName, char cScope, int iType )
/* We are ignoring it when it is the name of PRG file and we are
* not creating implicit starting procedure
*/
GenError( ERR_FUNC_RESERVED, *pFunction, szFunName );
GenError( _szCErrors, 'E', ERR_FUNC_RESERVED, *pFunction, szFunName );
}
FixReturns(); /* fix all previous function returns offsets */
@@ -2933,7 +2925,7 @@ int GetLocalVarPos( char * szVarName ) /* returns the order + 1 of a variable if
* It is not possible to access a parameter of a codeblock in which
* the current codeblock is defined
*/
GenError( ERR_OUTER_VAR, szVarName, NULL );
GenError( _szCErrors, 'E', ERR_OUTER_VAR, szVarName, NULL );
else
{
/* We want to access a local variable defined in a function that
@@ -3232,7 +3224,7 @@ void LineBody( void ) /* generates the pcode with the currently compiled source
/* This line can be placed inside a procedure or function only */
if( ! _iStartProc && functions.iCount <= 1 )
{
GenError( ERR_OUTSIDE, NULL, NULL );
GenError( _szCErrors, 'E', ERR_OUTSIDE, NULL, NULL );
}
functions.pLast->bFlags |= FUN_STATEMENTS;
if( _iLineNumbers )
@@ -3664,7 +3656,7 @@ void CheckDuplVars( PVAR pVar, char * szVarName, int iVarScope )
{
if( iVarScope != VS_PARAMETER )
--iLine;
GenError( ERR_VAR_DUPL, szVarName, NULL );
GenError( _szCErrors, 'E', ERR_VAR_DUPL, szVarName, NULL );
}
else
pVar = pVar->pNext;
@@ -3831,7 +3823,7 @@ void FixReturns( void ) /* fixes all last defined function returns jumps offsets
pLoop =pLoop->pNext;
itoa( pLoop->wLine, cLine, 10 );
GenError( ERR_UNCLOSED_STRU, cLine, NULL );
GenError( _szCErrors, 'E', ERR_UNCLOSED_STRU, cLine, NULL );
}
*/
}