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
Objective: 2 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 analysis void 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(“Goodbyen”) ; . ; %% 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.out hello world Goodbye % 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 examples abc 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/ bison What 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
yacc and lex used together 13 Lex: 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.
lex / yacc 14 mylang.y y.tab.c lex.yy.c y.tab.h mylang.l yacc gcc lex Source code mylang Compiled code /interpreted output
Yaac input 15 FIRST PART %% Production action %% THIRD PART
yacc productions 16 $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).
yacc example production 17 Source 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
TECHNOLOGIES USED C++ Object oriented Techniques Flex Analyzer implementation Bison / YACC programming technique
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

BUILDING BASIC STRECH SQL COMPILER

  • 1.
    1 Headline Goes Here SpeakerName 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: 2 Introduction to SQL-compiler. LanguageProcessing lex/flex and implementation? Demonstration yacc/ bison and implementation SQL compiler : Working Model Tools and technologies ? Functionality
  • 3.
    Introduction 3 SQL Structured Query Language Standardized language forrequesting 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.
    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
  • 5.
    lex/flex Lex is ascanner 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.
  • 6.
    Lexical analysis void 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 …
  • 7.
    lex input FIRST PART %% Patternaction …. %% THIRD PART
  • 8.
    lex input example(I) Filename: ex I .I %% “hello world” printf(“Goodbyen”) ; . ; %% Prints “Goodbye” anytime the string “hello world” is encountered. Does nothing for anyother character.
  • 9.
    using lex % lexexI .I % cc lex.yy.c -II % ./a.out hello world Goodbye % 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)
  • 10.
    lex pattern examples abcMatch 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.
    11 yacc/ bison What isyacc/bison ? Hows does it works ?
  • 12.
    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 lexused together 13 Lex: 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 14 mylang.yy.tab.c lex.yy.c y.tab.h mylang.l yacc gcc lex Source code mylang Compiled code /interpreted output
  • 15.
  • 16.
    yacc productions 16 $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 production 17 Sourcecode a = b + c * d Lexical analyzer Syntax analyzer Id1 = id2 + id3 * id4 yacc lex patterns grammar = id1 + id2 * id3 id4
  • 18.
    TOOLS USED Operating System •LINUX Software • Flex/ lex , Bison/ Yaac • gcc compiler • gedit
  • 19.
    TECHNOLOGIES USED C++ Object orientedTechniques Flex Analyzer implementation Bison / YACC programming technique
  • 20.
    FUNCTIONALITY Compiles the sqlqueries Parses the given commands Detects the errors Compiler frontened analyses the source code Manages the symbol table
  • 21.
    21  Ashwin Shahi Ankit Verma  Ajeet Dubey sql_compiler@gmail.com