Plov003 : compile 'test3'
The next source is 'test3' and it is listed below:
PROGRAM Number1 CONSTANTS pi = 314 ee = 272 END VARIABLES A B C Def GhYh J123 END END Number1I added VARIABLES. See what it does so far:
an@beryllium:~/modula/Plov$ Plov003 <test3 PROGRAM Number1 CONSTANTS pi = ee = END VARIABLES A Illegal identifier name : A B Illegal identifier name : B C Illegal identifier name : C Def GhYh J123 END END Number1 Number1 Program type. RETURN Keyword type. EXIT Keyword type. LOOP Keyword type. BEGIN Keyword type. END Keyword type. IF Keyword type. THEN Keyword type. ELSIF Keyword type. ODD Keyword type. PROCEDURE Keyword type. PROGRAM Keyword type. CONSTANTS Keyword type. VARIABLES Keyword type. pi Constant = 314 type. ee Constant = 272 type. Def Variable type. J123 Variable type. jan@beryllium:~/modula/Plov$Something fishy going on here. The Constants are now OK. But the single letter variables are treated as 'illegal'. I have a hunch what's wrong. But from the three multiletter variables (Def GhYh J123) only the first and third are listed in the symbol table....
PROCEDURE isAlpha (chr : CHAR) : BOOLEAN;
BEGIN
chr := CAP (chr);
IF (chr >= 'A') AND (chr <= 'Z') THEN
RETURN TRUE
END;
RETURN FALSE
END isAlpha;
PROCEDURE isAlphaNum (chr : CHAR) : BOOLEAN;
BEGIN
RETURN isAlpha (chr) OR isDigit (chr)
END isAlphaNum;
PROCEDURE isNumber (str : Identifier) : BOOLEAN;
VAR i : CARDINAL;
BEGIN
i := 0;
REPEAT
IF isDigit (str [i]) = FALSE THEN RETURN FALSE END;
INC (i)
UNTIL (str [i] = 0C) OR (i > HIGH (str));
RETURN TRUE
END isNumber;
PROCEDURE isIdentifier (str : Identifier) : BOOLEAN;
VAR i : CARDINAL;
BEGIN
IF NOT isAlpha (str [0]) THEN RETURN FALSE END;
IF Strings.Length (str) = 1 THEN RETURN TRUE END;
i := 1;
REPEAT
IF NOT isAlphaNum (str [i]) THEN RETURN FALSE END;
INC (i)
UNTIL (str [i] = 0C) OR (i > HIGH (str));
RETURN TRUE
END isIdentifier;
See what it does:
jan@beryllium:~/modula/Plov$ Plov003 <test3 PROGRAM Number1 CONSTANTS pi = ee = END VARIABLES A B C Def GhYh J123 END Duplicate identifier : END END Number1 Number1 Program type. RETURN Keyword type. EXIT Keyword type. LOOP Keyword type. BEGIN Keyword type. END Keyword type. IF Keyword type. THEN Keyword type. ELSIF Keyword type. ODD Keyword type. PROCEDURE Keyword type. PROGRAM Keyword type. CONSTANTS Keyword type. VARIABLES Keyword type. pi Constant = 314 type. ee Constant = 272 type. A Variable type. C Variable type. GhYh Variable type. jan@beryllium:~/modula/Plov$Better now. Single letter variables are now accepted and included in the symbol table, but also here: only two out of three are included. Fixed it: GetSymbol was placed inside the REPEAT loop instead of outside:
PROCEDURE VariableDeclaration;
BEGIN
GetSymbol; (* Used to be below the line with 'currentType' in it *)
REPEAT
currentType := Vartype;
IF isIdentifier (token) THEN
IF StoreSymbol (token) = TRUE THEN
GetSymbol
ELSE
ErrorMessage (6) (* Duplicate identifier *)
END
ELSE
ErrorMessage (5) (* Illegal Identifier *)
END
UNTIL Strings.StrEq (token, "END");
IF SyntaxError THEN Synchronize END;
GetSymbol
END VariableDeclaration;
And now fr a new testrun:
jan@beryllium:~/modula/Plov$ Plov003 <test3 PROGRAM Number1 CONSTANTS pi = ee = END VARIABLES A B C Def GhYhJ123 END END Number1 Number1 Program type. RETURN Keyword type. EXIT Keyword type. LOOP Keyword type. BEGIN Keyword type. END Keyword type. IF Keyword type. THEN Keyword type. ELSIF Keyword type. ODD Keyword type. PROCEDURE Keyword type. PROGRAM Keyword type. CONSTANTS Keyword type. VARIABLES Keyword type. pi Constant = 314 type. ee Constant = 272 type. A Variable type. B Variable type. C Variable type. Def Variable type. GhYh Variable type. J123 Variable type. jan@beryllium:~/modula/Plov$FIXED! Constants and variables are stored in the symbol table! Most problems are so simple to solve, if you feel the force to control the source!
Plov003 : compile 'test5'
Source to compile:
PROGRAM Number1 CONSTANTS pi = 314 ee = 272 END VARIABLES A B C Def GhYh J123 NH4NO3 END BEGIN END Number1Compilation result:
jan@beryllium:~/modula/Plov$ Plov003 <test5 PROGRAM Number1 CONSTANTS pi = ee = END VARIABLES A B C Def GhYhJ123 NH4NO3 END BEGIN END Number1 Number1 Program type RETURN Keyword type EXIT Keyword type LOOP Keyword type BEGIN Keyword type END Keyword type IF Keyword type THEN Keyword type ELSIF Keyword type ODD Keyword type PROCEDURE Keyword type PROGRAM Keyword type CONSTANTS Keyword type VARIABLES Keyword type pi Constant type = 314 ee Constant type = 272 A Variable type B Variable type C Variable type Def Variable type GhYh Variable type J123 Variable type NH4NO3 Variable type jan@beryllium:~/modula/Plov$Nice going!
Plov003 : compile 'test4'
Source to compile :
PROGRAM Number1 CONSTANTS pi = 314 ee = 272 END VARIABLES A B C Def GhYh J123 NH4NO3 END PROCEDURE AddItUp BEGIN END AddItUp BEGIN AddItUp END Number1Compilation results :
jan@beryllium:~/modula/Plov$ Plov003 <test4 PROGRAM Number1 CONSTANTS pi = ee = END VARIABLES A B C Def GhYhJ123 NH4NO3 END PROCEDURE AddItUp BEGIN END AddItUp END expected BEGIN Procedure names do not match. AddItUp AddItUp BEGIN expected jan@beryllium:~/modula/Plov$Error messages and the program gets stuck in an endless loop. After few seconds the system gets sluggish and the CPU fan goes into third gear. Work to do!
The work to do was a constant juggling with placement of the 'GetSymbol' command. In one function it worked and then when another function was used, the BlockBody function had the GetSymbol call in the wrong place. But now it works...
jan@beryllium:~/modula/Plov$ Plov003 <test4 PROGRAM Number1 CONSTANTS pi = ee = END VARIABLES A B C Def GhYhJ123 NH4NO3 END PROCEDURE AddItUp BEGIN END AddItUp BEGIN AddItUp END Number1 Number1 Program type RETURN Keyword type EXIT Keyword type LOOP Keyword type BEGIN Keyword type END Keyword type IF Keyword type THEN Keyword type ELSIF Keyword type ODD Keyword type PROCEDURE Keyword type PROGRAM Keyword type CONSTANTS Keyword type VARIABLES Keyword type pi Constant type = 314 ee Constant type = 272 A Variable type B Variable type C Variable type Def Variable type GhYh Variable type J123 Variable type NH4NO3 Variable type AddItUp Procedure type jan@beryllium:~/modula/Plov$
Plov003 : compile 'test6'
Source to compile :
PROGRAM Number1 CONSTANTS pi = 314 ee = 272 END VARIABLES A B C Def GhYh J123 NH4NO3 END PROCEDURE Diff BEGIN END Diff PROCEDURE AddItUp BEGIN END AddItUp BEGIN AddItUp Diff END Number1Compilation results :
jan@beryllium:~/modula/Plov$ Plov003 <test6 PROGRAM Number1 CONSTANTS pi = ee = END VARIABLES A B C Def GhYhJ123 NH4NO3 END PROCEDURE Diff BEGIN END Diff PROCEDURE AddItUp BEGIN END AddItUp BEGINAddItUp Diff END Number1 Number1 Program type RETURN Keyword type EXIT Keyword type LOOP Keyword type BEGIN Keyword type END Keyword type IF Keyword type THEN Keyword type ELSIF Keyword type ODD Keyword type PROCEDURE Keyword type PROGRAM Keyword type CONSTANTS Keyword type VARIABLES Keyword type pi Constant type = 314 ee Constant type = 272 A Variable type B Variable type C Variable type Def Variable type GhYh Variable type J123 Variable type NH4NO3 Variable type Diff Procedure type AddItUp Procedure type jan@beryllium:~/modula/Plov$More than one variable. More than one cosntant. More than one procedure. All symbols recognized and processed. One should have a fine feeling at such a moment. I am one of those!
Page created on 6 October 2007 and
Page equipped with GoogleBuster technology