/// <inheritdoc/> public override ParseError ParseNextChar(char c) { if (c == '}' && _depth == 0) { ParserStatus status = _childParser.Finalize(); if (status.Failed) { return(new ParseError(status)); } _node.AddChild(_childParser.Tree.Root); Output = _node; return(new ParseError()); } else { if (c == '{') { _depth++; } else if (c == '}') { _depth--; } ParserStatus status = _childParser.ParseNextChar(c); return(new ParseError(status)); } }
private ParseError FinalizeChild() { ParserStatus status = _childParser.Finalize(); if (status.Failed) { return new ParseError(status); } _node.AddChild(_childParser.Tree.Root); return new ParseError(); }
/// <inheritdoc/> public override ParseError ParseNextChar(char c) { if ((c == ',' || c == '>') && _depth == 0) { ParserStatus error = _childParser.Finalize(); if (error.Failed) { return(new ParseError(error)); } ExpTree tree = _childParser.Tree; _childParser = new DefaultParser(); if (tree == null) { return(new ParseError(ErrorType.UNKNOWN)); } _children.Add(tree.Root); if (c == '>') { Output = new TensorNode(new int[] { _children.Count }, _children); } return(new ParseError()); } else { if (c == '<') { _depth++; } else if (c == '>') { _depth--; } ParserStatus result = _childParser.ParseNextChar(c); return(new ParseError(result)); } }
/// <inheritdoc/> public override ParseError ParseNextChar(char c) { switch (_state) { case State.ARGUMENT_X: return(ParseUintArg(c)); case State.OPEN_Y: case State.ARGUMENT_Y: return(ParseUintArg(c)); case State.OPEN_EXPRESSION: if (c == '{') { _state = State.EXPRESSION; _matrix = new TensorNode(_sizes); return(new ParseError()); } else { return(new ParseError(ErrorType.CANNOT_PROCEED)); } case State.EXPRESSION: { if ((c == '}' || c == ',') && _depth == 0) { ParserStatus status = _childParser.Finalize(); if (status.Failed) { return(new ParseError(status)); } ExpTree tree = _childParser.Tree; _childParser = new DefaultParser(); if (tree == null) { return(new ParseError(ErrorType.UNKNOWN)); } _matrix.AddChild(tree.Root); if (c == '}') { _state = State.DONE; Output = _matrix; } return(new ParseError()); } else { if (c == '{') { _depth++; } else if (c == '}') { _depth--; } ParserStatus result = _childParser.ParseNextChar(c); return(new ParseError(result)); } } default: return(new ParseError(ErrorType.UNKNOWN)); } }
/// <inheritdoc/> public override ParseError ParseNextChar(char c) { switch (_state) { case State.VAR: { if (char.IsLetter(c)) { _node.Variable = new VarValueNode(c); _state = State.CLOSING_VAR; return(new ParseError()); } return(new ParseError(ErrorType.DERIVATIVE_MUST_BE_VARIABLE)); } case State.CLOSING_VAR: { if (c == ']') { _state = State.OPEN_EXPRESSION; return(new ParseError()); } if (c == ',') { _state = State.LOWER; _node.IsDeterminate = true; return(new ParseError()); } return(new ParseError(ErrorType.MUST_BE, ']')); // TODO: Multiple MUST_BE characters. } case State.LOWER: { if (c == ',' && _depth == 0) { ParserStatus status = _childParser.Finalize(); if (status.Failed) { return(new ParseError(status)); } ExpTree tree = _childParser.Tree; if (tree == null) { return(new ParseError(ErrorType.UNKNOWN)); } _node.LowerBound = tree.Root; _state = State.UPPER; _childParser = new DefaultParser(); return(new ParseError()); } else { if (c == '{') { _depth++; } else if (c == '}') { _depth--; } ParserStatus result = _childParser.ParseNextChar(c); return(new ParseError(result)); } } case State.UPPER: { if (c == ']' && _depth == 0) { ParserStatus status = _childParser.Finalize(); if (status.Failed) { return(new ParseError(status)); } ExpTree tree = _childParser.Tree; if (tree == null) { return(new ParseError(ErrorType.UNKNOWN)); } _node.UpperBound = tree.Root; _state = State.OPEN_EXPRESSION; _childParser = new DefaultParser(); return(new ParseError()); } else { if (c == '{') { _depth++; } else if (c == '}') { _depth--; } ParserStatus result = _childParser.ParseNextChar(c); return(new ParseError(result)); } } case State.OPEN_EXPRESSION: { if (c != '{') { return(new ParseError(ErrorType.MUST_BE, '{')); } _state = State.EXPRESSION; return(new ParseError()); } case State.EXPRESSION: { if (c == '}' && _depth == 0) { ParserStatus status = _childParser.Finalize(); if (status.Failed) { return(new ParseError(status)); } ExpTree tree = _childParser.Tree; if (tree == null) { return(new ParseError(ErrorType.UNKNOWN)); } _node.AddChild(tree.Root); _state = State.DONE; Output = _node; return(new ParseError()); } else { if (c == '{') { _depth++; } else if (c == '}') { _depth--; } ParserStatus result = _childParser.ParseNextChar(c); return(new ParseError(result)); } } default: return(new ParseError(ErrorType.UNKNOWN)); } }
/// <inheritdoc/> public override ParseError ParseNextChar(char c) { switch (_state) { case State.VAR: if (!char.IsLetter(c)) { return(new ParseError(ErrorType.DERIVATIVE_MUST_BE_VARIABLE)); } _node.Variable = new VarValueNode(c); _state = State.CLOSING_VAR; return(new ParseError()); case State.CLOSING_VAR: if (c != ']') { return(new ParseError(ErrorType.MUST_BE, ']')); } _state = State.OPEN_EXPRESSION; return(new ParseError()); case State.OPEN_EXPRESSION: if (c != '{') { return(new ParseError(ErrorType.MUST_BE, '{')); } _state = State.EXPRESSION; return(new ParseError()); case State.EXPRESSION: { if (c == '}' && _depth == 0) { ParserStatus status = _childParser.Finalize(); if (status.Failed) { return(new ParseError(status)); } ExpTree tree = _childParser.Tree; if (tree == null) { return(new ParseError(ErrorType.UNKNOWN)); } _node.AddChild(tree.Root); _state = State.DONE; Output = _node; return(new ParseError()); } else { if (c == '{') { _depth++; } else if (c == '}') { _depth--; } ParserStatus result = _childParser.ParseNextChar(c); return(new ParseError(result)); } } default: return(new ParseError(ErrorType.UNKNOWN)); } }