(* * This module tests the latest and greatest grammar notation features, * including keywordless obj defs, '->' as LHS/RHS separator, and space as a * RHS element separator. *) module grammar; define obj attribute typ:integer; rule program = "program" d:decls "begin" s:stmts "end" { d.:typ = "" ; } ; rule decls = decl*; rule stmts = stmt*; rule decl = ; rule stmt = ; rule program0 = "program" decls "begin" stmts "end" {}; rule program1 = "program" decls "begin" stmts "end"; rule program2 = YPROGRAM d:decls YBEGIN s:stmts YEND; rule program3 = YPROGRAM d:decls YBEGIN s:stmts YEND { this.:typ = if (d.:typ = "OK") and (s.:typ = "OK") then "OK" else "ERROR";} ; rule program4 = YPROGRAM d:decls YBEGIN s:stmts YEND { this.:typ = if (d.:typ = "OK") and (s.:typ = "OK") then "OK" else "ERROR";} ; (* The next two lines are syntactially illegal because the equivalent of Yacc * embedded action routines is not supported in RSL. Curly-brace-enclosed * action routines can only be defined after each rule alternative, not * between and'd RHS constituents. * rule program5 = YPROGRAM {} d:decls {} YBEGIN {} s:stmts {} YEND {}; rule program6 = YPROGRAM {} d:decls {} YBEGIN {} s:stmts {} YEND {}; * *) rule program5 = YPROGRAM {} | d:decls {} | YBEGIN {} | s:stmts {} | YEND {}; rule x = "a" "b" "c" "d" | "e" "f" "g" "h"; rule x1 = a* b* | c*; rule a = ; rule b = ; rule c = ; rule decls2 = ds:decl* {this.:typ = if (forall (d in ds) d.:typ = "OK") then "OK" else "ERROR";} ; rule decl2 = (* ... *) ; -- comment are just to such up compiler rule stmts2 = ss:stmt*; rule stmt2 = (* ... *) ; -- comment are just to such up compiler (* Explicit token defs as opaque objects. *) rule YPROGRAM = ; rule YBEGIN = ; rule YEND = ; end grammar;