Skip to content

Commit

Permalink
Fixed adjacent multiplication issues
Browse files Browse the repository at this point in the history
  • Loading branch information
TheUnlocked committed Apr 30, 2018
1 parent afc2dee commit e98e218
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 38 deletions.
6 changes: 3 additions & 3 deletions FAILang/FAILang.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
<Authors>Unlocked</Authors>
<Company />
<Product />
<Version>0.4.2</Version>
<AssemblyVersion>0.4.2.0</AssemblyVersion>
<FileVersion>0.4.2.0</FileVersion>
<Version>0.4.3</Version>
<AssemblyVersion>0.4.3.0</AssemblyVersion>
<FileVersion>0.4.3.0</FileVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand Down
60 changes: 32 additions & 28 deletions FAILang/FAILangVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,46 +204,32 @@ public override IType VisitPostfix([NotNull] FAILangParser.PostfixContext contex
IType rightIndex = null;
if (indexer.r_index != null)
rightIndex = VisitExpression(indexer.r_index);
return new IndexerExpression(VisitType(context.type()), leftIndex, rightIndex, indexer.elipsis != null);
}
else if (context.atom() != null)
{
return new BinaryOperatorExpression(BinaryOperator.MULTIPLY, VisitType(context.type()), VisitAtom(context.atom()));
return new IndexerExpression(VisitMultiplier(context.multiplier()), leftIndex, rightIndex, indexer.elipsis != null);
}
else
return VisitType(context.type());
return VisitMultiplier(context.multiplier());
}

public override IType VisitType([NotNull] FAILangParser.TypeContext context)
public override IType VisitMultiplier([NotNull] FAILangParser.MultiplierContext context)
{
if (context.t_number != null)
{
var number = context.t_number;
Number n;
if (number.Text.Equals("i"))
return new Number(Complex.ImaginaryOne);
n = new Number(Complex.ImaginaryOne);
else if (number.Text.EndsWith('i'))
return new Number(Complex.ImaginaryOne * Convert.ToDouble(number.Text.TrimEnd('i')));
n = new Number(Complex.ImaginaryOne * Convert.ToDouble(number.Text.TrimEnd('i')));
else
return new Number(Convert.ToDouble(number.Text));
}
else if (context.t_string != null)
{
var str = context.t_string;
string processed = str.Text.Substring(1, str.Text.Length - 2)
.Replace("\\\\", "\\")
.Replace("\\b", "\b")
.Replace("\\f", "\f")
.Replace("\\n", "\n")
.Replace("\\r", "\r")
.Replace("\\t", "\t")
.Replace("\\v", "\v")
.Replace("\\\"", "\"");
return new MathString(processed);
n = new Number(Convert.ToDouble(number.Text));

if (context.atom() != null)
{
return new BinaryOperatorExpression(BinaryOperator.MULTIPLY, n, VisitAtom(context.atom()));
}
else
return n;
}
else if (context.t_boolean != null)
return context.t_boolean.Text.Equals("true") ? MathBool.TRUE : MathBool.FALSE;
else if (context.t_undefined != null)
return Undefined.instance;
else
return VisitAtom(context.atom());
}
Expand Down Expand Up @@ -276,6 +262,24 @@ public override IType VisitAtom([NotNull] FAILangParser.AtomContext context)
return VisitVector(context.vector());
else if (context.tuple() != null)
return VisitTuple(context.tuple());
else if (context.t_string != null)
{
var str = context.t_string;
string processed = str.Text.Substring(1, str.Text.Length - 2)
.Replace("\\\\", "\\")
.Replace("\\b", "\b")
.Replace("\\f", "\f")
.Replace("\\n", "\n")
.Replace("\\r", "\r")
.Replace("\\t", "\t")
.Replace("\\v", "\v")
.Replace("\\\"", "\"");
return new MathString(processed);
}
else if (context.t_boolean != null)
return context.t_boolean.Text.Equals("true") ? MathBool.TRUE : MathBool.FALSE;
else if (context.t_undefined != null)
return Undefined.instance;

return null;
}
Expand Down
14 changes: 7 additions & 7 deletions FAILang/Grammar/FAILang.g4
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,12 @@ prefix
;

postfix
: type ( indexer | atom )?
: multiplier ( indexer )?
;

type
: atom
| t_number=NUMBER
| t_string=STRING
| t_boolean=BOOLEAN
| t_undefined=UNDEFINED
multiplier
: t_number=NUMBER atom?
| atom
;

atom
Expand All @@ -85,6 +82,9 @@ atom
| piecewise
| tuple
| vector
| t_string=STRING
| t_boolean=BOOLEAN
| t_undefined=UNDEFINED
;

lambda
Expand Down

0 comments on commit e98e218

Please sign in to comment.