public Token Expect(TokenClass clazz) { Token ret = null; if (Accept(clazz, ref ret)) { return(ret); } Token offender = ReadToken(); if (offender != null) { errorLog.AddError(ErrorType.ParserError, offender.Location, "Unexpected '{0}' (Expected '{1}')", offender.ToString(), Token.ClassToString(clazz)); } else { errorLog.AddError(ErrorType.ParserError, offender.Location, "Unexpected end of file (Expected {0})", Token.ClassToString(clazz)); throw new Exception(""); } return(new Token(clazz, "", Location)); }
public override void Accept(BinaryExpression pattern) { switch (pattern.Operation) { case BinaryOperation.Or: case BinaryOperation.And: pattern.Left.Visit(this); pattern.Right.Visit(this); break; default: errorLog.AddError(ErrorType.ParserError, pattern.Location, "Binary operator can not be used on patterns!"); break; } }
private Token NextToken() { char ch = (char)PeekChar(); switch (ch) { case '#': return(ReadComment()); case '\'': case '"': return(ReadStringLiteral()); case '_': return(ReadIdentifier()); case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': return(ReadNumber()); case '+': case '-': case '*': case '/': case '.': case '=': case '<': case '>': case '~': case '!': case '&': case '^': case '|': case '%': case '@': case '?': return(ReadOperator()); case '{': ReadChar(); return(new Token(TokenClass.OpenBrace, "{", location)); case '}': ReadChar(); return(new Token(TokenClass.CloseBrace, "}", location)); case '(': ReadChar(); return(new Token(TokenClass.OpenParan, "(", location)); case ')': ReadChar(); return(new Token(TokenClass.CloseParan, ")", location)); case '[': ReadChar(); return(new Token(TokenClass.OpenBracket, "[", location)); case ']': ReadChar(); return(new Token(TokenClass.CloseBracket, "]", location)); case ';': ReadChar(); return(new Token(TokenClass.SemiColon, ";", location)); case ':': ReadChar(); return(new Token(TokenClass.Colon, ":", location)); case ',': ReadChar(); return(new Token(TokenClass.Comma, ",", location)); default: if (char.IsLetter(ch)) { return(ReadIdentifier()); } errorLog.AddError(ErrorType.LexerError, location, "Unexpected '{0}'", (char)ReadChar()); return(null); } }
public override void Accept(IfStatement ifStmt) { errorLog.AddError(ErrorType.ParserError, ifStmt.Location, "Statement not allowed outside function body!"); }
public override void Accept(UseStatement useStmt) { errorLog.AddError(ErrorType.ParserError, useStmt.Location, "use statement not valid inside function body!"); }