BUILDING BASIC STRECH SQL COMPILER
-
Upload
ajeet-dubey -
Category
Software
-
view
376 -
download
2
Transcript of BUILDING BASIC STRECH SQL COMPILER
![Page 1: BUILDING BASIC STRECH SQL COMPILER](https://reader035.fdocuments.us/reader035/viewer/2022062523/58ecdb271a28ab87618b4743/html5/thumbnails/1.jpg)
1
Headline Goes HereSpeaker Name or Subhead Goes Here
DO NOT USE PUBLICLY PRIOR TO 10/23/12
Structured Query Language (SQL) Compiler
Mentor : Mr. Ashish Pandey Sir
![Page 2: BUILDING BASIC STRECH SQL COMPILER](https://reader035.fdocuments.us/reader035/viewer/2022062523/58ecdb271a28ab87618b4743/html5/thumbnails/2.jpg)
2
Objective:Introduction to SQL-compiler.
Language Processing
lex/flex and implementation?
Demonstration
yacc/ bison and implementation
SQL compiler : Working Model
Tools and technologies ?
Functionality
![Page 3: BUILDING BASIC STRECH SQL COMPILER](https://reader035.fdocuments.us/reader035/viewer/2022062523/58ecdb271a28ab87618b4743/html5/thumbnails/3.jpg)
Introduction
3
SQL
Structured Query Language
Standardized language for requesting
information from a database.
COMPILER
Program that translates source
code into object code
high-level language statements into a
lower-level representation.
SQL + COMPILER
SQL-COMPILER
![Page 4: BUILDING BASIC STRECH SQL COMPILER](https://reader035.fdocuments.us/reader035/viewer/2022062523/58ecdb271a28ab87618b4743/html5/thumbnails/4.jpg)
4
Scanner(lexical analysis)
Machine-specific code improvement (optional)
Parser(syntax analysis)
Symantic analysis and code generation
Machine-independent code improvement(optional)
Target code generation
Source file(character stream)
Token stream
Parse Tree
Abstract syntax tree
Modified intermediate form
Target language
Modified target language
Language Processing
![Page 5: BUILDING BASIC STRECH SQL COMPILER](https://reader035.fdocuments.us/reader035/viewer/2022062523/58ecdb271a28ab87618b4743/html5/thumbnails/5.jpg)
lex/flex
Lex is a scanner generator.
Input is a set of regular expression and associated (written in c).
Output is a table driven scanner(lex.yy.c).
Flex: an source implementation of the original UNIX lex utility.
![Page 6: BUILDING BASIC STRECH SQL COMPILER](https://reader035.fdocuments.us/reader035/viewer/2022062523/58ecdb271a28ab87618b4743/html5/thumbnails/6.jpg)
Lexical analysisvoid swap (int *v1, int *v2){int tmp;tmp = *v1;*v1 = *v2;*v2 = tmp;}
Scanner: produces a stream of tokens from the input source
} ; tmp ( voidswap Parser…
![Page 7: BUILDING BASIC STRECH SQL COMPILER](https://reader035.fdocuments.us/reader035/viewer/2022062523/58ecdb271a28ab87618b4743/html5/thumbnails/7.jpg)
lex input
FIRST PART
%%
Pattern action
….
%%
THIRD PART
![Page 8: BUILDING BASIC STRECH SQL COMPILER](https://reader035.fdocuments.us/reader035/viewer/2022062523/58ecdb271a28ab87618b4743/html5/thumbnails/8.jpg)
lex input example (I)Filename: ex I .I
%%
“hello world” printf(“Goodbye\n”) ;. ;
%% Prints “Goodbye” anytime the string “hello world” is encountered.
Does nothing for anyother character.
![Page 9: BUILDING BASIC STRECH SQL COMPILER](https://reader035.fdocuments.us/reader035/viewer/2022062523/58ecdb271a28ab87618b4743/html5/thumbnails/9.jpg)
using lex% lex exI .I% cc lex.yy.c -II% ./a.outhello worldGoodbye%
Process the lex file to generate a scanner(gets saved as lex.yy.c)
Run the scanner taking input from standard input.
Compile the scanner and grab main() from the lex library (-ll option)
![Page 10: BUILDING BASIC STRECH SQL COMPILER](https://reader035.fdocuments.us/reader035/viewer/2022062523/58ecdb271a28ab87618b4743/html5/thumbnails/10.jpg)
lex pattern examplesabc Match the string “abc”.
[a-z, A-Z] Match any lower or uppercase letter.
dog.*cat Match any string starting with dog. And ending with cat.
(ab)+ Match one or more occurrences of “ab”.
[^a-z] Matches any string of one or more characters that do not include lowercase a-z.
[+ -]?[0-9]+ Match any string of one or more digits with an optional prefix of + or -.
![Page 11: BUILDING BASIC STRECH SQL COMPILER](https://reader035.fdocuments.us/reader035/viewer/2022062523/58ecdb271a28ab87618b4743/html5/thumbnails/11.jpg)
11
yacc/ bisonWhat is yacc/bison ?
Hows does it works ?
![Page 12: BUILDING BASIC STRECH SQL COMPILER](https://reader035.fdocuments.us/reader035/viewer/2022062523/58ecdb271a28ab87618b4743/html5/thumbnails/12.jpg)
12
Scanner(lexical analysis)
Machine-specific code improvement (optional)
Parser(syntax analysis)
Symantic analysis and code generation
Machine-independent code improvement(optional)
Target code generation
Source file(character stream)
Token stream
Parse Tree
Abstract syntax tree
Modified intermediate form
Target language
Modified target language
Language Processing
![Page 13: BUILDING BASIC STRECH SQL COMPILER](https://reader035.fdocuments.us/reader035/viewer/2022062523/58ecdb271a28ab87618b4743/html5/thumbnails/13.jpg)
13
yacc and lex used togetherLex: semantic analysis
Splits the input file into tokens
yacc: yet another compiler compiler
Parses and does semantic processing on the stream of tokens produced by lex
Bison: GNU parser parser.
![Page 14: BUILDING BASIC STRECH SQL COMPILER](https://reader035.fdocuments.us/reader035/viewer/2022062523/58ecdb271a28ab87618b4743/html5/thumbnails/14.jpg)
14
lex / yacc
mylang.y y.tab.c
lex.yy.c
y.tab.h
mylang.l
yacc
gcc
lex
Source code
mylang
Compiled code/interpreted output
![Page 15: BUILDING BASIC STRECH SQL COMPILER](https://reader035.fdocuments.us/reader035/viewer/2022062523/58ecdb271a28ab87618b4743/html5/thumbnails/15.jpg)
15
Yaac inputFIRST PART
%%
Production action
%%
THIRD PART
![Page 16: BUILDING BASIC STRECH SQL COMPILER](https://reader035.fdocuments.us/reader035/viewer/2022062523/58ecdb271a28ab87618b4743/html5/thumbnails/16.jpg)
16
yacc productions
$1 , $2 …… $n can be refer to the values associated with symbols
$$ refer to the value of the left.Default action :$$ = $1
Every symbol have a value associated with it (including token and non-terminals).
![Page 17: BUILDING BASIC STRECH SQL COMPILER](https://reader035.fdocuments.us/reader035/viewer/2022062523/58ecdb271a28ab87618b4743/html5/thumbnails/17.jpg)
17
yacc example productionSource code a = b + c * d
Lexical analyzer
Syntax analyzer
Id1 = id2 + id3 * id4
yacc
lex patterns
grammar
=id1 +
id2 *
id3 id4
![Page 18: BUILDING BASIC STRECH SQL COMPILER](https://reader035.fdocuments.us/reader035/viewer/2022062523/58ecdb271a28ab87618b4743/html5/thumbnails/18.jpg)
TOOLS USED
Operating System• LINUX
Software• Flex/ lex , Bison/ Yaac• gcc compiler • gedit
![Page 19: BUILDING BASIC STRECH SQL COMPILER](https://reader035.fdocuments.us/reader035/viewer/2022062523/58ecdb271a28ab87618b4743/html5/thumbnails/19.jpg)
TECHNOLOGIES USED
C++
Object oriented Techniques
Flex Analyzer implementation
Bison / YACC programming technique
![Page 20: BUILDING BASIC STRECH SQL COMPILER](https://reader035.fdocuments.us/reader035/viewer/2022062523/58ecdb271a28ab87618b4743/html5/thumbnails/20.jpg)
FUNCTIONALITY
Compiles the sql queries
Parses the given commands
Detects the errors
Compiler frontened analyses the source code
Manages the symbol table