Git Product home page Git Product logo

vignif / lex-yacc-sql-parser Goto Github PK

View Code? Open in Web Editor NEW
13.0 2.0 3.0 333 KB

Simple parser for SQL standard language, this tool is developed using Lex and Yacc, project made for Language Processing Technologies @diism University of Siena. feel free to use it for academic purposes

License: MIT License

C 97.12% Lex 0.35% Yacc 0.77% C++ 1.76%
parser-sql academic siena sql-standard-language lex yacc tutorial example language-processing university parser

lex-yacc-sql-parser's Introduction

SQL parser with LEX / YACC

Simple parser for sql standard language, project made for Language Processing Technologies @diism University of Siena. This project presents a really simple parser for SQL language, with limited use cases and tokens supported. It's made for academic purposes and learning purposes, feel free to dig into the details of the rules and definitions in the source code. The compiled version of the program is also provided.

logo

The source file of yacc is defined in sql.y The source file of lex is defined in sql.l

An exensive description of the project is presented in: lex_yacc_project.pdf

Statement of the problem

Using lex/yacc implement a parser for the select SQL statement.
The syntax of the command is

select col1, col2,… from tab1, tab2,.. where cond

where the column (col1, col2,…) and table (tab1, tab2,..) names
have the usual structure of identifiers (alphanumeric strings
beginning with a letter) and cond is the condition that
is written by combining terms

col op col
col op const

using the connectors and, or. col is a name of a column, const is a constant
and op is a comparison operator among <, >, =. For instance

select serial, name, salary from employees, salaries where serial = code and
name = john and salary > 1000

In the code just print the matched terms.

How to use

There are two steps in compiling a Lex source program. First, the Lex source must be turned into a generated program in the host general purpose language. Then this program must be compiled and loaded, usually with a library of Lex subroutines.

Compile the executable in your machine

I've been using a linux distribution for this project, so make sure you have yacc and lex installed.

sudo apt-get update
sudo apt-get install bison
sudo apt-get install flex

Now you can build the executable for your own SQL parser with:

yacc -d --verbose sql.y
lex sql.l
gcc lex.yy.c y.tab.c utils.c -o sql -ll -ly -w

The executable is created in ./sql. Make sure the file can be executed with chmod +x ./sql.

The file text.txt defines line per line some dumb sql queries to be tested with your brand new parser.

./sql <test.txt

Use directly the executable

Alternatively you can also try directly the executable without compiling it on your machine.

The file text.txt defines line per line some dumb sql queries to be tested with your brand new parser.

./sql <test.txt

License

License

MIT license

  • Copyright 2021 © Francesco Vigni

lex-yacc-sql-parser's People

Contributors

vignif avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.