What is 吗 doing in 你有什么事吗？ In a Chinese lesson, I came across these sentences:



你有什么事吗？
Nǐ yǒu shénme shì mɑ?




你有什么事？
Nǐ yǒu shénme shì?



And both were translated as:

What's the matter?

I don't understand 1. Without 吗, I understand it literally as: You have what matter?. From Advanced yes-no questions in resources.allsetlearning, I know you can add 吗 to a sentence with another question word to convert it to a confirmation question. However, I don't see how 1. becomes a yes-no question. Which yes-no question that would be?
In Chinese grammar, words as 什么 are commonly known as interrogative substitutes, they substitute the word that should be found in the answer.
Therefore, they have inherent interrogative semantics, and don't require interrogative particles at the end of the sentence.
For example:

你在吃什么？What are you eating?
我在吃麻婆豆腐 I'm eating &quot;mapo&quot; tofu.

As you can see, the interrogative substitute and the noun phrase that answers the question are in the same place, and there's no 吗。
When you do place an interrogative particle at the end of the sentence, the interrogative substitute plays the role of an indefinite pronoun. We can summarize this in the following table:

什么，什么东西 -- what? -- anything -- (thing)
哪里，什么地方 -- where？-- anywhere -- (place)
谁，什么人 -- who? -- anyone -- (person)

A couple examples more:

你包里有什么东西？What's in your bag?
你包里有什么东西吗？Is there anything in your bag?


这个周末你准备去什么地方？Where do you plan to go this weekend?
这个周末你准备去什么地方吗? Do you plan to go anywhere this weekend?


谁认识他？Who knows him?
谁认识他吗？Does anyone know him?


So your sentence:

你有什么事吗 (interrogative + particle = indefinite) do you have anything? (= is there something wrong?)


你有什么事 (interrogative) what do you have? (= what's the matter)

At the end of the day, in this particular example both sentences can actually be translated as &quot;what's the matter&quot;, since in Chinese 有事 has an idiomatic meaning, but in general:
interrogative substitute + 吗 = indefinite pronoun.