Defines a C-style line comment token (`//...`) and categorizes it as whitespace so it is ignored by the parser.
ID: 1006
using uCalcSoftware;
var uc = new uCalc();
var t = uc.NewTransformer();
// By default, a comment would cause a syntax error.
Console.Write("Before: ");
Console.WriteLine(uc.EvalStr("10 + 5 // Add 5"));
// Add a new token definition for C-style comments.
// The regex `//.*` matches from '//' to the end of the line.
// We classify it as Whitespace so the parser skips it.
uc.ExpressionTokens.Add("//.*", TokenType.Whitespace);
Console.Write("After: ");
Console.WriteLine(uc.EvalStr("10 + 5 // Add 5"));
Before: Undefined identifier
After: 15 using uCalcSoftware; var uc = new uCalc(); var t = uc.NewTransformer(); // By default, a comment would cause a syntax error. Console.Write("Before: "); Console.WriteLine(uc.EvalStr("10 + 5 // Add 5")); // Add a new token definition for C-style comments. // The regex `//.*` matches from '//' to the end of the line. // We classify it as Whitespace so the parser skips it. uc.ExpressionTokens.Add("//.*", TokenType.Whitespace); Console.Write("After: "); Console.WriteLine(uc.EvalStr("10 + 5 // Add 5"));
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
auto t = uc.NewTransformer();
// By default, a comment would cause a syntax error.
cout << "Before: ";
cout << uc.EvalStr("10 + 5 // Add 5") << endl;
// Add a new token definition for C-style comments.
// The regex `//.*` matches from '//' to the end of the line.
// We classify it as Whitespace so the parser skips it.
uc.ExpressionTokens().Add("//.*", TokenType::Whitespace);
cout << "After: ";
cout << uc.EvalStr("10 + 5 // Add 5") << endl;
}
Before: Undefined identifier
After: 15 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; auto t = uc.NewTransformer(); // By default, a comment would cause a syntax error. cout << "Before: "; cout << uc.EvalStr("10 + 5 // Add 5") << endl; // Add a new token definition for C-style comments. // The regex `//.*` matches from '//' to the end of the line. // We classify it as Whitespace so the parser skips it. uc.ExpressionTokens().Add("//.*", TokenType::Whitespace); cout << "After: "; cout << uc.EvalStr("10 + 5 // Add 5") << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim t = uc.NewTransformer()
'// By default, a comment would cause a syntax error.
Console.Write("Before: ")
Console.WriteLine(uc.EvalStr("10 + 5 // Add 5"))
'// Add a new token definition for C-style comments.
'// The regex `//.*` matches from '//' to the end of the line.
'// We classify it as Whitespace so the parser skips it.
uc.ExpressionTokens.Add("//.*", TokenType.Whitespace)
Console.Write("After: ")
Console.WriteLine(uc.EvalStr("10 + 5 // Add 5"))
End Sub
End Module
Before: Undefined identifier
After: 15 Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim t = uc.NewTransformer() '// By default, a comment would cause a syntax error. Console.Write("Before: ") Console.WriteLine(uc.EvalStr("10 + 5 // Add 5")) '// Add a new token definition for C-style comments. '// The regex `//.*` matches from '//' to the end of the line. '// We classify it as Whitespace so the parser skips it. uc.ExpressionTokens.Add("//.*", TokenType.Whitespace) Console.Write("After: ") Console.WriteLine(uc.EvalStr("10 + 5 // Add 5")) End Sub End Module