From e620ffbd9432fc9ab4f3174ecf9c117db27af772 Mon Sep 17 00:00:00 2001 From: aarne Date: Thu, 23 Oct 2003 15:09:07 +0000 Subject: Working with interfaces and incomplete modules. --- src/GF/Source/GF.cf | 286 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 286 insertions(+) create mode 100644 src/GF/Source/GF.cf (limited to 'src/GF/Source/GF.cf') diff --git a/src/GF/Source/GF.cf b/src/GF/Source/GF.cf new file mode 100644 index 000000000..bb1d200cd --- /dev/null +++ b/src/GF/Source/GF.cf @@ -0,0 +1,286 @@ +-- AR 2/5/2003, 14-16 o'clock, Torino + +entrypoints Grammar, ModDef, OldGrammar, Exp ; -- let's see if more are needed + +comment "--" ; +comment "{-" "-}" ; + +-- the top-level grammar + +Gr. Grammar ::= [ModDef] ; + +-- semicolon after module is permitted but not obligatory + +terminator ModDef "" ; +_. ModDef ::= ModDef ";" ; + +-- The $main$ multilingual grammar structure + +MMain. ModDef ::= "grammar" Ident "=" "{" "abstract" "=" Ident ";" [ConcSpec] "}" ; + +ConcSpec. ConcSpec ::= Ident "=" ConcExp ; +separator ConcSpec ";" ; + +ConcExp. ConcExp ::= Ident [Transfer] ; + +separator Transfer "" ; +TransferIn. Transfer ::= "(" "transfer" "in" Open ")" ; +TransferOut. Transfer ::= "(" "transfer" "out" Open ")" ; + +-- the individual modules + +MModule. ModDef ::= ComplMod ModType "=" ModBody ; + +MTAbstract. ModType ::= "abstract" Ident ; +MTResource. ModType ::= "resource" Ident ; +MTInterface. ModType ::= "interface" Ident ; +MTConcrete. ModType ::= "concrete" Ident "of" Ident ; +MTInstance. ModType ::= "instance" Ident "of" Ident ; +MTTransfer. ModType ::= "transfer" Ident ":" Open "->" Open ; + +MBody. ModBody ::= Extend Opens "{" [TopDef] "}" ; +MWith. ModBody ::= Ident "with" [Open] ; +MReuse. ModBody ::= "reuse" Ident ; + +separator TopDef "" ; + +Ext. Extend ::= Ident "**" ; +NoExt. Extend ::= ; + +separator Open "," ; +NoOpens. Opens ::= ; +Opens. Opens ::= "open" [Open] "in" ; + +OName. Open ::= Ident ; +OQualQO. Open ::= "(" QualOpen Ident ")" ; +OQual. Open ::= "(" QualOpen Ident "=" Ident ")" ; + +CMCompl. ComplMod ::= ; +CMIncompl. ComplMod ::= "incomplete" ; + +QOCompl. QualOpen ::= ; +QOIncompl. QualOpen ::= "incomplete" ; +QOInterface. QualOpen ::= "interface" ; + +-- definitions after the $oper$ keywords + +DDecl. Def ::= [Ident] ":" Exp ; +DDef. Def ::= [Ident] "=" Exp ; +DPatt. Def ::= Ident [Patt] "=" Exp ; -- non-empty pattern list +DFull. Def ::= [Ident] ":" Exp "=" Exp ; + +-- top-level definitions + +DefCat. TopDef ::= "cat" [CatDef] ; +DefFun. TopDef ::= "fun" [FunDef] ; +DefDef. TopDef ::= "def" [Def] ; +DefData. TopDef ::= "data" [DataDef] ; + +DefTrans. TopDef ::= "transfer" [Def] ; + +DefPar. TopDef ::= "param" [ParDef] ; +DefOper. TopDef ::= "oper" [Def] ; + +DefLincat. TopDef ::= "lincat" [PrintDef] ; +DefLindef. TopDef ::= "lindef" [Def] ; +DefLin. TopDef ::= "lin" [Def] ; + +DefPrintCat. TopDef ::= "printname" "cat" [PrintDef] ; +DefPrintFun. TopDef ::= "printname" "fun" [PrintDef] ; +DefFlag. TopDef ::= "flags" [FlagDef] ; + +CatDef. CatDef ::= Ident [DDecl] ; +FunDef. FunDef ::= [Ident] ":" Exp ; + +DataDef. DataDef ::= Ident "=" [DataConstr] ; +DataId. DataConstr ::= Ident ; +DataQId. DataConstr ::= Ident "." Ident ; +separator DataConstr "|" ; + + +ParDef. ParDef ::= Ident "=" [ParConstr] ; +ParDefIndir. ParDef ::= Ident "=" "(" "in" Ident ")" ; +ParDefAbs. ParDef ::= Ident ; + +ParConstr. ParConstr ::= Ident [DDecl] ; + +PrintDef. PrintDef ::= [Ident] "=" Exp ; + +FlagDef. FlagDef ::= Ident "=" Ident ; + +terminator nonempty Def ";" ; +terminator nonempty CatDef ";" ; +terminator nonempty FunDef ";" ; +terminator nonempty DataDef ";" ; +terminator nonempty ParDef ";" ; + +terminator nonempty PrintDef ";" ; +terminator nonempty FlagDef ";" ; + +separator ParConstr "|" ; + +separator nonempty Ident "," ; + +-- definitions in records and $let$ expressions + +LDDecl. LocDef ::= [Ident] ":" Exp ; +LDDef. LocDef ::= [Ident] "=" Exp ; +LDFull. LocDef ::= [Ident] ":" Exp "=" Exp ; + +separator LocDef ";" ; + +-- terms and types + +EIdent. Exp4 ::= Ident ; +EConstr. Exp4 ::= "{" Ident "}" ; +ECons. Exp4 ::= "[" Ident "]" ; +ESort. Exp4 ::= Sort ; +EString. Exp4 ::= String ; +EInt. Exp4 ::= Integer ; +EMeta. Exp4 ::= "?" ; +EEmpty. Exp4 ::= "[" "]" ; +EStrings. Exp4 ::= "[" String "]" ; +ERecord. Exp4 ::= "{" [LocDef] "}" ; -- ! +ETuple. Exp4 ::= "<" [TupleComp] ">" ; --- needed for separator "," +EIndir. Exp4 ::= "(" "in" Ident ")" ; -- indirection, used in judgements +ETyped. Exp4 ::= "<" Exp ":" Exp ">" ; -- typing, used for annotations + +EProj. Exp3 ::= Exp3 "." Label ; +EQConstr. Exp3 ::= "{" Ident "." Ident "}" ; -- qualified constructor +EQCons. Exp3 ::= "[" Ident "." Ident "]" ; -- qualified constant + +EApp. Exp2 ::= Exp2 Exp3 ; +ETable. Exp2 ::= "table" "{" [Case] "}" ; +ETTable. Exp2 ::= "table" Exp4 "{" [Case] "}" ; +ECase. Exp2 ::= "case" Exp "of" "{" [Case] "}" ; +EVariants. Exp2 ::= "variants" "{" [Exp] "}" ; +EPre. Exp2 ::= "pre" "{" Exp ";" [Altern] "}" ; +EStrs. Exp2 ::= "strs" "{" [Exp] "}" ; +EConAt. Exp2 ::= Ident "@" Exp4 ; + +ESelect. Exp1 ::= Exp1 "!" Exp2 ; +ETupTyp. Exp1 ::= Exp1 "*" Exp2 ; +EExtend. Exp1 ::= Exp1 "**" Exp2 ; + +EAbstr. Exp ::= "\\" [Bind] "->" Exp ; +ECTable. Exp ::= "\\""\\" [Bind] "=>" Exp ; +EProd. Exp ::= Decl "->" Exp ; +ETType. Exp ::= Exp1 "=>" Exp ; -- these are thus right associative +EConcat. Exp ::= Exp1 "++" Exp ; +EGlue. Exp ::= Exp1 "+" Exp ; +ELet. Exp ::= "let" "{" [LocDef] "}" "in" Exp ; +EEqs. Exp ::= "fn" "{" [Equation] "}" ; + +coercions Exp 4 ; + +separator Exp ";" ; -- in variants + +-- patterns + +PW. Patt1 ::= "_" ; +PV. Patt1 ::= Ident ; +PCon. Patt1 ::= "{" Ident "}" ; +PQ. Patt1 ::= Ident "." Ident ; +PInt. Patt1 ::= Integer ; +PStr. Patt1 ::= String ; +PR. Patt1 ::= "{" [PattAss] "}" ; +PTup. Patt1 ::= "<" [PattTupleComp] ">" ; +PC. Patt ::= Ident [Patt] ; +PQC. Patt ::= Ident "." Ident [Patt] ; + +coercions Patt 1 ; + +PA. PattAss ::= [Ident] "=" Patt ; + +-- labels + +LIdent. Label ::= Ident ; +LVar. Label ::= "$" Integer ; + +-- basic types + +rules Sort ::= "Type" | "PType" | "Tok" | "Str" | "Strs" ; + +separator PattAss ";" ; + +AltP. PattAlt ::= Patt ; + +-- this is explicit to force higher precedence level on rhs +(:[]). [Patt] ::= Patt1 ; +(:). [Patt] ::= Patt1 [Patt] ; + +separator nonempty PattAlt "|" ; + +-- binds in lambdas and lin rules + +BIdent. Bind ::= Ident ; +BWild. Bind ::= "_" ; + +separator Bind "," ; + + +-- declarations in function types + +DDec. Decl ::= "(" [Bind] ":" Exp ")" ; +DExp. Decl ::= Exp2 ; -- can thus be an application + +-- tuple component (term or pattern) + +TComp. TupleComp ::= Exp ; +PTComp. PattTupleComp ::= Patt ; + +separator TupleComp "," ; +separator PattTupleComp "," ; + +-- case branches + +Case. Case ::= [PattAlt] "=>" Exp ; + +separator nonempty Case ";" ; + +-- cases in abstract syntax + +Equ. Equation ::= [Patt] "->" Exp ; + +separator Equation ";" ; + +-- prefix alternatives + +Alt. Altern ::= Exp "/" Exp ; + +separator Altern ";" ; + +-- in a context, higher precedence is required than in function types + +DDDec. DDecl ::= "(" [Bind] ":" Exp ")" ; +DDExp. DDecl ::= Exp4 ; -- can thus *not* be an application + +separator DDecl "" ; + + +-------------------------------------- + +-- for backward compatibility + +OldGr. OldGrammar ::= Include [TopDef] ; + +NoIncl. Include ::= ; +Incl. Include ::= "include" [FileName] ; + +FString. FileName ::= String ; + +terminator nonempty FileName ";" ; + +FIdent. FileName ::= Ident ; +FSlash. FileName ::= "/" FileName ; +FDot. FileName ::= "." FileName ; +FMinus. FileName ::= "-" FileName ; +FAddId. FileName ::= Ident FileName ; + +token LString '\'' (char - '\'')* '\'' ; +ELString. Exp4 ::= LString ; +ELin. Exp2 ::= "Lin" Ident ; + +DefPrintOld. TopDef ::= "printname" [PrintDef] ; +DefLintype. TopDef ::= "lintype" [Def] ; +DefPattern. TopDef ::= "pattern" [Def] ; -- cgit v1.2.3