niedziela, 23 listopada 2008

SBQL AST Visualizer

Napisałem na szybko wizualizator do drzew składniowych zapytań SBQL: tutaj! (do odpalenia wymagany pydot) W środku jest kilka obrazków z drzewkami.
Ostatecznie gramatyka wyszła mi taka:


Rule 1 query -> LPAREN query RPAREN
Rule 2 query -> LITERAL
Rule 3 query -> NUMBERLITERAL
Rule 4 query -> STRINGLITERAL
Rule 5 query -> UNARYOP query
Rule 6 query -> query SIMPLEBINARYOP query
Rule 7 query -> query DOT query
Rule 8 query -> query COMMA query
Rule 9 query -> query AS query
Rule 10 query -> query JOIN query
Rule 11 query -> query WHERE query
Rule 12 query -> query AND query
Rule 13 query -> query OR query

z kolejnością wiąząń:
precedence = (
('left', 'WHERE', 'JOIN') ,
('left', 'AND', 'OR'),
('left', 'SIMPLEBINARYOP'),
('left', 'AS', 'DOT')
)

na końcu pliku są takie przykłady:
data = {
"01simple": "(2+2 < 4) and 1",
"02projection" : '(Employee where salary < 200).(name, surname)',
"03more" :'(Employee where surname = "Kowalski" and salary < 200).name',
"04MappedJoin" : 'Employee.worksIn.Dept',
"05forjoin" : '(Employee where surname = "Kowalski" and worksIn.Departmet.isLocatedIn.Location.name = "Lodz").(surname, birthdate)',
"06join" : '(Employee as e join e.worksIn.Department as d join d.isLocatedIn.Location as l).(e.surname, l.name)',
"07join2" : '(Employee where surname = "Kowalski" and worksIn.Department.name = "Production").(surname, birthdate)'
}

1 komentarz:

kaskaderc pisze...

coś się dawno na twoim blogu nic nie dzieje ... hymmm ?