Source

hello / sql / sql_parser.mly

Full commit

%{

  open Printf
  let _ = Parsing.set_trace false;;
  let debugprint = ref true;;
  
  let print str = if !debugprint then print_endline str;;
  
  let parse_error s = print ("parse_error->"^s);;

%}

%token SELECT
%token INSERT
%token DELETE
%token UPDATE
%token INTO
%token VALUES
%token SET
%token FROM
%token WHERE
%token LIMIT
%token DOT
%token LBRACE RBRACE
%token COMMA
%token ASTERISK
%token GT LT EQ NEQ NOT
%token EOF

%token <int> INT

%token <string> LITERAL

%start input
%type <Sql.query> input

%%

input: | exp { $1 };

exp:
  | SELECT ASTERISK FROM LITERAL { Sql.Select(Sql.All_col, $4) };
  | SELECT columns  FROM LITERAL { Sql.Select(Sql.Columns($2), $4) };

columns:
  | LITERAL  { [$1] }
  | LITERAL COMMA columns { $1::$3 }
;