From 5c9f4e63f4d90d13a06ddca2df2be6d46ec567e2 Mon Sep 17 00:00:00 2001 From: LtWorf Date: Sat, 19 Jul 2008 15:30:01 +0000 Subject: [PATCH] first stub of relational algebra to python converter git-svn-id: http://galileo.dmi.unict.it/svn/relational/trunk@15 014f5005-505e-4b48-8d0a-63407b615a7c --- parser.py | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 parser.py diff --git a/parser.py b/parser.py new file mode 100644 index 0000000..49efb89 --- /dev/null +++ b/parser.py @@ -0,0 +1,60 @@ +# coding=UTF-8 +# Relation +# Copyright (C) 2008 Salvo "LtWorf" Tomaselli +# +# Relation is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# author Salvo "LtWorf" Tomaselli + +def parse(expr): + '''This function parses a relational algebra expression, converting it into python, + executable by eval function to get the result of the expression.''' + + #Selection σage > 25 Λ rank = weight(A) + #Projection π a,b(A) + #Rename ρid➡i,name➡n(A) + #A ᑌ B + #A ᐅᐊ B + #A ᑎ B + + result="" + symbols={} + symbols["*"]=".product(%s)" + symbols["-"]=".difference(%s)" + symbols["ᑌ"]=".union(%s)" + symbols["ᑎ"]=".intersection(%s)" + symbols["ᐅᐊ"]=".join(%s)" + symbols["ᐅᐊLEFT"]=".outer_left(%s)" + symbols["ᐅᐊRIGHT"]=".outer_right(%s)" + symbols["ᐅᐊFULL"]=".outer(%s)" + + tokens=expr.split(" ") + + i=0; + tk_l=len(tokens) + while i