Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

six "syntax error" messages

Status
Not open for further replies.

Cornelius19

Technical User
Mar 9, 2007
26
Hi,

I need to run an awk script written by someone else seven years ago and probably working fine in that configuration. Now I receive six "syntax error" messages (no other errors), the first two are:

awk: iprjen.awk:72: aFtagHierarchy[$1][
awk: iprjen.awk:72: ^ syntax error
awk: iprjen.awk:275: is_not_baseform = aFtagHierarchy[bfpos][featag]
awk: iprjen.awk:275: ^ syntax error

Here are the corresponding lines in the awk file:

lines 71-73 (in the BEGIN section):
Code:
      else {
         aFtagHierarchy[$1][$2] = $3;
      }

lines 273-278 (in a user defined function):
Code:
   	else 
   	{
   		is_not_baseform = aFtagHierarchy[bfpos][featag]
			if ( is_not_baseform == "" )
				is_not_baseform = "9";
		}

Do you have any idea what is wrong? I use gawk 3.1.5 (under cygwin).

Thanks,

Cornelius
 
Hi

Hmm... Sure it is [tt]gawk[/tt], the GNU implementation of [tt]awk[/tt] ? As far as I know, that was never valid code. In multiple dimensioned arrays use comma ( , ) to separate indexes written between a single pair of brackets ( [] ) :
Code:
      else {
         aFtagHierarchy[$1[red],[/red]$2] = $3;
      }

Feherke.
 
Thanks a lot for the suggestion: I used coma and single pair of brackets instead of the double pair of brackets and the two error messages disappeared.

I still get some errors however, here are the next two (the fifth and sixths are the same as the third):

Code:
awk: iprjen.awk:306:                substr(aPrintArray[1], 8, 1) = "0";
awk: iprjen.awk:306:                                             ^ syntax error
awk: iprjen.awk:307:             else {
awk: iprjen.awk:307:             ^ syntax error

Lines 305-307 are:
Code:
            if ( inflform == baseform )
               substr(aPrintArray[1], 8, 1) = "0";
            else {
Would you have some suggestion for these as well?

Thanks,

Cornelius

P.-S. The company who developed this code was sold to a second company and we bought that second company and we do not have much documentation. So, at this point, it is not clear which version of awk they were using.
 
Thanks a lot again. All the syntax error messages disappeared but a new one appeared instead:
Code:
awk: iprjen.awk:117: (FILENAME=iprjen.uni FNR=1) fatal: attempt to use scalar `a
PrintArray' as array
Here are lines 112-117:
Code:
      # if we have a print array, process it first
      if ( length(aPrintArray) > 0 ) {
         fnProcessParadigm();
      }
      # clean up: set counters back to zero
      delete aPrintArray;
I am wondering why it is considered a scalar. Curiously, it is not a problem in 113 but it is in 117.

Any suggestion?

Cornelius
 
Hi

You try to use both the [tt]length()[/tt] and [tt]delete[/tt] functions on the same variable. As [tt]length()[/tt] expects a scalar value and [tt]delete[/tt] expects an array element ( or array in [tt]gawk[/tt] ), one of them must fail.

As in standard [tt]awk[/tt] ( and neither in [tt]gawk[/tt] ) there is no function to get the size of an array ( Ok, [tt]asort()[/tt] returns the size, but you pay for it with the speed ), I suggest to add your own function and use it instead :
Code:
      # if we have a print array, process it first
      if ( [red]a[/red]length(aPrintArray) > 0 ) {
         fnProcessParadigm();
      }
      # clean up: set counters back to zero
      delete aPrintArray;



[gray]# ...[/gray]



[gray]# Calculates an array's size[/gray]
[gray]#   a - array which size to be calculated[/gray]
[gray]#   returns - the size of the array[/gray]
[b]function[/b] alength(a)
{
  n=0
  [b]for[/b] (i [b]in[/b] a) n++
  [b]return[/b] n
}

Feherke.
 
For your error posted 4 Jun 07 14:44, replace this:
substr(aPrintArray[1], 8, 1) = "0"
with this:
aPrintArray[1]=substr(aPrintArray[1],1,7)"0"substr(aPrintArray[1],9)

I wonder which version of awk was supposed to admit such syntax ...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks a lot – it is really great to be able to get help from knowledgeable people like you! I applied PHV’s modification and feherke’s function (and a couple of other easy changes). Now I can run the script, get an output file and the result looks good.

Cornelius

P.-S. I consider posting the script (or at least some problematic parts of it) in a new thread so that someone could identify the version of awk it would run on.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top