Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do Java, C++, C#, etc. get around this particular syntactic ambiguity with < and >?

I used to think C++ was the "weird" one with all the ambiguities with < and >, but after trying to implement a parser I think I found an example which breaks just about every language that uses < and > for generic types:

f(g<h, i>(j)); 

This could be syntactically either interpreted as a generic method call (g), or it could be interpreted as giving f the results of two comparisons.

How do such languages (especially Java, which I thought was supposed to be LALR(1)-parsable?) get around this syntactic ambiguity?

I just can't imagine any non-hacky/context-free way of dealing with this, and I'm baffled at how any such language can be context-free, let alone LALR(1)-parsable...

(It's worth noting that even a GLR parser can't return a single parse for this statement with no context!!)

like image 519
user541686 Avatar asked Jan 19 '13 08:01

user541686


People also ask

How Java is different from C and C?

C is a compiled language that is it converts the code into machine language so that it could be understood by the machine or system. Java is an Interpreted language that is in Java, the code is first transformed into bytecode and that bytecode is then executed by the JVM (Java Virtual Machine).

What is Java C and C++?

C++ and Java both are object-oriented programming languages. Yet, both languages differ from each other in many ways. C++ is derived from C and has the features of both procedural and object-oriented programming languages. C++ was designed for application and System development.

What is the use of C C++ Java?

C++ C++ is an object-oriented, general-purpose, programming language developed by Bjarne Stroustrup at Bell Labs in 1979. It is based on C language or we can say that it is an extension of C language. It is used to develop high-performance applications.

Is Java built on C or C++?

The syntax of Java is largely influenced by C++ and C. Unlike C++, which combines the syntax for structured, generic, and object-oriented programming, Java was built almost exclusively as an object-oriented language.


1 Answers

a generic method call in java would be <h,i>g(j) so there is no ambiguity :)

like image 72
Zubzub Avatar answered Oct 04 '22 14:10

Zubzub