Skip to content

Commit

Permalink
Merge pull request #8136 from tautschnig/cleanup/jsil_parsert
Browse files Browse the repository at this point in the history
jsil_parsert: construct with message handler
  • Loading branch information
tautschnig authored Dec 20, 2023
2 parents f0c2391 + c49b489 commit 856c641
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 32 deletions.
7 changes: 2 additions & 5 deletions src/jsil/jsil_language.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,11 @@ bool jsil_languaget::parse(
parse_path=path;

// parsing
jsil_parsert jsil_parser{message_handler};
jsil_parser.clear();
jsil_parser.set_file(path);
jsil_parser.in=&instream;
jsil_parser.log.set_message_handler(message_handler);

jsil_scanner_init();
bool result=jsil_parser.parse();

// save result
Expand Down Expand Up @@ -137,12 +136,10 @@ bool jsil_languaget::to_expr(
std::istringstream instream(code);

// parsing

jsil_parsert jsil_parser{message_handler};
jsil_parser.clear();
jsil_parser.set_file(irep_idt());
jsil_parser.in=&instream;
jsil_parser.log.set_message_handler(message_handler);
jsil_scanner_init();

bool result=jsil_parser.parse();

Expand Down
10 changes: 0 additions & 10 deletions src/jsil/jsil_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,3 @@ Author: Michael Tautschnig, [email protected]
/// Jsil Language

#include "jsil_parser.h"

jsil_parsert jsil_parser;

extern char *yyjsiltext;

int yyjsilerror(const std::string &error)
{
jsil_parser.parse_error(error, yyjsiltext);
return 0;
}
17 changes: 10 additions & 7 deletions src/jsil/jsil_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,24 @@ Author: Michael Tautschnig, [email protected]

#include "jsil_parse_tree.h"

int yyjsilparse();
class jsil_parsert;
int yyjsilparse(jsil_parsert &);
void jsil_scanner_init(jsil_parsert &);

class jsil_parsert:public parsert
{
public:
explicit jsil_parsert(message_handlert &message_handler)
: parsert(message_handler)
{
}

jsil_parse_treet parse_tree;

virtual bool parse() override
{
return yyjsilparse()!=0;
jsil_scanner_init(*this);
return yyjsilparse(*this) != 0;
}

virtual void clear() override
Expand All @@ -41,9 +49,4 @@ class jsil_parsert:public parsert
std::string string_literal;
};

extern jsil_parsert jsil_parser;

int yyjsilerror(const std::string &error);
void jsil_scanner_init();

#endif // CPROVER_JSIL_JSIL_PARSER_H
16 changes: 15 additions & 1 deletion src/jsil/parser.y
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
%{

// #define YYDEBUG 1
#define PARSER jsil_parser
#define PARSER (*jsil_parser)

#include "jsil_parser.h"

int yyjsillex();
extern char *yyjsiltext;

static jsil_parsert *jsil_parser;
int yyjsilparse(void);
int yyjsilparse(jsil_parsert &_jsil_parser)
{
jsil_parser = &_jsil_parser;
return yyjsilparse();
}

int yyjsilerror(const std::string &error)
{
jsil_parser->parse_error(error, yyjsiltext);
return 0;
}

#define YYSTYPE unsigned
#define YYSTYPE_IS_TRIVIAL 1

Expand Down
20 changes: 11 additions & 9 deletions src/jsil/scanner.l
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,23 @@
#include <ansi-c/literals/convert_float_literal.h>
#include <ansi-c/literals/convert_string_literal.h>

#define PARSER jsil_parser
#define PARSER (*jsil_parser)
#define YYSTYPE unsigned

#include "jsil_parser.h"
#include "jsil_y.tab.h"
// extern int yyjsildebug;

static jsil_parsert *jsil_parser;
void jsil_scanner_init(jsil_parsert &_jsil_parser)
{
jsil_parser = &_jsil_parser;
YY_FLUSH_BUFFER;
BEGIN(0);
}

int yyjsilerror(const std::string &error);

#define loc() \
{ newstack(yyjsillval); PARSER.set_source_location(parser_stack(yyjsillval)); }

Expand Down Expand Up @@ -71,14 +81,6 @@ string_lit ["]{s_char}*["]
%x STRING_LITERAL_COMMENT
%x STATEMENTS

%{
void jsil_scanner_init()
{
// yyjsildebug=1;
YY_FLUSH_BUFFER;
BEGIN(0);
}
%}
/* %option debug */

%%
Expand Down

0 comments on commit 856c641

Please sign in to comment.