Sie sind auf Seite 1von 3

Assignment 5

1. The context-free part of our language can be described by:


expr expr plus term
expr expr minus term
expr term
term term mult factor
term term div factor
term factor
factor identifier
factor integer
factor openpar expr closepar
openpar (
closepar )
mult*
div/
plus+
minusintegerd (d is {0, . . . , 9})
integer integer d (d is {0, . . . , 9})
identifierc (c is{a, . . . , z})
identifierc identifier (c is {a, . . . , z})
The start symbol is expr
Finish the derivation:
expr ab + 85 * c
Solution:-

-> expr
-> expr plus term> term plus term> factor plus term
-> identifier plus term
-> identifier plus term mult factor
-> identifier plus factor mult factor
-> identifier plus integer mult factor
-> identifier plus integer mult identifier
-> a identifier plus integer mult identifier

-> ab plus integer mult identifier


-> ab +integer mult identifier
-> ab + 8 integer mult identifier
-> ab+85 mult identifier
-> ab + 85 *identifier
-> ab + 85 * c

2. Java eliminated many unsafe features of C++, please list several unsafe
features of C++ and how Java improves them.
All system definitions are characterized in the collection of the class. Hence, in C++ it would resemble all the capacities
are inlined, however they're not (inlines are noted later).All system definitions are characterized in the collection of the
class. There's no degree determination administrator :: in Java. Java utilizes the speck for everything, except can escape
with it since you can characterize components just inside a class. Indeed the system definitions should dependably happen
inside a class, so there is no requirement for extension determination there either. One spot where you'll recognize the
distinction is in the calling of static strategies: you say ClassName.methodName( );. Moreover, bundle names are created
utilizing the dab, and to perform a sort of C++ #include you utilize the import magic word. Case in point: import
java.awt.*;. (#include does not straightforwardly guide to import, however it has a comparable vibe to it).Java, in the same
way as C++, has primitive sorts for proficient access. In Java, these are boolean, roast, byte, short, int, long, buoy, and
twofold. All the primitive sorts have indicated sizes that are machine autonomous for transportability. (This must have
some effect on execution, changing with the machine.) Type-checking and sort prerequisites are much more tightly in Java.
The aftereffect of an articulation like X + Y must be utilized; you can't simply say "X + Y" for the symptom. The singe sort
utilizes the global 16-bit Unicode character set, so it can consequently speak to most national characters. Static cited strings
are consequently changed over into String items. There is no free static character cluster string like there is in C and C++.
Java includes the triple right move >>> to go about as a "coherent" right move by embeddings zeroes at the top end; the
>> embeds the sign bit as it moves (a "math" shift).
In spite of the fact that they appear to be comparative, clusters have an altogether different structure and conduct in Java
than they do in C++. There's a read-just length part that lets you know how enormous the exhibit is, and run-time checking
tosses a special case in the event that you go too far out. All shows are made on the stack, and you can dole out one show to
another (the exhibit handle is essentially duplicated). The exhibit identifier is a top of the line object, with the greater part
of the systems regularly accessible to all different articles. All objects of non-primitive sorts can be made just through new.
There's no proportionate to making non-primitive items "on the stack" as in C++. All primitive sorts can be made just on
the stack, without new. There are wrapper classes for all primitive classes with the goal that you can make proportionate
pile based articles through new. (Shows of primitives are an extraordinary case: they can be dispensed by means of total
instatement as in C++, or by utilizing new.) No forward statements are vital in Java. In the event that you need to utilize a
class or a technique before it is characterized, you just utilize it the compiler guarantees that the proper definition exists.
Hence you don't have any of the forward referencing issues that you do in C++. Java has no preprocessor. On the off
chance that you need to utilize classes as a part of another library, you say import and the name of the library. There are no
preprocessor-like macros. Java uses bundles set up of namespaces. The name issue is dealt with by placing everything into
a class and by utilizing an office called "bundles" that performs the identical namespace separation for class names.
Bundles likewise gather library parts under a solitary library name. You basically import a bundle and the compiler deals
with the rest. Article handles characterized as class individuals are naturally introduced to invalid. Instatement of primitive
class information individuals is ensured in Java; on the off chance that you don't expressly instate them they get a default
esteem (a zero or equal). You can instate them unequivocally, either when you characterize them in the class or in the
constructor. The sentence structure bodes well than that for C++, and is steady for static and non-static individuals alike.
You don't have to remotely characterize capacity for static individuals as you do in C++. There are no Java pointers in the
feeling of C and C++. When you make an article with new, you get back a reference (which I've been calling a handle in
this book). Case in point: String s = new String("howdy"); On the other hand, not at all like C++ references that must be

introduced when made and can't be bounce back to an alternate area, Java references don't need to be bound at the purpose
of creation. They can likewise be bounce back freely, which kills some piece of the requirement for pointers. The other
explanation behind pointers in C and C++ is to have the capacity to point at wherever in memory at all (which makes them
perilous, which is the reason Java doesn't bolster them). Pointers are regularly seen as an effective approach to travel
through an exhibit of primitive variables; Java shows permit you to do that in a more secure design. A definitive answer for
pointer issues is local systems (talked about in Appendix A). Passing pointers to systems isn't an issue subsequent to there
are no worldwide capacities, just classes, and you can pass references to questions. The Java dialect promoters at first said
"No pointers!", yet when numerous software engineers addressed how you can function without pointers, the promoters
started saying "Confined pointers." You can decide whether its "truly" a pointer or not. In any occasion, there's no pointer
number juggling Java has built-in multithreading support. Theres a Thread class that you inherit to create a new thread
(you override the run( ) method). Mutual exclusion occurs at the level of objects using the synchronized keyword as a type
qualifier for methods. Only one thread may use a synchronized method of a particular object at any one time. Put another
way, when a synchronized method is entered, it first "locks" the object against any other synchronized method using that
object and "unlocks" the object only upon exiting the method. There are no explicit locks; they happen automatically. Here
are various C++ highlights that Java does not bolster. Now and again, a particular C++ offer essentially didn't identify with
the Java environment. In different cases, the creators of Java dispensed with a portion of the duplication of highlights that
exists in C++. In still different occasions, a highlight of C++ is not bolstered by Java in light of the fact that it was
esteemed excessively risky for Internet applets.
Maybe the single greatest contrast in the middle of Java and C++ is that Java does not bolster pointers. As a C++ developer
you realize that the pointer is one of C++'s most intense and critical dialect highlights. It is additionally one of its most
hazardous when utilized dishonorably. Pointers don't exist in Java for two reasons:
Pointers are characteristically unstable. For instance, utilizing a C++-style pointer, it is conceivable to obtain entrance to
memory addresses outside a program's code and information. A malignant system could make utilization of this to harm the
framework, perform unapproved
gets to, (for example, acquiring passwords), or overall damage security limitations.
Regardless of the possibility that pointers could be confined to the restrictions the Java run-time framework (which is
hypothetically conceivable, since Java projects are deciphered), the fashioners of Java accepted that they were inalienably
troublesome. Note Since pointers don't exist in Java, neither does the -> operator.
Here are a couple of a greater amount of the most essential "oversights":
Java does exclude structures or unions. These were felt to be repetitive subsequent to the class includes them.
Java does not bolster administrator over-burdening. Administrator over-burdening is in some cases a wellspring of
vagueness in a C++ program, and the Java configuration group felt that it causes more inconvenience than profit.
Java does not exclude a preprocessor nor does it bolster the preprocessor orders. The preprocessor assumes a less essential
part in C++ than it does in C. The architects of Java felt that it was time to kill it altogether.
Java does not perform any programmed sort changes that outcome in a loss of exactness. Case in point, a change from long
whole number to number must be unequivocally thrown. All the code in a Java system is embodied inside one or more
classes. Consequently, Java does not have what you typically consider as worldwide variables or worldwide capacities.
Java does not permit default contentions. In C++, you may determine an esteem that a
Parameter will have when there is no contention comparing to that parameter when the capacity is conjured. This is not
permitted in Java. Java does not bolster the legacy of various super classes by a subclass. In spite of the fact that Java
bolsters constructors, it doesn't have destructors. It does, on the other hand, include the conclude ( ) capacity.
Java does not bolster typedef. It is impractical to announce unsigned whole numbers in Java.Java does not permit the goto.
Java does not have the erase administrator. The << and >> in Java are not over-burden for I/O operations.
In Java, items are gone by reference just. In C++, items may be cruised by esteem or by reference.

References:Comparison of java and C++ retrieved from en.wikipedia.org/wiki/Comparison_of_Java_and_C%2B%2B


Java better then C++ retrieved from http://stackoverflow.com/questions/1085134/why-is-c-relatively-harder-to-usebad-choice-for-a-beginner
Numeric performance in C, C# and Java Peter Sestof IT University of Copenhagen Denmark
https://www.itu.dk/people/sestoft/papers/numericperformance.pdf
Java vs C++ retrieved from http://c2.com/cgi/wiki?JavaVsCpp

Das könnte Ihnen auch gefallen