Commits

PioneerAxon committed 5a45e82

Fix coding style issues Phase: 3

Comments (0)

Files changed (7)

 static gboolean
 l_check_if_function(LexerState* state)
 {
-	gchar* name = pl_get_marked_substring(state->prelexer);
-	if(!state->parent->function_is_defined)
-	{
-		free(name);
-		return FALSE;
-	}
-	if ((*(state->parent->function_is_defined))(state->parent, name))
-	{
-		free(name);
-		return TRUE;
-	}
-	else
-	{
-		free(name);
-		return FALSE;
-	}
+    gchar* name = pl_get_marked_substring(state->prelexer);
+    if(!state->parent->function_is_defined)
+    {
+        free(name);
+        return FALSE;
+    }
+    if ((*(state->parent->function_is_defined))(state->parent, name))
+    {
+        free(name);
+        return TRUE;
+    }
+    else
+    {
+        free(name);
+        return FALSE;
+    }
 }
 
 static gboolean
 l_check_if_number(LexerState* state)
 {
-	MPNumber tmp;
-	int count = 0;
-	gchar* text = pl_get_marked_substring(state->prelexer);
-	if(mp_set_from_string(text, state->parent->options->base, &tmp) == 0)
-	{
-		free(text);
-		return TRUE;
-	}
-	else
-	{
-		/* Try to rollback several characters to see, if that yeilds any number. */
-		while(strlen (text) > 0)
-		{
-			if(mp_set_from_string(text, state->parent->options->base, &tmp) == 0)
-			{
-				free(text);
-				return TRUE;
-			}
-			free(text);
-			count++;
-			pl_roll_back(state->prelexer);
-			text = pl_get_marked_substring(state->prelexer);
-		}
-		/* Undo all rollbacks. */
-		while(count--) 
-			pl_get_next_token (state->prelexer);
-		free(text);
-		return FALSE;
-	}
+    MPNumber tmp;
+    int count = 0;
+    gchar* text = pl_get_marked_substring(state->prelexer);
+    if(mp_set_from_string(text, state->parent->options->base, &tmp) == 0)
+    {
+        free(text);
+        return TRUE;
+    }
+    else
+    {
+        /* Try to rollback several characters to see, if that yeilds any number. */
+        while(strlen (text) > 0)
+        {
+            if(mp_set_from_string(text, state->parent->options->base, &tmp) == 0)
+            {
+                free(text);
+                return TRUE;
+            }
+            free(text);
+            count++;
+            pl_roll_back(state->prelexer);
+            text = pl_get_marked_substring(state->prelexer);
+        }
+        /* Undo all rollbacks. */
+        while(count--) 
+            pl_get_next_token (state->prelexer);
+        free(text);
+        return FALSE;
+    }
 }
 
 /* Insert generated token to the LexerState structure. */
 static LexerToken*
 l_insert_token(LexerState* state, const LexerTokenType type)
 {
-	state->tokens = (LexerToken *) realloc(state->tokens, (state->token_count + 1) * sizeof(LexerToken));
-	assert(state->tokens != NULL);
-	state->tokens[state->token_count].string = pl_get_marked_substring(state->prelexer);
-	state->tokens[state->token_count].start_index = state->prelexer->mark_index;
-	state->tokens[state->token_count].end_index = state->prelexer->next_index;
-	state->tokens[state->token_count].token_type = type;
-	state->token_count++;
-	return &state->tokens[state->token_count - 1];
+    state->tokens = (LexerToken *) realloc(state->tokens, (state->token_count + 1) * sizeof(LexerToken));
+    assert(state->tokens != NULL);
+    state->tokens[state->token_count].string = pl_get_marked_substring(state->prelexer);
+    state->tokens[state->token_count].start_index = state->prelexer->mark_index;
+    state->tokens[state->token_count].end_index = state->prelexer->next_index;
+    state->tokens[state->token_count].token_type = type;
+    state->token_count++;
+    return &state->tokens[state->token_count - 1];
 }
 
 /* Generates next token from pre-lexer stream and call l_insert_token() to insert it at the end. */
 static LexerToken*
 l_insert_next_token(LexerState* lstate)
 {
-	PreLexerState* state = lstate->prelexer;
-	LexerTokenType type;
-	gchar* tmp;
-	pl_set_marker(state);
-	/* Ignore all blank spaces. :) */
-	while((type = pl_get_next_token(state)) == PL_SKIP)
-		/* Set marker. Beginning of new token. */
-		pl_set_marker(state);
-	if(type == T_AND
-	 ||type == T_OR
-	 ||type == T_XOR
-	 ||type == T_NOT
-	 ||type == T_ADD
-	 ||type == T_SUBTRACT
-	 ||type == T_MULTIPLY
-	 ||type == T_DIVIDE
-	 ||type == T_L_FLOOR
-	 ||type == T_R_FLOOR
-	 ||type == T_L_CEILING
-	 ||type == T_R_CEILING
-	 ||type == T_ROOT
-	 ||type == T_ROOT_3
-	 ||type == T_ROOT_4
-	 ||type == T_ASSIGN
-	 ||type == T_L_R_BRACKET
-	 ||type == T_R_R_BRACKET
-	 ||type == T_L_S_BRACKET
-	 ||type == T_R_S_BRACKET
-	 ||type == T_L_C_BRACKET
-	 ||type == T_R_C_BRACKET
-	 ||type == T_ABS
-	 ||type == T_POWER
-	 ||type == T_FACTORIAL
-	 ||type == T_PERCENTAGE)
-	{
-		return l_insert_token(lstate, type);
-	}
-	/* [PL_SUPER_MINUS][PL_SUPER_DIGIT]+ */
-	if(type == PL_SUPER_MINUS)
-	{
-		if((type = pl_get_next_token(state)) != PL_SUPER_DIGIT)
-		{
-			/* ERROR: expected PL_SUP_DIGIT */
-			set_error(lstate->parent, PARSER_ERR_MP, tmp = pl_get_marked_substring (state));
-			free(tmp);
-			return l_insert_token(lstate, T_UNKNOWN);
-		}
-		/* Get all PL_SUPER_DIGITs. */
-		while (pl_get_next_token(state) == PL_SUPER_DIGIT);
-		pl_roll_back(state);
-		return l_insert_token(lstate, T_NSUP_NUMBER);
-	}
-	/* [PL_SUPER_DIGIT]+ */
-	if(type == PL_SUPER_DIGIT)
-	{
-		while(pl_get_next_token(state) == PL_SUPER_DIGIT);
-		pl_roll_back(state);
-		return l_insert_token(lstate, T_SUP_NUMBER);
-	}
-	/* [PL_SUB_DIGIT]+ */
-	if(type == PL_SUB_DIGIT)
-	{
-		while(pl_get_next_token(state) == PL_SUB_DIGIT);
-		pl_roll_back(state);
-		return l_insert_token(lstate, T_SUB_NUMBER);
-	}
-	/* [PL_FRACTION] */
-	if(type == PL_FRACTION)
-	{
-		return l_insert_token(lstate, T_NUMBER);
-	}
-	if(type == PL_DIGIT)
-	{
-		while((type = pl_get_next_token(state)) == PL_DIGIT);
-		if(type == PL_FRACTION)
-		{
-			return l_insert_token(lstate, T_NUMBER);
-		}
-		else if(type == PL_SUB_DIGIT)
-		{
-			while(pl_get_next_token(state) == PL_SUB_DIGIT);
-			pl_roll_back(state);
-			return l_insert_token(lstate, T_NUMBER);
-		}
-		else if(type == PL_DEGREE)
-		{
-			type = pl_get_next_token(state);
-			if(type == PL_DIGIT)
-			{
-				while((type = pl_get_next_token(state)) == PL_DIGIT);
-				if(type == PL_DECIMAL)
-				{
-					goto ANGLE_NUM_DM_STATE;
-				}
-				else if(type == PL_MINUTE)
-				{
-					type = pl_get_next_token(state);
-					if(type == PL_DIGIT)
-					{
-						while((type = pl_get_next_token(state)) == PL_DIGIT);
-						if(type == PL_DECIMAL)
-						{
-							goto ANGLE_NUM_DMS_STATE;
-						}
-						else if(type == PL_SECOND)
-						{
-							return l_insert_token(lstate, T_NUMBER);
-						}
-						else
-						{
-							/* ERROR: expected PL_SECOND */
-							set_error(lstate->parent, PARSER_ERR_MP, tmp = pl_get_marked_substring (state));
-							free(tmp);
-							return l_insert_token(lstate, T_UNKNOWN);
-						}
-					}
-					else if(type == PL_DECIMAL)
-					{
+    PreLexerState* state = lstate->prelexer;
+    LexerTokenType type;
+    gchar* tmp;
+    pl_set_marker(state);
+    /* Ignore all blank spaces. :) */
+    while((type = pl_get_next_token(state)) == PL_SKIP)
+        /* Set marker. Beginning of new token. */
+        pl_set_marker(state);
+    if(type == T_AND
+     ||type == T_OR
+     ||type == T_XOR
+     ||type == T_NOT
+     ||type == T_ADD
+     ||type == T_SUBTRACT
+     ||type == T_MULTIPLY
+     ||type == T_DIVIDE
+     ||type == T_L_FLOOR
+     ||type == T_R_FLOOR
+     ||type == T_L_CEILING
+     ||type == T_R_CEILING
+     ||type == T_ROOT
+     ||type == T_ROOT_3
+     ||type == T_ROOT_4
+     ||type == T_ASSIGN
+     ||type == T_L_R_BRACKET
+     ||type == T_R_R_BRACKET
+     ||type == T_L_S_BRACKET
+     ||type == T_R_S_BRACKET
+     ||type == T_L_C_BRACKET
+     ||type == T_R_C_BRACKET
+     ||type == T_ABS
+     ||type == T_POWER
+     ||type == T_FACTORIAL
+     ||type == T_PERCENTAGE)
+    {
+        return l_insert_token(lstate, type);
+    }
+    /* [PL_SUPER_MINUS][PL_SUPER_DIGIT]+ */
+    if(type == PL_SUPER_MINUS)
+    {
+        if((type = pl_get_next_token(state)) != PL_SUPER_DIGIT)
+        {
+            /* ERROR: expected PL_SUP_DIGIT */
+            set_error(lstate->parent, PARSER_ERR_MP, tmp = pl_get_marked_substring (state));
+            free(tmp);
+            return l_insert_token(lstate, T_UNKNOWN);
+        }
+        /* Get all PL_SUPER_DIGITs. */
+        while (pl_get_next_token(state) == PL_SUPER_DIGIT);
+        pl_roll_back(state);
+        return l_insert_token(lstate, T_NSUP_NUMBER);
+    }
+    /* [PL_SUPER_DIGIT]+ */
+    if(type == PL_SUPER_DIGIT)
+    {
+        while(pl_get_next_token(state) == PL_SUPER_DIGIT);
+        pl_roll_back(state);
+        return l_insert_token(lstate, T_SUP_NUMBER);
+    }
+    /* [PL_SUB_DIGIT]+ */
+    if(type == PL_SUB_DIGIT)
+    {
+        while(pl_get_next_token(state) == PL_SUB_DIGIT);
+        pl_roll_back(state);
+        return l_insert_token(lstate, T_SUB_NUMBER);
+    }
+    /* [PL_FRACTION] */
+    if(type == PL_FRACTION)
+    {
+        return l_insert_token(lstate, T_NUMBER);
+    }
+    if(type == PL_DIGIT)
+    {
+        while((type = pl_get_next_token(state)) == PL_DIGIT);
+        if(type == PL_FRACTION)
+        {
+            return l_insert_token(lstate, T_NUMBER);
+        }
+        else if(type == PL_SUB_DIGIT)
+        {
+            while(pl_get_next_token(state) == PL_SUB_DIGIT);
+            pl_roll_back(state);
+            return l_insert_token(lstate, T_NUMBER);
+        }
+        else if(type == PL_DEGREE)
+        {
+            type = pl_get_next_token(state);
+            if(type == PL_DIGIT)
+            {
+                while((type = pl_get_next_token(state)) == PL_DIGIT);
+                if(type == PL_DECIMAL)
+                {
+                    goto ANGLE_NUM_DM_STATE;
+                }
+                else if(type == PL_MINUTE)
+                {
+                    type = pl_get_next_token(state);
+                    if(type == PL_DIGIT)
+                    {
+                        while((type = pl_get_next_token(state)) == PL_DIGIT);
+                        if(type == PL_DECIMAL)
+                        {
+                            goto ANGLE_NUM_DMS_STATE;
+                        }
+                        else if(type == PL_SECOND)
+                        {
+                            return l_insert_token(lstate, T_NUMBER);
+                        }
+                        else
+                        {
+                            /* ERROR: expected PL_SECOND */
+                            set_error(lstate->parent, PARSER_ERR_MP, tmp = pl_get_marked_substring (state));
+                            free(tmp);
+                            return l_insert_token(lstate, T_UNKNOWN);
+                        }
+                    }
+                    else if(type == PL_DECIMAL)
+                    {
 ANGLE_NUM_DMS_STATE:
-						if((type = pl_get_next_token (state)) != PL_DIGIT)
-						{
-							/* ERROR: expected PL_DIGIT */
-							set_error(lstate->parent, PARSER_ERR_MP, tmp = pl_get_marked_substring(state));
-							free(tmp);
-							return l_insert_token(lstate, T_UNKNOWN);
-						}
-						while((type = pl_get_next_token(state)) == PL_DIGIT);
-						if(type == PL_SECOND)
-						{
-							return l_insert_token(lstate, T_NUMBER);
-						}
-						else
-						{
-							/* ERROR: expected PL_SECOND */
-							set_error(lstate->parent, PARSER_ERR_MP, tmp = pl_get_marked_substring(state));
-							free(tmp);
-							return l_insert_token(lstate, T_UNKNOWN);
-						}
-					}
-					else
-					{
-						pl_roll_back(state);
-						return l_insert_token(lstate, T_NUMBER);
-					}
-				}
-				else
-				{
-					/* ERROR: expected PL_MINUTE | PL_DIGIT */
-					set_error(lstate->parent, PARSER_ERR_MP, tmp = pl_get_marked_substring(state));
-					free(tmp);
-					return l_insert_token(lstate, T_UNKNOWN);
-				}
-			}
-			else if(type == PL_DECIMAL)
-			{
+                        if((type = pl_get_next_token (state)) != PL_DIGIT)
+                        {
+                            /* ERROR: expected PL_DIGIT */
+                            set_error(lstate->parent, PARSER_ERR_MP, tmp = pl_get_marked_substring(state));
+                            free(tmp);
+                            return l_insert_token(lstate, T_UNKNOWN);
+                        }
+                        while((type = pl_get_next_token(state)) == PL_DIGIT);
+                        if(type == PL_SECOND)
+                        {
+                            return l_insert_token(lstate, T_NUMBER);
+                        }
+                        else
+                        {
+                            /* ERROR: expected PL_SECOND */
+                            set_error(lstate->parent, PARSER_ERR_MP, tmp = pl_get_marked_substring(state));
+                            free(tmp);
+                            return l_insert_token(lstate, T_UNKNOWN);
+                        }
+                    }
+                    else
+                    {
+                        pl_roll_back(state);
+                        return l_insert_token(lstate, T_NUMBER);
+                    }
+                }
+                else
+                {
+                    /* ERROR: expected PL_MINUTE | PL_DIGIT */
+                    set_error(lstate->parent, PARSER_ERR_MP, tmp = pl_get_marked_substring(state));
+                    free(tmp);
+                    return l_insert_token(lstate, T_UNKNOWN);
+                }
+            }
+            else if(type == PL_DECIMAL)
+            {
 ANGLE_NUM_DM_STATE:
-				if((type = pl_get_next_token(state)) != PL_DIGIT)
-				{
-					/* ERROR: expected PL_DIGIT */
-					set_error(lstate->parent, PARSER_ERR_MP, tmp = pl_get_marked_substring(state));
-					free(tmp);
-					return l_insert_token(lstate, T_UNKNOWN);
-				}
-				while((type = pl_get_next_token(state)) == PL_DIGIT);
-				if(type == PL_MINUTE)
-				{
-					return l_insert_token(lstate, T_NUMBER);
-				}
-				else
-				{
-					/* ERROR: expected PL_MINUTE */
-					set_error(lstate->parent, PARSER_ERR_MP, tmp = pl_get_marked_substring(state));
-					free(tmp);
-					return l_insert_token(lstate, T_UNKNOWN);
-				}
-			}
-			else
-			{
-				return l_insert_token(lstate, T_NUMBER);
-			}
-		}
-		else if(type == PL_DECIMAL)
-		{
-			goto DECIMAL_STATE;
-		}
-		else if(type == PL_HEX)
-		{
-			goto HEX_DEC_STATE;
-		}
-		else
-		{
-			pl_roll_back(state);
-			return l_insert_token(lstate, T_NUMBER);
-		}
-	}
-	if(type == PL_DECIMAL)
-	{
+                if((type = pl_get_next_token(state)) != PL_DIGIT)
+                {
+                    /* ERROR: expected PL_DIGIT */
+                    set_error(lstate->parent, PARSER_ERR_MP, tmp = pl_get_marked_substring(state));
+                    free(tmp);
+                    return l_insert_token(lstate, T_UNKNOWN);
+                }
+                while((type = pl_get_next_token(state)) == PL_DIGIT);
+                if(type == PL_MINUTE)
+                {
+                    return l_insert_token(lstate, T_NUMBER);
+                }
+                else
+                {
+                    /* ERROR: expected PL_MINUTE */
+                    set_error(lstate->parent, PARSER_ERR_MP, tmp = pl_get_marked_substring(state));
+                    free(tmp);
+                    return l_insert_token(lstate, T_UNKNOWN);
+                }
+            }
+            else
+            {
+                return l_insert_token(lstate, T_NUMBER);
+            }
+        }
+        else if(type == PL_DECIMAL)
+        {
+            goto DECIMAL_STATE;
+        }
+        else if(type == PL_HEX)
+        {
+            goto HEX_DEC_STATE;
+        }
+        else
+        {
+            pl_roll_back(state);
+            return l_insert_token(lstate, T_NUMBER);
+        }
+    }
+    if(type == PL_DECIMAL)
+    {
 DECIMAL_STATE:
-		type = pl_get_next_token(state);
-		if(type == PL_DIGIT)
-		{
-			while((type = pl_get_next_token(state)) == PL_DIGIT);
-			if(type == PL_DEGREE)
-			{
-				return l_insert_token(lstate, T_NUMBER);
-			}
-			else if(type == PL_HEX)
-			{
-				goto DECIMAL_HEX_STATE;
-			}
-			else if(type == PL_SUB_DIGIT)
-			{
-				while(pl_get_next_token(state) == PL_SUB_DIGIT);
-				pl_roll_back(state);
-				return l_insert_token(lstate, T_NUMBER);
-			}
-			else
-			{
-				pl_roll_back(state);
-				return l_insert_token(lstate, T_NUMBER);
-			}
-		}
-		else if(type == PL_HEX)
-		{
-			goto DECIMAL_HEX_STATE;
-		}
-		else
-		{
-			/* ERROR: expected PL_DIGIT | PL_HEX */
-			set_error(lstate->parent, PARSER_ERR_MP, tmp = pl_get_marked_substring(state));
-			free(tmp);
-			return l_insert_token(lstate, T_UNKNOWN);
-		}
-	}
-	if(type == PL_HEX)
-	{
-		while((type = pl_get_next_token(state)) == PL_HEX);
-		if(type == PL_DIGIT)
-		{
+        type = pl_get_next_token(state);
+        if(type == PL_DIGIT)
+        {
+            while((type = pl_get_next_token(state)) == PL_DIGIT);
+            if(type == PL_DEGREE)
+            {
+                return l_insert_token(lstate, T_NUMBER);
+            }
+            else if(type == PL_HEX)
+            {
+                goto DECIMAL_HEX_STATE;
+            }
+            else if(type == PL_SUB_DIGIT)
+            {
+                while(pl_get_next_token(state) == PL_SUB_DIGIT);
+                pl_roll_back(state);
+                return l_insert_token(lstate, T_NUMBER);
+            }
+            else
+            {
+                pl_roll_back(state);
+                return l_insert_token(lstate, T_NUMBER);
+            }
+        }
+        else if(type == PL_HEX)
+        {
+            goto DECIMAL_HEX_STATE;
+        }
+        else
+        {
+            /* ERROR: expected PL_DIGIT | PL_HEX */
+            set_error(lstate->parent, PARSER_ERR_MP, tmp = pl_get_marked_substring(state));
+            free(tmp);
+            return l_insert_token(lstate, T_UNKNOWN);
+        }
+    }
+    if(type == PL_HEX)
+    {
+        while((type = pl_get_next_token(state)) == PL_HEX);
+        if(type == PL_DIGIT)
+        {
 HEX_DEC_STATE:
-			while(1)
-			{
-				type = pl_get_next_token(state);
-				if(type == PL_DIGIT || type == PL_HEX)
-				{
-					continue;
-				}
-				else if(type == PL_DECIMAL)
-				{
-					goto DECIMAL_HEX_STATE;
-				}
-				else if(type == PL_SUB_DIGIT)
-				{
-					while(pl_get_next_token(state) == PL_SUB_DIGIT);
-					pl_roll_back(state);
-					return l_insert_token(lstate, T_NUMBER);
-				}
-				else
-				{
-					if(l_check_if_number(lstate))
-						return l_insert_token(lstate, T_NUMBER);
-					/* ERROR: expected PL_DECIMAL | PL_DIGIT | PL_HEX */
-					set_error(lstate->parent, PARSER_ERR_MP, tmp = pl_get_marked_substring(state));
-					free(tmp);
-					return l_insert_token(lstate, T_UNKNOWN);
-				}
-			}
-		}
-		else if(type == PL_DECIMAL)
-		{
+            while(1)
+            {
+                type = pl_get_next_token(state);
+                if(type == PL_DIGIT || type == PL_HEX)
+                {
+                    continue;
+                }
+                else if(type == PL_DECIMAL)
+                {
+                    goto DECIMAL_HEX_STATE;
+                }
+                else if(type == PL_SUB_DIGIT)
+                {
+                    while(pl_get_next_token(state) == PL_SUB_DIGIT);
+                    pl_roll_back(state);
+                    return l_insert_token(lstate, T_NUMBER);
+                }
+                else
+                {
+                    if(l_check_if_number(lstate))
+                        return l_insert_token(lstate, T_NUMBER);
+                    /* ERROR: expected PL_DECIMAL | PL_DIGIT | PL_HEX */
+                    set_error(lstate->parent, PARSER_ERR_MP, tmp = pl_get_marked_substring(state));
+                    free(tmp);
+                    return l_insert_token(lstate, T_UNKNOWN);
+                }
+            }
+        }
+        else if(type == PL_DECIMAL)
+        {
 DECIMAL_HEX_STATE:
-			type = pl_get_next_token(state);
-			if(!(type == PL_DIGIT || type == PL_HEX))
-			{
-				/* ERROR: expected PL_DIGIT | PL_HEX */
-				set_error(lstate->parent, PARSER_ERR_MP, tmp = pl_get_marked_substring(state));
-				free(tmp);
-				return l_insert_token(lstate, T_UNKNOWN);
-			}
-			while(1)
-			{
-				type = pl_get_next_token(state);
-				if(type == PL_DIGIT || type == PL_HEX)
-				{
-					continue;
-				}
-				else if(type == PL_SUB_DIGIT)
-				{
-					while(pl_get_next_token(state) == PL_SUB_DIGIT);
-					pl_roll_back(state);
-					return l_insert_token(lstate, T_NUMBER);
-				}
-				else
-				{
-					pl_roll_back(state);
-					return l_insert_token(lstate, T_NUMBER);
-				}
-			}
-		}
-		else if(type == PL_SUB_DIGIT)
-		{
-			while(pl_get_next_token(state) == PL_SUB_DIGIT);
-			pl_roll_back(state);
-			if(l_check_if_number(lstate))
-			{
-				/* NUMBER */
-				return l_insert_token(lstate, T_NUMBER);
-			}
-			else
-			{
-				/* VARIABLE */
-				if(l_check_if_function(lstate))
-				{
-					return l_insert_token(lstate, T_FUNCTION);
-				}
-				else
-				{
-					return l_insert_token(lstate, T_VARIABLE);
-				}
-			}
-		}
-		else if(type == PL_LETTER)
-		{
-			goto LETTER_STATE;
-		}
-		else
-		{
-			pl_roll_back(state);
-			if(l_check_if_number(lstate))
-			{
-				/* NUMBER */
-				return l_insert_token(lstate, T_NUMBER);
-			}
-			else
-			{
-				/* VARIABLE */
-				if(l_check_if_function(lstate))
-				{
-					return l_insert_token(lstate, T_FUNCTION);
-				}
-				else
-				{
-					return l_insert_token(lstate, T_VARIABLE);
-				}
-			}
-		}
-	}
-	if(type == PL_LETTER)
-	{
+            type = pl_get_next_token(state);
+            if(!(type == PL_DIGIT || type == PL_HEX))
+            {
+                /* ERROR: expected PL_DIGIT | PL_HEX */
+                set_error(lstate->parent, PARSER_ERR_MP, tmp = pl_get_marked_substring(state));
+                free(tmp);
+                return l_insert_token(lstate, T_UNKNOWN);
+            }
+            while(1)
+            {
+                type = pl_get_next_token(state);
+                if(type == PL_DIGIT || type == PL_HEX)
+                {
+                    continue;
+                }
+                else if(type == PL_SUB_DIGIT)
+                {
+                    while(pl_get_next_token(state) == PL_SUB_DIGIT);
+                    pl_roll_back(state);
+                    return l_insert_token(lstate, T_NUMBER);
+                }
+                else
+                {
+                    pl_roll_back(state);
+                    return l_insert_token(lstate, T_NUMBER);
+                }
+            }
+        }
+        else if(type == PL_SUB_DIGIT)
+        {
+            while(pl_get_next_token(state) == PL_SUB_DIGIT);
+            pl_roll_back(state);
+            if(l_check_if_number(lstate))
+            {
+                /* NUMBER */
+                return l_insert_token(lstate, T_NUMBER);
+            }
+            else
+            {
+                /* VARIABLE */
+                if(l_check_if_function(lstate))
+                {
+                    return l_insert_token(lstate, T_FUNCTION);
+                }
+                else
+                {
+                    return l_insert_token(lstate, T_VARIABLE);
+                }
+            }
+        }
+        else if(type == PL_LETTER)
+        {
+            goto LETTER_STATE;
+        }
+        else
+        {
+            pl_roll_back(state);
+            if(l_check_if_number(lstate))
+            {
+                /* NUMBER */
+                return l_insert_token(lstate, T_NUMBER);
+            }
+            else
+            {
+                /* VARIABLE */
+                if(l_check_if_function(lstate))
+                {
+                    return l_insert_token(lstate, T_FUNCTION);
+                }
+                else
+                {
+                    return l_insert_token(lstate, T_VARIABLE);
+                }
+            }
+        }
+    }
+    if(type == PL_LETTER)
+    {
 LETTER_STATE:
-		while(1)
-		{
-			type = pl_get_next_token(state);
-			if(type == PL_LETTER || type == PL_HEX)
-			{
-				continue;
-			}
-			else if(type == PL_SUB_DIGIT)
-			{
-				while(pl_get_next_token(state) == PL_SUB_DIGIT);
-				pl_roll_back(state);
-				tmp = g_ascii_strdown(pl_get_marked_substring(state), -1);
-				if(g_strcmp0(tmp, "mod") == 0)
-				{
-					return l_insert_token(lstate, T_MOD);
-				}
-				if(g_strcmp0(tmp, "and") == 0)
-				{
-					return l_insert_token(lstate, T_AND);
-				}
-				if(g_strcmp0(tmp, "or") == 0)
-				{
-					return l_insert_token(lstate, T_OR);
-				}
-				if(g_strcmp0(tmp, "xor") == 0)
-				{
-					return l_insert_token(lstate, T_XOR);
-				}
-				if(g_strcmp0(tmp, "not") == 0)
-				{
-					return l_insert_token(lstate, T_NOT);
-				}
-				if(g_strcmp0(tmp, "in") == 0)
-				{
-					return l_insert_token(lstate, T_IN);
-				}
-				if(l_check_if_function(lstate))
-				{
-					return l_insert_token(lstate, T_FUNCTION);
-				}
-				else
-				{
-					return l_insert_token(lstate, T_VARIABLE);
-				}
-			}
-			else
-			{
-				pl_roll_back(state);
-				tmp = g_ascii_strdown(pl_get_marked_substring(state), -1);
-				if(g_strcmp0(tmp, "mod") == 0)
-				{
-					return l_insert_token(lstate, T_MOD);
-				}
-				if(g_strcmp0(tmp, "and") == 0)
-				{
-					return l_insert_token(lstate, T_AND);
-				}
-				if(g_strcmp0(tmp, "or") == 0)
-				{
-					return l_insert_token(lstate, T_OR);
-				}
-				if(g_strcmp0(tmp, "xor") == 0)
-				{
-					return l_insert_token(lstate, T_XOR);
-				}
-				if(g_strcmp0(tmp, "not") == 0)
-				{
-					return l_insert_token(lstate, T_NOT);
-				}
-				if(g_strcmp0(tmp, "in") == 0)
-				{
-					return l_insert_token(lstate, T_IN);
-				}
-				if(l_check_if_function(lstate))
-				{
-					return l_insert_token(lstate, T_FUNCTION);
-				}
-				else
-				{
-					return l_insert_token(lstate, T_VARIABLE);
-				}
-			}
-		}
-	}
-	if(type == PL_EOS)
-	{
-		return l_insert_token(lstate, PL_EOS);
-	}
-	/* ERROR: Unexpected token.. X( */
-	set_error(lstate->parent, PARSER_ERR_INVALID, tmp = pl_get_marked_substring(state));
-	free(tmp);
-	return l_insert_token(lstate, T_UNKNOWN);
+        while(1)
+        {
+            type = pl_get_next_token(state);
+            if(type == PL_LETTER || type == PL_HEX)
+            {
+                continue;
+            }
+            else if(type == PL_SUB_DIGIT)
+            {
+                while(pl_get_next_token(state) == PL_SUB_DIGIT);
+                pl_roll_back(state);
+                tmp = g_ascii_strdown(pl_get_marked_substring(state), -1);
+                if(g_strcmp0(tmp, "mod") == 0)
+                {
+                    return l_insert_token(lstate, T_MOD);
+                }
+                if(g_strcmp0(tmp, "and") == 0)
+                {
+                    return l_insert_token(lstate, T_AND);
+                }
+                if(g_strcmp0(tmp, "or") == 0)
+                {
+                    return l_insert_token(lstate, T_OR);
+                }
+                if(g_strcmp0(tmp, "xor") == 0)
+                {
+                    return l_insert_token(lstate, T_XOR);
+                }
+                if(g_strcmp0(tmp, "not") == 0)
+                {
+                    return l_insert_token(lstate, T_NOT);
+                }
+                if(g_strcmp0(tmp, "in") == 0)
+                {
+                    return l_insert_token(lstate, T_IN);
+                }
+                if(l_check_if_function(lstate))
+                {
+                    return l_insert_token(lstate, T_FUNCTION);
+                }
+                else
+                {
+                    return l_insert_token(lstate, T_VARIABLE);
+                }
+            }
+            else
+            {
+                pl_roll_back(state);
+                tmp = g_ascii_strdown(pl_get_marked_substring(state), -1);
+                if(g_strcmp0(tmp, "mod") == 0)
+                {
+                    return l_insert_token(lstate, T_MOD);
+                }
+                if(g_strcmp0(tmp, "and") == 0)
+                {
+                    return l_insert_token(lstate, T_AND);
+                }
+                if(g_strcmp0(tmp, "or") == 0)
+                {
+                    return l_insert_token(lstate, T_OR);
+                }
+                if(g_strcmp0(tmp, "xor") == 0)
+                {
+                    return l_insert_token(lstate, T_XOR);
+                }
+                if(g_strcmp0(tmp, "not") == 0)
+                {
+                    return l_insert_token(lstate, T_NOT);
+                }
+                if(g_strcmp0(tmp, "in") == 0)
+                {
+                    return l_insert_token(lstate, T_IN);
+                }
+                if(l_check_if_function(lstate))
+                {
+                    return l_insert_token(lstate, T_FUNCTION);
+                }
+                else
+                {
+                    return l_insert_token(lstate, T_VARIABLE);
+                }
+            }
+        }
+    }
+    if(type == PL_EOS)
+    {
+        return l_insert_token(lstate, PL_EOS);
+    }
+    /* ERROR: Unexpected token.. X( */
+    set_error(lstate->parent, PARSER_ERR_INVALID, tmp = pl_get_marked_substring(state));
+    free(tmp);
+    return l_insert_token(lstate, T_UNKNOWN);
 }
 
 /* Call l_insert_next_token() as many times as needed to completely tokenize the string. */
 void
 l_insert_all_tokens(LexerState* state)
 {
-	LexerToken* token;
-	while(1)
-	{
-		token = l_insert_next_token(state);
-		assert(token != NULL);
-		if(token->token_type == PL_EOS)
-		{
-			break;
-		}
-	}
+    LexerToken* token;
+    while(1)
+    {
+        token = l_insert_next_token(state);
+        assert(token != NULL);
+        if(token->token_type == PL_EOS)
+        {
+            break;
+        }
+    }
 }
 
 /* Create a lexer state from given input string. This will take care of pre-lexer state. */
 LexerState*
 l_create_lexer(const gchar* input, struct parser_state* parent)
 {
-	LexerState* ret;
-	ret = (LexerState *) malloc(sizeof(LexerState));
-	assert(ret != NULL);
-	ret->prelexer = pl_create_scanner(input);
-	ret->tokens = NULL;
-	ret->token_count = 0;
-	ret->next_token = 0;
-	ret->parent = parent;
-	return ret;
+    LexerState* ret;
+    ret = (LexerState *) malloc(sizeof(LexerState));
+    assert(ret != NULL);
+    ret->prelexer = pl_create_scanner(input);
+    ret->tokens = NULL;
+    ret->token_count = 0;
+    ret->next_token = 0;
+    ret->parent = parent;
+    return ret;
 }
 
 /* Destroy lexer state and free memory. */
 void
 l_destroy_lexer(LexerState* state)
 {
-	int l;
-	pl_destroy_scanner(state->prelexer);
-	for(l = 0; l < state->token_count; l++)
-	{
-		free(state->tokens[l].string);
-	}
-	free(state->tokens);
-	free(state);
+    int l;
+    pl_destroy_scanner(state->prelexer);
+    for(l = 0; l < state->token_count; l++)
+    {
+        free(state->tokens[l].string);
+    }
+    free(state->tokens);
+    free(state);
 }
 
 /* Get next token interface. Will be called by parser to get pointer to next token in token stream. */
 LexerToken*
 l_get_next_token(LexerState* state)
 {
-	/* Return PL_EOS token after token stream reaches to its end. */
-	if(state->next_token >= state->token_count)
-		return &state->tokens[state->token_count - 1];
-	return &state->tokens[state->next_token++];
+    /* Return PL_EOS token after token stream reaches to its end. */
+    if(state->next_token >= state->token_count)
+        return &state->tokens[state->token_count - 1];
+    return &state->tokens[state->next_token++];
 }
 
 /* Roll back one lexer token. */
 void
 l_roll_back(LexerState* state)
 {
-	if(state->next_token > 0)
-		state->next_token--;
+    if(state->next_token > 0)
+        state->next_token--;
 }
 /* Structure to hold single token. */
 typedef struct
 {
-	gchar* string;			/* Poniter to local copy of token string. */
-	guint start_index;		/* Start index in original stream. */
-	guint end_index;		/* End index in original stream. */
-	LexerTokenType token_type;	/* Type of token. */
+    gchar* string;			/* Poniter to local copy of token string. */
+    guint start_index;			/* Start index in original stream. */
+    guint end_index;			/* End index in original stream. */
+    LexerTokenType token_type;		/* Type of token. */
 } LexerToken;
 
 /* Structure to hold lexer state and all the tokens. */
 typedef struct
 {
-	PreLexerState *prelexer;	/* Pre-lexer state. Pre-lexer is part of lexer. */
-	LexerToken *tokens;		/* Pointer to the dynamic array of LexerTokens. */
-	guint token_count;		/* Count of tokens in array. */
-	guint next_token;		/* Index of next, to be sent, token. */
-	struct parser_state *parent;	/* Pointer to the parent parser. */
+    PreLexerState *prelexer;		/* Pre-lexer state. Pre-lexer is part of lexer. */
+    LexerToken *tokens;			/* Pointer to the dynamic array of LexerTokens. */
+    guint token_count;			/* Count of tokens in array. */
+    guint next_token;			/* Index of next, to be sent, token. */
+    struct parser_state *parent;	/* Pointer to the parent parser. */
 } LexerState;
 
 /* Create a new LexerState object and fill the dynamic array with tokens. */
 static guint
 p_get_precedence(LexerTokenType type)
 {
-	/* WARNING: This function doesn't work for Unary Plus and Unary Minus. Use their precedence directly while inserting them in tree. */
-	if(type == T_ADD
-	 ||type == T_SUBTRACT)
-		return P_AddSubtract;
-	if(type == T_MULTIPLY)
-		return P_Multiply;
-	if(type == T_MOD)
-		return P_Mod;
-	if(type == T_DIVIDE)
-		return P_Divide;
-	if(type == T_NOT)
-		return P_Not;
-	if(type == T_ROOT
-	 ||type == T_ROOT_3
-	 ||type == T_ROOT_4)
-		return P_Root;
-	if(type == T_FUNCTION)
-		return P_Function;
-	if(type == T_AND
-	 ||type == T_OR
-	 ||type == T_XOR)
-		return P_Boolean;
-	if(type == T_PERCENTAGE)
-		return P_Percentage;
-	if(type == T_POWER)
-		return P_Power;
-	if(type == T_FACTORIAL)
-		return P_Factorial;
-	if(type == T_NUMBER
-	 ||type == T_VARIABLE)
-		return P_NumberVariable;
-	return P_Unknown;
+    /* WARNING: This function doesn't work for Unary Plus and Unary Minus. Use their precedence directly while inserting them in tree. */
+    if(type == T_ADD
+     ||type == T_SUBTRACT)
+        return P_AddSubtract;
+    if(type == T_MULTIPLY)
+        return P_Multiply;
+    if(type == T_MOD)
+        return P_Mod;
+    if(type == T_DIVIDE)
+        return P_Divide;
+    if(type == T_NOT)
+        return P_Not;
+    if(type == T_ROOT
+     ||type == T_ROOT_3
+     ||type == T_ROOT_4)
+        return P_Root;
+    if(type == T_FUNCTION)
+        return P_Function;
+    if(type == T_AND
+     ||type == T_OR
+     ||type == T_XOR)
+        return P_Boolean;
+    if(type == T_PERCENTAGE)
+        return P_Percentage;
+    if(type == T_POWER)
+        return P_Power;
+    if(type == T_FACTORIAL)
+        return P_Factorial;
+    if(type == T_NUMBER
+     ||type == T_VARIABLE)
+        return P_NumberVariable;
+    return P_Unknown;
 }
 
 /* Return associativity of specific token type from precedence. */
 static Associativity
 p_get_associativity_p(Precedence type)
 {
-	if(type == P_Boolean
-	 ||type == P_Divide
-	 ||type == P_Mod
-	 ||type == P_Multiply
-	 ||type == P_AddSubtract)
-		return LEFT_ASSOCIATIVE;
-	if(type == P_Power)
-		return RIGHT_ASSOCIATIVE;
-	/* For all remaining / non-associative operators, return Left Associativity. */
-	return LEFT_ASSOCIATIVE;
+    if(type == P_Boolean
+     ||type == P_Divide
+     ||type == P_Mod
+     ||type == P_Multiply
+     ||type == P_AddSubtract)
+        return LEFT_ASSOCIATIVE;
+    if(type == P_Power)
+        return RIGHT_ASSOCIATIVE;
+    /* For all remaining / non-associative operators, return Left Associativity. */
+    return LEFT_ASSOCIATIVE;
 }
 
 /* Return associativity of specific token by converting it to precedence first. */
 static Associativity
 p_get_associativity(LexerToken* token)
 {
-	return p_get_associativity_p(p_get_precedence(token->token_type));
+    return p_get_associativity_p(p_get_precedence(token->token_type));
 }
 
 /* Generate precedence for a node from precedence value. Includes depth_level. */
 static guint
 p_make_precedence_p(ParserState* state, Precedence p)
 {
-	return (p + (state->depth_level * P_Depth));
+    return (p + (state->depth_level * P_Depth));
 }
 
 /* Generate precedence for a node from lexer token type. Includes depth_level. */
 static guint
 p_make_precedence_t(ParserState* state, LexerTokenType type)
 {
-	return (p_get_precedence(type) + (state->depth_level * P_Depth));
+    return (p_get_precedence(type) + (state->depth_level * P_Depth));
 }
 
 /* Allocate and create a new node. */
 static ParseNode*
 p_create_node(ParserState* state, LexerToken* token, guint precedence, Associativity associativity, void* value, void* (*function)(ParseNode*))
 {
-	ParseNode* new;
-	new = (ParseNode*) malloc(sizeof(ParseNode));
-	assert(new != NULL);
-	new->parent = NULL;
-	new->left = NULL;
-	new->right = NULL;
-	new->token = token;
-	new->precedence = precedence;
-	new->associativity = associativity;
-	new->value = value;
-	new->state = state;
-	new->evaluate = function;
-	return new;
+    ParseNode* new;
+    new = (ParseNode*) malloc(sizeof(ParseNode));
+    assert(new != NULL);
+    new->parent = NULL;
+    new->left = NULL;
+    new->right = NULL;
+    new->token = token;
+    new->precedence = precedence;
+    new->associativity = associativity;
+    new->value = value;
+    new->state = state;
+    new->evaluate = function;
+    return new;
 }
 
 /* Compares two nodes to decide, which will be parent and which willbe child. */
 static gint
 p_cmp_nodes(ParseNode* left, ParseNode* right)
 {
-	/* Return values.
-	   1 = right goes up (near root) in parse tree.
-	   0 = left  goes up (near root) in parse tree.
-	*/
-	if(left == NULL)
-		return 0;
-	if(left->precedence > right->precedence)
-	{
-		return 1;
-	}
-	else if(left->precedence < right->precedence)
-	{
-		return 0;
-	}
-	else
-	{
-		if(right->associativity == RIGHT_ASSOCIATIVE)
-		{
-			return 0;
-		}
-		else
-		{
-			return 1;
-		}
-	}
+    /* Return values.
+       1 = right goes up (near root) in parse tree.
+       0 = left  goes up (near root) in parse tree.
+    */
+    if(left == NULL)
+        return 0;
+    if(left->precedence > right->precedence)
+    {
+        return 1;
+    }
+    else if(left->precedence < right->precedence)
+    {
+        return 0;
+    }
+    else
+    {
+        if(right->associativity == RIGHT_ASSOCIATIVE)
+        {
+            return 0;
+        }
+        else
+        {
+            return 1;
+        }
+    }
 }
 
 /* Unified interface (unary and binary nodes) to insert node into parse tree. */
 static void
 p_insert_into_tree_all(ParserState* state, ParseNode* node, guint unary_function)
 {
-	if(state->root == NULL)
-	{
-		state->root = node;
-		state->right_most = state->root;
-		return;
-	}
-	ParseNode* tmp = state->right_most;
-	while(p_cmp_nodes(tmp, node))
-		tmp = tmp->parent;
-	if(unary_function)
-	{
-		/* If tmp is null, that means, we have to insert new node at root. */
-		if(tmp == NULL)
-		{
-			node->right = state->root;
-			node->right->parent = node;
-
-			state->root = node;
-		}
-		else
-		{
-			node->right = tmp->right;
-			if(node->right)
-				node->right->parent = node;
-
-			tmp->right = node;
-			if(tmp->right)
-				tmp->right->parent = tmp;
-
-		}
-		state->right_most = node;
-		while(state->right_most->right != NULL)
-			state->right_most = state->right_most->right;
-	}
-	else
-	{
-		/* If tmp is null, that means, we have to insert new node at root. */
-		if(tmp == NULL)
-		{
-			node->left = state->root;
-			node->left->parent = node;
-
-			state->root = node;
-		}
-		else
-		{
-			node->left = tmp->right;
-			if(node->left)
-				node->left->parent = node;
-
-			tmp->right = node;
-			if(tmp->right)
-				tmp->right->parent = tmp;
-
-		}
-		state->right_most = node;
-	}
+    if(state->root == NULL)
+    {
+        state->root = node;
+        state->right_most = state->root;
+        return;
+    }
+    ParseNode* tmp = state->right_most;
+    while(p_cmp_nodes(tmp, node))
+        tmp = tmp->parent;
+    if(unary_function)
+    {
+        /* If tmp is null, that means, we have to insert new node at root. */
+        if(tmp == NULL)
+        {
+            node->right = state->root;
+            node->right->parent = node;
+
+            state->root = node;
+        }
+        else
+        {
+            node->right = tmp->right;
+            if(node->right)
+                node->right->parent = node;
+
+            tmp->right = node;
+            if(tmp->right)
+                tmp->right->parent = tmp;
+
+        }
+        state->right_most = node;
+        while(state->right_most->right != NULL)
+            state->right_most = state->right_most->right;
+    }
+    else
+    {
+        /* If tmp is null, that means, we have to insert new node at root. */
+        if(tmp == NULL)
+        {
+            node->left = state->root;
+            node->left->parent = node;
+
+            state->root = node;
+        }
+        else
+        {
+            node->left = tmp->right;
+            if(node->left)
+                node->left->parent = node;
+
+            tmp->right = node;
+            if(tmp->right)
+                tmp->right->parent = tmp;
+
+        }
+        state->right_most = node;
+    }
 }
 
 /* Insert binary node into the parse tree. */
 static void
 p_insert_into_tree(ParserState* state, ParseNode* node)
 {
-	p_insert_into_tree_all(state, node, 0);
+    p_insert_into_tree_all(state, node, 0);
 }
 
 /* Insert unary node into the parse tree. */
 static void
 p_insert_into_tree_unary(ParserState* state, ParseNode* node)
 {
-	p_insert_into_tree_all(state, node, 1);
+    p_insert_into_tree_all(state, node, 1);
 }
 
 /* Recursive call to free every node of parse-tree. */
 static void
 p_destroy_all_nodes(ParseNode* node)
 {
-	if(node == NULL)
-		return;
-	p_destroy_all_nodes(node->left);
-	p_destroy_all_nodes(node->right);
-	/* Don't call free for tokens, as they are allocated and freed in lexer. */
-	/* WARNING: If node->value is freed elsewhere, please assign it NULL before calling p_destroy_all_nodes(). */
-	if(node->value)
-		free(node->value);
-	free(node);
+    if(node == NULL)
+        return;
+    p_destroy_all_nodes(node->left);
+    p_destroy_all_nodes(node->right);
+    /* Don't call free for tokens, as they are allocated and freed in lexer. */
+    /* WARNING: If node->value is freed elsewhere, please assign it NULL before calling p_destroy_all_nodes(). */
+    if(node->value)
+        free(node->value);
+    free(node);
 }
 
 /* Create parser state. */
 ParserState*
 p_create_parser(const gchar* input, MPEquationOptions* options)
 {
-	ParserState* state;
-	state = (ParserState*) malloc(sizeof(ParserState));
-	assert(state != NULL);
-	state->lexer = l_create_lexer(input, state);
-	state->root = NULL;
-	state->depth_level = 0;
-	state->right_most = NULL;
-	state->options = options;
-	state->error = 0;
-	state->error_token = NULL;
-	return state;
+    ParserState* state;
+    state = (ParserState*) malloc(sizeof(ParserState));
+    assert(state != NULL);
+    state->lexer = l_create_lexer(input, state);
+    state->root = NULL;
+    state->depth_level = 0;
+    state->right_most = NULL;
+    state->options = options;
+    state->error = 0;
+    state->error_token = NULL;
+    return state;
 }
 
 static guint statement (ParserState*);
 guint
 p_parse(ParserState* state)
 {
-	guint ret;
-	LexerToken* token;
-	MPNumber* ans;
-	l_insert_all_tokens(state->lexer);
-	ret = statement(state);
-	token = l_get_next_token(state->lexer);
-	if(token->token_type == T_ASSIGN)
-	{
-		token = l_get_next_token(state->lexer);
-		if(token->token_type != PL_EOS)
-		{
-		/* Full string is not parsed. */
-			if(!state->error)
-				set_error(state, PARSER_ERR_INVALID, token->string);
-			return PARSER_ERR_INVALID;
-		}
-	}
-	if(token->token_type != PL_EOS)
-	{
-		/* Full string is not parsed. */
-		if(!state->error)
-			set_error(state, PARSER_ERR_INVALID, token->string);
-		return PARSER_ERR_INVALID;
-	}
-	if(ret == 0)
-		/* Input can't be parsed with grammar. */
-		return PARSER_ERR_INVALID;
-	ans = (MPNumber *) (*(state->root->evaluate))(state->root);
-	if(ans)
-	{
-		mp_set_from_mp(ans, &state->ret);
-		free(ans);
-		return PARSER_ERR_NONE;
-	}
-	return PARSER_ERR_INVALID;
+    guint ret;
+    LexerToken* token;
+    MPNumber* ans;
+    l_insert_all_tokens(state->lexer);
+    ret = statement(state);
+    token = l_get_next_token(state->lexer);
+    if(token->token_type == T_ASSIGN)
+    {
+        token = l_get_next_token(state->lexer);
+        if(token->token_type != PL_EOS)
+        {
+        /* Full string is not parsed. */
+            if(!state->error)
+                set_error(state, PARSER_ERR_INVALID, token->string);
+            return PARSER_ERR_INVALID;
+        }
+    }
+    if(token->token_type != PL_EOS)
+    {
+        /* Full string is not parsed. */
+        if(!state->error)
+            set_error(state, PARSER_ERR_INVALID, token->string);
+        return PARSER_ERR_INVALID;
+    }
+    if(ret == 0)
+        /* Input can't be parsed with grammar. */
+        return PARSER_ERR_INVALID;
+    ans = (MPNumber *) (*(state->root->evaluate))(state->root);
+    if(ans)
+    {
+        mp_set_from_mp(ans, &state->ret);
+        free(ans);
+        return PARSER_ERR_NONE;
+    }
+    return PARSER_ERR_INVALID;
 }
 
 /* Destroy parser state. */
 void
 p_destroy_parser(ParserState* state)
 {
-	/* If state has a parse tree, destroy it first. */
-	if(state->root)
-	{
-		p_destroy_all_nodes(state->root);
-	}
-	l_destroy_lexer(state->lexer);
-	free(state);
+    /* If state has a parse tree, destroy it first. */
+    if(state->root)
+    {
+        p_destroy_all_nodes(state->root);
+    }
+    l_destroy_lexer(state->lexer);
+    free(state);
 }
 
 /* LL (*) parser. Lookahead count depends on tokens. Handle with care. :P */
 static gboolean
 p_check_variable(ParserState* state, gchar* name)
 {
-	gint result = 0;
-
-	const gchar *c, *next;
-	gchar *buffer;
-	MPNumber temp;
-
-	if(!(state->get_variable))
-	{
-		return FALSE;
-	}
-
-	/* If defined, then get the variable */
-	if((*(state->get_variable))(state, name, &temp))
-	{
-		return TRUE;
-	}
-
-	/* If has more than one character then assume a multiplication of variables */
-	if(utf8_next_char(name)[0] != '\0')
-	{
-		result = 1;
-		buffer = (gchar*) malloc(sizeof(gchar) * strlen(name));
-		for(c = name; *c != '\0'; c = next)
-		{
-			next = utf8_next_char(c);
-			snprintf(buffer, next - c + 1, "%s", c);
-			if(!(*(state->get_variable))(state, buffer, &temp))
-			{
-				result = 0;
-				break;
-			}
-		}
-		free(buffer);
-	}
-	if(!result)
-	{
-		return FALSE;
-	}
-	return TRUE;
+    gint result = 0;
+
+    const gchar *c, *next;
+    gchar *buffer;
+    MPNumber temp;
+
+    if(!(state->get_variable))
+    {
+        return FALSE;
+    }
+
+    /* If defined, then get the variable */
+    if((*(state->get_variable))(state, name, &temp))
+    {
+        return TRUE;
+    }
+
+    /* If has more than one character then assume a multiplication of variables */
+    if(utf8_next_char(name)[0] != '\0')
+    {
+        result = 1;
+        buffer = (gchar*) malloc(sizeof(gchar) * strlen(name));
+        for(c = name; *c != '\0'; c = next)
+        {
+            next = utf8_next_char(c);
+            snprintf(buffer, next - c + 1, "%s", c);
+            if(!(*(state->get_variable))(state, buffer, &temp))
+            {
+                result = 0;
+                break;
+            }
+        }
+        free(buffer);
+    }
+    if(!result)
+    {
+        return FALSE;
+    }
+    return TRUE;
 }
 
 static guint
 statement(ParserState* state)
 {
-	LexerToken* token;
-	LexerToken* token_old;
-	ParseNode* node;
-	token = l_get_next_token(state->lexer);
-	if(token->token_type == T_VARIABLE)
-	{
-		token_old = token;
-		token = l_get_next_token(state->lexer);
-		if(token->token_type == T_ASSIGN)
-		{
-			/* VARIABLE = expression. */
-
-			node = p_create_node(state, token_old, p_make_precedence_p(state, P_NumberVariable), p_get_associativity(token_old), NULL, pf_none);
-			p_insert_into_tree(state, node);
-
-			node = p_create_node(state, token, 0, p_get_associativity(token), NULL, pf_set_var);
-			p_insert_into_tree(state, node);
-
-			if(!expression(state))
-				return 0;
-			return 1;
-		}
-		else if(token->token_type == T_IN)
-		{
-			/* UNIT in UNIT. */
-			l_roll_back(state->lexer);
-			l_roll_back(state->lexer);
-			if(!unit(state))
-				return 0;
-			l_get_next_token(state->lexer);
-
-			node = p_create_node(state, token, 0, p_get_associativity(token), NULL, pf_convert_1);
-			p_insert_into_tree(state, node);
-
-			if(!unit(state))
-				return 0;
-			return 1;
-		}
-		else if(token->token_type == T_SUP_NUMBER)
-		{
-			token = l_get_next_token(state->lexer);
-			if(token->token_type == T_IN)
-			{
-				/* UNIT in UNIT */
-				l_roll_back(state->lexer);
-				l_roll_back(state->lexer);
-				l_roll_back(state->lexer);
-				if(!unit(state))
-					return 0;
-				l_get_next_token(state->lexer);
-
-				node = p_create_node(state, token, 0, p_get_associativity(token), NULL, pf_convert_1);
-				p_insert_into_tree(state, node);
-
-				if(!unit(state))
-					return 0;
-				return 1;
-			}
-			else
-			{
-				l_roll_back(state->lexer);
-				l_roll_back(state->lexer);
-				l_roll_back(state->lexer);
-				if(!expression(state))
-					return 0;
-				return 1;
-			}
-		}
-		else
-		{
-			l_roll_back(state->lexer);
-			l_roll_back(state->lexer);
-			if(!expression(state))
-				return 0;
-			return 1;
-		}
-	}
-	else if(token->token_type == T_NUMBER)
-	{
-		token_old = token;
-		token = l_get_next_token(state->lexer);
-		if(token->token_type == T_VARIABLE)
-		{
-			token = l_get_next_token(state->lexer);
-			if(token->token_type == T_IN)
-			{
-				/* NUMBER UNIT in UNIT */
-				l_roll_back(state->lexer);
-				l_roll_back(state->lexer);
-
-				node = p_create_node(state, token_old, p_make_precedence_t(state, token_old->token_type), p_get_associativity(token), NULL, pf_constant);
-				p_insert_into_tree(state, node);
-
-				if(!unit(state))
-					return 0;
-				token = l_get_next_token(state->lexer);
-
-				node = p_create_node(state, token, 0, p_get_associativity(token), NULL, pf_convert_number);
-				p_insert_into_tree(state, node);
-
-				if(!unit(state))
-					return 0;
-				return 1;
-			}
-			else if(token->token_type == T_SUP_NUMBER)
-			{
-				token = l_get_next_token(state->lexer);
-				if(token->token_type == T_IN)
-				{
-					/* NUMBER UNIT in UNIT */
-					l_roll_back(state->lexer);
-					l_roll_back(state->lexer);
-					l_roll_back(state->lexer);
-
-					node = p_create_node(state, token_old, p_make_precedence_t(state, token_old->token_type), p_get_associativity(token), NULL, pf_constant);
-					p_insert_into_tree(state, node);
-
-					if(!unit(state))
-						return 0;
-					token = l_get_next_token(state->lexer);
-
-					node = p_create_node(state, token, 0, p_get_associativity(token), NULL, pf_convert_number);
-					p_insert_into_tree(state, node);
-
-					if(!unit(state))
-						return 0;
-					return 1;
-				}
-				else
-				{
-					l_roll_back(state->lexer);
-					l_roll_back(state->lexer);
-					l_roll_back(state->lexer);
-					l_roll_back(state->lexer);
-					if(!expression(state))
-						return 0;
-					return 1;
-				}
-			}
-			else
-			{
-				l_roll_back(state->lexer);
-				l_roll_back(state->lexer);
-				l_roll_back(state->lexer);
-				if(!expression(state))
-					return 0;
-				return 1;
-			}
-		}
-		else
-		{
-			l_roll_back(state->lexer);
-			l_roll_back(state->lexer);
-			if(!expression(state))
-				return 0;
-			return 1;
-		}
-	}
-	else
-	{
-		l_roll_back(state->lexer);
-		if(!expression(state))
-			return 0;
-		return 1;
-	}
+    LexerToken* token;
+    LexerToken* token_old;
+    ParseNode* node;
+    token = l_get_next_token(state->lexer);
+    if(token->token_type == T_VARIABLE)
+    {
+        token_old = token;
+        token = l_get_next_token(state->lexer);
+        if(token->token_type == T_ASSIGN)
+        {
+            /* VARIABLE = expression. */
+
+            node = p_create_node(state, token_old, p_make_precedence_p(state, P_NumberVariable), p_get_associativity(token_old), NULL, pf_none);
+            p_insert_into_tree(state, node);
+
+            node = p_create_node(state, token, 0, p_get_associativity(token), NULL, pf_set_var);
+            p_insert_into_tree(state, node);
+
+            if(!expression(state))
+                return 0;
+            return 1;
+        }
+        else if(token->token_type == T_IN)
+        {
+            /* UNIT in UNIT. */
+            l_roll_back(state->lexer);
+            l_roll_back(state->lexer);
+            if(!unit(state))
+                return 0;
+            l_get_next_token(state->lexer);
+
+            node = p_create_node(state, token, 0, p_get_associativity(token), NULL, pf_convert_1);
+            p_insert_into_tree(state, node);
+
+            if(!unit(state))
+                return 0;
+            return 1;
+        }
+        else if(token->token_type == T_SUP_NUMBER)
+        {
+            token = l_get_next_token(state->lexer);
+            if(token->token_type == T_IN)
+            {
+                /* UNIT in UNIT */
+                l_roll_back(state->lexer);
+                l_roll_back(state->lexer);
+                l_roll_back(state->lexer);
+                if(!unit(state))
+                    return 0;
+                l_get_next_token(state->lexer);
+
+                node = p_create_node(state, token, 0, p_get_associativity(token), NULL, pf_convert_1);
+                p_insert_into_tree(state, node);
+
+                if(!unit(state))
+                    return 0;
+                return 1;
+            }
+            else
+            {
+                l_roll_back(state->lexer);
+                l_roll_back(state->lexer);
+                l_roll_back(state->lexer);
+                if(!expression(state))
+                    return 0;
+                return 1;
+            }
+        }
+        else
+        {
+            l_roll_back(state->lexer);
+            l_roll_back(state->lexer);
+            if(!expression(state))
+                return 0;
+            return 1;
+        }
+    }
+    else if(token->token_type == T_NUMBER)
+    {
+        token_old = token;
+        token = l_get_next_token(state->lexer);
+        if(token->token_type == T_VARIABLE)
+        {
+            token = l_get_next_token(state->lexer);
+            if(token->token_type == T_IN)
+            {
+                /* NUMBER UNIT in UNIT */
+                l_roll_back(state->lexer);
+                l_roll_back(state->lexer);
+
+                node = p_create_node(state, token_old, p_make_precedence_t(state, token_old->token_type), p_get_associativity(token), NULL, pf_constant);
+                p_insert_into_tree(state, node);
+
+                if(!unit(state))
+                    return 0;
+                token = l_get_next_token(state->lexer);
+
+                node = p_create_node(state, token, 0, p_get_associativity(token), NULL, pf_convert_number);
+                p_insert_into_tree(state, node);
+
+                if(!unit(state))
+                    return 0;
+                return 1;
+            }
+            else if(token->token_type == T_SUP_NUMBER)
+            {
+                token = l_get_next_token(state->lexer);
+                if(token->token_type == T_IN)
+                {
+                    /* NUMBER UNIT in UNIT */
+                    l_roll_back(state->lexer);
+                    l_roll_back(state->lexer);
+                    l_roll_back(state->lexer);
+
+                    node = p_create_node(state, token_old, p_make_precedence_t(state, token_old->token_type), p_get_associativity(token), NULL, pf_constant);
+                    p_insert_into_tree(state, node);
+
+                    if(!unit(state))
+                        return 0;
+                    token = l_get_next_token(state->lexer);
+
+                    node = p_create_node(state, token, 0, p_get_associativity(token), NULL, pf_convert_number);
+                    p_insert_into_tree(state, node);
+
+                    if(!unit(state))
+                        return 0;
+                    return 1;
+                }
+                else
+                {
+                    l_roll_back(state->lexer);
+                    l_roll_back(state->lexer);
+                    l_roll_back(state->lexer);
+                    l_roll_back(state->lexer);
+                    if(!expression(state))
+                        return 0;
+                    return 1;
+                }
+            }
+            else
+            {
+                l_roll_back(state->lexer);
+                l_roll_back(state->lexer);
+                l_roll_back(state->lexer);
+                if(!expression(state))
+                    return 0;
+                return 1;
+            }
+        }
+        else
+        {
+            l_roll_back(state->lexer);
+            l_roll_back(state->lexer);
+            if(!expression(state))
+                return 0;
+            return 1;
+        }
+    }
+    else
+    {
+        l_roll_back(state->lexer);
+        if(!expression(state))
+            return 0;
+        return 1;
+    }
 }
 
 static guint
 unit(ParserState* state)
 {
-	LexerToken* token;
-	LexerToken* token_old;
-	ParseNode* node;
-	token = l_get_next_token(state->lexer);
-	if(token->token_type == T_VARIABLE)
-	{
-		token_old = token;
-		token = l_get_next_token(state->lexer);
-		if(token->token_type == T_SUP_NUMBER)
-		{
-			/* VARIABLE POWER */
-
-			node = p_create_node(state, token_old, p_make_precedence_t(state, token_old->token_type), p_get_associativity(token_old), pf_make_unit(token_old->string, token->string), pf_none);
-			p_insert_into_tree(state, node);
-
-			return 1;
-		}
-		else
-		{
-			l_roll_back(state->lexer);
-			/* VARIABLE */
-
-			node = p_create_node(state, token_old, p_make_precedence_t(state, token_old->token_type), p_get_associativity(token_old), NULL, pf_none);
-			p_insert_into_tree(state, node);
-
-			return 1;
-		}
-	}
-	else
-	{
-		l_roll_back(state->lexer);
-		return 0;
-	}
+    LexerToken* token;
+    LexerToken* token_old;
+    ParseNode* node;
+    token = l_get_next_token(state->lexer);
+    if(token->token_type == T_VARIABLE)
+    {
+        token_old = token;
+        token = l_get_next_token(state->lexer);
+        if(token->token_type == T_SUP_NUMBER)
+        {
+            /* VARIABLE POWER */
+
+            node = p_create_node(state, token_old, p_make_precedence_t(state, token_old->token_type), p_get_associativity(token_old), pf_make_unit(token_old->string, token->string), pf_none);
+            p_insert_into_tree(state, node);
+
+            return 1;
+        }
+        else
+        {
+            l_roll_back(state->lexer);
+            /* VARIABLE */
+
+            node = p_create_node(state, token_old, p_make_precedence_t(state, token_old->token_type), p_get_associativity(token_old), NULL, pf_none);
+            p_insert_into_tree(state, node);
+
+            return 1;
+        }
+    }
+    else
+    {
+        l_roll_back(state->lexer);
+        return 0;
+    }
 }
 
 static guint
 expression(ParserState* state)
 {
-	if(!expression_1(state))
-		return 0;
-	if(!expression_2(state))
-		return 0;
-	return 1;
+    if(!expression_1(state))
+        return 0;
+    if(!expression_2(state))
+        return 0;
+    return 1;
 }
 
 static guint
 expression_1(ParserState* state)
 {
-	LexerToken* token;
-	ParseNode* node;
-	token = l_get_next_token(state->lexer);
-	if(token->token_type == PL_EOS
-	 ||token->token_type == T_ASSIGN)
-	{
-		l_roll_back(state->lexer);
-		return 0;
-	}
-	if(token->token_type == T_L_R_BRACKET)
-	{
-		state->depth_level++;
-		if(!expression(state))
-			return 0;
-		token = l_get_next_token(state->lexer);
-		if(token->token_type == T_R_R_BRACKET)
-		{
-			state->depth_level--;
-			return 1;
-		}
-		else
-		//Expected ")" here...
-			return 0;
-	}
-	else if(token->token_type == T_L_S_BRACKET)
-	{
-		state->depth_level++;
-
-		/* Give round, preference of P_Unknown aka 0, to keep it on the top of expression. */
-
-		node = p_create_node(state, token, p_make_precedence_p(state, P_Unknown), p_get_associativity(token), NULL, pf_do_round);
-		p_insert_into_tree_unary(state, node);
-
-		if(!expression(state))
-			return 0;
-		token = l_get_next_token(state->lexer);
-		if(token->token_type == T_R_S_BRACKET)
-		{
-			state->depth_level--;
-			return 1;
-		}
-		else
-		//Expected "]" here...
-			return 0;
-	}
-	else if(token->token_type == T_L_C_BRACKET)
-	{
-		state->depth_level++;
-
-		/* Give fraction, preference of P_Unknown aka 0, to keep it on the top of expression. */
-
-		node = p_create_node(state, token, p_make_precedence_p(state, P_Unknown), p_get_associativity(token), NULL, pf_do_fraction);
-		p_insert_into_tree_unary(state, node);
-
-		if(!expression(state))
-			return 0;
-		token = l_get_next_token(state->lexer);
-		if(token->token_type == T_R_C_BRACKET)
-		{
-			state->depth_level--;
-			return 1;
-		}
-		else
-		//Expected "}" here...
-			return 0;
-	}
-	else if(token->token_type == T_ABS)
-	{
-		state->depth_level++;
-
-		/* Give abs, preference of P_Unknown aka 0, to keep it on the top of expression. */
-
-		node = p_create_node(state, token, p_make_precedence_p(state, P_Unknown), p_get_associativity(token), NULL, pf_do_abs);
-		p_insert_into_tree_unary(state, node);
-
-		if(!expression(state))
-			return 0;
-		token = l_get_next_token(state->lexer);
-		if(token->token_type == T_ABS)
-		{
-			state->depth_level--;
-			return 1;
-		}
-		else
-		//Expected "|" here...
-			return 0;
-	}
-	else if(token->token_type == T_NOT)
-	{
-		/* NOT expression */
-
-		node = p_create_node(state, token, p_make_precedence_p(state, P_Not), p_get_associativity(token), NULL, pf_do_not);
-		p_insert_into_tree_unary(state, node);
-
-		if(!expression(state))
-			return 0;
-		return 1;
-	}
-	else if(token->token_type == T_NUMBER)
-	{
-		/* NUMBER */
-
-		node = p_create_node(state, token, p_make_precedence_t(state, token->token_type), p_get_associativity(token), NULL, pf_constant);
-		p_insert_into_tree(state, node);
-
-		token = l_get_next_token(state->lexer);
-		l_roll_back(state->lexer);
-
-		if(token->token_type == T_FUNCTION
-		 ||token->token_type == T_VARIABLE
-		 ||token->token_type == T_SUB_NUMBER
-		 ||token->token_type == T_ROOT
-		 ||token->token_type == T_ROOT_3
-		 ||token->token_type == T_ROOT_4)
-		{
-			/* NUMBER variable. */
-
-			node = p_create_node(state, NULL, p_make_precedence_p(state, P_Multiply), p_get_associativity_p(P_Multiply), NULL, pf_do_multiply);
-			p_insert_into_tree(state, node);
-
-			if(!variable(state))
-				return 0;
-			else
-				return 1;
-		}
-		else
-		{
-			return 1;
-		}
-	}
-	else if(token->token_type == T_L_FLOOR)
-	{
-		state->depth_level++;
-		/* Give floor, preference of P_Unknown aka 0, to keep it on the top of expression. */
-
-		node = p_create_node(state, NULL, p_make_precedence_p(state, P_Unknown), p_get_associativity_p(P_Unknown), NULL, pf_do_floor);
-		p_insert_into_tree_unary(state, node);
-
-		if(!expression(state))
-			return 0;
-		token = l_get_next_token(state->lexer);
-		if(token->token_type == T_R_FLOOR)
-		{
-			state->depth_level--;
-			return 1;
-		}
-		else
-		//Expected ⌋ here...
-			return 0;
-	}
-	else if(token->token_type == T_L_CEILING)
-	{
-		state->depth_level++;
-		/* Give ceiling, preference of P_Unknown aka 0, to keep it on the top of expression. */
-
-		node = p_create_node(state, NULL, p_make_precedence_p(state, P_Unknown), p_get_associativity_p(P_Unknown), NULL, pf_do_ceiling);
-		p_insert_into_tree_unary(state, node);
-
-		if(!expression(state))
-			return 0;
-		token = l_get_next_token(state->lexer);
-		if(token->token_type == T_R_CEILING)
-		{
-			state->depth_level--;