List:Internals« Previous MessageNext Message »
From:tc yang Date:November 18 2010 2:00am
Subject:Re: mysql grammatical and semantic souce code
View as plain text  
thanks Hartmut and Weldon!  these replies is very helpfull
I have a general understanding now to Lexical and syntax parsing
module. I will study in depth these dayes
thanks a lot

在 2010年11月18日 上午5:07,Weldon Whipple <weldon@stripped> 写道:
> TC,
>
> I've successfully expanded the MySQL syntax several times for local
> use. (I'm still looking for MySQL hacks I've made that are of
> sufficiently general interest for the open-source community. ... One
> of these days ... :-)
>
> Here are the steps I used to add SHOW BAN_STATISTICS, patterned after
> the google (or is it percona?) patch that implements SHOW
> USER_STATISTICS (and several other kinds of statistics):
>
> 1. In sql/lex.h: Add BAN_STATS_SYM symbol at the appropriate place.
> Also add SQLCOM_SHOW_BAN_STATS to the enum with all the SQLCOM_*
> values.
>
> { "BAN_STATISTICS",   SYM(BAN_STATS_SYM)},
>
> /* Later ... */
>
> SQLCOM_SHOW_BAN_STATS
>
> 2. In sql/sql_yacc.yy, add these:
>
> %token  BAN_STATS_SYM
>
> /* Then, later in the file, expend the SHOW section */
>
> | BAN_STATS_SYM wild_and_where
>          {
>             LEX *lex= Lex;
>             lex->sql_command= SQLCOM_SHOW_BAN_STATS;
>             if (prepare_schema_table(YYTHD, lex, 0, SCH_BAN_STATS))
>               MYSQL_YYABORT;
>          }
>
> (Of course, I had to implement prepare_schema_table and a bunch of
> other functions/methods to collect the data for the SHOWing. ... But
> the above should get you started.)
>
> My first use of lex and yacc was for a senior computer science project
> years ago. I THINK what MySQL uses is actually flex and bison (flex
> being the successor to lex and bison being the successor to [another
> (bovine?) animal] yacc), but I could be very wrong.
>
> I still have my old "lex and yacc" O'Reilly book (copyright 1992),
> which seems a bit outdated now. I found GNU Press's "The Bison Manual"
> (copyright 2003 by FSF--there's probably a more recent one online)
> quite handy. Appendix J of the "lex and yacc" book has lex and yacc
> code for a SQL parser (an old one, obviously), which is quite
> illuminating to read and understand.
>
> In the MySQL code, the following files warrant a look if you're
> extending the MySQL syntax:
>
> gen_lex_hash.cc  lex.h  lex_symbol.h  sql_lex.cc  sql_lex.h
>
> sql_yacc.yy generates sql_yacc.h and sql_yacc.cc during the build
> process, which are in turn compiled and linked into the mysqld
> executables, etc.
>
> I hope I haven't lied too much in the above. I'm just returning to my
> database-per-file binlog assignment which has been simmering on the
> back burner for 2-3 weeks while I wrote an apache module. ... So some
> of this isn't completely fresh in my memory.
>
> ... But I couldn't leave you without an answer: Yes (AFAICT), mysql
> DOES use current generations of the old lex and yacc (maybe flex and
> bison or some variants??)
>
> Good luck!
>
> 2010/11/17 tc yang <yangtc.sub@stripped>:
>> thanks a lot!
>> mysql not use lex for tokenizing, only use  sql_lex.cc and the
>> lex_hash.h to  supply the same interface as lex/flex supplied? and the
>> up level also use yacc?
>> I can find sql_yacc.yy,  Is it equal .y file? when I see other yacc
>> demo, yacc file always named .y
>> In websit http://forge.mysql.com/wiki/MySQL_Internals,I can't find
>> subject helpfull for this Lexical and grammatical implement
>>
>>
>> 在 2010年11月17日 下午2:46,Hartmut Holzgraefe
> <hartmut.holzgraefe@stripped> 写道:
>>> On 11/17/2010 06:33 AM, tc yang wrote:
>>>> 在 2010年11月17日 上午11:22,tc
> yang<yangtc.sub@stripped>写道:
>>>>>
>>>>> hi:
>>>>>      I recently study mysql source code,  grammatical and semantic
> analysis,mysql source version 5.57
>>>>>      but I can't find .l file for lex and .y for yacc in mysql
> level,innbase dictonary have /pars0lex.l, why mysql don't have lex source?
>>>>>      in sql directory only have sql_lex.cc,this is generated from lex
> source ? and where is the lex source(".l" file), and how is generated?
>>>
>>> mysql does not use lex/flex for tokenizing, it uses a self made scanner
>>> instead, which consists of sql_lex.cc and the lex_hash.h header
>>> generated by the bundled gen_lex_hash tool
>>>
>>> the lex and yacc files in the innobase stem back from the time when
>>> InnoDB was meant to be a standalone SQL database, most of this parser
>>> is not in use anymore, parts of it are still needed to parse foreign
>>> key constraint definitions though as far as i remember.
>>>
>>> --
>>> hartmut
>>>
>>> --
>>> MySQL Internals Mailing List
>>> For list archives: http://lists.mysql.com/internals
>>> To unsubscribe:    http://lists.mysql.com/internals?unsub=1
>>>
>>>
>>
>> --
>> MySQL Internals Mailing List
>> For list archives: http://lists.mysql.com/internals
>> To unsubscribe:    http://lists.mysql.com/internals?unsub=1
>>
>>
>
Thread
Re: mysql grammatical and semantic souce codetc yang17 Nov
  • Re: mysql grammatical and semantic souce codeHartmut Holzgraefe17 Nov
    • Re: mysql grammatical and semantic souce codetc yang17 Nov
      • Re: mysql grammatical and semantic souce codeHartmut Holzgraefe17 Nov
        • Re: mysql grammatical and semantic souce codeRick James17 Nov
          • Re: mysql grammatical and semantic souce codeSergei Golubchik17 Nov
      • Re: mysql grammatical and semantic souce codeWeldon Whipple17 Nov
        • Re: mysql grammatical and semantic souce codetc yang18 Nov