summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlo Zancanaro <carlo@carlo-laptop>2012-05-17 01:58:42 +1000
committerCarlo Zancanaro <carlo@carlo-laptop>2012-05-17 01:58:42 +1000
commit12b86dc91316a5591c22160a9312e62c77a65b2f (patch)
treec1689f6d50fc529d9b0dcd38a021a15109c5867d
parentfcecd0e7dc0bf103986c02e2f29fb518cd5571c5 (diff)
Fix a segfault and a stupid parser decision.
-rw-r--r--impl/EquationSystem.g2
-rw-r--r--impl/Expression.hpp4
-rw-r--r--impl/MaxStrategy.hpp8
-rw-r--r--impl/antlr/test-file5
4 files changed, 12 insertions, 7 deletions
diff --git a/impl/EquationSystem.g b/impl/EquationSystem.g
index d7e55a7..6db7045 100644
--- a/impl/EquationSystem.g
+++ b/impl/EquationSystem.g
@@ -27,7 +27,7 @@ term : NUMBER | VARIABLE ;
NUMBER : (DIGIT)+ ;
-VARIABLE: (LETTER)+ ;
+VARIABLE: (LETTER) (LETTER | DIGIT)* ;
WHITESPACE : ( '\t' | ' ' | '\u000C' )+
{
$channel = HIDDEN;
diff --git a/impl/Expression.hpp b/impl/Expression.hpp
index 913bf7a..5cf82d4 100644
--- a/impl/Expression.hpp
+++ b/impl/Expression.hpp
@@ -1,7 +1,7 @@
#ifndef EXPRESSION_HPP
#define EXPRESSION_HPP
-//#include <pair>
+#include <iostream>
#include "VariableAssignment.hpp"
#include "Operator.hpp"
@@ -50,7 +50,7 @@ struct MaxExpression : public Expression<T> {
if (value > best.first)
best = std::pair<T, unsigned int>(value, i);
}
- std::cout << "Best strategy: (" << best.first << ", " << best.second << ")" << std::endl;
+ std::cerr << "Best strategy: (" << best.first << ", " << best.second << ")" << std::endl;
return best;
}
private:
diff --git a/impl/MaxStrategy.hpp b/impl/MaxStrategy.hpp
index e52fd99..f4e4055 100644
--- a/impl/MaxStrategy.hpp
+++ b/impl/MaxStrategy.hpp
@@ -1,6 +1,7 @@
#ifndef MAX_STRATEGY_HPP
#define MAX_STRATEGY_HPP
+#include <iostream>
#include "Expression.hpp"
#include "EquationSystem.hpp"
#include "VariableAssignment.hpp"
@@ -69,7 +70,12 @@ struct MaxStrategy {
if (best.first > oldValue)
newStrategy[*expr] = best.second;
}
- std::cout << "Strat improvement: " << newStrategy[*s.getMax(0)] << std::endl;
+ std::cerr << "Strat improvement: ";
+ if (_length > 0)
+ std::cerr << newStrategy[*s.getMax(0)];
+ else
+ std::cerr << "no max expressions";
+ std::cerr << std::endl;
return newStrategy;
}
diff --git a/impl/antlr/test-file b/impl/antlr/test-file
index 6f2cff5..8c865bf 100644
--- a/impl/antlr/test-file
+++ b/impl/antlr/test-file
@@ -1,3 +1,2 @@
-x = max(0, min(x, y))
-y = max(0, x+5, x)
-z = max(0, z+1, x)
+y = min(0-1, z)
+z = min(0, y+1)