Cheap and Secure Web Hosting Provider : See Now

Distinction between statements, declarations, and expressions in formal grammar

, , No Comments
Problem Detail: 

I am learning basic grammar and parsing concepts and ran into this statement:

Nonterminal symbols represent syntactic entities: statements, declarations, or expressions.

But the three terms (statements, declarations, expressions) were not really defined. I have plenty of programming experience so I have a fairly intuitive grasp of the terms, but I'm wondering, from a language grammar standpoint, what are the generally accepted definitions for each? When I searched online I found several language-specific discussions but nothing that gave a general definition of these terms that can apply across any language.

Are there such definitions out there? Thanks.

Asked By : Dave
Answered By : Yuval Filmus

These are informal terms. For example, in the C language:

  1. Statements are things like x = 3;.
  2. Declarations are things like int x;.
  3. Expressions are things like x * y.

So declarations are a particular type of statements, and expressions appear in statements.

A better formulation of the statement you quoted would be:

Nonterminal symbols represent syntactic entities such as statements, declarations, or expressions.

Best Answer from StackOverflow

Question Source : http://cs.stackexchange.com/questions/65433

3200 people like this

 Download Related Notes/Documents

0 comments:

Post a Comment

Let us know your responses and feedback