public AddError ( string message, SourceLocation location ) : void | ||
message | string | |
location | SourceLocation | |
Résultat | void |
// expression : term [ OR term ]... private Expression Expression() { var exp = Term(); if (exp != null) { while (!_tokenzier.IsEndOfFile) { using (var lookahead = _tokenzier.BeginLookahead()) { var op = _tokenzier.NextToken(); if (op != null && op.Kind == TokenKind.OR) { var sourceLocation = _tokenzier.CurrentLocation; var right = Term(); if (right != null) { lookahead.Accept(); exp = new LogicalBindaryExpression(exp, right, LogicalOperator.OR); } else { _context.AddError("Missing right operand for operator " + op.Kind + ".", sourceLocation); break; } } else { break; } } } } return(exp); }
private Token Number() { SkipWhitespaces(); if (_source.IsEndOfFile) { return(null); } Token token = null; var state = NumberParseState.InPrimaryPart; using (var lookahead = _source.BeginLookahead()) { _buffer.Clear(); var startPosition = _source.Position; while (!_source.IsEndOfFile) { var ch = _source.Peek(); if (char.IsDigit(ch)) { if (state == NumberParseState.BeginFractionalPart) { state = NumberParseState.InFractionalPart; } _buffer.Append(ch); _source.MoveNext(); if (_source.IsEndOfFile && (state == NumberParseState.InPrimaryPart || state == NumberParseState.InFractionalPart)) { lookahead.Accept(); token = new Token(_buffer.ToString(), TokenKind.Number, new SourceLocation(startPosition)); break; } } else if (ch == '.') { state = NumberParseState.BeginFractionalPart; _buffer.Append(ch); _source.MoveNext(); } else { if (state == NumberParseState.BeginFractionalPart) { _context.AddError("Missing fractional part.", new SourceLocation(_source.Position)); break; } else { lookahead.Accept(); token = new Token(_buffer.ToString(), TokenKind.Number, new SourceLocation(startPosition)); break; } } } } return(token); }