From: <ibr...@us...> - 2012-03-15 22:31:39
|
Revision: 4242 http://tora.svn.sourceforge.net/tora/?rev=4242&view=rev Author: ibre5041 Date: 2012-03-15 22:31:33 +0000 (Thu, 15 Mar 2012) Log Message: ----------- Modified Paths: -------------- branches/tora-trotl/sandbox.cpp/Makefile branches/tora-trotl/sandbox.cpp/PLSQLLexer.g branches/tora-trotl/sandbox.cpp/PLSQL_DMLParser.g branches/tora-trotl/sandbox.cpp/UserTraits.hpp branches/tora-trotl/sandbox.cpp/t1.cpp Modified: branches/tora-trotl/sandbox.cpp/Makefile =================================================================== --- branches/tora-trotl/sandbox.cpp/Makefile 2012-03-13 22:35:24 UTC (rev 4241) +++ branches/tora-trotl/sandbox.cpp/Makefile 2012-03-15 22:31:33 UTC (rev 4242) @@ -5,10 +5,7 @@ SOURCES = $(wildcard *.cpp) GRAMMAROPTIONS=-report -Xconversiontimeout 1500000 -Xmultithreaded -Xwatchconversion -INCLUDES= -I. \ - -I/home/ivan/devel/antlr-cpp/include/ \ - -I/usr/include/qt4 \ - -I/usr/include/qt4/QtCore +INCLUDES= -I. -I/home/ivan/devel/antlr-cpp/include/ LIBS = Modified: branches/tora-trotl/sandbox.cpp/PLSQLLexer.g =================================================================== --- branches/tora-trotl/sandbox.cpp/PLSQLLexer.g 2012-03-13 22:35:24 UTC (rev 4241) +++ branches/tora-trotl/sandbox.cpp/PLSQLLexer.g 2012-03-15 22:31:33 UTC (rev 4242) @@ -20,8 +20,17 @@ options { language=Cpp; +// filter=true; } +tokens { // moved to the import vocabulary + UNSIGNED_INTEGER; // Imaginary token based on subtoken typecasting - see the rule <EXACT_NUM_LIT> + APPROXIMATE_NUM_LIT; // Imaginary token based on subtoken typecasting - see the rule <EXACT_NUM_LIT> + MINUS_SIGN; // Imaginary token based on subtoken typecasting - see the rule <SEPARATOR> + DOUBLE_PERIOD; + UNDERSCORE; // Imaginary token based on subtoken typecasting - see the rule <INTRODUCER> +} + @lexer::includes { #include "UserTraits.hpp" @@ -31,35 +40,27 @@ User } -// tokens { // moved to the import vocabulary -// UNSIGNED_INTEGER; // Imaginary token based on subtoken typecasting - see the rule <EXACT_NUM_LIT> -// APPROXIMATE_NUM_LIT; // Imaginary token based on subtoken typecasting - see the rule <EXACT_NUM_LIT> -// MINUS_SIGN; // Imaginary token based on subtoken typecasting - see the rule <SEPARATOR> -// DOUBLE_PERIOD; -// UNDERSCORE; // Imaginary token based on subtoken typecasting - see the rule <INTRODUCER> -// } +@header { +/* + * Oracle(c) PL/SQL 11g Parser + * + * Copyright (c) 2009-2011 Alexandre Porcelli <ale...@gm...> + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +} -// @header { -// /** -// * Oracle(c) PL/SQL 11g Parser -// * -// * Copyright (c) 2009-2011 Alexandre Porcelli <ale...@gm...> -// * -// * Licensed under the Apache License, Version 2.0 (the "License"); -// * you may not use this file except in compliance with the License. -// * You may obtain a copy of the License at -// * -// * http://www.apache.org/licenses/LICENSE-2.0 -// * -// * Unless required by applicable law or agreed to in writing, software -// * distributed under the License is distributed on an "AS IS" BASIS, -// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// * See the License for the specific language governing permissions and -// * limitations under the License. -// */ -// } - -// @members { +@members { // // buffer (queue) to hold the emit()'d tokens // // private LinkedList<Token> tokenBuffer = new LinkedList<Token>(); @@ -74,53 +75,53 @@ // // } -// /** -// * Return a token from this source; i.e., match a token on the char stream. -// */ -// // public Token nextToken() { -// // while (true) { -// // if (tokenBuffer.size() == 0) { -// // state.token = null; -// // state.channel = Token.DEFAULT_CHANNEL; -// // state.tokenStartCharIndex = input.index(); -// // state.tokenStartCharPositionInLine = input.getCharPositionInLine(); -// // state.tokenStartLine = input.getLine(); -// // state.text = null; -// // if (input.LA(1) == CharStream.EOF) { -// // return Token.EOF_TOKEN; -// // } -// // try { -// // int m = input.mark(); -// // state.backtracking = 1; -// // state.failed = false; -// // mTokens(); -// // state.backtracking = 0; + /** + * Return a token from this source; i.e., match a token on the char stream. + */ + // public Token nextToken() { + // while (true) { + // if (tokenBuffer.size() == 0) { + // state.token = null; + // state.channel = Token.DEFAULT_CHANNEL; + // state.tokenStartCharIndex = input.index(); + // state.tokenStartCharPositionInLine = input.getCharPositionInLine(); + // state.tokenStartLine = input.getLine(); + // state.text = null; + // if (input.LA(1) == CharStream.EOF) { + // return Token.EOF_TOKEN; + // } + // try { + // int m = input.mark(); + // state.backtracking = 1; + // state.failed = false; + // mTokens(); + // state.backtracking = 0; -// // if (state.failed) { -// // input.rewind(m); -// // input.consume(); -// // } else { -// // emit(); -// // } -// // } catch (RecognitionException re) { -// // // shouldn't happen in backtracking mode, but... -// // reportError(re); -// // recover(re); -// // } -// // } else { -// // Token result = tokenBuffer.poll(); -// // if (result == Token.SKIP_TOKEN || result.getType() == Token.INVALID_TOKEN_TYPE || result == null) -// // { -// // // discard -// // // SKIP & INVALID -// // // tokens -// // continue; -// // } -// // return result; -// // } -// // } -// // } -// } + // if (state.failed) { + // input.rewind(m); + // input.consume(); + // } else { + // emit(); + // } + // } catch (RecognitionException re) { + // // shouldn't happen in backtracking mode, but... + // reportError(re); + // recover(re); + // } + // } else { + // Token result = tokenBuffer.poll(); + // if (result == Token.SKIP_TOKEN || result.getType() == Token.INVALID_TOKEN_TYPE || result == null) + // { + // // discard + // // SKIP & INVALID + // // tokens + // continue; + // } + // return result; + // } + // } + // } +} FOR_NOTATION : UNSIGNED_INTEGER @@ -841,7 +842,7 @@ PLSQL_NON_RESERVED_MODEL : 'MODEL' - //{ + { // "MODEL" is a keyword if and only if it is followed by ("main"|"partition"|"dimension") // otherwise it is a identifier(REGULAR_ID). // This wodoo implements something like context sensitive lexer. @@ -895,7 +896,7 @@ // } // else if( t1 != null && t1.getType() == Token.EOF) // } // input.rewind(markModel); - //} + } ; PLSQL_NON_RESERVED_ELSIF Modified: branches/tora-trotl/sandbox.cpp/PLSQL_DMLParser.g =================================================================== --- branches/tora-trotl/sandbox.cpp/PLSQL_DMLParser.g 2012-03-13 22:35:24 UTC (rev 4241) +++ branches/tora-trotl/sandbox.cpp/PLSQL_DMLParser.g 2012-03-15 22:31:33 UTC (rev 4242) @@ -24,102 +24,13 @@ import PLSQLKeys, PLSQLCommons; -// @lexer::includes -// { -// #include "UserTraits.hpp" -// } @parser::includes { #include "UserTraits.hpp" #include "PLSQLLexer.hpp" } -//@lexer::namespace { User } @parser::namespace { User } -@members{ -// bool isTableAlias() { -// // String lt1 = input.LT(1).getText().toLowerCase(); -// // String lt2 = ""; -// // if (input.LT(2).getText() != null){ -// // lt2 = input.LT(2).getText().toLowerCase(); -// // } -// -// // if ((lt1.equals("partition") && lt2.equals("by")) || lt1.equals("cross") -// // || lt1.equals("natural") || lt1.equals("inner") -// // || lt1.equals("join") -// // || ((lt1.equals("full") || lt1.equals("left") || lt1.equals("right")) && (lt2.equals("outer") || lt2.equals("join")))) { -// // return false; -// // } -// return true; -// } -// -// template<class StringType> -// bool isStandardPredictionFunction(StringType const& originalFunctionName) { -// // String functionName = originalFunctionName.toLowerCase(); -// // if (functionName.equals("prediction") -// // || functionName.equals("prediction_bounds") -// // || functionName.equals("prediction_cost") -// // || functionName.equals("prediction_details") -// // || functionName.equals("prediction_probability") -// // || functionName.equals("prediction_set")) { -// // return true; -// // } -// return false; -// } -// -// template<class StringType> -// bool enablesWithinOrOverClause(StringType const& originalFunctionName) { -// // String functionName = originalFunctionName.toLowerCase(); -// // if (functionName.equals("cume_dist") -// // || functionName.equals("dense_rank") -// // || functionName.equals("listagg") -// // || functionName.equals("percent_rank") -// // || functionName.equals("percentile_cont") -// // || functionName.equals("percentile_disc") -// // || functionName.equals("rank")) { -// // return true; -// // } -// return false; -// } -// -// template<class StringType> -// bool enablesUsingClause(StringType const& originalFunctionName) { -// // String functionName = originalFunctionName.toLowerCase(); -// // if (functionName.startsWith("cluster_") -// // || functionName.startsWith("feature_")) { -// // return true; -// // } -// return false; -// } -// -// template<class StringType> -// bool enablesOverClause(StringType const& originalFunctionName) { -// // String functionName = originalFunctionName.toLowerCase(); -// // if (functionName.equals("avg") || functionName.equals("corr") -// // || functionName.equals("lag") || functionName.equals("lead") -// // || functionName.equals("max") || functionName.equals("median") -// // || functionName.equals("min") || functionName.equals("ntile") -// // || functionName.equals("ratio_to_report") -// // || functionName.equals("row_number") -// // || functionName.equals("sum") -// // || functionName.equals("variance") -// // || functionName.startsWith("regr_") -// // || functionName.startsWith("stddev") -// // || functionName.startsWith("var_") -// // || functionName.startsWith("covar_")) { -// // return true; -// // } -// return false; -// } -// -// template<class StringType> -// int equalsIgnoreCase(StringType const& s1, const char* s2) -// { -// //return !strcasecmp(s1->getText()->chars, s2); -// return true; -// } -} - //SHOULD BE OVERRIDEN! compilation_unit : seq_of_statements* EOF @@ -238,7 +149,7 @@ | dml_table_expression_clause (pivot_clause|unpivot_clause)? ) flashback_query_clause* - ({isTableAlias()}? table_alias)? + ({isTableAlias(LT(1), LT(2))}? table_alias)? ; join_clause Modified: branches/tora-trotl/sandbox.cpp/UserTraits.hpp =================================================================== --- branches/tora-trotl/sandbox.cpp/UserTraits.hpp 2012-03-13 22:35:24 UTC (rev 4241) +++ branches/tora-trotl/sandbox.cpp/UserTraits.hpp 2012-03-15 22:31:33 UTC (rev 4242) @@ -10,7 +10,8 @@ // The compiler must use -I (or set the project settings in VS2005) // to locate the antlr3 runtime files and -I. to find this file // -#include <antlr3.hpp> +#include <antlr3.hpp> +#include <algorithm> namespace User { @@ -48,90 +49,113 @@ typedef PLSQLTraits PLSQLLexerTraits; typedef PLSQLTraits PLSQL_DMLParser_PLSQLCommonsTraits; typedef PLSQLTraits PLSQL_DMLParser_PLSQLKeysTraits; - //typedef PLSQLTraits PLSQL_DMLParserParserTraits; typedef PLSQLTraits PLSQL_DMLParserTraits; -} + + template<class CommonTokenType> + inline bool isTableAlias(CommonTokenType *LT1, CommonTokenType *LT2) { + PLSQLTraits::StringType lt1 = LT1->getText(); + PLSQLTraits::StringType lt2 = ""; + std::transform(lt1.begin(), lt1.end(), lt1.begin(), ::toupper); + + if ( LT2 && LT2->getText() != ""){ + lt2 = LT2->getText(); + std::transform(lt2.begin(), lt2.end(), lt2.begin(), ::toupper); + } + + if ( (lt1 == "PARTITION" && lt2 == "BY") + || lt1 == "CROSS" + || lt1 == "NATURAL" + || lt1 == "INNER" + || lt1 == "JOIN" + || ( (lt1 == "FULL" || lt1 == "LEFT" || lt1 == "RIGHT") && (lt2 == "OUTER" || lt2 == "JOIN" ) ) + ) + { + return false; + } + return true; + } - inline bool isTableAlias() { -// // String lt1 = input.LT(1).getText().toLowerCase(); -// // String lt2 = ""; -// // if (input.LT(2).getText() != null){ -// // lt2 = input.LT(2).getText().toLowerCase(); -// // } + template<class StringType> + inline bool isStandardPredictionFunction(StringType const& originalFunctionName) { + StringType functionName = originalFunctionName; + std::transform(functionName.begin(), functionName.end(), functionName.begin(), ::toupper); + + if ( functionName == "PREDICTION" + || functionName == "PREDICTION_BOUNDS" + || functionName == "PREDICTION_COST" + || functionName == "PREDICTION_DETAILS" + || functionName == "PREDICTION_PROBABILITY" + || functionName == "PREDICTION_SET") + { + return true; + } + return false; + } -// // if ((lt1.equals("partition") && lt2.equals("by")) || lt1.equals("cross") -// // || lt1.equals("natural") || lt1.equals("inner") -// // || lt1.equals("join") -// // || ((lt1.equals("full") || lt1.equals("left") || lt1.equals("right")) && (lt2.equals("outer") || lt2.equals("join")))) { -// // return false; -// // } - return true; - } + template<class StringType> + inline bool enablesWithinOrOverClause(StringType const& originalFunctionName) { + StringType functionName = originalFunctionName; + std::transform(functionName.begin(), functionName.end(), functionName.begin(), ::toupper); + + if ( functionName == "CUME_DIST" + || functionName == "DENSE_RANK" + || functionName == "LISTAGG" + || functionName == "PERCENT_RANK" + || functionName == "PERCENTILE_CONT" + || functionName == "PERCENTILE_DISC" + || functionName == "RANK") + { + return true; + } + return false; + } - template<class StringType> - inline bool isStandardPredictionFunction(StringType const& originalFunctionName) { -// // String functionName = originalFunctionName.toLowerCase(); -// // if (functionName.equals("prediction") -// // || functionName.equals("prediction_bounds") -// // || functionName.equals("prediction_cost") -// // || functionName.equals("prediction_details") -// // || functionName.equals("prediction_probability") -// // || functionName.equals("prediction_set")) { -// // return true; -// // } - return false; - } + template<class StringType> + inline bool enablesUsingClause(StringType const& originalFunctionName) { + StringType functionName = originalFunctionName; + std::transform(functionName.begin(), functionName.end(), functionName.begin(), ::toupper); + // if (functionName.startsWith("cluster_") || functionName.startsWith("feature_")) + // { + // return true; + // } + return false; + } - template<class StringType> - inline bool enablesWithinOrOverClause(StringType const& originalFunctionName) { -// // String functionName = originalFunctionName.toLowerCase(); -// // if (functionName.equals("cume_dist") -// // || functionName.equals("dense_rank") -// // || functionName.equals("listagg") -// // || functionName.equals("percent_rank") -// // || functionName.equals("percentile_cont") -// // || functionName.equals("percentile_disc") -// // || functionName.equals("rank")) { -// // return true; -// // } - return false; - } + template<class StringType> + inline bool enablesOverClause(StringType const& originalFunctionName) { + StringType functionName = originalFunctionName; + std::transform(functionName.begin(), functionName.end(), functionName.begin(), ::toupper); + if ( functionName == "AVG" + || functionName == "CORR" + || functionName == "LAG" + || functionName == "LEAD" + || functionName == "MAX" + || functionName == "MEDIAN" + || functionName == "MIN" + || functionName == "NTILE" + || functionName == "RATIO_TO_REPORT" + || functionName == "ROW_NUMBER" + || functionName == "SUM" + || functionName == "VARIANCE" + // || functionName.startsWith("regr_") + // || functionName.startsWith("stddev") + // || functionName.startsWith("var_") + // || functionName.startsWith("covar_") + ) + { + return true; + } + return false; + } - template<class StringType> - inline bool enablesUsingClause(StringType const& originalFunctionName) { -// // String functionName = originalFunctionName.toLowerCase(); -// // if (functionName.startsWith("cluster_") -// // || functionName.startsWith("feature_")) { -// // return true; - // } - return false; - } + template<class StringType> + inline bool equalsIgnoreCase(StringType const& s1, const char* s2) + { + //return !strcasecmp(s1.c_str(), s2); + StringType s1U = s1; + std::transform(s1U.begin(), s1U.end(), s1U.begin(), ::toupper); + return s1U == s2; + } +} - template<class StringType> - inline bool enablesOverClause(StringType const& originalFunctionName) { -// // String functionName = originalFunctionName.toLowerCase(); -// // if (functionName.equals("avg") || functionName.equals("corr") -// // || functionName.equals("lag") || functionName.equals("lead") -// // || functionName.equals("max") || functionName.equals("median") -// // || functionName.equals("min") || functionName.equals("ntile") -// // || functionName.equals("ratio_to_report") -// // || functionName.equals("row_number") -// // || functionName.equals("sum") -// // || functionName.equals("variance") -// // || functionName.startsWith("regr_") -// // || functionName.startsWith("stddev") -// // || functionName.startsWith("var_") -// // || functionName.startsWith("covar_")) { -// // return true; -// // } - return false; - } - - template<class StringType> - inline bool equalsIgnoreCase(StringType const& s1, const char* s2) - { - return !strcasecmp(s1.c_str(), s2); - //return false; - } - #endif Modified: branches/tora-trotl/sandbox.cpp/t1.cpp =================================================================== --- branches/tora-trotl/sandbox.cpp/t1.cpp 2012-03-13 22:35:24 UTC (rev 4241) +++ branches/tora-trotl/sandbox.cpp/t1.cpp 2012-03-15 22:31:33 UTC (rev 4242) @@ -143,10 +143,10 @@ // && (buf[buflen-1] == 'a' || buf[buflen-1] == 'A') // ) { - printf(" - %s\n", dirfil->d_name); - //printf(" S"); fflush(stdout); - parseFile((ANTLR_UINT8*) buf); - // putc('E', stdout); fflush(stdout); + printf(" - %s\n", dirfil->d_name); + //printf(" S"); fflush(stdout); + parseFile((ANTLR_UINT8*) buf); + // putc('E', stdout); fflush(stdout); } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |