BUILDING BASIC STRECH SQL COMPILER

21
1 Headline Goes Here Speaker Name or Subhead Goes Here DO NOT USE PUBLICLY PRIOR TO 10/23/12 Structured Query Language (SQL) Compiler Mentor : Mr. Ashish Pandey Sir

Transcript of BUILDING BASIC STRECH SQL COMPILER

Page 1: BUILDING BASIC STRECH SQL COMPILER

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

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

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

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

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

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

lex input

FIRST PART

%%

Pattern action

….

%%

THIRD PART

Page 8: BUILDING BASIC STRECH SQL COMPILER

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

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

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

11

yacc/ bisonWhat is yacc/bison ?

Hows does it works ?

Page 12: BUILDING BASIC STRECH SQL COMPILER

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

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

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

15

Yaac inputFIRST PART

%%

Production action

%%

THIRD PART

Page 16: BUILDING BASIC STRECH SQL COMPILER

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

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

TOOLS USED

Operating System• LINUX

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

Page 20: BUILDING BASIC STRECH SQL COMPILER

FUNCTIONALITY

Compiles the sql queries

Parses the given commands

Detects the errors

Compiler frontened analyses the source code

Manages the symbol table

Page 21: BUILDING BASIC STRECH SQL COMPILER

21

Ashwin Shahi Ankit Verma Ajeet Dubey

[email protected]