SCT Implementation

SCT Implementation

Appendix SCT implementation In this appendix code is presented for an implementation of SCT evaluat ion together with t he grammar definit ions from t his book. T he implement ation is separated into three programs. The first is an awk script used to generate Standard ML code for sequence assign­ ments. The second is a Standard ML program providing t he SCT evaluation routine. The third is a Standard ML program containing the grammar definitions. Information on using t hese programs is also given. A wk script to generate sequence assignments { print " (*the as signment data t ype*) " for (i = 1; i <= NF ; i++) printf("'l,s%s:fol list%s", i == 1 ? \ ''type assn= { '' : '''' , $ i , i < NF ? "}\n\n" ) print '' (* the empty assignment *) '' for (i = 1; i <= NF; i ++) printf ( "%s%s=nil %s ", i == 1 ? \ "val assnO:assn = { " : 11 11 , $i, i < NF ? "}\ n\n") print '' ( * t he err or assi gnment *) u for (i = 1; i <= NF ; i ++) printf("%s%s= [Error \"%s error\"]%s", i == 1 ? \ "val assnError: assn = {" : "", $i, $i , i < NF? ", " : "}\ n\ n") print '' (* v returns t he sequenc e v alue g assigns t o name *) '' for (i = 1; i <= NF; i ++) printf("%s\"%s \ " => #%s g%s " , i == 1? \ "f un v (name : st ring, g :assn):fol list =\n (case name\n of \ $i , $i, i < NF ? " I " : " I _ => nil)\n\n" ) 205 206 THE SEMANTICS OF GRAMMATICAL DEPENDENCIES print"(* vtop returns the frontmost value of the s equence g assigns name *) " print "fun vtop (name:string, g:assn) :fol _,, pri nt '' if v ( name, g) = nil'' print then Error (name-\" error\") else hd (v (name, g) ) \ n" print "(* vend returns t he endmos t value of the s equence g assi gns t o name *) " print "fun vend (name:string, g:assn) :fol _,, print if v ( name , g) = nil'' print " then Error (name-\" error \ ") else hd (rev ( v (name , g)))\n" print '' (* vtl returns the sequence value g assigns t o name *)" print "(* minus the frontmost value *)" print "fun vtl (name: string, g :assn) :fol lis t=" print '' if v (name, g) = nil'' print " then [Error (name-\" error\ ") ] else tl (v (name, g) )\n" print '' (* vrevtlrev returns the s equence value g assigns t o name *)" print '' (* minus the endmost v alue *)" print "fun vrevt lrev (name:string , g : assn) :fol list=" print " if v ( name, g) =nil t hen [Er r or (n ame-\" error\") ] " print " el s e rev (tl (rev (v (name , g) ) ))\n" print '' ( * pop retur ns s e quence a ssi gnment g but with the front most val ue *) '' print '' ( * a s signed t o name remo v e d print ''fun pop (name: string, (g, str) : assn * string) : assn * string =" print " if g = assnError then (g, s t r) else" print if vtl (name, g) = [Error (name-\" error\ ") ] " print " then (assnError , (name- \ " error , no pop\") ) else (case name" for (i = 1 ; i <= NF; i ++) { print f ( "%s\"%s\ 11 => ({ " , i == 1 ? 11 of 11 : " I " $ i ) for ( j = 1; j <= NF ; j++) printf("%s=%s g ) %s", $j, i == j ? "vtl (name,": 11 (# "$j , j < NF? 11 , n 11 11 ) printf("'l.s", i < NF? "}, str)\n " : \ "}, str)\n I _ => (assnError , \ "no \ " -name- \" name, no pop\")\n )\n\ n" ) } print " (* endpop r eturns sequence assignment g but wi th the endmo st va lue*) " print '' (* as s i gne d to name r emoved *) " pr int "f un e ndpop (name: s tring , (g , str ) :assn * string ) :assn * string=" print " if g = assnError then (g, str) else" print if vrevtlrev (name, g) = [Error (name-\" error\ ")]" print " then (a ssnError, (name-\ " error, no endpop\") ) else (case name" for (i = 1 ; i <= NF; i ++ ) { printf("/,s \"%s \ " => ({", i == 1 ? " of " II I " $ i ) for (j = 1 ; j <= NF; j++) printf ( "%s =% s g)%s " , $j , i == j ? \ "vr evtlrev (name .": ''(#"$j, j < NF ? " : "") printf("'l.s" , i < NF ? "}, str)\n " : \ ''} , s tr) \n I _ => ( assnError, \"no \ '' "' name "' \ " name, no endpop\" ) \n )\n\n11 ) } .

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    2 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us