[antlr-interest] Operator overloading?
Randall R Schulz
rschulz at sonic.net
Thu Feb 22 14:21:35 PST 2007
Vladimir,
On Thursday 22 February 2007 14:02, Vladimir Gusev wrote:
> Hello,
>
> Is there a way to implement in my language operator overloading using
> ANTLR? I would appreciate any thoughts about this.
Operator overloading is really not a syntactic aspect of any given
programming language (that I know of). It's more a matter of symbol
table organization and semantic actions to verify that a fragment of
code that is (purely) syntactically valid is actually grammatical or
legal in the larger sense of the rules for valid programs of that
language.
For example, in Java the methods in a (putative) method overload set
must each be distinct from all others (in that overload set) without
regard to their return types (i.e., their argument signatures must all
be distinct). It would probably not make sense (or even be possible) to
try to encode this rule syntactically.
Instead, the parser would just make sure the parentheses, argument
type / argument name pairs, commas, etc. were lexically and
syntactically valid. Then, once a syntactically correct class
definition was parsed, a later pass of the compiler (or verifier or
translator, etc.) would verify the aforementioned rule, along with all
the other non-syntactic rules governing valid Java programs.
> Thanks.
>
> Vladimir
Randall Schulz
More information about the antlr-interest
mailing list