Take the following statement as an example: a<b>(c). Syntactically, this statement can be parsed by the following two rules:
- A boolean expression comparing
a, b, and c.
- An invocation of function
a, with a parameter called c and a placeholder called b.
Admittedly, it is rather rare to place a single operand inside parentheses; however, since Rouge is an educational language, it should not be ruled out that a user might want to write a program containing an expression like that.
Technically, this ambiguity can be resolved during static analysis by checking whether a is saved in the symbol table as a function or not. However, this still wouldn't work when a is meant to be invoked but has not been defined. In this case, the interpreter would run the static analysis for boolean expressions, even though the user intended to perform a function call.
Therefore, this ambiguity should be resolved on the syntactic level. One solution to this problem involves forcing the user to use parenthesis when chaining multiple operators in a single boolean expression. For instance, the above statement (if it were intended to be a boolean expression) would have to be rewritten like so:
(a<b)>(c) or a<(b>c)
Take the following statement as an example:
a<b>(c). Syntactically, this statement can be parsed by the following two rules:a,b, andc.a, with a parameter calledcand a placeholder calledb.Admittedly, it is rather rare to place a single operand inside parentheses; however, since Rouge is an educational language, it should not be ruled out that a user might want to write a program containing an expression like that.
Technically, this ambiguity can be resolved during static analysis by checking whether
ais saved in the symbol table as a function or not. However, this still wouldn't work whenais meant to be invoked but has not been defined. In this case, the interpreter would run the static analysis for boolean expressions, even though the user intended to perform a function call.Therefore, this ambiguity should be resolved on the syntactic level. One solution to this problem involves forcing the user to use parenthesis when chaining multiple operators in a single boolean expression. For instance, the above statement (if it were intended to be a boolean expression) would have to be rewritten like so:
(a<b)>(c)ora<(b>c)