Beispiel #1
0
/// primary
///   ::= identifierexpr
///   ::= numberexpr
///   ::= parenexpr
static ExprAST *ParsePrimary() {
  switch (CurTok) {
  default: return Error("unknown token when expecting an expression");
  case tok_identifier: return ParseIdentifierExpr();
  case tok_number:     return ParseNumberExpr();
  case '(':            return ParseParenExpr();
  }
}
Beispiel #2
0
/// primary
///   ::= identifierexpr
///   ::= numberexpr
///   ::= parenexpr
static ExprAST *ParsePrimary() {
  switch (CurTok) {
  default: return Error("unknown token when expecting an expression");
  case tok_identifier: printf("<identifier, %s>\n", IdentifierStr.c_str()); return ParseIdentifierExpr();
  case tok_number:     printf("<number, %f>\n", NumVal); return ParseNumberExpr();
  case '(':            return ParseParenExpr();
  }
}
Beispiel #3
0
/* Handles primary expressions, where
* primary ::= identifierexpr
*         ::= numberexpr
*         ::= parenexpr
* by using look-ahead to see what kind of expression
* we should parse.
*/
static std::unique_ptr<ExprAST> ParsePrimary()
{
    switch(CurTok) {
        default:
            return Error("Expected an expression but got an unknown token.");
        case tok_ident:
            return ParseIdentifierExpr();
        case tok_number:
            return ParseNumberExpr();
        case '(':
            return ParseParenExpr();
    }
}
/* primary
 * ::= identifierexpr
 * ::= numberexpr
 * ::= parenexpr
 * ::= const string
 * */
static shared_ptr<ExprAST> ParsePrimary() {
    switch (CurTok) {
        case T_BRACE_SL:
            return ParseParenExpr();
        case T_IDENTIFIER:
            return ParseIdentifierExpr();
        case T_NUMBER:
            return ParseNumberExpr();
        case T_DQUOTE:
            return ParseConststringExpr();
        case T_SQUOTE:
            return ParseConststringExpr();
        default:
            return Error("unknown token when expected an expression  ");
    }
}
Beispiel #5
0
// primary
//		::= identifierexpr
//		::= floatexpr
//		::= intexpr
//		::= boolexpr
//		::= parenexpr
//		::= externexpr
ExprAST *Parser::ParsePrimary() {
	if (Lex.tok == tok_extern) return ParseExtern();
	if (Lex.tok == tok_identifier) return ParseIdentifierExpr();
	if (Lex.tok == tok_true || Lex.tok == tok_false) return ParseBoolExpr();
	if (Lex.tok == tok_int) return ParseIntExpr();
	if (Lex.tok == tok_float) return ParseFloatExpr();
	if (Lex.tok == tok_if) return ParseIfThenElse();
	if (Lex.tok == tok_while || Lex.tok == tok_until) return ParseWhile();
	if (Lex.tok == tok_break || Lex.tok == tok_continue) {
		BreakContE t = (Lex.tok == tok_break ? bc_break : bc_continue);
		Lex.gettok();
		return new BreakContAST(Lex.tag(), t);
	}
	if (Lex.tokStr == "(") return ParseParenExpr();
	Lex.tag().Throw("Unknown token '" + Lex.tokStr + "' when expecting an expression.");
	return 0;
}
Beispiel #6
0
/// primary
///   ::= identifierexpr
///   ::= numberexpr
///   ::= parenexpr
std::unique_ptr<ExprAST> UDFParser::ParsePrimary() {
  switch (cur_tok_) {
    default:
      return LogError("unknown token when expecting an expression");
    case tok_identifier:
      return ParseIdentifierExpr();
    case tok_number:
      return ParseNumberExpr();
    case '(':
      return ParseParenExpr();
    case tok_return:
      return ParseReturn();
    case tok_if:
      return ParseIfExpr();
    case tok_semicolon:
      return nullptr;
  }
}
Beispiel #7
0
// primary
//   ::= identifierexpr
//   ::= numberexpr
//   ::= parenexpr
//   ::= ifexpr
//   ::= forexpr
//   ::= varexpr
std::unique_ptr<CExprAST> CParser::ParsePrimary()
{
	switch (m_CurrentToken) {
	default:
		return LogError("unknown token when expecting an expression!");
	case tIdentifier:
		return ParseIdentifierExpr();
	case tNumber:
		return ParseNumber();
	case '(':
		return ParseParenExpr();
	case tIf:
		return ParseIfExpr();
	case tFor:
		return ParseForExpr();
	case tVar:
		return ParseVarExpr();
	}
}