-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use SyntaxNumber as Expression ... well, sort of ...
- Loading branch information
Showing
5 changed files
with
170 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 0 additions & 47 deletions
47
TypeCobol/Compiler/CodeElements/Expressions/SyntaxInteger.cs
This file was deleted.
Oops, something went wrong.
130 changes: 130 additions & 0 deletions
130
TypeCobol/Compiler/CodeElements/Expressions/SyntaxNumber.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
using System; | ||
using TypeCobol.Compiler.Scanner; | ||
|
||
namespace TypeCobol.Compiler.CodeElements | ||
{ | ||
|
||
/// <summary> | ||
/// Integer, Decimal or Floating Point value defined by a single Token in the Cobol syntax | ||
/// </summary> | ||
public class SyntaxNumber | ||
{ | ||
public SyntaxNumber(Token token) | ||
{ | ||
Token = token; | ||
} | ||
|
||
/// <summary> | ||
/// Token defining the number value | ||
/// </summary> | ||
public Token Token { get; private set; } | ||
} | ||
|
||
/// <summary> | ||
/// Integer value defined by a single Token in the Cobol syntax | ||
/// </summary> | ||
public class SyntaxInteger : SyntaxNumber | ||
{ | ||
public SyntaxInteger(Token token) | ||
: base(token) | ||
{ } | ||
|
||
/// <summary> | ||
/// Integer value defined by the Token | ||
/// </summary> | ||
public long Value | ||
{ | ||
get | ||
{ | ||
if (Token.TokenType == TokenType.IntegerLiteral) | ||
{ | ||
return ((IntegerLiteralValue)Token.LiteralValue).Number; | ||
} | ||
else | ||
{ | ||
throw new InvalidOperationException("An integer value can not be defined by a token of type : " + Token.TokenType); | ||
} | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Debug string | ||
/// </summary> | ||
public override string ToString() | ||
{ | ||
return Value.ToString(); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Decimal value defined by a single Token in the Cobol syntax | ||
/// </summary> | ||
public class SyntaxDecimal : SyntaxNumber | ||
{ | ||
public SyntaxDecimal(Token token) | ||
: base(token) | ||
{ } | ||
|
||
/// <summary> | ||
/// Integer value defined by the Token | ||
/// </summary> | ||
public double Value | ||
{ | ||
get | ||
{ | ||
if (Token.TokenType == TokenType.DecimalLiteral) | ||
{ | ||
return ((DecimalLiteralValue)Token.LiteralValue).Number; | ||
} | ||
else | ||
{ | ||
throw new InvalidOperationException("A decimal value can not be defined by a token of type : " + Token.TokenType); | ||
} | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Debug string | ||
/// </summary> | ||
public override string ToString() | ||
{ | ||
return Value.ToString(); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Decimal value defined by a single Token in the Cobol syntax | ||
/// </summary> | ||
public class SyntaxFloat : SyntaxNumber | ||
{ | ||
public SyntaxFloat(Token token) | ||
: base(token) | ||
{ } | ||
|
||
/// <summary> | ||
/// Integer value defined by the Token | ||
/// </summary> | ||
public double Value | ||
{ | ||
get | ||
{ | ||
if (Token.TokenType == TokenType.FloatingPointLiteral) | ||
{ | ||
return ((DecimalLiteralValue)Token.LiteralValue).Number; | ||
} | ||
else | ||
{ | ||
throw new InvalidOperationException("A floating point value can not be defined by a token of type : " + Token.TokenType); | ||
} | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Debug string | ||
/// </summary> | ||
public override string ToString() | ||
{ | ||
return Value.ToString(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters