LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-29-2010, 08:04 AM   #1
Asido
Member
 
Registered: Jan 2010
Location: Denmark
Distribution: Gentoo, Archlinux, FreeBSD, Slackware
Posts: 84

Rep: Reputation: 24
Syntax error, need some help (pascal)


I have an error, which I have no idea why appears. All brackets seems ok.

error:
Code:
(20,17) Error: Illegal qualifier
(20,19) Fatal: Syntax error, ")" expected but "." found
Code:
   
   1. program trans;
   2.
      type autobusai = record
   3.
              stot: string[20];
   4.
              marsrutas: integer;
   5.
              end;
   6.
      type masyvas1 = array [1..100] of autobusai;
   7.
      type masyvas2 = array [1..100] of integer;
   8.
      var a: masyvas1; atr, k:  masyvas2; f: text; n, max: integer;
   9.
       
  10.
      procedure skaitymas (var f: text; var n: integer; a: masyvas1; k: masyvas2);
  11.
      var i, j: integer;
  12.
      begin
  13.
              assign(f, 'U2.txt');
  14.
              reset(f);
  15.
              readln(f, n);
  16.
              for i:=1 to n do
  17.
                      begin
  18.
                      read(f, a[i].stot, k[i]);                      
  19.
                      for j:=1 to k[i] do                                      
  20.
                              read(f, a[i][j].marsrutas);             //n-stoteliu sk, k-marsrutu sk
  21.
                      readln(f);
  22.
                      end;
  23.
              close(f);
  24.
      end;
  25.
       
  26.
      procedure atrinkimas (a: masyvas1; var atr, k: masyvas2; n: integer);
  27.
      var h, f, i, j: integer;
  28.
      begin
  29.
              for h:=1 to n do
  30.
                      begin
  31.
                      for f:=1 to k[i] do
  32.
                              atr[a[h][f].marsrutas] := 0;
  33.
                      end;
  34.
       
  35.
              for i:=1 to n do
  36.
                      begin
  37.
                      for j:=1 to k[i] do
  38.
                              atr[a[i][j].marsrutas] := atr[a[i][j].marsrutas] + 1;
  39.
                      end;
  40.
      end;
  41.
       
  42.
      function maximum (a: masyvas1; var atr, k: masyvas2; n: integer) : integer;
  43.
      var i, j: integer;
  44.
      begin
  45.
              maximum := atr[a[1][1].marsrutas];
  46.
              for i:=1 to n do
  47.
                      begin
  48.
                      for j:=1 to k[i] do
  49.
                              begin
  50.
                              if maximum < atr[a[i][j].marsrutas]
  51.
                                      then maximum := atr[a[i][j].marsrutas];
  52.
                              end;
  53.
                      end;
  54.
      end;
  55.
       
  56.
      procedure rasymas (var f: text; max, n: integer; a: masyvas1; k: masyvas2);
  57.
      var i, j: integer;
  58.
      begin
  59.
              assign(f, 'U2rez.txt');
  60.
              rewrite(f);
  61.
              writeln(f, max);
  62.
              for i:=1 to n do
  63.
                      begin
  64.
                      for j:=1 to k[i] do
  65.
                              begin
  66.
                              if a[i][j].marsrutas = max
  67.
                                      then writeln(f, a[i].stot);
  68.
                              end;
  69.
                      end;
  70.
      end;
  71.
       
  72.
      begin
  73.
              skaitymas(f, n, a, k);
  74.
              atrinkimas(a, atr, k, n);
  75.
              max := maximum(a, atr, k, n);
  76.
              rasymas(f, max, n, a, k);
  77.
      end.
Anyone can tell me what is wrong there?

Last edited by Asido; 05-01-2010 at 05:06 AM.
 
Old 04-29-2010, 08:18 AM   #2
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by Asido View Post
I have an error, which I have no idea why appears. All brackets seems ok.

error:
Code:
(20,17) Error: Illegal qualifier
(20,19) Fatal: Syntax error, ")" expected but "." found
code: http://pastebin.com/E3n8AvpD

Anyone can tell me what is wrong there?
Does Pascal support '//' comments:

Code:
                read(f, a[i].stot, k[i]);                       //n-stoteliu sk, k-marsrutu sk
?
 
Old 04-29-2010, 08:23 AM   #3
Asido
Member
 
Registered: Jan 2010
Location: Denmark
Distribution: Gentoo, Archlinux, FreeBSD, Slackware
Posts: 84

Original Poster
Rep: Reputation: 24
Quote:
Originally Posted by Sergei Steshenko View Post
Does Pascal support '//' comments:

Code:
                read(f, a[i].stot, k[i]);                       //n-stoteliu sk, k-marsrutu sk
?
Yes, of course. And without them the same.

Last edited by Asido; 04-29-2010 at 08:29 AM.
 
Old 04-29-2010, 08:31 AM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Quote:
Without them the same.
Them being the slashes or the whole remark "//n-stoteliu sk, k-marsrutu sk"?

A quick search, as it has been years since doing Pascal, yielded that comments are set in curly braces, ie {}
 
Old 04-29-2010, 08:40 AM   #5
Asido
Member
 
Registered: Jan 2010
Location: Denmark
Distribution: Gentoo, Archlinux, FreeBSD, Slackware
Posts: 84

Original Poster
Rep: Reputation: 24
Quote:
Originally Posted by grail View Post
Them being the slashes or the whole remark "//n-stoteliu sk, k-marsrutu sk"?

A quick search, as it has been years since doing Pascal, yielded that comments are set in curly braces, ie {}
Free Pascal supports the use of nested comments. The following constructs are valid comments:

(* This is an old style comment *)
{ This is a Turbo Pascal comment }
// This is a Delphi comment. All is ignored till the end of the line.

Anyway, I have no idea whats wrong in there, but I am sure it is not the comments
 
Old 04-29-2010, 09:03 AM   #6
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by Asido View Post
Yes, of course. And without them the same.
Then use the "comment out" approach. I.e. start replacing procedure/function bodies with empty ones until the error disappears. The last emptied body will be the culprit.

When you find it, start restoring pieces of code until you realize which piece of code caused the error.
 
Old 04-29-2010, 10:15 AM   #7
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Asido, my Pascal is quite rusty, but looking at line 20 of your code it looks like it tries to assign a record of a two-dimensional array "a". But in the declaration scope the array is one-dimensional:
Code:
type autobusai = record
        stot: string[20];
        marsrutas: integer;
        end;
type masyvas1 = array [1..100] of autobusai;
var a: masyvas1;
I interpret this as declaring an array of 100 elements, each of them being a record made of a string of maximum length 20 and an integer. If this is correct you cannot assign the following:
Code:
read(f, a[i][j].marsrutas);
hence the error from the compiler.
 
Old 04-29-2010, 02:03 PM   #8
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Asido -

Please stop using "pastebin": you can post your code snippets directly into LQ (just remember to use code blocks.

In any case:
Code:
type 

  autobusai = record
    stot: string[20];
    marsrutas: integer;
    end;

  masyvas1 = array [1..100] of autobusai;

var 
  a: masyvas1;
* String is an array of char (just FYI: not relevant here one way or the other)
By default, it's variable length
"string[20]" is exactly 20 printable characters: no more, no less
* masyvas1 is an array of "autobusai" records

So:
Code:
  read(f, a[i].stot);  // This will read one string
'Hope that helps .. PSM

Last edited by paulsm4; 04-29-2010 at 04:59 PM. Reason: Correction
 
Old 04-29-2010, 03:38 PM   #9
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Quote:
Originally Posted by paulsm4 View Post
Code:
  read(f, a[i].marsrutas[j]);  // This will read one string
Paul, the field "marsrutas" is a scalar integer and it can't accept an index. Maybe the statement should assign the character array "stot", as you pointed out. Anyway, I don't understand what's the intent of this code, first because we don't know what is the content of the input file, second because... I cannot translate from Lithuanian!
 
Old 04-29-2010, 04:57 PM   #10
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Crap - sorry

To read the integer:
Code:
read(f, a[i].marsrutas);  // This will read one integer
To read the string:
Code:
read(f, a[i].stot);  // This will read one string
To get a syntax error:
Code:
read(f, a[i][j].marsrutas); // This is just WRONG
Let us know what you find.

Last edited by paulsm4; 04-29-2010 at 05:02 PM.
 
Old 04-29-2010, 05:10 PM   #11
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Quote:
Originally Posted by paulsm4 View Post
To read the integer:
To read the string:
To get a syntax error:
He he.. wonderful!
 
Old 04-30-2010, 11:19 AM   #12
Asido
Member
 
Registered: Jan 2010
Location: Denmark
Distribution: Gentoo, Archlinux, FreeBSD, Slackware
Posts: 84

Original Poster
Rep: Reputation: 24
Ok, so I'll better write what i actually need to do, since I am kinda confused with the code now. I need to make a program which reads U2.txt and picks the number which is repeated the most after the string and it should be written in the U2rez.txt. The U2.txt example:
Code:
5  {<--this number shows the amount of strings}
Rytas               5 1 2 5 4 6
Vakarai             3 12 5 4
Baltasis lokys      6 12 1 6 8 7 3
Panerys             1 12
Rudasis tiltas      3 8 14 4
{first number after the string shows the amount of numbers in the line}
In this example there are 2 such number - 4 and 12. In such case the smaller must be written.
Furthermore, the string must be typed in which this number is.
If I use the U2 example above, the U2rez should look like this:
Code:
4
Rytas
Vakarai
Rudasis tiltas
My code is in the first post. (sorry for using pastebin before)

Last edited by Asido; 04-30-2010 at 11:26 AM.
 
Old 04-30-2010, 12:08 PM   #13
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Quote:
I need to make a program which reads U2.txt and picks the number which is repeated the most after the string
I a not sure how with the example you have given that your results meet this criteria??

Code:
Rytas               5 1 2 5 4 6
Vakarai             3 12 5 4
Baltasis lokys      6 12 1 6 8 7 3
Panerys             1 12
Rudasis tiltas      3 8 14 4
To me it appears that all the bolded numbers appear 3 times ... unless I missing something??
 
Old 04-30-2010, 12:57 PM   #14
Asido
Member
 
Registered: Jan 2010
Location: Denmark
Distribution: Gentoo, Archlinux, FreeBSD, Slackware
Posts: 84

Original Poster
Rep: Reputation: 24
Quote:
Originally Posted by grail View Post
I a not sure how with the example you have given that your results meet this criteria??

Code:
Rytas               5 1 2 5 4 6
Vakarai             3 12 5 4
Baltasis lokys      6 12 1 6 8 7 3
Panerys             1 12
Rudasis tiltas      3 8 14 4
To me it appears that all the bolded numbers appear 3 times ... unless I missing something??
As I said, the first number indicates how many numbers there is in that line, so it doesn't count.

EDIT:-----------------------------------------------------------------------------------------------

Well, finally I managed to make it work. If someone is interested in code (have no idea why should be :P), here it is:
Code:
program trans;
type autobusai = record
	stot: string[20];
	atr, k, tikr: integer;
	end;
type masyvas1 = array [1..100] of autobusai;
type masyvas2 = array [1..100,1..100] of integer;
var a: masyvas1; marsrutas:  masyvas2; f: text; n, max: integer;

procedure skaitymas (var f: text; var n: integer; var a: masyvas1; var marsrutas: masyvas2);
var i, j: integer;
begin
	assign(f, 'U2.txt');
	reset(f);
	readln(f, n);
	for i:=1 to n do
		begin
		read(f, a[i].stot, a[i].k);			
		for j:=1 to a[i].k do					 
			read(f, marsrutas[i][j]);		//n-stoteliu sk, k-marsrutu sk
			
		readln(f);
		end;
	close(f);
end;

procedure atrinkimas (var a: masyvas1; var marsrutas: masyvas2; n: integer);
var h, f, i, j: integer;
begin
	for h:=1 to n do
		begin
		for f:=1 to a[h].k do
			a[marsrutas[h][f]].atr := 0;
		end;

	for i:=1 to n do
		begin
		for j:=1 to a[i].k do
			a[marsrutas[i][j]].atr := a[marsrutas[i][j]].atr + 1;
		end;
end;

function maximum (var a: masyvas1; var marsrutas: masyvas2; n: integer) : integer;
var i, j, l, t, b, p: integer;
begin
	maximum := a[marsrutas[1][1]].atr;
	for i:=1 to n do
		begin
		for j:=1 to a[i].k do
			begin
			if maximum < a[marsrutas[i][j]].atr
				then maximum := a[marsrutas[i][j]].atr;
			end;
		end;
	
	p := 1;
	for l:=1 to n do
		begin
		for t:=1 to a[l].k do
			begin
			if a[marsrutas[l][t]].atr = maximum
				then
				begin
				a[p].tikr := marsrutas[l][t];
				p := p + 1;
				end;
			end;
		end;
	
	maximum := a[1].tikr;
	for b:=2 to p do
		begin
		if a[b].tikr < maximum
			then a[b].tikr := maximum;
		end;
end;

procedure rasymas (var f: text; max, n: integer; a: masyvas1; marsrutas: masyvas2);
var i, j: integer;
begin
	assign(f, 'U2rez.txt');
	rewrite(f);
	
	writeln(f, max);		
		
	for i:=1 to n do
		begin
		for j:=1 to a[i].k do
			begin
			if marsrutas[i][j] = max
				then writeln(f, a[i].stot);
			end;
		end;
	close(f);
end;

begin
	skaitymas(f, n, a, marsrutas);
	atrinkimas(a, marsrutas, n);
	max := maximum(a, marsrutas, n);
	rasymas(f, max, n, a, marsrutas);
end.

Last edited by Asido; 05-01-2010 at 05:11 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Pascal IDE with code completion Bjorne Programming 3 02-13-2006 09:46 AM
Can someone help me with Pascal? randyriver10 Programming 2 09-29-2005 04:09 PM
Compiling Pascal... sanmartin Linux - Software 2 04-16-2005 06:59 PM
Pascal code Gerardoj Programming 6 09-28-2003 12:46 PM
Pascal Code Explanation Gerardoj Programming 1 09-25-2003 01:15 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:03 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration