<> <> <> <> <> <, < predicates to HerculesAlgebra (February 14, 1984 2:13 am) >> <> <> <> DIRECTORY Rope, Lexer, Parser, OldUnparser, OldParseWindow, OldJunoParserEtc, HerculesAlgebra USING [Se, leftPren, colon, semicolon, comma, assign, approx, minus, rightarrow, suchthat, equals, paint, ends, width], IO, ViewerTools, ViewerClasses, Atom, List USING [Memb]; HerculesParserEtcImpl: PROGRAM IMPORTS ViewerTools, OldParseWindow, Atom EXPORTS OldJunoParserEtc = BEGIN OPEN OldJunoParserEtc, Pw: OldParseWindow, Alg: HerculesAlgebra; junoA: PUBLIC Pw.Handle; SetUpParser: PUBLIC PROC[fileName:Rope.ROPE] = BEGIN junoA _ Pw.NewHandle[ViewerTools.MakeNewTextViewer[ [file: fileName, name: fileName, iconic: FALSE, column: right]]]; junoA.WellFormed _ Definition; END; Parse: PUBLIC PROC = {Pw.ParseViewer[junoA]}; Se: TYPE = Alg.Se; -- Symbolic Expression Sp: TYPE = Pw.SyntacticPredicate; Definition: Sp = {RETURN [Pw.HasForm[f, colon, Template, Command]]}; Template: Sp = {RETURN [Pw.HasForm[f, leftPren, Var, VarList]]}; VarList: Sp = {RETURN [Pw.Or[Var[f], Pw.HasForm[f, comma, Var, VarList]]]}; Var: Sp = {IF ISTYPE[NARROW[Car[NARROW[f]], REF ANY], ATOM] THEN RETURN [[Yes, NIL]] ELSE RETURN [[OfCourseNot, f]]}; Command: Sp = {RETURN [ Pw.Or[AtomicCommand[f], Pw.Or[Alternation[f], Pw.Or[Iteration[f], Pw.Or[PushState[f], Composition[f]]]]]]}; AtomicCommand: Sp = {RETURN [Pw.Or[Call[f], Assignment[f]]]}; Call: Sp = {RETURN [Pw.Or [Pw.HasForm[f, leftPren, PrefixOp, Expr], PrefixCall[f]]]}; PrefixCall: Sp = {RETURN [ISTYPE [Car[f], LIST OF Se] AND PrefixOp [Car [Car[Se]] AND [Pw.HasForm[f, leftPren, PrefixOp, Expr], PrefixCall[f]]]}; PrefixOp: Sp = {RETURN [Pw.Or[Var[f], LambdaExpr[f]]]}; LambdaExpr: Sp = {RETURN [FALSE]}; -- will be Pw.HasForm[f, colon, Parms, Expr] Expr: Sp = {RETURN [Pw.Or[Var[f], Pw.Or[Literal[f], Pw.Or[Call[f], InfixExpr[f]]]]]}; InfixExpr: Sp = {RETURN [Pw.HasForm[f, InfixOp, Args, Args]]}; --- OOOPS - types! infixOps: LIST = LIST [Alg.plus, Alg.minus, Alg.times, Alg.slash, Alg.div, Alg.mod, Alg.comma, Alg.semicolon, Alg.equals, Alg.paint, Alg.ends, Alg.width]; InfixOp: Sp = {RETURN [List.Memb[Car[f], infixOps]]}; Literal: Sp = {RETURN [Pw.Or[RopeLiteral[f], NumLiteral[f]]]}; RopeLiteral: Sp = {IF ISTYPE[Car[f], Rope.ROPE] THEN RETURN [[Yes, NIL]] ELSE RETURN [[OfCourseNot, f]]}; NumLiteral: Sp = {IF ISTYPE[Car[f], REF INT] OR ISTYPE[Car[f], REF REAL] THEN RETURN [[Yes, NIL]] ELSE RETURN [[OfCourseNot, f]]}; NumExpr: Sp = {RETURN [Pw.Or[NumLiteral[f], Pw.Or[Var[f], -- evaluating to a number Pw.Or[Call[f], -- returning a number InfixExpr[f]]]]]}; CoordsExpr: Sp = {RETURN [Pw.Or[NumPairExpr[f], Pw.HasForm[f, Alg.rel, NumExpr, FrameExpr]]]]}; CoordExpr: Sp = {RETURN [Pw.Or[Var[f], -- evaluating to either a point or a real pair Pw.Or[NumPairExpr[f], Pw.HasForm[f, Alg.rel, NumPairExpr, FrameExpr]]]]}; Num: Sp = {RETURN [Pw.Or[Num2[f], Pw.HasForm[f, minus, Num2, NIL]]]}; Assignment: Sp = {aw: Pw.VerdictAndCulprit _ Pw.HasForm[f, assign, VarList, VarList]; IF aw.verdict = Yes AND InfixLength[Cadr[NARROW[Car[NARROW[f]]]]] # InfixLength[Caddr[NARROW[Car[NARROW[f]]]]] THEN RETURN [[No, f]] ELSE RETURN [aw]}; ThreeVars: Sp = {RETURN [Pw.HasForm[f, comma, Var, TwoVars]]}; TwoVars: Sp = {RETURN[Pw.HasForm[f, comma, Var, Var]]}; Alternation: Sp = {RETURN[Pw.HasForm[f, $if, Gcl, NIL]]}; Iteration: Sp = {RETURN[Pw.HasForm[f, $do, Gcl, NIL]]}; PushState: Sp = {RETURN[ Pw.Or[Pw.HasForm[f, $width, TwoVars, Command], Pw.Or[Pw.HasForm[f, $width, PrenTwoVars, Command], Pw.Or[Pw.HasForm[f, $width, Num, Command], Pw.Or[Pw.HasForm[f, $paint, Var, Command], Pw.Or[Pw.HasForm[f, $paint, PrenNumTriple, Command], Pw.HasForm[f, $ends, Var, Command]]]]]]]}; PrenNumTriple: Sp = {RETURN [Pw.HasForm[f, leftPren, NumTriple, NIL]]}; NumTriple: Sp = {RETURN [Pw.HasForm[f, comma, Num, NumPair]]}; Gcl: Sp = GuardedCommand; GuardedCommand: Sp = {RETURN[Pw.HasForm[f, rightarrow, Predicate, Command]]}; Predicate: Sp = {RETURN[Pw.HasForm[f, suchthat, LocalList, CList]]}; LocalList: Sp = {RETURN[Pw.Or[Local[f], Pw.HasForm[f, comma, Local, LocalList]]]}; Local: Sp = {RETURN[Pw.Or[Var[f], Pw.HasForm[f, approx, Var, HintCoords]]]}; HintCoords: Sp = {RETURN [Pw.Or[PrenNumPair[f], Pw.HasForm[f, $rel, PrenNumPair, PrenFrame]]]}; PrenNumPair: Sp = {RETURN [Pw.HasForm[f, leftPren, NumPair, NIL]]}; NumPair: Sp = {RETURN [Pw.HasForm[f, comma, Num, Num]]}; PrenFrame: Sp = {RETURN[Pw.HasForm[f, leftPren, Frame, NIL]]}; Frame: Sp = {RETURN[Pw.Or[Var[f], Pw.Or[TwoVars[f], ThreeVars[f]]]]}; CList: Sp = {RETURN[Pw.Or[Constraint[f], Pw.HasForm[f, $and, Constraint, CList]]]}; Constraint: Sp = -- new [JS] {RETURN[Pw.Or[NakedConstraint[f], Pw.HasForm[f, $rel, RelConstraint, PrenFrame]]]}; NakedConstraint: Sp = -- old Constraint [JS] {RETURN[ Pw.Or[LitTrue[f], Pw.Or[Para[f], Pw.Or[Ver[f], Pw.Or[Hor[f], RelConstraint[f]]]]]]}; RelConstraint: Sp = -- A constraint that can be relativized - new [JS] {RETURN[ Pw.Or[Cong[f], Pw.Or[Perp[f], Equal[f]]]]}; LitTrue: Sp = {IF Car[NARROW[f]] = $T THEN RETURN [[Yes, NIL]] ELSE RETURN [[OfCourseNot, f]]}; Cong: Sp = {RETURN[Pw.HasForm[f, $cong, PrenTwoVars, PrenTwoVars]]}; Para: Sp = {RETURN[Pw.HasForm[f, $para, PrenTwoVars, PrenTwoVars]]}; Perp: Sp = {RETURN[Pw.HasForm[f, $perp, PrenTwoVars, PrenTwoVars]]}; Equal: Sp = {RETURN[Pw.HasForm[f, equals, Var, PrenNumPair]]}; Hor: Sp = {RETURN[Pw.HasForm[f, $hor, PrenTwoVars, NIL]]}; Ver: Sp = {RETURN[Pw.HasForm[f, $ver, PrenTwoVars, NIL]]}; PrenThreeVars: Sp = {RETURN[Pw.HasForm[f, leftPren, ThreeVars, NIL]]}; PrenTwoVars: Sp = {RETURN[Pw.HasForm[f, leftPren, TwoVars, NIL]]}; Composition: Sp = {RETURN[Pw.HasForm[f, semicolon, Command, Command]]}; InfixLength: PROC[l: Se] RETURNS [INT] = {IF ISTYPE[NARROW[l, REF ANY], ATOM] THEN RETURN[1] ELSE RETURN[1 + InfixLength[Caddr[NARROW[l]]]]}; WellFormed: PUBLIC PROC [f: Se] RETURNS [Pw.VerdictAndCulprit] = {RETURN[Definition[f]]}; Car: PROC [r: Se] RETURNS [Se] = {RETURN[NARROW[r, LIST OF REF ANY].first]}; Cdr: PROC [r: Se] RETURNS [Se] = {RETURN[NARROW[r, LIST OF REF ANY].rest]}; Cadr: PROC [r: Se] RETURNS [Se] = {RETURN[Car[Cdr[r]]]}; Caddr: PROC [r: Se] RETURNS [Se] = {RETURN[Car[Cdr[Cdr[r]]]]}; Cddr: PROC [r: Se] RETURNS [Se] = {RETURN[Cdr[Cdr[r]]]}; Caar: PROC [r: Se] RETURNS [Se] = {RETURN[Car[Car[r]]]}; Cadar: PROC [l: Se] RETURNS [Se] = { RETURN[ Car[ Cdr[ Car[ l ] ] ] ] }; Caddar: PROC [l: Se] RETURNS [Se] = { RETURN[ Car[ Cdr[ Cdr[ Car[ l ] ] ] ] ] }; Cadddar: PROC [l: Se] RETURNS [Se] = { RETURN[ Car[ Cdr[ Cdr[ Cdr[ Car[ l ] ] ] ] ] ] }; Cadddr: PROC [l: Se] RETURNS [Se] = { RETURN[ Car[ Cdr[ Cdr[ Cdr[ l ] ] ] ] ] }; Caddddar: PROC [l: Se] RETURNS [Se] = { RETURN[ Car[ Cdr[ Cdr[ Cdr[ Cdr[ Car[ l ] ] ] ] ] ] ] }; Cddar: PROC [l: Se] RETURNS [Se] = { RETURN[ Cdr[ Cdr[ Car[ l ] ] ] ] }; END. <> <<-- Added perpendicular constraint -- Added relativized constraints -- Added = (eq) constraint -- Added (n,n,n) paint option -- Allowed syntactic variannt (v, v) width as equivalent to v,v width>> <> <<>> <> <<-- Restricted relativizable constraints to cong, perp and $=>> <<-- Restored binding power of $== to 6, so that local declarations return to the form ($== ($rel )) instead of ($rel ($== ) )>> <<-- Fixed syntax to accept absolute hints: p == (0, 1) (without reference frame)>> <> <<>> <> <<-- Renamed HerculesParserEtcImpl>> <<>> <> <>