So, suppose we have such a grammar:
Program β (Definitions | lambda)
Definitions-> Definitions Definitions
Definitions-> "int" Definition ";" | "int" Definition, Definition ";"
Definition β Name "=" Expression
Expression-> Term "+" Expression
Expression-> Expression "-" Term
Expression-> Expression "*" Factor
Deadline β "3" | "fourteen"
Factor β "3" | "fourteen"
Expression β "3" | "fourteen"
Note that my trailing characters are enclosed in quotation marks, and I omit the part where Name is defined as a combination of letters and numbers and underscores starting with a letter or underscore :)
So in your example:
Line 1 int i = 3, j = 14;
Line 2 int i = 3 + j * 14;
i and j are Names. 3, 14 (line 1) and 3 + j * 14 (line 2) are expressions. Then, in line 2, 3 is the term, j * 14 is an expression, j is a factor and 14 is a factor :)
AlexK source share