BUILDING BASIC STRECH SQL COMPILER

Preview:

Citation preview

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

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

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

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

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.

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…

lex input

FIRST PART

%%

Pattern action

….

%%

THIRD PART

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.

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)

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 -.

11

yacc/ bisonWhat is yacc/bison ?

Hows does it works ?

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

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.

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

15

Yaac inputFIRST PART

%%

Production action

%%

THIRD PART

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).

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

TOOLS USED

Operating System• LINUX

Software• Flex/ lex , Bison/ Yaac• gcc compiler • gedit

FUNCTIONALITY

Compiles the sql queries

Parses the given commands

Detects the errors

Compiler frontened analyses the source code

Manages the symbol table

21

Ashwin Shahi Ankit Verma Ajeet Dubey

sql_compiler@gmail.com

Recommended