Can you decide grammaticality from the sentence alone?

I would like a generative BNF-style complete description for English grammar. Some of the more subtle stuff leads to awkward questions of grammaticality (a complete answer to this question, and all related questions, is a publication with a complete description of a comprehensible and comprehensive formal grammar which generates exactly the set of grammatical English sentences):

Here is question 1: is grammaticality of verbs ever dependent on external context from other sentences? If so, then those constructions obviously require some semantics.

The two sentences below are the context

  1. John smiled at Lisa at Kinko's.
  2. John asked Lisa for advice at Kinko's.

After either 1 or 2, you say:

  • I did what John did at Kinkos at James
  • I did what John did at Kinkos of my friend

I believe the second form is certainly not grammatical in case 1. How about case 2? I am not sure if the first sentence is grammatical even in case 1. Should they be

  • I did what John did to Lisa at Kinkos to James?

In other words, do the arguments have to match "do" or the verb that is implied by context by the "do"?

More generally, are there any cases where the grammaticality of a sentence requires looking at other sentences for context?


Upon further reflection, and Ron's response to my comment, I did want to expand my comment to an answer.

In other words, do the arguments have to match "do" or the verb that is implied by context by the "do"?

"Do" is a special verb that usually does not stand alone. Consider these exchanges:

"Did you meet Patty?" "I did, at the mall."

"Did you go with Patty?" "I did, to the mall."

The responses are really just ellipsis. The full thoughts are:

"I did meet Patty at the mall."

"I did go with Patty to the mall."

Despite the omission of the helping verb, the preposition still needs to match it in the ellipse or it will sound wrong.

Now something closer to your example:

I did what Patty did, at the mall. (Patty put up some posters for the musical)

I did what Patty did, to the mall. (Patty vandalized the theater)

Depending on what Patty did, either could be correct.

So I guess the short answer is yes: context matters.

However, in all of these situations, the context you need comes from the speaker's intent not from the surrounding sentences. When I say "what Patty did" I could be talking about something that happened months or years ago. When I make an ellipsis in thought, the context necessary to decipher that ellipsis may or may not be present in the preceding sentences - it may hearken back to something earlier in the conversation.