Check-in [776298dbea]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:better error checking for compileProgram
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:776298dbeac82977c21cf1bfdf239ed5a553047f
User & Date: kbk 2014-08-06 13:08:39
Context
2014-10-25
18:55
datalog: test assertion of a single fact. check-in: 3e177181c8 user: kbk tags: trunk
2014-08-06
13:08
better error checking for compileProgram check-in: 776298dbea user: kbk tags: trunk
2014-08-03
23:19
Substantial code and commentary cleanup in datalog.tcl check-in: c9faa932a7 user: kbk tags: trunk
Changes

Changes to library/datalog.tcl.

1971
1972
1973
1974
1975
1976
1977
1978
1979
1980














1981
1982
1983
1984
1985
1986
1987
....
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
# # Populate the 'grandparent' relation
# listGrandparents
# # What items are the grandparents of item 0?
# puts [grandparents 0]; # prints a list containing 3, 4, 5, and 6

proc bdd::datalog::compileProgram {db prelude programText args} {

    set postlude [lindex $args end]

    variable parser















    try {

	set program [bdd::datalog::program new $db]

	# Do lexical analysis of the program
	lassign [lex $programText] tokens values
................................................................................

	# Translate the execution plan to relational algebra
	$program translateExecutionPlan $plan

	# Generate code
	append result \
	    $prelude \n \
	    [$program generateCode {*}[lrange $args 0 end-1]] \n \
	    $postlude

    } finally {

	$program destroy

    }
    return $result

}

package provide tclbdd::datalog 0.1







|

|
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|












1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
....
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
# # Populate the 'grandparent' relation
# listGrandparents
# # What items are the grandparents of item 0?
# puts [grandparents 0]; # prints a list containing 3, 4, 5, and 6

proc bdd::datalog::compileProgram {db prelude programText args} {

    variable parser

    switch -exact -- [llength $args] {
	1 {
	    lassign $args postlude
	    set dictAndAction {}
	}
	3 {
	    lassign $args dict action postlude
	    set dictAndAction [list $dict $action]
	}
	default {
	    set methd [lindex [info level 0] 0]
	    return -code error -errorcode {TCL WRONGARGS} \
		"wrong # args: should be $methd db prelude programText ?dictVar action? postlude"
	}
    }

    try {

	set program [bdd::datalog::program new $db]

	# Do lexical analysis of the program
	lassign [lex $programText] tokens values
................................................................................

	# Translate the execution plan to relational algebra
	$program translateExecutionPlan $plan

	# Generate code
	append result \
	    $prelude \n \
	    [$program generateCode {*}$dictAndAction] \n \
	    $postlude

    } finally {

	$program destroy

    }
    return $result

}

package provide tclbdd::datalog 0.1