summaryrefslogtreecommitdiff
path: root/src/parser/antlr_parser.cpp
diff options
context:
space:
mode:
authorChristopher L. Conway <christopherleeconway@gmail.com>2010-02-16 19:35:34 +0000
committerChristopher L. Conway <christopherleeconway@gmail.com>2010-02-16 19:35:34 +0000
commit421446830d238e4a82fb0407621b2876b6e46a74 (patch)
tree29badf8de1a2603bbc9e4af6da45ee113f46bfa8 /src/parser/antlr_parser.cpp
parentbe1edc45cd31ea61ebb80641ae90c96c46a532ea (diff)
Moving parser error checking into AntlrParser
Diffstat (limited to 'src/parser/antlr_parser.cpp')
-rw-r--r--src/parser/antlr_parser.cpp44
1 files changed, 41 insertions, 3 deletions
diff --git a/src/parser/antlr_parser.cpp b/src/parser/antlr_parser.cpp
index 24d0ac3d7..af3ce9d1b 100644
--- a/src/parser/antlr_parser.cpp
+++ b/src/parser/antlr_parser.cpp
@@ -297,12 +297,21 @@ void AntlrParser::parseError(string message)
bool AntlrParser::checkDeclaration(string varName,
DeclarationCheck check,
- SymbolType type) {
+ SymbolType type)
+ throw (antlr::SemanticException) {
switch(check) {
case CHECK_DECLARED:
- return isDeclared(varName, type);
+ if( !isDeclared(varName, type) ) {
+ parseError("Symbol " + varName + " not declared");
+ } else {
+ return true;
+ }
case CHECK_UNDECLARED:
- return !isDeclared(varName, type);
+ if( isDeclared(varName, type) ) {
+ parseError("Symbol " + varName + " previously declared");
+ } else {
+ return true;
+ }
case CHECK_NONE:
return true;
default:
@@ -310,5 +319,34 @@ bool AntlrParser::checkDeclaration(string varName,
}
}
+bool AntlrParser::checkFunction(string name)
+ throw (antlr::SemanticException) {
+ if( !isFunction(name) ) {
+ parseError("Expecting function symbol, found '" + name + "'");
+ }
+
+ return true;
+}
+
+bool AntlrParser::checkArity(Kind kind, unsigned int numArgs)
+ throw (antlr::SemanticException) {
+ unsigned int min = minArity(kind);
+ unsigned int max = maxArity(kind);
+
+ if( numArgs < min || numArgs > max ) {
+ stringstream ss;
+ ss << "Expecting ";
+ if( numArgs < min ) {
+ ss << "at least " << min << " ";
+ } else {
+ ss << "at most " << max << " ";
+ }
+ ss << "arguments for operator '" << kind << "', ";
+ ss << "found " << numArgs;
+ parseError(ss.str());
+ }
+ return true;
+}
+
}/* CVC4::parser namespace */
}/* CVC4 namespace */
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback