Skip to content

Commit

Permalink
parsing projection variables, not complete - getting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
arijitsh committed Nov 7, 2024
1 parent 1fe2b2b commit c88e102
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
6 changes: 5 additions & 1 deletion include/stp/cpp_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,21 @@ class Cpp_interface

// Obtain the symbols for the current frame
ASTVec& getSymbols();
ASTVec& getProjSymbols();

private:
vector<std::string> _scoped_functions;
ASTVec _scoped_symbols;
ASTVec _scoped_proj_symbols;
std::unordered_map<std::string, Function>* _global_function_context;
};

// The vector of all frames that have been created by calling push
std::vector< SolverFrame* > frames;
std::vector<SolverFrame*> frames;

// Obtain the symbols/functions for the current frame
ASTVec& getCurrentSymbols();
ASTVec& getCurrentProjSymbols();
vector<std::string>& getCurrentFunctions();

void checkInvariant();
Expand Down Expand Up @@ -196,6 +199,7 @@ class Cpp_interface

DLL_PUBLIC void deleteNode(ASTNode* n);
DLL_PUBLIC void addSymbol(ASTNode& s);
DLL_PUBLIC void addProjSymbol(ASTNode& s);

DLL_PUBLIC void success();
DLL_PUBLIC void error(std::string msg);
Expand Down
15 changes: 15 additions & 0 deletions lib/Interface/cpp_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ ASTVec& Cpp_interface::getCurrentSymbols()
return frames.back()->getSymbols();
}

ASTVec& Cpp_interface::getCurrentProjSymbols()
{
return frames.back()->getProjSymbols();
}

vector<std::string>& Cpp_interface::getCurrentFunctions()
{
return frames.back()->getFunctions();
Expand Down Expand Up @@ -334,6 +339,11 @@ void Cpp_interface::addSymbol(ASTNode& s)
getCurrentSymbols().push_back(s);
}

void Cpp_interface::addProjSymbol(ASTNode& s)
{
getCurrentSymbols().push_back(s);
}

void Cpp_interface::success()
{
if (print_success)
Expand Down Expand Up @@ -709,4 +719,9 @@ ASTVec& Cpp_interface::SolverFrame::getSymbols()
{
return _scoped_symbols;
}

ASTVec& Cpp_interface::SolverFrame::getProjSymbols()
{
return _scoped_proj_symbols;
}
} // namespace stp
1 change: 1 addition & 0 deletions lib/Parser/smt2.lex
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ bv{DIGIT}+ { smt2lval.str = new std::string(smt2text+2); return BVCO
"check-sat-assuming" { return CHECK_SAT_ASSUMING_TOK;}
"declare-const" { return DECLARE_CONST_TOK;}
"declare-fun" { return DECLARE_FUNCTION_TOK; }
"proj-var" { return DECLARE_PROJ_VAR_TOK; }
"declare-sort" { return DECLARE_SORT_TOK;}
"define-fun" { return DEFINE_FUNCTION_TOK; }
"define-fun-rec" { return DECLARE_FUN_REC_TOK;}
Expand Down
19 changes: 18 additions & 1 deletion lib/Parser/smt2.y
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@
%token CHECK_SAT_ASSUMING_TOK
%token DECLARE_CONST_TOK
%token DECLARE_FUNCTION_TOK
%token DECLARE_PROJ_VAR_TOK
%token DECLARE_SORT_TOK
%token DEFINE_FUNCTION_TOK
%token DECLARE_FUN_REC_TOK
Expand Down Expand Up @@ -432,6 +433,11 @@ cmdi:
{
stp::GlobalParserInterface->success();
}
|
DECLARE_PROJ_VAR_TOK projvar_decl
{
stp::GlobalParserInterface->success();
}
|
DECLARE_FUNCTION_TOK var_decl
{
Expand Down Expand Up @@ -692,7 +698,18 @@ SOURCE_TOK
| LICENSE_TOK
;


projvar_decl:
STRING_TOK
{
// TODO AS: There should be a check saying that the variable is already declared.
ASTNode s = stp::GlobalParserInterface->LookupOrCreateSymbol($1->c_str());
stp::GlobalParserInterface->addProjSymbol(s);
//Sort_symbs has the indexwidth/valuewidth. Set those fields in
//var
s.SetIndexWidth(0);
delete $1;
}
;

var_decl:
STRING_TOK LPAREN_TOK RPAREN_TOK LPAREN_TOK UNDERSCORE_TOK BITVEC_TOK NUMERAL_TOK RPAREN_TOK
Expand Down

0 comments on commit c88e102

Please sign in to comment.