public TestMethodDeclaration(String name, StatementList stmts, ExpressionList exps, SymbolExpression error) : base(name) { this.statements = stmts; this.assertions = exps; this.error = error; }
public static bool TryParseExpression(List <Token> tokens, out IExpression result) { // Number if (NumberExpression.TryParse(tokens, out NumberExpression numExpr)) { result = numExpr; return(true); } // Symbol else if (SymbolExpression.TryParse(tokens, out SymbolExpression symExpr)) { result = symExpr; return(true); } // Function definition else if (FunctionExpression.TryParse(tokens, out FunctionExpression funcExpr)) { result = funcExpr; return(true); } // Function call else if (CallExpression.TryParse(tokens, out CallExpression callExpr)) { result = callExpr; return(true); } result = null; return(false); }
public void Power_Simplify_WhenExponentEqualsOne() { var @base = new SymbolExpression("x"); var expression = Exponentiate(@base, 1); var simplifier = new ExponentOneSimplifier(); var result = simplifier.Simplify(expression, CancellationToken.None); Assert.AreEqual(@base, result); }
public void Power_Simplify_WhenBaseEqualsOne() { var exponent = new SymbolExpression("x"); var expression = Exponentiate(1, exponent); var simplifier = new BaseOneSimplifier(); var result = simplifier.Simplify(expression, CancellationToken.None); Assert.IsInstanceOfType(result, typeof(NumberExpression)); Assert.AreEqual(1, result.GetConstantValue()); }
public async Task <object?> Evaluate(string filePath, SymbolExpression expr, IExpressionVisitor expressionVisitor) { object?prop; IEnumerable <ISymbolExpressionPart> rest = expr.Rest; if ((expr.First, expr.Rest?.FirstOrDefault()) is (Identifier id1, Identifier id2) && _propertyProvider.IsNamespaceKnown(id1.Value)) { prop = await _propertyProvider.GetValue(filePath, id1.Value, id2.Value).ConfigureAwait(false); rest = expr.Rest.Skip(1); }
Value Assign(SymbolExpression left, Value value, IDictionary<String, Value> symbols) { if (symbols.ContainsKey(left.SymbolName)) { symbols[left.SymbolName] = value.Copy(); } else { Context.AssignVariable(left.SymbolName, value.Copy()); } return value; }
public override NFAModel ConvertSymbol(SymbolExpression exp) { NFAState tail = new NFAState(); int cclass = CompactCharSetManager.GetCompactClass(exp.Symbol); NFAEdge entryEdge = new NFAEdge(cclass, tail); NFAModel symbolNfa = new NFAModel(); symbolNfa.AddState(tail); symbolNfa.TailState = tail; symbolNfa.EntryEdge = entryEdge; return(symbolNfa); }
public async Task <object?> Visit(Expression value, string filePath) { return(value switch { LiteralExpression lit => lit.Value, CallExpression cal => await _functionExecutor.Call(cal.Function, filePath, await Visit(cal.Arguments, filePath).ConfigureAwait(false)).ConfigureAwait(false), SymbolExpression sym => await _symbolEvaluator.Evaluate(filePath, sym, this).ConfigureAwait(false), FormattedExpression frm => await Visit(frm.Expression, filePath).ConfigureAwait(false) switch { IFormattable x => x.ToString(frm.Formatter.Format, frm.Formatter.Invariant ? CultureInfo.InvariantCulture : FormatProvider), _ => throw new NotImplementedException() },
public static Boolean IsAssigned(this ContainerExpression container, SymbolExpression symbol) { var expressions = container.Expressions; if (expressions.Length > 0) { var leftExpression = expressions[0]; container = leftExpression as ContainerExpression; if (container != null) { return container.IsAssigned(symbol); } return Object.ReferenceEquals(leftExpression, symbol); } return false; }
public void MethodInvocationsOnClassBody() { String contents = "class MyClass \r\n" + " attr_accessor (:name) \r\n" + "end \r\n"; CompilationUnitNode unit = RookParser.ParseContents(contents); Assert.IsNotNull(unit); Assert.AreEqual(0, unit.Namespaces.Count); Assert.AreEqual(1, unit.ClassesTypes.Count); ClassDefinitionStatement ClassDefinitionStatement = unit.ClassesTypes[0] as ClassDefinitionStatement; Assert.IsNotNull(ClassDefinitionStatement); Assert.AreEqual("MyClass", ClassDefinitionStatement.Name); Assert.AreEqual(0, ClassDefinitionStatement.BaseTypes.Count); Assert.AreEqual(1, ClassDefinitionStatement.Statements.Count); ExpressionStatement stmt = ClassDefinitionStatement.Statements[0] as ExpressionStatement; Assert.IsNotNull(stmt); Assert.IsNotNull(stmt.Expression); MethodInvokeExpression minv = stmt.Expression as MethodInvokeExpression; Assert.IsNotNull(minv); Assert.IsNotNull(minv.Target); Assert.IsNotNull(minv.Arguments); Assert.AreEqual(1, minv.Arguments.Count); Assert.AreEqual("attr_accessor", (minv.Target as IdentifierReferenceExpression).Name); SymbolExpression se = minv.Arguments[0] as SymbolExpression; Assert.IsNotNull(se); Assert.AreEqual(":name", se.Name); }
private Expression ParseAtomExpression() { switch (TokenType()) { case var token when token == FSharpTokenType.PP_CONDITIONAL_SYMBOL: var sym = new SymbolExpression(myLexer.GetTokenText()); myLexer.Advance(); return(sym); case var token when token == FSharpTokenType.PP_LPAR: myLexer.Advance(); var expr = ParseExpression(); if (TokenType() != FSharpTokenType.PP_RPAR) { return(new ErrorExpression()); } myLexer.Advance(); return(expr); default: myLexer.Advance(); return(new ErrorExpression()); } }
public Indexer(SymbolExpression expression) { Symbol = expression; }
public abstract T ConvertSymbol(SymbolExpression exp);
//constant: // Integer // Float // String // Boolean //symbol: // ReplacementSymbol // Symbol //value: // constant // symbol // operation // scope //operation: value Operator value //list-expression: value-source , value-source //scope: StartScope value-source EndScope //value-source: // value // scope // function // operation //function: symbol StartScope list-expression EndScope | symbol StartScope value-source EndScope public static Expression Parse(List <Token> tokens) { if (tokens == null || tokens.None()) { return(new NullExpression()); } var remainder = tokens.ToList(); Expression program = null; while (remainder.Any()) { Production parsed = null; var current = remainder.First(); switch (current.TokenClass) { case TokenClass.StartScope: parsed = new ScopedExpression().Parse(remainder); if (parsed.Expression != null) { break; } parsed = new SeparatedExpression().Parse(remainder); if (parsed.Expression != null) { break; } parsed = new ErrorExpression().Parse(program, remainder); break; case TokenClass.Whitespace: parsed = new WhitespaceExpression().Parse(remainder); break; case TokenClass.Symbol: parsed = new OperationExpression().Parse(remainder); if (parsed.Expression != null) { break; } parsed = new FunctionExpression().Parse(remainder); if (parsed.Expression != null) { break; } parsed = new SymbolExpression().Parse(remainder); if (parsed.Expression != null) { break; } parsed = new ErrorExpression().Parse(program, remainder); break; case TokenClass.ReplacementSymbol: parsed = new OperationExpression().Parse(remainder); if (parsed.Expression != null) { break; } parsed = new ReplacementSymbolExpression().Parse(remainder); break; case TokenClass.Float: case TokenClass.Integer: parsed = new OperationExpression().Parse(remainder); if (parsed.Expression != null) { break; } parsed = NumericExpression.TryParseNumeric(remainder); break; case TokenClass.String: parsed = new OperationExpression().Parse(remainder); if (parsed.Expression != null) { break; } parsed = new StringExpression().Parse(remainder); break; case TokenClass.Boolean: parsed = new OperationExpression().Parse(remainder); if (parsed.Expression != null) { break; } parsed = new BooleanExpression().Parse(remainder); break; case TokenClass.Operator: parsed = NumericExpression.TryParseNumeric(remainder); if (parsed.Expression != null) { break; } parsed = new OperationExpression().Parse(program, remainder); if (parsed.Expression != null) { break; } parsed = new ErrorExpression().Parse(program, remainder); break; case TokenClass.Error: throw new Exception("Unexpected sequence: " + remainder.First().Lexeme); default: throw new ArgumentOutOfRangeException(); } if (parsed.Expression != null && !(parsed.Expression is WhitespaceExpression)) { program = parsed.Expression; } remainder = parsed.RemainingTokens; } if (program == null || remainder.Any()) { throw new ParserException(remainder.Select(c => c.Lexeme).StringConcat()); } return(program); }
Value HandleMultipleOutputs(Value value, SymbolExpression[] vars, IDictionary<String, Value> symbols) { if (value is ArgumentsValue) { var av = (ArgumentsValue)value; var l = Math.Min(vars.Length, av.Length); for (var i = 0; i != l; i++) { Assign(vars[i], av.Values[i], symbols); } return av; } foreach (var sym in vars) { Assign(sym, value, symbols); } return value; }