Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
oceanbase
miniob
提交
28eee7d5
M
miniob
项目概览
oceanbase
/
miniob
1 年多 前同步成功
通知
74
Star
1521
Fork
537
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
分析
仓库
DevOps
项目成员
Pages
M
miniob
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Pages
分析
分析
仓库分析
DevOps
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
提交
未验证
提交
28eee7d5
编写于
11月 17, 2022
作者:
羽飞
提交者:
GitHub
11月 17, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
opt lex and yacc (#123)
上级
da389bf8
变更
10
展开全部
隐藏空白更改
内联
并排
Showing
10 changed file
with
608 addition
and
595 deletion
+608
-595
src/observer/CMakeLists.txt
src/observer/CMakeLists.txt
+1
-1
src/observer/sql/parser/gen_parser.sh
src/observer/sql/parser/gen_parser.sh
+3
-0
src/observer/sql/parser/lex_sql.cpp
src/observer/sql/parser/lex_sql.cpp
+285
-226
src/observer/sql/parser/lex_sql.h
src/observer/sql/parser/lex_sql.h
+8
-7
src/observer/sql/parser/lex_sql.l
src/observer/sql/parser/lex_sql.l
+63
-48
src/observer/sql/parser/parse.cpp
src/observer/sql/parser/parse.cpp
+2
-8
src/observer/sql/parser/parse_defs.h
src/observer/sql/parser/parse_defs.h
+0
-8
src/observer/sql/parser/yacc_sql.cpp
src/observer/sql/parser/yacc_sql.cpp
+104
-197
src/observer/sql/parser/yacc_sql.hpp
src/observer/sql/parser/yacc_sql.hpp
+135
-0
src/observer/sql/parser/yacc_sql.y
src/observer/sql/parser/yacc_sql.y
+7
-100
未找到文件。
src/observer/CMakeLists.txt
浏览文件 @
28eee7d5
...
...
@@ -24,7 +24,7 @@ FOREACH (F ${ALL_SRC})
ENDFOREACH
(
F
)
SET
(
LIBRARIES common pthread dl event_pthreads event
jsoncpp
)
SET
(
LIBRARIES common pthread dl event_pthreads event
libjsoncpp.a
)
# 指定目标文件位置
SET
(
EXECUTABLE_OUTPUT_PATH
${
PROJECT_BINARY_DIR
}
/../../bin
)
...
...
src/observer/sql/parser/gen_parser.sh
0 → 100755
浏览文件 @
28eee7d5
#!/bin/bash
flex
--outfile
lex_sql.cpp
--header-file
=
lex_sql.h lex_sql.l
`
which bison
`
-d
--output
yacc_sql.cpp yacc_sql.y
src/observer/sql/parser/lex
.yy.c
→
src/observer/sql/parser/lex
_sql.cpp
浏览文件 @
28eee7d5
此差异已折叠。
点击以展开。
src/observer/sql/parser/lex
.yy
.h
→
src/observer/sql/parser/lex
_sql
.h
浏览文件 @
28eee7d5
...
...
@@ -2,7 +2,9 @@
#define yyHEADER_H 1
#define yyIN_HEADER 1
#line 6 "lex.yy.h"
#line 6 "lex_sql.h"
#line 8 "lex_sql.h"
#define YY_INT_ALIGNED short int
...
...
@@ -49,7 +51,6 @@ typedef int16_t flex_int16_t;
typedef
uint16_t
flex_uint16_t
;
typedef
int32_t
flex_int32_t
;
typedef
uint32_t
flex_uint32_t
;
typedef
uint64_t
flex_uint64_t
;
#else
typedef
signed
char
flex_int8_t
;
typedef
short
int
flex_int16_t
;
...
...
@@ -160,7 +161,7 @@ struct yy_buffer_state
/* Number of characters read into yy_ch_buf, not including EOB
* characters.
*/
yy_size_
t
yy_n_chars
;
in
t
yy_n_chars
;
/* Whether we "own" the buffer - i.e., we know we created it,
* and can realloc() it to grow it, and should free() it to
...
...
@@ -204,7 +205,7 @@ void yypop_buffer_state (yyscan_t yyscanner );
YY_BUFFER_STATE
yy_scan_buffer
(
char
*
base
,
yy_size_t
size
,
yyscan_t
yyscanner
);
YY_BUFFER_STATE
yy_scan_string
(
yyconst
char
*
yy_str
,
yyscan_t
yyscanner
);
YY_BUFFER_STATE
yy_scan_bytes
(
yyconst
char
*
bytes
,
yy_size_
t
len
,
yyscan_t
yyscanner
);
YY_BUFFER_STATE
yy_scan_bytes
(
yyconst
char
*
bytes
,
in
t
len
,
yyscan_t
yyscanner
);
void
*
yyalloc
(
yy_size_t
,
yyscan_t
yyscanner
);
void
*
yyrealloc
(
void
*
,
yy_size_t
,
yyscan_t
yyscanner
);
...
...
@@ -260,7 +261,7 @@ FILE *yyget_out (yyscan_t yyscanner );
void
yyset_out
(
FILE
*
out_str
,
yyscan_t
yyscanner
);
yy_size_
t
yyget_leng
(
yyscan_t
yyscanner
);
in
t
yyget_leng
(
yyscan_t
yyscanner
);
char
*
yyget_text
(
yyscan_t
yyscanner
);
...
...
@@ -333,9 +334,9 @@ extern int yylex \
#undef YY_DECL
#endif
#line
88
"lex_sql.l"
#line
103
"lex_sql.l"
#line 34
0 "lex.yy
.h"
#line 34
1 "lex_sql
.h"
#undef yyIN_HEADER
#endif
/* yyHEADER_H */
src/observer/sql/parser/lex_sql.l
浏览文件 @
28eee7d5
...
...
@@ -2,9 +2,15 @@
#include<string.h>
#include<stdio.h>
/**
* flex 代码包含三个部分,使用 %% 分隔
* 第一个部分的代码是C代码,flex会原样复制到目标文件中
* 第二个部分是规则部分,使用正则表达式定义一系列规则
* 第三个部分还是C代码,flex 会复制此段代码
*/
struct ParserContext;
#include "yacc_sql.
tab.h
"
#include "yacc_sql.
hpp
"
extern int atoi();
extern double atof();
...
...
@@ -21,6 +27,8 @@ extern double atof();
%option noyywrap
%option bison-bridge
%option reentrant
/* 不区分大小写 */
%option case-insensitive
WHITE_SAPCE [\ \t\b\f]
DIGIT [0-9]+
...
...
@@ -30,61 +38,68 @@ DOT \.
QUOTE [\'\"]
%x STR
/* 规则匹配的优先级:*/
/* 1. 匹配的规则长的优先 */
/* 2. 写在最前面的优先 */
/* yylval 就可以认为是 yacc 中 %union 定义的结构体(union 结构) */
%%
{WHITE_SAPCE} // ignore whitespace
\n ;
[\-]?{DIGIT}+
yylval->number=atoi(yytext); RETURN_TOKEN(NUMBER);
[\-]?{DIGIT}+{DOT}{DIGIT}+
yylval->floats=(float)(atof(yytext)); RETURN_TOKEN(FLOAT);
[\-]?{DIGIT}+ yylval->number=atoi(yytext); RETURN_TOKEN(NUMBER);
[\-]?{DIGIT}+{DOT}{DIGIT}+ yylval->floats=(float)(atof(yytext)); RETURN_TOKEN(FLOAT);
";"
RETURN_TOKEN(SEMICOLON);
{DOT}
RETURN_TOKEN(DOT);
"*"
RETURN_TOKEN(STAR);
[Ee][Xx][Ii][Tt]
RETURN_TOKEN(EXIT);
[Hh][Ee][Ll][Pp]
RETURN_TOKEN(HELP);
[Dd][Ee][Ss][Cc]
RETURN_TOKEN(DESC);
[Cc][Rr][Ee][Aa][Tt][Ee]
RETURN_TOKEN(CREATE);
[Dd][Rr][Oo][Pp]
RETURN_TOKEN(DROP);
[Tt][Aa][Bb][Ll][Ee]
RETURN_TOKEN(TABLE);
[Tt][Aa][Bb][Ll][Ee][Ss]
RETURN_TOKEN(TABLES);
[Ii][Nn][Dd][Ee][Xx]
RETURN_TOKEN(INDEX);
[Oo][Nn]
RETURN_TOKEN(ON);
[Ss][Hh][Oo][Ww]
RETURN_TOKEN(SHOW);
[Ss][Yy][Nn][Cc]
RETURN_TOKEN(SYNC);
[Ss][Ee][Ll][Ee][Cc][Tt]
RETURN_TOKEN(SELECT);
[Ff][Rr][Oo][Mm]
RETURN_TOKEN(FROM);
[Ww][Hh][Ee][Rr][Ee]
RETURN_TOKEN(WHERE);
[Aa][Nn][Dd]
RETURN_TOKEN(AND);
[Ii][Nn][Ss][Ee][rR][tT]
RETURN_TOKEN(INSERT);
[Ii][Nn][Tt][Oo]
RETURN_TOKEN(INTO);
[Vv][Aa][Ll][Uu][Ee][Ss]
RETURN_TOKEN(VALUES);
[Dd][Ee][Ll][Ee][Tt][Ee]
RETURN_TOKEN(DELETE);
[Uu][Pp][Dd][Aa][Tt][Ee]
RETURN_TOKEN(UPDATE);
[Ss][Ee][Tt]
RETURN_TOKEN(SET);
[Bb][Ee][Gg][Ii][Nn]
RETURN_TOKEN(TRX_BEGIN);
[Cc][Oo][Mm][Mm][Ii][Tt]
RETURN_TOKEN(TRX_COMMIT);
[Rr][Oo][Ll][Ll][Bb][Aa][Cc][Kk]
RETURN_TOKEN(TRX_ROLLBACK);
[Ii][Nn][Tt]
RETURN_TOKEN(INT_T);
[Cc][Hh][Aa][Rr]
RETURN_TOKEN(STRING_T);
[Ff][Ll][Oo][Aa][Tt]
RETURN_TOKEN(FLOAT_T);
[Ll][Oo][Aa][Dd]
RETURN_TOKEN(LOAD);
[Dd][Aa][Tt][Aa]
RETURN_TOKEN(DATA);
[Ii][Nn][Ff][Ii][Ll][Ee]
RETURN_TOKEN(INFILE);
{ID}
yylval->string=strdup(yytext); RETURN_TOKEN(ID);
"("
RETURN_TOKEN(LBRACE);
")"
RETURN_TOKEN(RBRACE);
";" RETURN_TOKEN(SEMICOLON);
{DOT} RETURN_TOKEN(DOT);
"*" RETURN_TOKEN(STAR);
EXIT
RETURN_TOKEN(EXIT);
HELP
RETURN_TOKEN(HELP);
DESC
RETURN_TOKEN(DESC);
CREATE
RETURN_TOKEN(CREATE);
DROP
RETURN_TOKEN(DROP);
TABLE
RETURN_TOKEN(TABLE);
TABLES
RETURN_TOKEN(TABLES);
INDEX
RETURN_TOKEN(INDEX);
ON
RETURN_TOKEN(ON);
SHOW
RETURN_TOKEN(SHOW);
SYNC
RETURN_TOKEN(SYNC);
SELECT
RETURN_TOKEN(SELECT);
FROM
RETURN_TOKEN(FROM);
WHERE
RETURN_TOKEN(WHERE);
AND
RETURN_TOKEN(AND);
INSERT
RETURN_TOKEN(INSERT);
INTO
RETURN_TOKEN(INTO);
VALUES
RETURN_TOKEN(VALUES);
DELETE
RETURN_TOKEN(DELETE);
UPDATE
RETURN_TOKEN(UPDATE);
SET
RETURN_TOKEN(SET);
BEGIN
RETURN_TOKEN(TRX_BEGIN);
COMMIT
RETURN_TOKEN(TRX_COMMIT);
ROLLBACK
RETURN_TOKEN(TRX_ROLLBACK);
INT
RETURN_TOKEN(INT_T);
CHAR
RETURN_TOKEN(STRING_T);
FLOAT
RETURN_TOKEN(FLOAT_T);
LOAD
RETURN_TOKEN(LOAD);
DATA
RETURN_TOKEN(DATA);
INFILE
RETURN_TOKEN(INFILE);
{ID} yylval->string=strdup(yytext); RETURN_TOKEN(ID);
"(" RETURN_TOKEN(LBRACE);
")" RETURN_TOKEN(RBRACE);
"," RETURN_TOKEN(COMMA);
"=" RETURN_TOKEN(EQ);
"<=" RETURN_TOKEN(LE);
"<>" RETURN_TOKEN(NE);
"<" RETURN_TOKEN(LT);
">=" RETURN_TOKEN(GE);
">" RETURN_TOKEN(GT);
{QUOTE}[\40\42\47A-Za-z0-9_/\.\-]*{QUOTE} yylval->string=strdup(yytext); RETURN_TOKEN(SSS);
"," RETURN_TOKEN(COMMA);
"=" RETURN_TOKEN(EQ);
"<=" RETURN_TOKEN(LE);
"<>" RETURN_TOKEN(NE);
"!=" RETURN_TOKEN(NE);
"<" RETURN_TOKEN(LT);
">=" RETURN_TOKEN(GE);
">" RETURN_TOKEN(GT);
\"[^"]*\" yylval->string=strdup(yytext); RETURN_TOKEN(SSS);
'[^']*\' yylval->string = strdup(yytext); RETURN_TOKEN(SSS);
.
printf("Unknown character [%c]\n",yytext[0]); return yytext[0];
. printf("Unknown character [%c]\n",yytext[0]); return yytext[0];
%%
void scan_string(const char *str, yyscan_t scanner) {
...
...
src/observer/sql/parser/parse.cpp
浏览文件 @
28eee7d5
...
...
@@ -19,9 +19,6 @@ See the Mulan PSL v2 for more details. */
RC
parse
(
char
*
st
,
Query
*
sqln
);
#ifdef __cplusplus
extern
"C"
{
#endif // __cplusplus
void
relation_attr_init
(
RelAttr
*
relation_attr
,
const
char
*
relation_name
,
const
char
*
attribute_name
)
{
if
(
relation_name
!=
nullptr
)
{
...
...
@@ -388,13 +385,10 @@ void query_destroy(Query *query)
query_reset
(
query
);
free
(
query
);
}
#ifdef __cplusplus
}
// extern "C"
#endif // __cplusplus
////////////////////////////////////////////////////////////////////////////////
extern
"C"
int
sql_parse
(
const
char
*
st
,
Query
*
sqls
);
int
sql_parse
(
const
char
*
st
,
Query
*
sqls
);
RC
parse
(
const
char
*
st
,
Query
*
sqln
)
{
...
...
@@ -404,4 +398,4 @@ RC parse(const char *st, Query *sqln)
return
SQL_SYNTAX
;
else
return
SUCCESS
;
}
\ No newline at end of file
}
src/observer/sql/parser/parse_defs.h
浏览文件 @
28eee7d5
...
...
@@ -180,10 +180,6 @@ typedef struct Query {
union
Queries
sstr
;
}
Query
;
#ifdef __cplusplus
extern
"C"
{
#endif // __cplusplus
void
relation_attr_init
(
RelAttr
*
relation_attr
,
const
char
*
relation_name
,
const
char
*
attribute_name
);
void
relation_attr_destroy
(
RelAttr
*
relation_attr
);
...
...
@@ -241,8 +237,4 @@ Query *query_create(); // create and init
void
query_reset
(
Query
*
query
);
void
query_destroy
(
Query
*
query
);
// reset and delete
#ifdef __cplusplus
}
#endif // __cplusplus
#endif // __OBSERVER_SQL_PARSER_PARSE_DEFS_H__
src/observer/sql/parser/yacc_sql.
tab.c
→
src/observer/sql/parser/yacc_sql.
cpp
浏览文件 @
28eee7d5
此差异已折叠。
点击以展开。
src/observer/sql/parser/yacc_sql.
tab.h
→
src/observer/sql/parser/yacc_sql.
hpp
浏览文件 @
28eee7d5
...
...
@@ -35,11 +35,11 @@
especially those whose name start with YY_ or yy_. They are
private implementation details that can be changed or removed. */
#ifndef YY_YY_YACC_SQL_
TAB_H
_INCLUDED
#
define YY_YY_YACC_SQL_TAB_H
_INCLUDED
#ifndef YY_YY_YACC_SQL_
HPP
_INCLUDED
#
define YY_YY_YACC_SQL_HPP
_INCLUDED
/* Debug traces. */
#ifndef YYDEBUG
#define YYDEBUG 0
#
define YYDEBUG 0
#endif
#if YYDEBUG
extern
int
yydebug
;
...
...
@@ -47,67 +47,69 @@ extern int yydebug;
/* Token kinds. */
#ifndef YYTOKENTYPE
#define YYTOKENTYPE
enum
yytokentype
{
YYEMPTY
=
-
2
,
YYEOF
=
0
,
/* "end of file" */
YYerror
=
256
,
/* error */
YYUNDEF
=
257
,
/* "invalid token" */
SEMICOLON
=
258
,
/* SEMICOLON */
CREATE
=
259
,
/* CREATE */
DROP
=
260
,
/* DROP */
TABLE
=
261
,
/* TABLE */
TABLES
=
262
,
/* TABLES */
INDEX
=
263
,
/* INDEX */
SELECT
=
264
,
/* SELECT */
DESC
=
265
,
/* DESC */
SHOW
=
266
,
/* SHOW */
SYNC
=
267
,
/* SYNC */
INSERT
=
268
,
/* INSERT */
DELETE
=
269
,
/* DELETE */
UPDATE
=
270
,
/* UPDATE */
LBRACE
=
271
,
/* LBRACE */
RBRACE
=
272
,
/* RBRACE */
COMMA
=
273
,
/* COMMA */
TRX_BEGIN
=
274
,
/* TRX_BEGIN */
TRX_COMMIT
=
275
,
/* TRX_COMMIT */
TRX_ROLLBACK
=
276
,
/* TRX_ROLLBACK */
INT_T
=
277
,
/* INT_T */
STRING_T
=
278
,
/* STRING_T */
FLOAT_T
=
279
,
/* FLOAT_T */
HELP
=
280
,
/* HELP */
EXIT
=
281
,
/* EXIT */
DOT
=
282
,
/* DOT */
INTO
=
283
,
/* INTO */
VALUES
=
284
,
/* VALUES */
FROM
=
285
,
/* FROM */
WHERE
=
286
,
/* WHERE */
AND
=
287
,
/* AND */
SET
=
288
,
/* SET */
ON
=
289
,
/* ON */
LOAD
=
290
,
/* LOAD */
DATA
=
291
,
/* DATA */
INFILE
=
292
,
/* INFILE */
EQ
=
293
,
/* EQ */
LT
=
294
,
/* LT */
GT
=
295
,
/* GT */
LE
=
296
,
/* LE */
GE
=
297
,
/* GE */
NE
=
298
,
/* NE */
NUMBER
=
299
,
/* NUMBER */
FLOAT
=
300
,
/* FLOAT */
ID
=
301
,
/* ID */
PATH
=
302
,
/* PATH */
SSS
=
303
,
/* SSS */
STAR
=
304
,
/* STAR */
STRING_V
=
305
/* STRING_V */
};
typedef
enum
yytokentype
yytoken_kind_t
;
# define YYTOKENTYPE
enum
yytokentype
{
YYEMPTY
=
-
2
,
YYEOF
=
0
,
/* "end of file" */
YYerror
=
256
,
/* error */
YYUNDEF
=
257
,
/* "invalid token" */
SEMICOLON
=
258
,
/* SEMICOLON */
CREATE
=
259
,
/* CREATE */
DROP
=
260
,
/* DROP */
TABLE
=
261
,
/* TABLE */
TABLES
=
262
,
/* TABLES */
INDEX
=
263
,
/* INDEX */
SELECT
=
264
,
/* SELECT */
DESC
=
265
,
/* DESC */
SHOW
=
266
,
/* SHOW */
SYNC
=
267
,
/* SYNC */
INSERT
=
268
,
/* INSERT */
DELETE
=
269
,
/* DELETE */
UPDATE
=
270
,
/* UPDATE */
LBRACE
=
271
,
/* LBRACE */
RBRACE
=
272
,
/* RBRACE */
COMMA
=
273
,
/* COMMA */
TRX_BEGIN
=
274
,
/* TRX_BEGIN */
TRX_COMMIT
=
275
,
/* TRX_COMMIT */
TRX_ROLLBACK
=
276
,
/* TRX_ROLLBACK */
INT_T
=
277
,
/* INT_T */
STRING_T
=
278
,
/* STRING_T */
FLOAT_T
=
279
,
/* FLOAT_T */
HELP
=
280
,
/* HELP */
EXIT
=
281
,
/* EXIT */
DOT
=
282
,
/* DOT */
INTO
=
283
,
/* INTO */
VALUES
=
284
,
/* VALUES */
FROM
=
285
,
/* FROM */
WHERE
=
286
,
/* WHERE */
AND
=
287
,
/* AND */
SET
=
288
,
/* SET */
ON
=
289
,
/* ON */
LOAD
=
290
,
/* LOAD */
DATA
=
291
,
/* DATA */
INFILE
=
292
,
/* INFILE */
EQ
=
293
,
/* EQ */
LT
=
294
,
/* LT */
GT
=
295
,
/* GT */
LE
=
296
,
/* LE */
GE
=
297
,
/* GE */
NE
=
298
,
/* NE */
NUMBER
=
299
,
/* NUMBER */
FLOAT
=
300
,
/* FLOAT */
ID
=
301
,
/* ID */
PATH
=
302
,
/* PATH */
SSS
=
303
,
/* SSS */
STAR
=
304
,
/* STAR */
STRING_V
=
305
/* STRING_V */
};
typedef
enum
yytokentype
yytoken_kind_t
;
#endif
/* Value type. */
#if !defined YYSTYPE && !defined YYSTYPE_IS_DECLARED
union
YYSTYPE
{
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
union
YYSTYPE
{
#line 106 "yacc_sql.y"
struct
_Attr
*
attr
;
...
...
@@ -116,15 +118,18 @@ union YYSTYPE {
char
*
string
;
int
number
;
float
floats
;
char
*
position
;
char
*
position
;
#line 124 "yacc_sql.hpp"
#line 124 "yacc_sql.tab.h"
};
typedef
union
YYSTYPE
YYSTYPE
;
#define YYSTYPE_IS_TRIVIAL 1
#define YYSTYPE_IS_DECLARED 1
#
define YYSTYPE_IS_TRIVIAL 1
#
define YYSTYPE_IS_DECLARED 1
#endif
int
yyparse
(
void
*
scanner
);
#endif
/* !YY_YY_YACC_SQL_TAB_H_INCLUDED */
int
yyparse
(
void
*
scanner
);
#endif
/* !YY_YY_YACC_SQL_HPP_INCLUDED */
src/observer/sql/parser/yacc_sql.y
浏览文件 @
28eee7d5
...
...
@@ -2,9 +2,9 @@
%{
#include "sql/parser/parse_defs.h"
#include "sql/parser/yacc_sql.
tab.h
"
#include "sql/parser/lex
.yy
.h"
// #include "common/log/log.h" // 包含C++中的头文件
#include "sql/parser/yacc_sql.
hpp
"
#include "sql/parser/lex
_sql
.h"
#include "common/log/log.h"
#include<stdio.h>
#include<stdlib.h>
...
...
@@ -25,7 +25,7 @@ typedef struct ParserContext {
//获取子串
char *substr(const char *s,int n1,int n2)/*从s中提取下标为n1~n2的字符组成一个新字符串,然后返回这个新串的首地址*/
{
char *sp = malloc(sizeof(char) * (n2 - n1 + 2));
char *sp =
(char *)
malloc(sizeof(char) * (n2 - n1 + 2));
int i, j = 0;
for (i = n1; i <= n2; i++) {
sp[j++] = s[i];
...
...
@@ -226,7 +226,6 @@ create_table: /*create table 语句的语法解析树*/
CREATE TABLE ID LBRACE attr_def attr_def_list RBRACE SEMICOLON
{
CONTEXT->ssql->flag=SCF_CREATE_TABLE;//"create_table";
// CONTEXT->ssql->sstr.create_table.attribute_count = CONTEXT->value_length;
create_table_init_name(&CONTEXT->ssql->sstr.create_table, $3);
//临时变量清零
CONTEXT->value_length = 0;
...
...
@@ -241,23 +240,15 @@ attr_def:
ID_get type LBRACE number RBRACE
{
AttrInfo attribute;
attr_info_init(&attribute, CONTEXT->id, $2, $4);
attr_info_init(&attribute, CONTEXT->id,
(AttrType)
$2, $4);
create_table_append_attribute(&CONTEXT->ssql->sstr.create_table, &attribute);
// CONTEXT->ssql->sstr.create_table.attributes[CONTEXT->value_length].name =(char*)malloc(sizeof(char));
// strcpy(CONTEXT->ssql->sstr.create_table.attributes[CONTEXT->value_length].name, CONTEXT->id);
// CONTEXT->ssql->sstr.create_table.attributes[CONTEXT->value_length].type = $2;
// CONTEXT->ssql->sstr.create_table.attributes[CONTEXT->value_length].length = $4;
CONTEXT->value_length++;
}
|ID_get type
{
AttrInfo attribute;
attr_info_init(&attribute, CONTEXT->id, $2, 4);
attr_info_init(&attribute, CONTEXT->id,
(AttrType)
$2, 4);
create_table_append_attribute(&CONTEXT->ssql->sstr.create_table, &attribute);
// CONTEXT->ssql->sstr.create_table.attributes[CONTEXT->value_length].name=(char*)malloc(sizeof(char));
// strcpy(CONTEXT->ssql->sstr.create_table.attributes[CONTEXT->value_length].name, CONTEXT->id);
// CONTEXT->ssql->sstr.create_table.attributes[CONTEXT->value_length].type=$2;
// CONTEXT->ssql->sstr.create_table.attributes[CONTEXT->value_length].length=4; // default attribute length
CONTEXT->value_length++;
}
;
...
...
@@ -281,14 +272,7 @@ ID_get:
insert: /*insert 语句的语法解析树*/
INSERT INTO ID VALUES LBRACE value value_list RBRACE SEMICOLON
{
// CONTEXT->values[CONTEXT->value_length++] = *$6;
CONTEXT->ssql->flag=SCF_INSERT;//"insert";
// CONTEXT->ssql->sstr.insertion.relation_name = $3;
// CONTEXT->ssql->sstr.insertion.value_num = CONTEXT->value_length;
// for(i = 0; i < CONTEXT->value_length; i++){
// CONTEXT->ssql->sstr.insertion.values[i] = CONTEXT->values[i];
// }
inserts_init(&CONTEXT->ssql->sstr.insertion, $3, CONTEXT->values, CONTEXT->value_length);
//临时变量清零
...
...
@@ -330,20 +314,18 @@ update: /* update 语句的语法解析树*/
CONTEXT->ssql->flag = SCF_UPDATE;//"update";
Value *value = &CONTEXT->values[0];
updates_init(&CONTEXT->ssql->sstr.update, $2, $4, value,
CONTEXT->conditions, CONTEXT->condition_length);
CONTEXT->conditions, CONTEXT->condition_length);
CONTEXT->condition_length = 0;
}
;
select: /* select 语句的语法解析树*/
SELECT select_attr FROM ID rel_list where SEMICOLON
{
// CONTEXT->ssql->sstr.selection.relations[CONTEXT->from_length++]=$4;
selects_append_relation(&CONTEXT->ssql->sstr.selection, $4);
selects_append_conditions(&CONTEXT->ssql->sstr.selection, CONTEXT->conditions, CONTEXT->condition_length);
CONTEXT->ssql->flag=SCF_SELECT;//"select";
// CONTEXT->ssql->sstr.selection.attr_num = CONTEXT->select_length;
//临时变量清零
CONTEXT->condition_length=0;
...
...
@@ -376,15 +358,11 @@ attr_list:
RelAttr attr;
relation_attr_init(&attr, NULL, $2);
selects_append_attribute(&CONTEXT->ssql->sstr.selection, &attr);
// CONTEXT->ssql->sstr.selection.attributes[CONTEXT->select_length].relation_name = NULL;
// CONTEXT->ssql->sstr.selection.attributes[CONTEXT->select_length++].attribute_name=$2;
}
| COMMA ID DOT ID attr_list {
RelAttr attr;
relation_attr_init(&attr, $2, $4);
selects_append_attribute(&CONTEXT->ssql->sstr.selection, &attr);
// CONTEXT->ssql->sstr.selection.attributes[CONTEXT->select_length].attribute_name=$4;
// CONTEXT->ssql->sstr.selection.attributes[CONTEXT->select_length++].relation_name=$2;
}
;
...
...
@@ -417,16 +395,6 @@ condition:
Condition condition;
condition_init(&condition, CONTEXT->comp, 1, &left_attr, NULL, 0, NULL, right_value);
CONTEXT->conditions[CONTEXT->condition_length++] = condition;
// $$ = ( Condition *)malloc(sizeof( Condition));
// $$->left_is_attr = 1;
// $$->left_attr.relation_name = NULL;
// $$->left_attr.attribute_name= $1;
// $$->comp = CONTEXT->comp;
// $$->right_is_attr = 0;
// $$->right_attr.relation_name = NULL;
// $$->right_attr.attribute_name = NULL;
// $$->right_value = *$3;
}
|value comOp value
{
...
...
@@ -436,17 +404,6 @@ condition:
Condition condition;
condition_init(&condition, CONTEXT->comp, 0, NULL, left_value, 0, NULL, right_value);
CONTEXT->conditions[CONTEXT->condition_length++] = condition;
// $$ = ( Condition *)malloc(sizeof( Condition));
// $$->left_is_attr = 0;
// $$->left_attr.relation_name=NULL;
// $$->left_attr.attribute_name=NULL;
// $$->left_value = *$1;
// $$->comp = CONTEXT->comp;
// $$->right_is_attr = 0;
// $$->right_attr.relation_name = NULL;
// $$->right_attr.attribute_name = NULL;
// $$->right_value = *$3;
}
|ID comOp ID
{
...
...
@@ -458,15 +415,6 @@ condition:
Condition condition;
condition_init(&condition, CONTEXT->comp, 1, &left_attr, NULL, 1, &right_attr, NULL);
CONTEXT->conditions[CONTEXT->condition_length++] = condition;
// $$=( Condition *)malloc(sizeof( Condition));
// $$->left_is_attr = 1;
// $$->left_attr.relation_name=NULL;
// $$->left_attr.attribute_name=$1;
// $$->comp = CONTEXT->comp;
// $$->right_is_attr = 1;
// $$->right_attr.relation_name=NULL;
// $$->right_attr.attribute_name=$3;
}
|value comOp ID
{
...
...
@@ -477,18 +425,6 @@ condition:
Condition condition;
condition_init(&condition, CONTEXT->comp, 0, NULL, left_value, 1, &right_attr, NULL);
CONTEXT->conditions[CONTEXT->condition_length++] = condition;
// $$=( Condition *)malloc(sizeof( Condition));
// $$->left_is_attr = 0;
// $$->left_attr.relation_name=NULL;
// $$->left_attr.attribute_name=NULL;
// $$->left_value = *$1;
// $$->comp=CONTEXT->comp;
// $$->right_is_attr = 1;
// $$->right_attr.relation_name=NULL;
// $$->right_attr.attribute_name=$3;
}
|ID DOT ID comOp value
{
...
...
@@ -499,17 +435,6 @@ condition:
Condition condition;
condition_init(&condition, CONTEXT->comp, 1, &left_attr, NULL, 0, NULL, right_value);
CONTEXT->conditions[CONTEXT->condition_length++] = condition;
// $$=( Condition *)malloc(sizeof( Condition));
// $$->left_is_attr = 1;
// $$->left_attr.relation_name=$1;
// $$->left_attr.attribute_name=$3;
// $$->comp=CONTEXT->comp;
// $$->right_is_attr = 0; //属性值
// $$->right_attr.relation_name=NULL;
// $$->right_attr.attribute_name=NULL;
// $$->right_value =*$5;
}
|value comOp ID DOT ID
{
...
...
@@ -521,16 +446,6 @@ condition:
Condition condition;
condition_init(&condition, CONTEXT->comp, 0, NULL, left_value, 1, &right_attr, NULL);
CONTEXT->conditions[CONTEXT->condition_length++] = condition;
// $$=( Condition *)malloc(sizeof( Condition));
// $$->left_is_attr = 0;//属性值
// $$->left_attr.relation_name=NULL;
// $$->left_attr.attribute_name=NULL;
// $$->left_value = *$1;
// $$->comp =CONTEXT->comp;
// $$->right_is_attr = 1;//属性
// $$->right_attr.relation_name = $3;
// $$->right_attr.attribute_name = $5;
}
|ID DOT ID comOp ID DOT ID
{
...
...
@@ -542,14 +457,6 @@ condition:
Condition condition;
condition_init(&condition, CONTEXT->comp, 1, &left_attr, NULL, 1, &right_attr, NULL);
CONTEXT->conditions[CONTEXT->condition_length++] = condition;
// $$=( Condition *)malloc(sizeof( Condition));
// $$->left_is_attr = 1; //属性
// $$->left_attr.relation_name=$1;
// $$->left_attr.attribute_name=$3;
// $$->comp =CONTEXT->comp;
// $$->right_is_attr = 1; //属性
// $$->right_attr.relation_name=$5;
// $$->right_attr.attribute_name=$7;
}
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录