another day, another error...module programming

[b]I get this error: [/b]abbe@abbe-laptop:~Pascal$ gpc -o unitTest.pas

symbolTable.pas
symbolTable.pas:6: error: syntax error before ','
symbolTable.pas:30: error: unknown identifier 'table'
symbolTable.pas:30: error: missing semicolon
symbolTable.pas:31: error: unknown identifier 'table'
symbolTable.pas:32: error: unknown identifier 'table'
symbolTable.pas:35: error: syntax error before 'begin'
symbolTable.pas:46: error: syntax error before ','

[b]when I compile the following code:[/b]

[CODE]
program unitTest;
import symbolTable;
begin
addSymbol('hello', 1, 1.5)
end.

{next file}

module symbolTable interface;

export symbolTable = (addSymbol, inTable, getType, getValue);
procedure addSymbol(name : string, dt : integer, val : real);
function inTable(name: string): Boolean;
function getType(name : string): integer;
function getValue(name:string): real;

end.

module symbolTable implementation;

import
standardinput;
standardoutput;

Type
table = ^item;
item = record
name : string;
datatype : integer;
val : real;
next : table;
end;

var
symTable : table;
sym : table;
temp : table;

procedure initialize();
begin
symTable := nil;
new(sym);
symTable := sym;
sym^.name:='hi';
sym^.dataType :=100;
sym^.value := -30;

writeln(sym^.name);
end;

procedure addSymbol(name : string, dt : integer, val : real);
begin
initialize();
end;
end.

[/CODE]

OK, this is just a test unit for a module of a much larger program. I'm such a newbie I don't get the syntax yet and would appreciate someone to have a look.

Thank you forf your help.

abbe

Comments

  • Hi !

    In GNU Pascal (as in most of Pascal compilers) the syntax of a unit is :
    [code]Unit SymbolTbl;

    INTERFACE

    procedure addSymbol(name : string, dt : integer, val : real);
    function inTable(name: string): Boolean;
    function getType(name : string): integer;
    function getValue(name:string): real;

    IMPLEMENTATION

    procedure addSymbol(name : string, dt : integer, val : real);
    begin
    { body }
    end;

    function inTable(name: string): Boolean;
    begin
    { body }
    end;

    function getType(name : string): integer;
    begin
    { body }
    end;

    function getValue(name:string): real;
    begin
    { body }
    end;

    BEGIN
    { Optional initialization code }
    END.[/code]
    Now the calling program :
    [code]program unitTest;
    Uses symbolTbl;
    begin
    addSymbol('hello', 1, 1.5)
    end.[/code]

  • So, is a unit the 'same' as a module? My assignment requires modules. I have a lexical analizer and a parser, both successful in this format with 'modules.' For some reason its not working with the symbol table, and I CAN'T figure it out!!! Especially since no matter what changes I do to it, it has the very same error messages. Like nothing I do changes anything. (GRRRRRRRRRRRRRRRRRRRRRRRR). I can't find much information on Modules when I google and my teacher hasn't responded to emails. This is due Monday night!

    abbe
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories