I am learning context-free grammar, and I don't understand how to identity expression, factor and term in a programming language like C or C++.
Suppose we have an assignment statement, id := E, where E is any arithmetic expression.
What is a term? What is an expression? and What is a factor in an actual piece of code?
We can have
int i = 3, j = 14
int i = 3 + j * 14;
Thank you very much.
The "factor", "term" and "expression" concepts come from math and don't really have to do with programming languages.
Factors are things you multiply:
1*2*(3+4)
Terms are things you add:
1 + 2 + (3*4)
And expressions are for the whole result
1 + 3 * 7
In context-free language parsing you use these distinctions to organize the precedences between operators. So an expression is made of a sum of terms and a term is made of a product of factors and a factor is either a number or a parenthesized subexpression.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With