// // File GRREAD.RF // // Project: GR // $use Class; $use Convert; $use Dos; $use StdIO; $use GrScn; $use GrPrn; $func Parse e.Chl = (e.Tokens) (e.Rules); $func Grammar sC sI = sC sI (e.Tokens) (e.Rules); $func TokenSeq sC sI (e.Tokens) = sC sI (e.Tokens); $func GroupSeq sC sI (e.Groups) = sC sI (e.Groups); $func Group sC sI = sC sI (e.Group); $func RhsSeq sC sI (e.Group) = sC sI (e.Group); $func RhsSeqRest sC sI (e.Group) = sC sI (e.Group); $func Rhs sC sI (e.Rhs) = sC sI (e.Rhs); $func? IsKeyword s.KW sC sI = sC sI ; $func Keyword s.KW sC sI = sC sI ; $func? IsName sC sI = sC sI s.Name; $func Name sC sI = sC sI s.Name; $func CheckGrammar (e.Tokens) (e.Rules) = ; $func InsertTags (e.Tokens) (e.Rules) = e.TaggedRules; $func InsertTagsRhsList (e.Tokens) (e.RhsList) = e.TaggedRhsList; $func InsertTagsRhs (e.Tokens) (e.Rhs) = e.TaggedRhs; $channel Input; ReadGrammar e.FileName = { = ; = , , , ; }, :: (e.Tokens) (e.Rules), , , (e.Tokens) (); Parse s.Chl = , > :: sC sI (e.Tokens) (e.Rules), , { sC sI : Key Eof = ; = ; }, = (e.Tokens) (e.Rules); Grammar sC sI = :: sC sI (e.Tokens), :: sC sI, :: sC sI (e.Rules), = sC sI (e.Tokens) (e.Rules); TokenSeq sC sI (e.Tokens) = { :: sC sI s.Name = ; :: sC sI = ; = sC sI (e.Tokens); }; GroupSeq sC sI (e.Groups) = { sC sI : Key Eof = sC sI (e.Groups); = :: sC sI (e.Group), = ; }; Group sC sI = :: sC sI s.Name, :: sC sI, :: sC sI (e.Group), :: sC sI = sC sI (e.Group); RhsSeq sC sI (e.Group) = :: sC sI (e.Rhs) = ; RhsSeqRest sC sI (e.Group) = { :: sC sI = :: sC sI (e.Rhs), ; = sC sI (e.Group); }; Rhs sC sI (e.Rhs) = { :: sC sI s.Name = ; = sC sI (e.Rhs); }; IsKeyword s.KW_ Key s.KW_ = ; Keyword s.KW sC sI = { sC sI : Key s.KW = ; = ; }, ; IsName Name sI = sI; Name sC sI = { sC : Name = ; = ; }, = sI; CheckGrammar (e.Tokens) (e.Rules) = { e.Rules : = ; e.Rules : e (s.NT e) e, e.Tokens : e s.NT e = ; e.Rules : e (s.NT e) e (s.NT e) e = ; e.Rules : e (s e (e s.NT e) e) e, # \{ e.Tokens : e s.NT e; }, # \{ e.Rules : e (s.NT e) e; } = ; = ; }; InsertTags { (e.Tokens) () = ; (e.Tokens) ((s.N e.RhsList) e.Rules) = (s.N ) ; }; InsertTagsRhsList { (e.Tokens) () = ; (e.Tokens) ((e.Rhs) e.Rest) = () ; }; InsertTagsRhs (e.Tokens) (e.Rhs) = e.Rhs : { = ; s.Sym e.Rest, { e.Tokens : e s.Sym e = T; = N; } :: s.Tag, = (s.Tag s.Sym) ; };