summaryrefslogtreecommitdiff
path: root/src/parser
diff options
context:
space:
mode:
authorMorgan Deters <mdeters@cs.nyu.edu>2013-03-01 18:31:10 -0500
committerMorgan Deters <mdeters@cs.nyu.edu>2013-03-25 20:35:54 -0400
commitef189453232a4dff9d3cfebafc6101bf8416b549 (patch)
tree3940f9d503cfc69431a3ac85b717fd4871241553 /src/parser
parent30333c667c982a3ce4c4efcec705724d22f12ec2 (diff)
java input stream adapters working
Diffstat (limited to 'src/parser')
-rw-r--r--src/parser/antlr_input.h3
-rw-r--r--src/parser/antlr_line_buffered_input.cpp13
-rw-r--r--src/parser/antlr_line_buffered_input.h5
-rw-r--r--src/parser/bounded_token_buffer.cpp2
-rw-r--r--src/parser/parser.cpp36
-rw-r--r--src/parser/parser.i15
6 files changed, 35 insertions, 39 deletions
diff --git a/src/parser/antlr_input.h b/src/parser/antlr_input.h
index 020db0d50..89f6c8db5 100644
--- a/src/parser/antlr_input.h
+++ b/src/parser/antlr_input.h
@@ -185,8 +185,9 @@ public:
std::string getUnparsedText();
/** Get the ANTLR3 lexer for this input. */
- pANTLR3_LEXER getAntlr3Lexer(){ return d_lexer; };
+ pANTLR3_LEXER getAntlr3Lexer() { return d_lexer; }
+ pANTLR3_INPUT_STREAM getAntlr3InputStream() { return d_antlr3InputStream; }
protected:
/** Create an input. This input takes ownership of the given input stream,
* and will delete it at destruction time.
diff --git a/src/parser/antlr_line_buffered_input.cpp b/src/parser/antlr_line_buffered_input.cpp
index 8c4f1b0be..46853056b 100644
--- a/src/parser/antlr_line_buffered_input.cpp
+++ b/src/parser/antlr_line_buffered_input.cpp
@@ -21,15 +21,11 @@
#include <cassert>
#include "util/output.h"
+#include "parser/antlr_line_buffered_input.h"
namespace CVC4 {
namespace parser {
-typedef struct ANTLR3_LINE_BUFFERED_INPUT_STREAM {
- ANTLR3_INPUT_STREAM antlr;
- std::istream* in;
-} *pANTLR3_LINE_BUFFERED_INPUT_STREAM;
-
static pANTLR3_INPUT_STREAM antlr3CreateLineBufferedStream(std::istream& in);
static void
@@ -213,7 +209,9 @@ myLA(pANTLR3_INT_STREAM is, ANTLR3_INT32 la) {
Debug("pipe") << "LA" << std::endl;
if (( ((pANTLR3_UINT8)input->nextChar) + la - 1) >= (((pANTLR3_UINT8)input->data) + input->sizeBuf))
{
- std::istream& in = *((pANTLR3_LINE_BUFFERED_INPUT_STREAM)input)->in;
+ std::istream& in = *((CVC4::parser::pANTLR3_LINE_BUFFERED_INPUT_STREAM)input)->in;
+ //MGD
+ // in.clear();
if(!in) {
Debug("pipe") << "EOF" << std::endl;
return ANTLR3_CHARSTREAM_EOF;
@@ -246,7 +244,7 @@ myLA(pANTLR3_INT_STREAM is, ANTLR3_INT32 la) {
++input->sizeBuf;
}
- Debug("pipe") << "READ POINTER[" << la << "] AT: >>" << std::string(((char*)input->nextChar), input->sizeBuf - (((char*)input->nextChar) - (char*)input->data) + 1) << "<< returning '" << (char)(*((pANTLR3_UINT8)input->nextChar + la - 1)) << "' (" << (unsigned)(*((pANTLR3_UINT8)input->nextChar + la - 1)) << ")" << std::endl;
+ Debug("pipe") << "READ POINTER[" << la << "] AT: >>" << std::string(((char*)input->nextChar), input->sizeBuf - (((char*)input->nextChar) - (char*)input->data)) << "<< returning '" << (char)(*((pANTLR3_UINT8)input->nextChar + la - 1)) << "' (" << (unsigned)(*((pANTLR3_UINT8)input->nextChar + la - 1)) << ")" << std::endl;
return (ANTLR3_UCHAR)(*((pANTLR3_UINT8)input->nextChar + la - 1));
}
@@ -356,7 +354,6 @@ antlr3CreateLineBufferedStream(std::istream& in)
input->isAllocated = ANTLR3_FALSE;
((pANTLR3_LINE_BUFFERED_INPUT_STREAM)input)->in = &in;
-
// Call the common 8 bit input stream handler
// initialization.
//
diff --git a/src/parser/antlr_line_buffered_input.h b/src/parser/antlr_line_buffered_input.h
index 83df19a2d..fb0c16dbe 100644
--- a/src/parser/antlr_line_buffered_input.h
+++ b/src/parser/antlr_line_buffered_input.h
@@ -25,6 +25,11 @@
namespace CVC4 {
namespace parser {
+typedef struct ANTLR3_LINE_BUFFERED_INPUT_STREAM {
+ ANTLR3_INPUT_STREAM antlr;
+ std::istream* in;
+} *pANTLR3_LINE_BUFFERED_INPUT_STREAM;
+
pANTLR3_INPUT_STREAM
antlr3LineBufferedStreamNew(std::istream& in, ANTLR3_UINT32 encoding, pANTLR3_UINT8 name);
diff --git a/src/parser/bounded_token_buffer.cpp b/src/parser/bounded_token_buffer.cpp
index 6a6ae8609..108b67307 100644
--- a/src/parser/bounded_token_buffer.cpp
+++ b/src/parser/bounded_token_buffer.cpp
@@ -473,9 +473,11 @@ static pANTLR3_COMMON_TOKEN nextToken(pBOUNDED_TOKEN_BUFFER buffer) {
tokenStream = buffer->commonTstream;
+ /*
if( buffer->done == ANTLR3_TRUE ) {
return &(tokenStream->tstream->tokenSource->eofToken);
}
+ */
/* Pick out the next token from the token source
* Remember we just get a pointer (reference if you like) here
diff --git a/src/parser/parser.cpp b/src/parser/parser.cpp
index 8b77362b2..90f17426b 100644
--- a/src/parser/parser.cpp
+++ b/src/parser/parser.cpp
@@ -446,26 +446,20 @@ Command* Parser::nextCommand() throw(ParserException) {
if(!d_commandQueue.empty()) {
cmd = d_commandQueue.front();
d_commandQueue.pop_front();
- if(cmd == NULL) {
- setDone();
- }
+ setDone(cmd == NULL);
} else {
- if(!done()) {
- try {
- cmd = d_input->parseCommand();
- d_commandQueue.push_back(cmd);
- cmd = d_commandQueue.front();
- d_commandQueue.pop_front();
- if(cmd == NULL) {
- setDone();
- }
- } catch(ParserException& e) {
- setDone();
- throw;
- } catch(exception& e) {
- setDone();
- parseError(e.what());
- }
+ try {
+ cmd = d_input->parseCommand();
+ d_commandQueue.push_back(cmd);
+ cmd = d_commandQueue.front();
+ d_commandQueue.pop_front();
+ setDone(cmd == NULL);
+ } catch(ParserException& e) {
+ setDone();
+ throw;
+ } catch(exception& e) {
+ setDone();
+ parseError(e.what());
}
}
Debug("parser") << "nextCommand() => " << cmd << std::endl;
@@ -478,9 +472,7 @@ Expr Parser::nextExpression() throw(ParserException) {
if(!done()) {
try {
result = d_input->parseExpr();
- if(result.isNull()) {
- setDone();
- }
+ setDone(result.isNull());
} catch(ParserException& e) {
setDone();
throw;
diff --git a/src/parser/parser.i b/src/parser/parser.i
index 5e10973d4..5b23555ea 100644
--- a/src/parser/parser.i
+++ b/src/parser/parser.i
@@ -9,14 +9,13 @@ namespace CVC4 {
%ignore operator<<(std::ostream&, DeclarationCheck);
%ignore operator<<(std::ostream&, SymbolType);
- class ParserExprStream : public CVC4::ExprStream {
- Parser* d_parser;
- public:
- ParserExprStream(Parser* parser) : d_parser(parser) {}
- ~ParserExprStream() { delete d_parser; }
- Expr nextExpr() { return d_parser->nextExpression(); }
- };/* class Parser::ExprStream */
-
+ class ParserExprStream : public CVC4::ExprStream {
+ Parser* d_parser;
+ public:
+ ParserExprStream(Parser* parser) : d_parser(parser) {}
+ ~ParserExprStream() { delete d_parser; }
+ Expr nextExpr() { return d_parser->nextExpression(); }
+ };/* class Parser::ExprStream */
}/* namespace CVC4::parser */
}/* namespace CVC4 */
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback