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
Open sidebar
CTA-LAPP
PHOENIX_LIBS
ParserGenerator
Commits
146586c0
Commit
146586c0
authored
Jan 13, 2021
by
Pierre Aubert
Browse files
Start to take account operator priority in parsing
parent
9103e7b2
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
11 deletions
+25
-11
TESTS/TEST_OPERATOR/CMakeLists.txt
TESTS/TEST_OPERATOR/CMakeLists.txt
+2
-0
src/CppBackEnd/repr_cpp_backend.cpp
src/CppBackEnd/repr_cpp_backend.cpp
+4
-3
src/CppBackEnd/repr_cpp_token_operator.cpp
src/CppBackEnd/repr_cpp_token_operator.cpp
+19
-8
No files found.
TESTS/TEST_OPERATOR/CMakeLists.txt
View file @
146586c0
...
...
@@ -20,3 +20,5 @@ add_test(NAME Test_test_math_operator_parser_input
add_test
(
NAME Test_test_math_operator_parser_input3
COMMAND
${
CMAKE_CURRENT_BINARY_DIR
}
/test_math_operator_parser_input -i
${
CMAKE_CURRENT_SOURCE_DIR
}
/fileAdd3.math -r
"(a+(b+c))"
WORKING_DIRECTORY
${
CMAKE_CURRENT_BINARY_DIR
}
)
src/CppBackEnd/repr_cpp_backend.cpp
View file @
146586c0
...
...
@@ -654,9 +654,10 @@ std::string graph_cpp_vecGraphDeclInternalRepresentationHeader(const PVecGraphTo
///Save the two header and source files of a PTabGraphToken
/** @param tabGraphToken : PTabGraphToken to be saved
* @param baseFileName : base name of the current file
* @return full header
*/
std
::
string
graph_cpp_tabGraphTokenParserHeader
(
const
PTabGraphToken
&
tabGraphToken
){
std
::
string
graph_cpp_tabGraphTokenParserHeader
(
const
PTabGraphToken
&
tabGraphToken
,
const
std
::
string
&
baseFileName
){
std
::
string
body
(
""
);
body
+=
licenceSaveStr
();
std
::
string
mainParser
(
tabGraphToken
.
getName
());
...
...
@@ -668,6 +669,7 @@ std::string graph_cpp_tabGraphTokenParserHeader(const PTabGraphToken & tabGraphT
body
+=
"#include <string>
\n
"
;
body
+=
"#include <vector>
\n
"
;
body
+=
"#include
\"
PMultiFileParser.h
\"\n
"
;
body
+=
"#include
\"
"
+
baseFileName
+
"Operator.h
\"\n
"
;
body
+=
"
\n
"
;
const
PVecSourceToken
&
vecSource
=
tabGraphToken
.
getVecSource
();
...
...
@@ -1010,7 +1012,7 @@ bool graph_cpp_tabGraphTokenParser(const PTabGraphToken & tabGraphToken){
std
::
string
fileHeader
(
baseFileName
+
".h"
);
std
::
string
fileSource
(
baseFileName
+
".cpp"
);
std
::
string
headerStr
(
graph_cpp_tabGraphTokenParserHeader
(
tabGraphToken
));
std
::
string
headerStr
(
graph_cpp_tabGraphTokenParserHeader
(
tabGraphToken
,
baseFileName
));
std
::
string
sourceStr
(
graph_cpp_tabGraphTokenParserSource
(
tabGraphToken
));
if
(
!
saveFileContent
(
fileHeader
,
headerStr
)){
...
...
@@ -1052,7 +1054,6 @@ bool graph_cpp_tabGraphTokenParserFull(const PTabGraphToken & tabGraphToken){
}
}
body
+=
"
\n
"
;
body
+=
"#include
\"
"
+
baseFileName
+
"Operator.h
\"\n
"
;
body
+=
"#include
\"
"
+
baseFileName
+
"_to_language.h
\"\n
"
;
body
+=
"#include
\"
"
+
baseFileName
+
".h
\"\n
"
;
...
...
src/CppBackEnd/repr_cpp_token_operator.cpp
View file @
146586c0
...
...
@@ -50,15 +50,26 @@ std::string repr_cpp_singleTokenOperator(const POperator & op, const PGraphToken
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
"
;
body
+=
"
\t\n
"
;
body
+=
"
\t
bool isStandardPushBack(true);
\n
"
;
body
+=
"
\t
if(isAnOperator(e)){
\n
"
;
body
+=
"
\t\t
long priorityOp(get_priority_operator(op)), priorityInput(get_priority_operator("
+
varName
+
"));
\n
"
;
body
+=
"
\t\t
if(priorityOp > priorityInput){
\n
"
;
body
+=
"
\t\t\t
//repr_cpp_token_operator : Let's get the last operand of the input "
+
varName
+
"
\n
"
;
body
+=
"
\t\t\t\n
"
;
body
+=
"
\t\t\t\n
"
;
body
+=
"
\t\t\t\n
"
;
body
+=
"
\t\t\t
isStandardPushBack = false;
\n
"
;
body
+=
"
\t\t
}
\n
"
;
body
+=
"
\t
}
\n
"
;
body
+=
"
\t
if(isStandardPushBack){
\n
"
;
body
+=
"
\t\t
vecOperand.push_back("
+
varName
+
");
\n
"
;
body
+=
"
\t\t
vecOperand.push_back(rightOp);
\n
"
;
body
+=
"
\t\t
//repr_cpp_token_operator : Finally, put the operator in the in/out parameter
\n
"
;
body
+=
"
\t\t
"
+
varName
+
" = op;
\n
"
;
body
+=
"
\t
}
\n
"
;
return
body
;
}
...
...
@@ -117,7 +128,7 @@ std::string repr_cpp_tokenOperatorSourceOperatorDo(const std::string & parserNam
body
+=
"
\t
//repr_cpp_token_operator : If there is no operand
\n
"
;
body
+=
"
\t
if(_vecOp.size() == 0lu){return false;}
\n
"
;
body
+=
"
\t
return
fals
e;
\n
"
;
body
+=
"
\t
return
tru
e;
\n
"
;
body
+=
"}
\n\n
"
;
return
body
;
}
...
...
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