* Optimised the SDF grammar.

This commit is contained in:
Eelco Dolstra 2004-01-29 14:24:53 +00:00
parent 3648d1c732
commit abd1878b26
2 changed files with 15 additions and 94 deletions

View file

@ -15,9 +15,9 @@ imports Fix-Exprs Fix-Layout
%% Expressions. %% Expressions.
module Fix-Exprs module Fix-Exprs
imports Fix-Lexicals URI imports Fix-Lexicals
exports exports
sorts Expr Formal Bind Binds BindSemi ExprList sorts Expr Formal Bind Binds ExprList
context-free syntax context-free syntax
Id -> Expr {cons("Var")} Id -> Expr {cons("Var")}
@ -44,10 +44,8 @@ exports
"let" "{" Binds "}" -> Expr {cons("LetRec")} "let" "{" Binds "}" -> Expr {cons("LetRec")}
"{" Binds "}" -> Expr {cons("Attrs")} "{" Binds "}" -> Expr {cons("Attrs")}
Id "=" Expr -> Bind {cons("Bind")} Bind* -> Binds
{Bind ";"}* -> Binds Id "=" Expr ";" -> Bind {cons("Bind")}
Bind ";" -> BindSemi
BindSemi* -> Binds
"[" ExprList "]" -> Expr {cons("List")} "[" ExprList "]" -> Expr {cons("List")}
"" -> ExprList {cons("ExprNil")} "" -> ExprList {cons("ExprNil")}
@ -65,8 +63,6 @@ exports
Expr "||" Expr -> Expr {cons("OpOr"), right} Expr "||" Expr -> Expr {cons("OpOr"), right}
Expr "->" Expr -> Expr {cons("OpImpl"), right} Expr "->" Expr -> Expr {cons("OpImpl"), right}
Bool -> Expr {cons("Bool")}
context-free priorities context-free priorities
Expr "." Id -> Expr Expr "." Id -> Expr
@ -87,7 +83,7 @@ exports
module Fix-Lexicals module Fix-Lexicals
exports exports
sorts Id Int Str Path PathComp Bool sorts Id Int Str Path PathComp Uri
lexical syntax lexical syntax
[a-zA-Z\_][a-zA-Z0-9\_\']* -> Id [a-zA-Z\_][a-zA-Z0-9\_\']* -> Id
"rec" -> Id {reject} "rec" -> Id {reject}
@ -95,97 +91,24 @@ exports
"if" -> Id {reject} "if" -> Id {reject}
"then" -> Id {reject} "then" -> Id {reject}
"else" -> Id {reject} "else" -> Id {reject}
"true" -> Id {reject}
"false" -> Id {reject}
"assert" -> Id {reject} "assert" -> Id {reject}
[0-9]+ -> Int [0-9]+ -> Int
"\"" ~[\n\"]* "\"" -> Str "\"" ~[\n\"]* "\"" -> Str
PathComp ("/" PathComp)+ -> Path "." ("/" PathComp)+ -> Path
".." ("/" PathComp)+ -> Path
("/" PathComp)+ -> Path ("/" PathComp)+ -> Path
[a-zA-Z0-9\.\_\-\+]+ -> PathComp [a-zA-Z0-9\.\_\-\+]+ -> PathComp
"true" -> Bool [a-zA-Z] [a-zA-Z0-9\+\-\.]* ":" [a-zA-Z0-9\%\/\?\:\@\&\=\+\$\,\-\_\.\!\~\*\']* -> Uri
"false" -> Bool
lexical restrictions lexical restrictions
Id -/- [a-zA-Z0-9\_\'] Id -/- [a-zA-Z0-9\_\']
Int -/- [0-9] Int -/- [0-9]
Path -/- [a-zA-Z0-9\.\_\-\+\/] Path -/- [a-zA-Z0-9\.\_\-\+\/]
Uri -/- [a-zA-Z0-9\%\/\?\:\@\&\=\+\$\,\-\_\.\!\~\*\']
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% URIs (RFC 2396, appendix A).
module URI
exports
sorts Uri Uhierpart Uopaquepart Uuricnoslash Unetpath Uabspath
Urelpath Urelsegment Uscheme Uauthority Uregname Userver
Uuserinfo Uhostport Uhost Uhostname Udomainlabel Utoplabel
UIPv4address Uport Upath Upathsegments Usegment Uparam
Upchar Uquery Ufragment Uuric Ureserved Uunreserved Umark
Uescaped Uhex Ualphanum Ualpha Ulowalpha Uupalpha Udigit
lexical syntax
Uscheme ":" (Uhierpart | Uopaquepart) -> Uri
(Unetpath | Uabspath) ("?" Uquery)? -> Uhierpart
Uuricnoslash Uuric* -> Uopaquepart
Uunreserved | Uescaped | [\;\?\:\@\&\=\+\$\,] -> Uuricnoslash
"//" Uauthority Uabspath? -> Unetpath
"/" Upathsegments -> Uabspath
"//" Uuric* -> Uabspath {reject}
Urelsegment Uabspath? -> Urelpath
(Uunreserved | Uescaped | [\;\@\&\=\+\$\,])+ -> Urelsegment
Ualpha (Ualpha | Udigit | [\+\-\.])* -> Uscheme
Userver | Uregname -> Uauthority
(Uunreserved | Uescaped | [\$\,\;\:\@\&\=\+])+ -> Uregname
((Uuserinfo "@") Uhostport) -> Userver
(Uunreserved | Uescaped | [\;\:\&\=\+\$\,])* -> Uuserinfo
Uhost (":" Uport)? -> Uhostport
Uhostname | UIPv4address -> Uhost
(Udomainlabel ".")+ Utoplabel "."? -> Uhostname
Ualphanum | Ualphanum (Ualphanum | "-")* Ualphanum -> Udomainlabel
Ualpha | Ualpha (Ualphanum | "-")* Ualphanum -> Utoplabel
Udigit+ "." Udigit+ "." Udigit+ "." Udigit+ -> UIPv4address
Udigit* -> Uport
Uabspath | Uopaquepart -> Upath
Usegment ("/" Usegment)* -> Upathsegments
Upchar* (";" Uparam)* -> Usegment
Upchar* -> Uparam
Uunreserved | Uescaped | [\:\@\&\=\+\$\,] -> Upchar
Uuric* -> Uquery
Uuric* -> Ufragment
Ureserved | Uunreserved | Uescaped -> Uuric
[\;\/\?\:\@\&\=\+\$\,] -> Ureserved
Ualphanum | Umark -> Uunreserved
[\-\_\.\!\~\*\'\(\)] -> Umark
"%" Uhex Uhex -> Uescaped
Udigit | [A-Fa-f] -> Uhex
Ualpha | Udigit -> Ualphanum
Ulowalpha | Uupalpha -> Ualpha
[a-z] -> Ulowalpha
[A-Z] -> Uupalpha
[0-9] -> Udigit
lexical restrictions
Uri -/- [a-zA-Z0-9\-\_\.\!\~\*\'\(\)\/]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@ -193,18 +116,16 @@ exports
module Fix-Layout module Fix-Layout
exports exports
sorts HashComment Asterisk Comment EOF sorts HashComment Asterisk Comment
lexical syntax lexical syntax
[\ \t\n] -> LAYOUT [\ \t\n] -> LAYOUT
HashComment -> LAYOUT HashComment -> LAYOUT
Comment -> LAYOUT Comment -> LAYOUT
"#" ~[\n]* ([\n] | EOF) -> HashComment "#" ~[\n]* -> HashComment
"//" ~[\n]* ([\n] | EOF) -> HashComment
"/*" ( ~[\*] | Asterisk )* "*/" -> Comment "/*" ( ~[\*] | Asterisk )* "*/" -> Comment
[\*] -> Asterisk [\*] -> Asterisk
"" -> EOF
lexical restrictions lexical restrictions
Asterisk -/- [\/] Asterisk -/- [\/]
EOF -/- ~[] HashComment -/- ~[\n]
context-free restrictions context-free restrictions
LAYOUT? -/- [\ \t\n] | [\#] LAYOUT? -/- [\ \t\n]

View file

@ -45,10 +45,10 @@ struct Cleanup : TermFun
return ATmake("Int(<int>)", n); return ATmake("Int(<int>)", n);
} }
if (atMatch(m, e) >> "Bool" >> "true") if (atMatch(m, e) >> "Var" >> "true")
return ATmake("Bool(True)"); return ATmake("Bool(True)");
if (atMatch(m, e) >> "Bool" >> "false") if (atMatch(m, e) >> "Var" >> "false")
return ATmake("Bool(False)"); return ATmake("Bool(False)");
if (atMatch(m, e) >> "ExprNil") if (atMatch(m, e) >> "ExprNil")