Sets module

Former-commit-id: 4bacf7f752
This commit is contained in:
Norayr Chilingarian 2014-01-24 23:04:41 +04:00
parent 54aa81283c
commit f20e35c84d
18 changed files with 622 additions and 39 deletions

View file

@ -8,7 +8,7 @@
END*)
MODULE CRA; (* handles the DFA *)
IMPORT Oberon, Texts, Sets, CRS, CRT;
IMPORT Out := Console, (*Oberon,*) Texts := CmdlnTexts, Sets := Sets0, CRS, CRT;
CONST
maxStates = 300;
@ -72,22 +72,37 @@ BEGIN CRS.Error(200+nr, CRS.pos)
END SemErr;
PROCEDURE Put(ch: CHAR);
BEGIN Texts.Write(out, ch) END Put;
BEGIN
(*Texts.Write(out, ch)*)
Out.Char(ch)
END Put;
PROCEDURE PutS(s: ARRAY OF CHAR);
VAR i: INTEGER;
BEGIN i := 0;
WHILE (i < LEN(s)) & (s[i] # 0X) DO
IF s[i] = "$" THEN Texts.WriteLn(out) ELSE Texts.Write(out, s[i]) END;
IF s[i] = "$" THEN
(*Texts.WriteLn(out)*)
Out.Ln
ELSE
(*Texts.Write(out, s[i])*)
Out.Char(s[i])
END;
INC(i)
END
END PutS;
PROCEDURE PutI(i: INTEGER);
BEGIN Texts.WriteInt(out, i, 0) END PutI;
BEGIN
(*Texts.WriteInt(out, i, 0)*)
Out.Int(i, 0)
END PutI;
PROCEDURE PutI2(i, n: INTEGER);
BEGIN Texts.WriteInt(out, i, n) END PutI2;
BEGIN
(*Texts.WriteInt(out, i, n) *)
Out.Int(i, n)
END PutI2;
PROCEDURE PutC(ch: CHAR);
BEGIN
@ -611,7 +626,7 @@ BEGIN
END;
action := action^.next
END;
Texts.Append(Oberon.Log, out.buf)
(*Texts.Append(Oberon.Log, out.buf)*)
END MeltStates;
PROCEDURE MakeDeterministic*(VAR correct: BOOLEAN);
@ -688,10 +703,11 @@ BEGIN
i := 0;
WHILE i <= CRT.maxC DO
CRT.GetClass(i, set); CRT.GetClassName(i, name); PutS(name); PutS(": ");
Sets.Print(out, set, 80, 13); Texts.WriteLn(out);
(*Sets.Print(out, set, 80, 13); Texts.WriteLn(out);*)
Sets.Write(set, 80, 13); Out.Ln;
INC(i)
END;
Texts.Append(Oberon.Log, out.buf)
(*Texts.Append(Oberon.Log, out.buf)*)
END PrintStates;
@ -763,8 +779,16 @@ BEGIN
Texts.Read (fram, ch); INC(i);
UNTIL ch # stopStr[i];
(*stopStr[0..i-1] found; 1 unrecognized character*)
j := 0; WHILE j < i DO Texts.Write(out, stopStr[j]); INC(j) END
ELSE Texts.Write (out, ch); Texts.Read(fram, ch)
j := 0;
WHILE j < i DO
(*Texts.Write(out, stopStr[j]);*)
Out.Char(stopStr[j]);
INC(j)
END
ELSE
(*Texts.Write (out, ch);*)
Out.Char (ch);
Texts.Read(fram, ch)
END
END
END CopyFramePart;
@ -891,10 +915,11 @@ BEGIN
COPY(sn.name, scanner); l := Length(scanner); scanner[l] := "S"; scanner[l+1] := 0X;
NEW(t); Texts.Open(t, "Scanner.FRM"); Texts.OpenReader(fram, t, 0);
IF t.len = 0 THEN
Texts.WriteString(out, "Scanner.FRM not found"); Texts.WriteLn(out);
Texts.Append(Oberon.Log, out.buf); HALT(99)
(*Texts.WriteString(out, "Scanner.FRM not found"); Texts.WriteLn(out);*)
Out.String("Scanner.FRM not found"); Out.Ln;
(*Texts.Append(Oberon.Log, out.buf);*) HALT(99)
END;
Texts.Append(Oberon.Log, out.buf);
(*Texts.Append(Oberon.Log, out.buf);*)
(*------- *S.MOD -------*)
CopyFramePart("-->modulename"); PutS(scanner);
@ -930,12 +955,13 @@ BEGIN
PutS("start["); PutI(4*i+j); PutS("]:="); PutI(startTab[4*i+j]); PutS("; ");
INC(j)
END;
Texts.WriteLn(out);
(*Texts.WriteLn(out); *)
Out.Ln;
INC(i)
END;
CopyFramePart("-->modulename"); PutS(scanner); Put(".");
NEW(t); t.notify := Show; Texts.Open(t, ""); Texts.Append(t, out.buf);
NEW(t); (*t.notify := Show;*) Texts.Open(t, ""); Texts.Append(t, out.buf);
l := Length(scanner); scanner[l] := "."; scanner[l+1] := "M"; scanner[l+2] := "o"; scanner[l+3] := "d"; scanner[l+4] := 0X;
Texts.Close(t, scanner)
END WriteScanner;

View file

@ -1,7 +1,7 @@
(* parser module generated by Coco-R *)
MODULE CRP;
IMPORT CRS, CRT, CRA, CRX, Sets, Texts, Oberon;
IMPORT CRS, CRT, CRA, CRX, Sets := Sets0, Texts := CmdlnTexts, Out := Console (*Oberon*);
CONST
maxP = 42;
@ -591,7 +591,8 @@ BEGIN
CRS.GetName(CRS.pos, CRS.len, name);
IF name # gramName THEN SemErr(17) END;
IF CRS.errors = 0 THEN
Texts.WriteString(w, " checking"); Texts.Append(Oberon.Log, w.buf);
(*Texts.WriteString(w, " checking"); Texts.Append(Oberon.Log, w.buf);*)
Out.String(" checking");
CRT.CompSymbolSets;
IF ok THEN CRT.TestCompleteness(ok) END;
IF ok THEN
@ -602,12 +603,14 @@ BEGIN
IF CRT.ddt[0] THEN CRA.PrintStates END;
IF CRT.ddt[7] THEN CRT.XRef END;
IF ok THEN
Texts.WriteString(w, " +parser");
Texts.Append(Oberon.Log, w.buf);
(*Texts.WriteString(w, " +parser");*)
Out.String(" +parser");
(*Texts.Append(Oberon.Log, w.buf);*)
CRX.GenCompiler;
IF genScanner THEN
Texts.WriteString(w, " +scanner");
Texts.Append(Oberon.Log, w.buf);
(*Texts.WriteString(w, " +scanner");*)
Out.String(" +scanner");
(*Texts.Append(Oberon.Log, w.buf);*)
CRA.WriteScanner(ok)
END;
IF CRT.ddt[8] THEN CRX.WriteStatistics END
@ -615,8 +618,11 @@ BEGIN
ELSE ok := FALSE
END;
IF CRT.ddt[6] THEN CRT.PrintSymbolTable END;
IF ok THEN Texts.WriteString(w, " done") END;
Texts.WriteLn(w); Texts.Append(Oberon.Log, w.buf) ;
IF ok THEN
(*Texts.WriteString(w, " done") END;*)
Out.String(" done") END;
(*Texts.WriteLn(w); Texts.Append(Oberon.Log, w.buf) ;*)
Out.Ln;
Expect(10);
END CR;

View file

@ -1,6 +1,6 @@
MODULE CRT; (* Cocol-R Tables *)
IMPORT Texts := CmdlnTexts, Out := Console, (*Oberon,*) Sets;
IMPORT Texts := CmdlnTexts, Out := Console, (*Oberon,*) Sets := Sets0;
CONST
maxSymbols* = 300; (*max nr of t, nt, and pragmas*)

View file

@ -1,6 +1,6 @@
MODULE CRX;
IMPORT Oberon, Texts, Sets, CRS, CRT, SYSTEM;
IMPORT Out := Console, (*Oberon,*) Texts := CmdlnTexts, Sets := Sets0, CRS, CRT, SYSTEM;
CONST
symSetSize = 100;
@ -23,8 +23,10 @@ VAR
PROCEDURE Restriction(n: INTEGER);
BEGIN
Texts.WriteLn(w); Texts.WriteString(w, "Restriction ");
Texts.WriteInt(w, n, 0); Texts.WriteLn(w); Texts.Append(Oberon.Log, w.buf);
(*Texts.WriteLn(w); Texts.WriteString(w, "Restriction ");*)
Out.Ln; Out.String("Restriction ");
(*Texts.WriteInt(w, n, 0); Texts.WriteLn(w); Texts.Append(Oberon.Log, w.buf);*)
Out.Int(n, 0); Out.Ln;
HALT(99)
END Restriction;
@ -415,8 +417,9 @@ BEGIN
NEW(t); Texts.Open(t, "Parser.FRM"); Texts.OpenReader(fram, t, 0);
IF t.len = 0 THEN
Texts.WriteString(w, "Parser.FRM not found"); Texts.WriteLn(w);
Texts.Append(Oberon.Log, w.buf); HALT(99)
(*Texts.WriteString(w, "Parser.FRM not found"); Texts.WriteLn(w);*)
Out.String("Parser.FRM not found"); Out.Ln;
(*Texts.Append(Oberon.Log, w.buf);*) HALT(99)
END ;
Texts.OpenWriter(err); Texts.WriteLn(err);
@ -425,7 +428,9 @@ BEGIN
(*----- write *P.Mod -----*)
Texts.OpenWriter(syn);
NEW(t); t.notify := Show; Texts.Open(t, "");
NEW(t);
(*t.notify := Show; *)
Texts.Open(t, "");
CopyFramePart("-->modulename"); PutS(parser);
CopyFramePart("-->scanner"); PutS(scanner);
IF CRT.importPos.beg >= 0 THEN PutS(", "); CopySourcePart(CRT.importPos, 0) END ;
@ -457,11 +462,16 @@ END GenCompiler;
PROCEDURE WriteStatistics*;
BEGIN
Texts.WriteInt (w, CRT.maxT + 1, 0); Texts.WriteString(w, " t, ");
(*Texts.WriteInt (w, CRT.maxT + 1, 0); Texts.WriteString(w, " t, ");*)
Out.Int (CRT.maxT + 1, 0); Out.String(" t, ");
Texts.WriteInt (w, CRT.maxSymbols - CRT.firstNt + CRT.maxT + 1, 0); Texts.WriteString(w, " syms, ");
Texts.WriteInt (w, CRT.nNodes, 0); Texts.WriteString(w, " nodes, ");
Texts.WriteInt (w, maxSS, 0); Texts.WriteString(w, "sets");
Texts.WriteLn(w); Texts.Append(Oberon.Log, w.buf)
(*Texts.WriteInt (w, CRT.nNodes, 0); Texts.WriteString(w, " nodes, ");*)
Out.Int (CRT.nNodes, 0); Out.String(" nodes, ");
(*Texts.WriteInt (w, maxSS, 0); Texts.WriteString(w, "sets");*)
Out.Int (maxSS, 0); Out.String("sets");
(*Texts.WriteLn(w); *)
Out.Ln;
(*Texts.Append(Oberon.Log, w.buf)*)
END WriteStatistics;
PROCEDURE Init*;

View file

@ -19,7 +19,7 @@
==========================================================================*)
MODULE Coco;
IMPORT Oberon, TextFrames, Texts, Viewers, CRS, CRP, CRT;
IMPORT (*Oberon, TextFrames,*) Texts := CmdlnTexts,(* Viewers,*) CRS, CRP, CRT, Out := Console;
CONST minErrDist = 8;
@ -29,7 +29,9 @@ VAR w: Texts.Writer; lastErrPos: LONGINT;
PROCEDURE Error (n: INTEGER; pos: LONGINT);
PROCEDURE Msg (s: ARRAY OF CHAR);
BEGIN Texts.WriteString(w, s)
BEGIN
(*Texts.WriteString(w, s)*)
Out.String(s);
END Msg;
BEGIN
@ -95,7 +97,8 @@ BEGIN
| 53: Msg("invalid Declaration")
| 54: Msg("this symbol not expected in CR")
| 55: Msg("invalid CR")
ELSE Texts.WriteString(w, "error "); Texts.WriteInt(w, n, 0)
ELSE (*Texts.WriteString(w, "error "); Texts.WriteInt(w, n, 0)*)
Out.String("error "); Out.Int(n, 0)
END
ELSE
CASE n OF
@ -125,10 +128,12 @@ BEGIN
| 224: Msg("tokens must not contain blanks")
| 225: Msg("comment delimiter must not exceed 2 characters")
| 226: Msg("character set contains more than one character")
ELSE Texts.WriteString(w, "error "); Texts.WriteInt(w, n, 0)
ELSE (*Texts.WriteString(w, "error "); Texts.WriteInt(w, n, 0)*)
Out.String("error "); Out.Int(n, 0);
END
END;
Texts.WriteLn(w); Texts.Append(Oberon.Log, w.buf)
(*Texts.WriteLn(w); Texts.Append(Oberon.Log, w.buf)*)
Out.Ln
END Error;
PROCEDURE Options(VAR s: Texts.Scanner);
@ -146,6 +151,21 @@ BEGIN
END;
END Options;
PROCEDURE Options0(VAR s: ARRAY OF CHAR);
VAR i: INTEGER;
BEGIN
IF s.nextCh = "\" THEN Texts.Scan(s); Texts.Scan(s);
IF s.class = Texts.Name THEN i := 0;
WHILE s.s[i] # 0X DO
IF CAP(s.s[i]) = "X" THEN CRT.ddt[7] := TRUE
ELSIF CAP(s.s[i]) = "S" THEN CRT.ddt[1] := TRUE
END;
INC(i)
END
END
END;
END Options;
PROCEDURE Compile*;
VAR v: Viewers.Viewer; f: TextFrames.Frame; s: Texts.Scanner; src, t: Texts.Text;