12.2 Variable Statement
518089
private VariableStatementTree parseVariableStatement() {
    SourcePosition start = getTreeStartLocation();
    VariableDeclarationListTree declarations = parseVariableDeclarationList();
    eatPossibleImplicitSemiColon();
    return new VariableStatementTree(getTreeLocation(start), declarations);
  }
864140
def p_var_decl(p):
    
    for vardata in p[2]:
        SYMBOL_TABLE.declare_variable(vardata[0], vardata[1], p[3])

    p[0] = None
1156570
private function _processVariable($text) {
		// Check the variable naming convention
		if (!in_array($text, $this->_systemVariables)) {
			$this->_checkVariableNaming($text);
		}

		// Check the variable name's length
		$this->_checkVariableNameLength($text);

		// Check if the variable is not a deprecated system variable
		$this->_checkDeprecation($text);

		// Check if the variable is not replaced
		$this->_checkReplacements($text);

		// Check if the variable is a function parameter
		if (!empty($this->_functionParameters[$text]) && $this->_inFunction) {

			$this->_functionParameters[$text] = "used";
		} else if (!$this->_inFunctionStatement) {

			// Global variable
			$pos = $this->tokenizer->getCurrentPosition();
			$nextTokenInfo = $this->tokenizer->peekNextValidToken($pos + 1);

			// if the next token is an equal, we suppose that this is an affectation
			$nextTokenText = $nextTokenInfo->text;
			$affectionTokens = array(
				'=',
				'+=',
				'*=',
				'/=',
				'-=',
				'%=',
				'&=',
				'|=',
				'^=',
				'<<=',
				'>>=',
				'.='
			);
			$isAffectation = in_array($nextTokenText, $affectionTokens);

			// Check if the variable has already been met
			if (empty($this->_variables[$text]) && !in_array($text, $this->_systemVariables)) {
				// The variable is met for the first time
				$variable = new VariableInfo();
				$variable->name = $text;
				$variable->line = $this->lineNumber; // We store the first declaration of the variable
				$this->_variables[$text] = $variable;
			} else if ($isAffectation) {
				// The variable is reaffected another value, this doesn't count as a valid use.
			} else {

				// Manage the case of $this->attribute
				if ($text === '$this') {

					$nextTokenInfo2 = $this->tokenizer->peekNextValidToken($nextTokenInfo->position);

					if ($this->tokenizer->checkToken($nextTokenInfo2, T_OBJECT_OPERATOR)) {

						// Detect $this inside a static function.
						if ($this->_functionStatic) {
							if ($this->_isActive('thisInStatic')) {
								$this->_writeError('thisInStatic', $this->_getMessage('THIS_IN_STATIC_FUNCTION'));
							}
						}

						$nextTokenInfo3 = $this->tokenizer->peekNextValidToken($nextTokenInfo2->position + 1);

						// This does not look like a function call, it should be a class attribute.
						// We eliminate the $this-> part
						$text = '$' . $nextTokenInfo3->text;
					}
				}

				// The variable is met again, we suppose we have used it for something
				if (!empty($this->_variables[$text])) {
					$variable = $this->_variables[$text];
					$variable->isUsed = true;
					$this->_variables[$text] = $variable;
				}
			}
		}
	}
321368
@Override
	public String onVariable(String variable) {
		switch(variable) {
		case "USERHOME":
			return System.getProperty("user.home");
		case "WINDIR":
			return System.getenv("windir");
		case "SYSTEMROOT":
			return System.getenv("SystemRoot");
		case "COMMONPROGRAMFILES":
			return System.getenv("CommonProgramFiles");
		case "PROGRAMFILES":
			return System.getenv("ProgramFiles");
		case "TEMP":
			return System.getenv("TEMP");
		case "SYSTEMDRIVE":
			return System.getenv("SystemDrive");
		case "USERPROFILE":
			return System.getenv("USERPROFILE");
		case "APPDATA":
			return System.getenv("APPDATA");
		}
		return null;
	}
679080
function variableText( $var, $namespace = "", $attrs = array() )
    {
        $txt = "$";
        if ( $namespace != "" )
            $txt .= "$namespace:";
        $txt .= $var;
        if ( !empty( $attrs ) )
            $txt .= "." . implode( ".", $attrs );
        return $txt;
    }
117424
def _has_var_attr(cls, dataset, vname, attr, concept_name, priority=BaseCheck.HIGH):
        
        val = True
        msgs = []
        if vname not in dataset.variables:
            val = False
            msgs.append("Variable '{}' not present while checking for attr '{}' for IOOS concept: '{}'".format(vname, attr, concept_name))
        else:
            v = dataset.variables[vname]
            if attr not in v.ncattrs():
                val = False
                msgs.append("Attr '{}' not present on var '{}' while checking for IOOS concept: '{}'".format(attr, vname, concept_name))

        return Result(priority, val, concept_name, msgs)
449781
def _eval_variables(self):
        
        for k, v in listitems(self._variables):
            self._variables[k] = v() if hasattr(v, '__call__') else v
598802
private boolean vForVariable(String loopVariablesDefinition, TemplateParserContext context) {
    Matcher matcher = VFOR_VARIABLE.matcher(loopVariablesDefinition);
    if (matcher.matches()) {
      initLoopVariable(matcher.group(1), matcher.group(2), context);
      indexVariableInfo = null;
      return true;
    }

    return false;
  }
852709
public final void localVariableDeclaration() throws RecognitionException {
		VarDecl_stack.push(new VarDecl_scope());

		int localVariableDeclaration_StartIndex = input.index();

		ParserRuleReturnScope variableModifier1 =null;
		ParserRuleReturnScope type2 =null;


		            VarDecl_stack.peek().descr = new JavaLocalDeclarationDescr();
		        
		try {
			if ( state.backtracking>0 && alreadyParsedRule(input, 82) ) { return; }

			// src/main/resources/org/drools/compiler/semantics/java/parser/Java.g:710:5: ( ( variableModifier )* type variableDeclarators ';' )
			// src/main/resources/org/drools/compiler/semantics/java/parser/Java.g:711:5: ( variableModifier )* type variableDeclarators ';'
			{
			// src/main/resources/org/drools/compiler/semantics/java/parser/Java.g:711:5: ( variableModifier )*
			loop106:
			while (true) {
				int alt106=2;
				int LA106_0 = input.LA(1);
				if ( (LA106_0==58||LA106_0==83) ) {
					alt106=1;
				}

				switch (alt106) {
				case 1 :
					// src/main/resources/org/drools/compiler/semantics/java/parser/Java.g:711:7: variableModifier
					{
					pushFollow(FOLLOW_variableModifier_in_localVariableDeclaration2865);
					variableModifier1=variableModifier();
					state._fsp--;
					if (state.failed) return;
					if ( state.backtracking==0 ) {
					            VarDecl_stack.peek().descr.updateStart( ((CommonToken)(variableModifier1!=null?(variableModifier1.start):null)).getStartIndex() - 1 );
					            VarDecl_stack.peek().descr.addModifier( (variableModifier1!=null?input.toString(variableModifier1.start,variableModifier1.stop):null) );
					        }
					}
					break;

				default :
					break loop106;
				}
			}

			pushFollow(FOLLOW_type_in_localVariableDeclaration2888);
			type2=type();
			state._fsp--;
			if (state.failed) return;
			if ( state.backtracking==0 ) {
			            VarDecl_stack.peek().descr.updateStart( ((CommonToken)(type2!=null?(type2.start):null)).getStartIndex() - 1 );
			            VarDecl_stack.peek().descr.setType( (type2!=null?input.toString(type2.start,type2.stop):null) );
			            VarDecl_stack.peek().descr.setEnd( ((CommonToken)(type2!=null?(type2.stop):null)).getStopIndex() );
			        }
			pushFollow(FOLLOW_variableDeclarators_in_localVariableDeclaration2904);
			variableDeclarators();
			state._fsp--;
			if (state.failed) return;
			match(input,52,FOLLOW_52_in_localVariableDeclaration2906); if (state.failed) return;
			}

			if ( state.backtracking==0 ) {
			            addLocalDeclaration( VarDecl_stack.peek().descr );
			        }
		}
		catch (RecognitionException re) {
			reportError(re);
			recover(input,re);
		}
		finally {
			// do for sure before leaving
			if ( state.backtracking>0 ) { memoize(input, 82, localVariableDeclaration_StartIndex); }

			VarDecl_stack.pop();

		}
	}
257234
protected void computeVariablesFromObject(MtasParserObject object,
      Map<String, List<MtasParserObject>> currentList,
      Map<String, Map<String, String>> variables) {
    MtasParserType<MtasParserVariable> parserType = object.getType();
    String id = object.getId();
    if (id != null) {
      for (MtasParserVariable variable : parserType.getItems()) {
        if (!variables.containsKey(variable.variable)) {
          variables.put(variable.variable, new HashMap<String, String>());
        }
        StringBuilder builder = new StringBuilder();
        for (MtasParserVariableValue variableValue : variable.values) {
          if (variableValue.type.equals("attribute")) {
            String subValue = object.getAttribute(variableValue.name);
            if (subValue != null) {
              builder.append(subValue);
            }
          }
        }
        variables.get(variable.variable).put(id, builder.toString());
      }
    }
  }
212097
def let_variable(self, frame_id, var_name, expression_value):
        
        breakpoints_backup = IKBreakpoint.backup_breakpoints_state()
        IKBreakpoint.disable_all_breakpoints()

        let_expression = "%s=%s" % (var_name, expression_value,)

        eval_frame = ctypes.cast(frame_id, ctypes.py_object).value
        global_vars = eval_frame.f_globals
        local_vars = eval_frame.f_locals
        try:
            exec(let_expression, global_vars, local_vars)
            error_message=""
        except Exception as e:
            t, result = sys.exc_info()[:2]
            if isinstance(t, str):
                result_type = t
            else: 
                result_type = str(t.__name__)
            error_message = "%s: %s" % (result_type, result,)

        IKBreakpoint.restore_breakpoints_state(breakpoints_backup)

        _logger.e_debug("let_variable(%s) => %s", 
                        let_expression, 
                        error_message or 'succeed')
        return error_message
168542
@Override
	protected void putVariables(Map<String, String> variables) {
		variables.put(ScopeFormat.SCOPE_TASK_VERTEX_ID, vertexId.toString());
		variables.put(ScopeFormat.SCOPE_TASK_NAME, taskName);
		variables.put(ScopeFormat.SCOPE_TASK_ATTEMPT_ID, executionId.toString());
		variables.put(ScopeFormat.SCOPE_TASK_ATTEMPT_NUM, String.valueOf(attemptNumber));
		variables.put(ScopeFormat.SCOPE_TASK_SUBTASK_INDEX, String.valueOf(subtaskIndex));
	}
1318698
def VAR_DECL(self, cursor):
        """"""
        # get the name
        name = self.get_unique_name(cursor)
        log.debug('VAR_DECL: name: %s', name)
        # Check for a previous declaration in the register
        if self.is_registered(name):
            return self.get_registered(name)
        # get the typedesc object
        _type = self._VAR_DECL_type(cursor)
        # transform the ctypes values into ctypeslib
        init_value = self._VAR_DECL_value(cursor, _type)
        # finished
        log.debug('VAR_DECL: _type:%s', _type.name)
        log.debug('VAR_DECL: _init:%s', init_value)
        log.debug('VAR_DECL: location:%s', getattr(cursor, 'location'))
        obj = self.register(name, typedesc.Variable(name, _type, init_value))
        self.set_location(obj, cursor)
        self.set_comment(obj, cursor)
        return True
1297804
def p_variable(p):
    ''''''
    if len(p) == 6:
        name, dims = p[3]
        params = p[4]
        if params is not None:
            p[0] = ast.MethodCall(p[1], name, params, lineno=p.lineno(2))
        else:
            p[0] = ast.ObjectProperty(p[1], name, lineno=p.lineno(2))
        for class_, dim, lineno in dims:
            p[0] = class_(p[0], dim, lineno=lineno)
        for (name, dims), params in p[5]:
            if params is not None:
                p[0] = ast.MethodCall(p[0], name, params, lineno=p.lineno(2))
            else:
                p[0] = ast.ObjectProperty(p[0], name, lineno=p.lineno(2))
            for class_, dim, lineno in dims:
                p[0] = class_(p[0], dim, lineno=lineno)
    else:
        p[0] = p[1]
1335368
def add_output_variable(self, var):
        """"""
        assert(isinstance(var, Variable))
        self.output_variable_list.append(var)
420112
function checkVariable(variable) {
            if (variable.writeable === false && exceptions.indexOf(variable.name) === -1) {
                variable.references.forEach(checkReference);
            }
        }
428124
private Environment checkVariableDeclarations(Tuple<Decl.Variable> decls, Environment environment) {
		for (int i = 0; i != decls.size(); ++i) {
			environment = checkVariableDeclaration(decls.get(i), environment);
		}
		return environment;
	}