Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Docker-in-Docker (DinD) capabilities of public runners deactivated.
More info
Open sidebar
CTA-LAPP
PHOENIX_LIBS
ParserGenerator
Commits
dec4bc95
Commit
dec4bc95
authored
Jan 11, 2021
by
Pierre Aubert
Browse files
Fix one token operator
parent
e0096644
Pipeline
#99080
passed with stages
in 10 minutes and 9 seconds
Changes
8
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
131 additions
and
20 deletions
+131
-20
TESTS/TEST_OPERATOR/CMakeLists.txt
TESTS/TEST_OPERATOR/CMakeLists.txt
+2
-2
TESTS/TEST_OPERATOR/fileAdd.math
TESTS/TEST_OPERATOR/fileAdd.math
+2
-0
TESTS/TEST_OPERATOR/main_test.cpp
TESTS/TEST_OPERATOR/main_test.cpp
+47
-0
src/CppBackEnd/repr_cpp_backend.cpp
src/CppBackEnd/repr_cpp_backend.cpp
+15
-0
src/CppBackEnd/repr_cpp_graphToken.cpp
src/CppBackEnd/repr_cpp_graphToken.cpp
+16
-13
src/CppBackEnd/repr_cpp_token_operator.cpp
src/CppBackEnd/repr_cpp_token_operator.cpp
+27
-5
src/Stmt/PStmt.cpp
src/Stmt/PStmt.cpp
+20
-0
src/Stmt/PStmt.h
src/Stmt/PStmt.h
+2
-0
No files found.
TESTS/TEST_OPERATOR/CMakeLists.txt
View file @
dec4bc95
...
...
@@ -3,9 +3,9 @@ cmake_minimum_required(VERSION 3.0)
# compileLibTestGenerator(test_math_operator_parser "PTestOperatorParser" parser_operator.pdecparser)
compileMainTestGenerator
(
test_math_operator_parser
"PTestOperatorParser"
parser_operator.pdecparser main_test.cpp
)
#
compileMainTestGenerator(test_math_operator_parser "PTestOperatorParser" parser_operator.pdecparser main_test.cpp)
# Only when the test will be OK
#
compileTestGenerator(test_math_operator_parser "PTestOperatorParser" parser_operator.pdecparser main_test.cpp
var_decl.txt
)
compileTestGenerator
(
test_math_operator_parser
"PTestOperatorParser"
parser_operator.pdecparser main_test.cpp
fileAdd.math
)
TESTS/TEST_OPERATOR/fileAdd.math
0 → 100644
View file @
dec4bc95
a + b
TESTS/TEST_OPERATOR/main_test.cpp
View file @
dec4bc95
...
...
@@ -4,11 +4,25 @@
Licence : CeCILL-C
****************************************/
#include "OptionParser.h"
// To get the generated parser
#include "PTestOperatorParserFull.h"
using
namespace
std
;
///Create the OptionParser of this program
/** @return OptionParser of this program
*/
OptionParser
createOptionParser
(){
OptionParser
parser
(
true
,
__PROGRAM_VERSION__
);
parser
.
setExampleLongOption
(
"use_parser --input=fileName.shadok"
);
parser
.
setExampleShortOption
(
"use_parser -i fileName.shadok"
);
parser
.
addOption
(
"input"
,
"i"
,
OptionType
::
FILENAME
,
true
,
"input shadok file name"
);
return
parser
;
}
///Test the conversion of and add expression into a string
/** @return true on success, false otherwise
*/
...
...
@@ -29,6 +43,8 @@ bool testExprAddToString(){
std
::
string
exprStr
=
gExprVarName
(
exprAdd
);
std
::
cout
<<
"testExprAddToString : exprAdd = '"
<<
exprStr
<<
"'"
<<
std
::
endl
;
// std::cout << "testExprAddToString : exprAdd ok example :"<< std::endl;
// exprAdd.print();
return
exprStr
==
"(a+b)"
;
}
...
...
@@ -111,10 +127,41 @@ bool testExprAdd3ToString(){
return
exprStr
==
"((a+b)+(c+d))"
;
}
///Parse a source file
/** @param fileName : name of the source file
* @return true on success, false otherwise
*/
bool
testParseFileName
(
const
std
::
string
&
fileName
){
//We create the parser
PTestOperatorParser
parser
;
if
(
!
parser
.
load
(
fileName
)){
cerr
<<
"testParseFileName : can't load file '"
<<
fileName
<<
"'"
<<
endl
;
return
false
;
}
//We get the parsed internal representation
PExpr
&
source
=
parser
.
getPExprE
();
std
::
cout
<<
"PExpr full stmt :"
<<
std
::
endl
;
source
.
print
();
std
::
string
exprStr
=
gExprVarName
(
source
);
std
::
cout
<<
"testParseFileName : exprStr = '"
<<
exprStr
<<
"'"
<<
std
::
endl
;
return
exprStr
==
"(a+b)"
;
}
int
main
(
int
argc
,
char
**
argv
){
OptionParser
optionParser
=
createOptionParser
();
optionParser
.
parseArgument
(
argc
,
argv
);
const
OptionMode
&
defaultMode
=
optionParser
.
getDefaultMode
();
std
::
string
fileName
(
""
);
defaultMode
.
getValue
(
fileName
,
"input"
);
bool
b
(
testExprAddToString
());
b
&=
testExprAdd2ToString
();
b
&=
testExprAdd3ToString
();
b
&=
testParseFileName
(
fileName
);
if
(
b
){
return
0
;}
else
{
return
-
1
;}
}
...
...
src/CppBackEnd/repr_cpp_backend.cpp
View file @
dec4bc95
...
...
@@ -809,6 +809,21 @@ std::string graph_cpp_parseFileSource(const PTabGraphToken & tabGraphToken){
}
}
body
+=
"
\t
//Put all the other else for all the concerned graphs
\n
"
;
body
+=
"
\t
//No need to parse the operators here because we integrate them in the parsing of attribute
\n
"
;
// const PVecOperator & vecOperator = tabGraphToken.getVecOperator();
// if(vecOperator.size() != 0lu){
// for(PVecOperator::const_iterator it(vecOperator.begin()); it != vecOperator.end(); ++it){
// body += "\t";
// if(useElse){
// body += "else ";
// }
// // body += "if(" + it->getName() + "(p_"+it->getVarType() + it->getVarName() + ")){}\n";
//
// useElse = true;
// }
// }
const
PVecGraphToken
&
vecGraph
=
tabGraphToken
.
getVecGraph
();
if
(
vecGraph
.
size
()
!=
0lu
){
for
(
PVecGraphToken
::
const_iterator
it
(
vecGraph
.
begin
());
it
!=
vecGraph
.
end
();
++
it
){
...
...
src/CppBackEnd/repr_cpp_graphToken.cpp
View file @
dec4bc95
...
...
@@ -43,30 +43,33 @@ std::string graph_cpp_graphTokenImplementation(const PTabGraphToken & tabGraphTo
if
(
vecToken
.
size
()
==
0lu
){
return
"
\t
return true; //No sub tokens in the current graph
\n
"
;}
long
unsigned
int
tokenIndex
(
1lu
);
body
+=
getTypeCheckInit
(
graphToken
.
getVarName
(),
graphToken
.
getVarType
());
body
+=
"
\t
//Check if this graph is used by Operator
\n
"
;
//Standard graph token parsing part
for
(
PVecToken
::
const_iterator
it
(
vecToken
.
begin
());
it
!=
vecToken
.
end
();
++
it
){
body
+=
"
\t
if(!"
+
it
->
getFunctionName
()
+
"Do("
+
graphToken
.
getVarName
()
+
")){
\n
"
;
for
(
long
unsigned
int
i
(
0lu
);
i
<
tokenIndex
;
++
i
){
body
+=
"
\t\t
"
+
vecToken
[
tokenIndex
-
i
-
1lu
].
getFunctionName
()
+
"Undo("
+
graphToken
.
getVarName
()
+
");
\n
"
;
}
body
+=
"
\t\t
return false;
\n
"
;
body
+=
"
\t
}
\n
"
;
++
tokenIndex
;
}
body
+=
"
\t
//repr_cpp_graphToken : Check if this graph is used by Operator
\n
"
;
PVecOperator
vecOp
;
search_operatorByGraphUse
(
vecOp
,
tabGraphToken
.
getVecOperator
(),
graphToken
.
getName
());
if
(
vecOp
.
size
()
!=
0lu
){
//Operator Part
std
::
string
prevElse
(
""
);
body
+=
"
\t
//This graph is used by the following Operator
\n
"
;
body
+=
"
\t
//
repr_cpp_graphToken :
This graph is used by the following Operator
\n
"
;
for
(
PVecOperator
::
iterator
it
(
vecOp
.
begin
());
it
!=
vecOp
.
end
();
++
it
){
std
::
string
opValue
(
repr_cpp_operator_getEnumValue
(
it
->
getValueEnum
()));
std
::
string
baseFctName
(
"Operator"
+
repr_cpp_operator_getEnumValue
(
it
->
getValueEnum
()));
body
+=
"
\t
"
+
prevElse
+
"if("
+
graphToken
.
getName
()
+
baseFctName
+
"Do("
+
graphToken
.
getVarName
()
+
")){return true;}
\n
"
;
prevElse
=
"else "
;
}
body
+=
"
\t
//Now continue the standard parsing without Operator
\n
"
;
}
//Standard graph token parsing part
for
(
PVecToken
::
const_iterator
it
(
vecToken
.
begin
());
it
!=
vecToken
.
end
();
++
it
){
body
+=
"
\t
if(!"
+
it
->
getFunctionName
()
+
"Do("
+
graphToken
.
getVarName
()
+
")){
\n
"
;
for
(
long
unsigned
int
i
(
0lu
);
i
<
tokenIndex
;
++
i
){
body
+=
"
\t\t
"
+
vecToken
[
tokenIndex
-
i
-
1lu
].
getFunctionName
()
+
"Undo("
+
graphToken
.
getVarName
()
+
");
\n
"
;
}
body
+=
"
\t\t
return false;
\n
"
;
body
+=
"
\t
}
\n
"
;
++
tokenIndex
;
body
+=
"
\t
//repr_cpp_graphToken : Now continue the standard parsing without Operator
\n
"
;
}
body
+=
"
\t
return true;
\n
"
;
body
+=
"}
\n\n
"
;
...
...
src/CppBackEnd/repr_cpp_token_operator.cpp
View file @
dec4bc95
...
...
@@ -34,8 +34,30 @@ std::string repr_cpp_tokenOperatorHeader(const PTabGraphToken & tabGraphToken, c
*/
std
::
string
repr_cpp_singleTokenOperator
(
const
POperator
&
op
,
const
PGraphToken
&
graphToken
){
std
::
string
body
(
""
),
name
(
graphToken
.
getName
()),
varName
(
graphToken
.
getVarName
()),
varType
(
graphToken
.
getVarType
());
body
+=
"
\t
//Let's parse an Operator with 1 token
\n
"
;
body
+=
"
\t
if(isMatch(
\"
"
+
op
.
getVecToken
().
front
()
+
"
\"
)){return false;}
\n
"
;
body
+=
"
\t
//repr_cpp_token_operator : Let's parse an Operator with 1 token
\n
"
;
body
+=
"
\t
//repr_cpp_token_operator : the first operand is already parsed and given as parameter
\n
"
;
body
+=
"
\t
//repr_cpp_token_operator : it would be great to add a while
\n\n
"
;
body
+=
"
\t
if(!isMatch(
\"
"
+
op
.
getVecToken
().
front
()
+
"
\"
)){return false;}
\n
"
;
body
+=
"
\t
//repr_cpp_token_operator : Let's call the graph token of the second operand
\n
"
;
body
+=
"
\t
PStmt rightOp = "
+
op
.
getExprClass
()
+
"_default();
\n
"
;
std
::
string
rightOperandGraph
(
op
.
getVecExprGraph
().
back
());
body
+=
"
\t
if(!"
+
rightOperandGraph
+
"(rightOp)){return false;}
\n
"
;
body
+=
"
\t
//repr_cpp_token_operator : here the operator is well parsed
\n
"
;
body
+=
"
\t
PStmt op = "
+
op
.
getExprClass
()
+
"_default();
\n
"
;
// body += "\top.setType("+op.getValueEnum()+");\n";
body
+=
"
\t
"
+
op
.
getExprClass
()
+
"_set"
+
firstToUpper
(
op
.
getAttrEnum
())
+
"(op, "
+
op
.
getValueEnum
()
+
");
\n
"
;
body
+=
"
\t
PStmt & vecOperand = PExpr_getVecOperand(op);
\n
"
;
body
+=
"
\t
vecOperand.push_back("
+
varName
+
");
\n
"
;
body
+=
"
\t
vecOperand.push_back(rightOp);
\n
"
;
body
+=
"
\t
//repr_cpp_token_operator : Finally, put the operator in the in/out parameter
\n
"
;
body
+=
"
\t
"
+
varName
+
" = op;
\n
"
;
return
body
;
}
...
...
@@ -47,7 +69,7 @@ std::string repr_cpp_singleTokenOperator(const POperator & op, const PGraphToken
*/
std
::
string
repr_cpp_doubleTokenOperator
(
const
POperator
&
op
,
const
PGraphToken
&
graphToken
){
std
::
string
body
(
""
),
name
(
graphToken
.
getName
()),
varName
(
graphToken
.
getVarName
()),
varType
(
graphToken
.
getVarType
());
body
+=
"
\t
//Let's parse an Operator with 2 tokens
\n
"
;
body
+=
"
\t
//
repr_cpp_token_operator :
Let's parse an Operator with 2 tokens
\n
"
;
return
body
;
}
...
...
@@ -59,7 +81,7 @@ std::string repr_cpp_doubleTokenOperator(const POperator & op, const PGraphToken
*/
std
::
string
repr_cpp_tripleTokenOperator
(
const
POperator
&
op
,
const
PGraphToken
&
graphToken
){
std
::
string
body
(
""
),
name
(
graphToken
.
getName
()),
varName
(
graphToken
.
getVarName
()),
varType
(
graphToken
.
getVarType
());
body
+=
"
\t
//Let's parse an Operator with 3 tokens
\n
"
;
body
+=
"
\t
//
repr_cpp_token_operator :
Let's parse an Operator with 3 tokens
\n
"
;
return
body
;
}
...
...
@@ -92,7 +114,7 @@ std::string repr_cpp_tokenOperatorSourceOperatorDo(const std::string & parserNam
}
body
+=
"
\t
PStmt & _vecOp = "
+
varType
+
"_get"
+
firstToUpper
(
op
.
getVecOp
())
+
"("
+
varName
+
");
\n
"
;
body
+=
"
\t
//If there is no operand
\n
"
;
body
+=
"
\t
//
repr_cpp_token_operator :
If there is no operand
\n
"
;
body
+=
"
\t
if(_vecOp.size() == 0lu){return false;}
\n
"
;
body
+=
"
\t
return false;
\n
"
;
...
...
src/Stmt/PStmt.cpp
View file @
dec4bc95
...
...
@@ -206,6 +206,26 @@ bool PStmt::isType(unsigned int type) const{
return
p_type
==
type
;
}
///Print the PStmt
/** @param indentation : indentation of the print
*/
void
PStmt
::
print
(
const
std
::
string
&
indentation
)
const
{
std
::
cout
<<
indentation
<<
"PStmt(type = "
<<
p_type
<<
", sign = "
<<
p_sign
<<
", datasize = "
<<
p_data
.
size
();
if
(
p_data
.
size
()
!=
0lu
){
std
::
cout
<<
", data = "
<<
((
void
*
)
p_data
.
data
());
}
std
::
cout
<<
")"
;
if
(
p_vecStmt
.
size
()
!=
0lu
){
std
::
cout
<<
"{"
<<
std
::
endl
;
for
(
std
::
vector
<
PStmt
>::
const_iterator
it
(
p_vecStmt
.
begin
());
it
!=
p_vecStmt
.
end
();
++
it
){
it
->
print
(
indentation
+
"
\t
"
);
}
std
::
cout
<<
indentation
<<
"}"
<<
std
::
endl
;
}
else
{
std
::
cout
<<
";"
<<
std
::
endl
;
}
}
///Copy function of PStmt
/** @param other : class to copy
*/
...
...
src/Stmt/PStmt.h
View file @
dec4bc95
...
...
@@ -62,6 +62,8 @@ class PStmt{
bool
isType
(
unsigned
int
type
)
const
;
void
print
(
const
std
::
string
&
indentation
=
""
)
const
;
protected:
void
copyPStmt
(
const
PStmt
&
other
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment