VariableDeclaration::VariableDeclaration(lexer::Lexer &lex, symtable::SymbolTable * table) : Statement(table) {
        switch(NextType(lex)) {
            case lexer::VAR:
                consumeLexemeType(lex,lexer::VAR);
                variable = true;
                break;
            case lexer::CONST:
                consumeLexemeType(lex,lexer::CONST);
                variable = false;
                break;
            default:
                throw std::runtime_error(std::string(__FILE__) + ":" + std::to_string(__LINE__) + ", expected var or const");
        }

        kind = variable? symtable::Var:symtable::Const;

        name = new Identifier(lex, table);

        
        if(NextType(lex) == lexer::EQUAL) {
            consumeLexemeType(lex,lexer::EQUAL);
            value = new Expression(lex, table);
        } else {
            type = new Type(lex, table);
        }
        
    }
Exemple #2
0
static TRI_aql_scope_t* CreateScope (TRI_aql_context_t* const context, 
                                     const TRI_aql_scope_e type) {
  TRI_aql_scope_t* scope;

  assert(context);

  scope = (TRI_aql_scope_t*) TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, sizeof(TRI_aql_scope_t), false);

  if (scope == NULL) {
    return NULL;
  }

  scope->_id = NextId(context);
  scope->_type = NextType(context, type);
  scope->_ranges = NULL;
  scope->_selfContained = true;

  TRI_InitAssociativePointer(&scope->_variables, 
                             TRI_UNKNOWN_MEM_ZONE, 
                             &TRI_HashStringKeyAssociativePointer,
                             &TRI_HashVariableAql,
                             &TRI_EqualVariableAql, 
                             0);

  return scope;
}
Exemple #3
0
    // E = F | F ( "+" | "-" | "|" ) E
    // F = T | T ( "*" | "/" | "%" | "&" ) F
    // T = (E) | ID | LIT | F_CALL
    Factor::Factor(lexer::Lexer & lex, symtable::SymbolTable * table) : Ast(table) { //, lhs(nullptr), rhs(nullptr), op(nullptr) {
        rhs = new Term(lex, table);        
        
        bool doIt = true;

        Operator* op;

        while(doIt) {
            switch(NextType(lex)) {
                case lexer::MUL:
                    op = new Operator(Operator::MultiplicationOperator);
                    list.push_back({rhs,op});
                    lex.Next();
                    lex.HasNext();
                    rhs = new Term(lex, table);
                    break;
                case lexer::DIV:
                    op = new Operator(Operator::DivisionOperator);
                    list.push_back({rhs,op});
                    lex.Next();
                    lex.HasNext();
                    rhs = new Term(lex, table);
                    break;
                case lexer::AND:
                    op = new Operator(Operator::AndOperator);
                    list.push_back({rhs,op});
                    lex.Next();
                    lex.HasNext();
                    rhs = new Term(lex, table);
                    break;
                case lexer::MOD:
                    op = new Operator(Operator::ModulusOperator);
                    list.push_back({rhs,op});
                    lex.Next();
                    lex.HasNext();
                    rhs = new Term(lex, table);
                    break;
                default:
                    doIt = false;
                    //op = new Operator(Operator::None);
                    break;
            }
        }

        /*
        // We found an operator, consume it
        if(op->GetType() != Operator::None) {
            lex.Next();
            lex.HasNext();
            rhs = new Factor(lex,table);
        }
        */
    }
Exemple #4
0
static TRI_aql_scope_t* CreateScope (TRI_aql_context_t* const context,
                                     const TRI_aql_scope_e type) {
  TRI_aql_scope_t* scope;
  int res;

  assert(context);

  scope = (TRI_aql_scope_t*) TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, sizeof(TRI_aql_scope_t), false);

  if (scope == NULL) {
    return NULL;
  }

  scope->_type             = NextType(context, type);
  scope->_ranges           = NULL;
  scope->_selfContained    = true;
  scope->_empty            = false;
  scope->_level            = 0; // init with a dummy value

  scope->_limit._offset    = 0;
  scope->_limit._limit     = INT64_MAX;
  scope->_limit._status    = TRI_AQL_LIMIT_UNDEFINED;
  scope->_limit._hasFilter = false;
  scope->_limit._found     = 0;

  if (context->_fullCount) {
    // if option "fullCount" is specified, we must ignore all limit optimisations
    scope->_limit._status = TRI_AQL_LIMIT_IGNORE;
  }


  TRI_InitVectorPointer(&scope->_sorts, TRI_UNKNOWN_MEM_ZONE);

  res = TRI_InitAssociativePointer(&scope->_variables,
                                   TRI_UNKNOWN_MEM_ZONE,
                                   &TRI_HashStringKeyAssociativePointer,
                                   &TRI_HashVariableAql,
                                   &TRI_EqualVariableAql,
                                   0);

  if (res != TRI_ERROR_NO_ERROR) {
    TRI_DestroyVectorPointer(&scope->_sorts);
    TRI_Free(TRI_UNKNOWN_MEM_ZONE, scope);

    return NULL;
  }

  return scope;
}