From 1e93f62a3f95f6afd7b0858b4136d036b889bd86 Mon Sep 17 00:00:00 2001 From: Tony Zhang <tony.zhang.domore@outlook.com> Date: Sun, 23 Feb 2020 17:34:31 -0500 Subject: [PATCH] Fix bug caused by yytext --- SQLPGrammar.y | 40 ++++++++++++++++++++-------------------- SQLPRefExp.y | 19 +++++++++---------- SQLPScanner.l | 14 ++++++++------ SQLPSchema.y | 32 ++++++++++++++++---------------- 4 files changed, 53 insertions(+), 52 deletions(-) diff --git a/SQLPGrammar.y b/SQLPGrammar.y index c38a09c..641d6bd 100644 --- a/SQLPGrammar.y +++ b/SQLPGrammar.y @@ -200,55 +200,55 @@ AttrPath VarIdentifier : IDENTIFIER { - printf("VarIdentifier is |%s| ", yytext); - $$ = create_var(yytext); + printf("VarIdentifier is |%s| ", identifier); + $$ = create_var(identifier); } TableIdentifier : IDENTIFIER { - printf("TableIdentifier is |%s| ", yytext); - $$ = create_var(yytext); + printf("TableIdentifier is |%s| ", identifier); + $$ = create_var(identifier); } AttrIdentifier : IDENTIFIER { - printf("AttrIdentifier is |%s| ", yytext); - $$ = create_var(yytext); + printf("AttrIdentifier is |%s| ", identifier); + $$ = create_var(identifier); } CompOperator : EQ { printf("CompOperator EQ\n"); - $$ = create_op(yytext); + $$ = create_op("="); } | NE { printf("CompOperator NE\n"); - $$ = create_op(yytext); + $$ = create_op("<>"); } | LE { printf("CompOperator LE\n"); - $$ = create_op(yytext); + $$ = create_op("<="); } | GE { printf("CompOperator GE\n"); - $$ = create_op(yytext); + $$ = create_op(">="); } | LT { printf("CompOperator LT\n"); - $$ = create_op(yytext); + $$ = create_op("<"); } | GT { printf("CompOperator GT\n"); - $$ = create_op(yytext); + $$ = create_op(">"); } ; @@ -317,25 +317,25 @@ Term Integer : INTEGER { - printf("INTEGER is |%s|", yytext); - $$ = create_constant(yytext); + printf("INTEGER is |%s|", constant); + $$ = create_constant(constant); } Constant : INTEGER { - printf("INTEGER is |%s|", yytext); - $$ = create_constant(yytext); + printf("INTEGER is |%s|", constant); + $$ = create_constant(constant); } | REAL { - printf("REAL is |%s|", yytext); - $$ = create_constant(yytext); + printf("REAL is |%s|", constant); + $$ = create_constant(constant); } | STRING { - printf("STRING is |%s|", yytext); - $$ = create_constant(yytext); + printf("STRING is |%s|", constant); + $$ = create_constant(constant); } ; diff --git a/SQLPRefExp.y b/SQLPRefExp.y index 1b6d3d6..d206369 100644 --- a/SQLPRefExp.y +++ b/SQLPRefExp.y @@ -34,7 +34,7 @@ SQLPRefExp ; OidExpLst - : OidExpLst ';' OidExp + : OidExpLst ';' OidExp { printf("OidExpLst\n"); $$ = create_oidexplst_operator($1, $3); @@ -86,12 +86,12 @@ Col AttrPath : AttrIdentifier - { + { printf("path id\n"); $$ = create_pf($1, NULL); } | AttrIdentifier '.' AttrPath - { + { printf("Path Function\n"); $$ = create_pf($1, $3); } @@ -100,21 +100,20 @@ AttrPath VarIdentifier : IDENTIFIER { - printf("|%s| ", yytext); - $$ = create_var(yytext); + printf("|%s| ", identifier); + $$ = create_var(identifier); } TableIdentifier : IDENTIFIER { - printf("|%s| ", yytext); - $$ = create_table(yytext); + printf("|%s| ", identifier); + $$ = create_table(identifier); } AttrIdentifier : IDENTIFIER { - printf("|%s| ", yytext); - $$ = create_attr(yytext); + printf("|%s| ", identifier); + $$ = create_attr(identifier); } - diff --git a/SQLPScanner.l b/SQLPScanner.l index 964ddd8..b6f3555 100644 --- a/SQLPScanner.l +++ b/SQLPScanner.l @@ -32,6 +32,8 @@ int LineNumber = 1; char LineBuffer[200]; +char identifier[200]; +char constant[200]; %} %p 3000 @@ -121,14 +123,14 @@ E [Ee][+-]?{D}+ "with" { strcat(LineBuffer, yytext); return(WITH); } "->" { strcat(LineBuffer, yytext); return(REF); } -{L}({L}|{D})* { strcat(LineBuffer, yytext); return(IDENTIFIER); } +{L}({L}|{D})* { strcpy(identifier, yytext); strcat(LineBuffer, yytext); return(IDENTIFIER); } -{D}+ { strcat(LineBuffer, yytext); return(INTEGER); } -{D}+{E} { strcat(LineBuffer, yytext); return(REAL); } -{D}*"."{D}+({E})? { strcat(LineBuffer, yytext); return(REAL); } -{D}+"."{D}*({E})? { strcat(LineBuffer, yytext); return(REAL); } +{D}+ { strcpy(constant, yytext); strcat(LineBuffer, yytext); return(INTEGER); } +{D}+{E} { strcpy(constant, yytext); strcat(LineBuffer, yytext); return(REAL); } +{D}*"."{D}+({E})? { strcpy(constant, yytext); strcat(LineBuffer, yytext); return(REAL); } +{D}+"."{D}*({E})? { strcpy(constant, yytext); strcat(LineBuffer, yytext); return(REAL); } -\"(\\.|[^\\"])*\" { strcat(LineBuffer, yytext); return(STRING); } +\"(\\.|[^\\"])*\" { strcpy(constant, yytext); strcat(LineBuffer, yytext); return(STRING); } ":=" { strcat(LineBuffer, yytext); return(ASSIGN); } "<=" { strcat(LineBuffer, yytext); return(LE); } diff --git a/SQLPSchema.y b/SQLPSchema.y index 2486fd2..54ee426 100644 --- a/SQLPSchema.y +++ b/SQLPSchema.y @@ -194,57 +194,57 @@ AttrPath Type : INTCLASS { - printf("INTCLASS is |%s|", yytext); - $$ = create_type(yytext); + printf("INTCLASS is |Integer|"); + $$ = create_type("Integer"); } | STRCLASS { - printf("STRCLASS is |%s|", yytext); - $$ = create_type(yytext); + printf("STRCLASS is |String|"); + $$ = create_type("String"); } | OID { - printf("OID is |%s|", yytext); - $$ = create_type(yytext); + printf("OID is |Oid|"); + $$ = create_type("Oid"); } ; AttributeIdentifier : IDENTIFIER { - printf("AttributeIdentifier is |%s| ", yytext); - $$ = create_attr(yytext); + printf("AttributeIdentifier is |%s| ", identifier); + $$ = create_attr(identifier); } ; TableIdentifier : IDENTIFIER { - printf("|%s| ", yytext); - $$ = create_table(yytext); + printf("|%s| ", identifier); + $$ = create_table(identifier); } ; VarIdentifier : IDENTIFIER { - printf("|%s| ", yytext); - $$ = create_var(yytext); + printf("|%s| ", identifier); + $$ = create_var(identifier); } ; ReferringType : IDENTIFIER { - printf("ClassIdentifier is |%s| ", yytext); - $$ = create_rt(yytext); + printf("ClassIdentifier is |%s| ", identifier); + $$ = create_rt(identifier); } ; ClassIdentifier : IDENTIFIER { - printf("ClassIdentifier is |%s| ", yytext); - $$ = create_class(yytext); + printf("ClassIdentifier is |%s| ", identifier); + $$ = create_class(identifier); } ; -- GitLab