Permalink
Browse files

Implemented add assign, and subtract assign operators.

  • Loading branch information...
1 parent 5fae5f8 commit 07fb2b1b82e957cbe9b450315db85bcfc49fd0be @GilesBathgate committed Apr 21, 2012
Showing with 65 additions and 3 deletions.
  1. +2 −0 gen-bnf.sed
  2. +3 −1 rapcad.bnf
  3. +2 −0 src/abstracttokenbuilder.h
  4. +2 −0 src/expression.h
  5. +2 −0 src/lexer.l
  6. +5 −1 src/parser.y
  7. +12 −0 src/syntaxhighlighter.cpp
  8. +2 −0 src/syntaxhighlighter.h
  9. +10 −0 src/tokenbuilder.cpp
  10. +2 −0 src/tokenbuilder.h
  11. +3 −1 src/treeevaluator.cpp
  12. +14 −0 src/value.cpp
  13. +6 −0 src/value.h
View
@@ -9,6 +9,8 @@ s@//@@;
s/DOCSTART /"\/\*\*" /;
s/ INC/ "++"/;
s/ DEC/ "--"/;
+s/ ADDA/ "+="/;
+s/ SUBA/ "-="/;
s/DOCEND/"\*\/"/;
s/DOCPARAM /"@" /;
s/ AP / "~=" /;
View
@@ -81,6 +81,8 @@
| <variable> "~=" <expression>
| <variable> "++"
| <variable> "--"
+ | <variable> "+=" <expression>
+ | <variable> "-=" <expression>
| "const" <identifier> '=' <expression>
| "param" <identifier> '=' <expression>
@@ -105,7 +107,7 @@
| <number>
| '[' <expression> ':' <expression> ']'
| '[' <expression> ':' <expression> ':' <expression> ']'
- | '[' <vector_expression> ']'
+ | '[' <vector_expression> <optional_commas> ']'
| <expression> '^' <expression>
| <expression> '*' <expression>
| <expression> '~' <expression>
@@ -62,6 +62,8 @@ class AbstractTokenBuilder
virtual unsigned int buildComponentwiseDivide()=0;
virtual unsigned int buildIncrement()=0;
virtual unsigned int buildDecrement()=0;
+ virtual unsigned int buildAddAssign()=0;
+ virtual unsigned int buildSubtractAssign()=0;
virtual unsigned int buildOuterProduct()=0;
virtual unsigned int buildNamespace()=0;
virtual unsigned int buildAssign()=0;
View
@@ -36,6 +36,8 @@ class Expression : public VisitableTree
ComponentwiseDivide,
Increment,
Decrement,
+ AddAssign,
+ SubAssign,
OuterProduct,
Modulus,
Dot,
View
@@ -80,7 +80,9 @@ NL \n|\r\n
"&&" { return tokenizer->buildAnd(); }
"||" { return tokenizer->buildOr(); }
"++" { return tokenizer->buildIncrement(); }
+"+=" { return tokenizer->buildAddAssign(); }
"--" { return tokenizer->buildDecrement(); }
+"-=" { return tokenizer->buildSubtractAssign(); }
"**" { return tokenizer->buildOuterProduct(); }
".*" { return tokenizer->buildComponentwiseMultiply(); }
"./" { return tokenizer->buildComponentwiseDivide(); }
View
@@ -82,7 +82,7 @@ static Reporter* reporter;
%left EQ NE
%left '!' '+' '-' '~'
%left '*' '/' '%'
-%left INC DEC
+%left INC DEC ADDA SUBA
%left CM CD CP
%right '^'
%left '[' ']'
@@ -250,6 +250,10 @@ assign_statement
{ $$ = builder->buildStatement($1,Expression::Increment); }
| variable DEC
{ $$ = builder->buildStatement($1,Expression::Decrement); }
+ | variable ADDA expression
+ { $$ = builder->buildStatement($1,Expression::AddAssign,$3); }
+ | variable SUBA expression
+ { $$ = builder->buildStatement($1,Expression::SubAssign,$3); }
| CONST IDENTIFIER '=' expression
{ $$ = builder->buildStatement($2,Variable::Const,$4); }
| PARAM IDENTIFIER '=' expression
View
@@ -282,6 +282,18 @@ unsigned int SyntaxHighlighter::buildDecrement()
return YY_CONTINUE;
}
+unsigned int SyntaxHighlighter::buildAddAssign()
+{
+ setFormat(startIndex,lexerleng,operatorFormat);
+ return YY_CONTINUE;
+}
+
+unsigned int SyntaxHighlighter::buildSubtractAssign()
+{
+ setFormat(startIndex,lexerleng,operatorFormat);
+ return YY_CONTINUE;
+}
+
unsigned int SyntaxHighlighter::buildOuterProduct()
{
setFormat(startIndex,lexerleng,operatorFormat);
View
@@ -72,6 +72,8 @@ class SyntaxHighlighter : public QSyntaxHighlighter, private AbstractTokenBuilde
unsigned int buildComponentwiseDivide();
unsigned int buildIncrement();
unsigned int buildDecrement();
+ unsigned int buildAddAssign();
+ unsigned int buildSubtractAssign();
unsigned int buildOuterProduct();
unsigned int buildNamespace();
unsigned int buildAssign();
View
@@ -231,6 +231,16 @@ unsigned int TokenBuilder::buildDecrement()
return DEC;
}
+unsigned int TokenBuilder::buildAddAssign()
+{
+ return ADDA;
+}
+
+unsigned int TokenBuilder::buildSubtractAssign()
+{
+ return SUBA;
+}
+
unsigned int TokenBuilder::buildOuterProduct()
{
return CP;
View
@@ -65,6 +65,8 @@ class TokenBuilder : public AbstractTokenBuilder
unsigned int buildComponentwiseDivide();
unsigned int buildIncrement();
unsigned int buildDecrement();
+ unsigned int buildAddAssign();
+ unsigned int buildSubtractAssign();
unsigned int buildOuterProduct();
unsigned int buildNamespace();
unsigned int buildAssign();
View
@@ -270,7 +270,9 @@ void TreeEvaluator::visit(AssignStatement* stmt)
}
switch(op) {
- case Expression::Append: {
+ case Expression::Append:
+ case Expression::AddAssign:
+ case Expression::SubAssign: {
result=Value::operation(lvalue,op,result);
break;
}
View
@@ -121,6 +121,11 @@ Value* Value::operator+(Value& v)
return operation(v,Expression::Add);
}
+Value* Value::operator+=(Value& v)
+{
+ return operation(v,Expression::AddAssign);
+}
+
Value* Value::operator++(int)
{
return operation(Expression::Increment);
@@ -136,6 +141,11 @@ Value* Value::operator-(Value& v)
return operation(v,Expression::Subtract);
}
+Value* Value::operator-=(Value& v)
+{
+ return operation(v,Expression::SubAssign);
+}
+
Value* Value::operator--(int)
{
return operation(Expression::Decrement);
@@ -244,6 +254,10 @@ Value* Value::operation(Value* p_left, Expression::Operator_e e, Value* p_right)
return left+right;
case Expression::Subtract:
return left-right;
+ case Expression::AddAssign:
+ return left+=right;
+ case Expression::SubAssign:
+ return left-=right;
case Expression::LessThan:
return left<right;
case Expression::LessOrEqual:
View
@@ -47,9 +47,11 @@ class Value
Value* operator%(Value&);
Value* operator+();
Value* operator+(Value&);
+ Value* operator+=(Value&);
Value* operator++(int);
Value* operator-();
Value* operator-(Value&);
+ Value* operator-=(Value&);
Value* operator--(int);
Value* operator<(Value&);
Value* operator<=(Value&);
@@ -111,6 +113,10 @@ A Value::basicOperation(B left, Expression::Operator_e e, B right)
return left+right;
case Expression::Subtract:
return left-right;
+ case Expression::AddAssign:
+ return left+=right;
+ case Expression::SubAssign:
+ return left-=right;
case Expression::LessThan:
return left<right;
case Expression::LessOrEqual:

0 comments on commit 07fb2b1

Please sign in to comment.