Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Document preview thumbnail
Preview 3 out of 19 pages
Exam (elaborations)

CS 326 Final Exam 2025

Document preview thumbnail
Preview 3 out of 19 pages

Generate a Grammar that is Syntactically Valid, but show an input string that would not type check. (test question from subprograms slide part 2) - Correct Ans-e = expression f = factor start - e ';' e - e +/- f | f f - f */ / atom | atom atom - string | int "Bob" / 26 ; //could be valid string if you want it to be it is syntactically valid but semantically drugs. What is "auto-boxing" - Correct Ans-Conversion between primitive types and the corresponding wrapper classes is automatic. ie. int a = 10; Integer b = a; //Auto boxing (int to Integer) int c = b; // Unboxing (Integer to int) ie. Primitive Data Types: These are the basic data types in Java such as 'int' , 'double', 'char', and 'boolean'. They are not objects and do not belong to any class. They are stored efficiently and have a lower memory footprint. Wrapper Classes: for every primitive data type in Java, there is a corresponding wrapper class, like 'Integer' for 'int', 'Double' for 'double', 'Character' for 'char', and 'Boolean' for 'boolean'. These classes encapsulate the primitive data type in an object allowing them to be used in places where only objects can be utilized. Auto Boxing - is the process where the Java compiler automatically converts the primitive type into its corresponding wrapper class object. For example, when you type int, to an Integer object, Java automatically converts the int to an Integer. Unboxing the reverse process called unboxing, where the object of a wrapper class is converted back to a primitive type What is the potential negative about "auto boxing" in relation to Java? Think int - Integer (Lec 10.19.23) Subprograms 3 - Correct Ans-Has to be an object because Java weaves it into the bytecode that way. Under the hood, when calling a generic, the generic is called an object type. Thus, it has to be that way or the program does not work - mathematically required. The problem is objects are generally bigger and slower. Instead of using ALU - you have to make an object to put in a variable which all takes time.. size of object + heap + field of actual 32 bits and something to access (getter/setter/caller) which all takes up some space. Generic is called The syntax of a programming language is?' ref ch 3 - Correct Ans-The form of its expressions, statements, and program units. The semantics of a programming language is? ref ch 3 - Correct Ans-The meaning of those expressions, statements, and programming units. Why are syntax and semantics closely related? ref ch 3 - Correct Ans-A well-designed programming language, semantics should follow directly from syntax; that is, the appearance of a statement should strongly suggest what the statement is meant to accomplish. Strings of a language are called? - Correct Ans-sentences or statements. What are Lexemes? ref ch 3 - Correct Ans-lowest-level of syntactical units. They include its numeric literals, operators, and special words, etc. One can think of programs as strings of lexemes rather than characters What are Identifiers? ref Ch 3 - Correct Ans-Identifiers - when partitioned into groups (ie. names of variables, classes, etc) What are Tokens? ref ch 3 - Correct Ans-Each lexeme group that is represented by a name or token. So, a token of a language is a category of its lexemes. What is a grammar? ref ch 3 - Correct Ans-Grammars are formal language-generation mechanisms. They commonly are used to describe the syntax of a programming language Who created Context-Free Grammars? ref ch 3 - Correct Ans-Noam Chomsky Who created BNF? ref ch 3 - Correct Ans-John Backus and Peter Naur What is BNF? ref ch 3 - Correct Ans-It is a natural notation for describing syntax. What is a meta-language? ref ch 3 - Correct Ans-A metalanguage is a language that is used to describe another language. BNF is a metalanguage for programming languages.

Content preview

CS326



CS 326 Final Exam 2025
Generate a Grammar that is Syntactically Valid, but show an input string that would not
type check.

(test question from subprograms slide part 2) - Correct Ans-e = expression
f = factor

start -> e ';'
e -> e +/- f | f
f -> f */ / atom
| atom
atom -> string
| int

"Bob" / 26 ; //could be valid string if you want it to be
it is syntactically valid but semantically drugs.

What is "auto-boxing" - Correct Ans-Conversion between primitive types and the
corresponding wrapper classes is automatic.

ie. int a = 10;
Integer b = a; //Auto boxing (int to Integer)
int c = b; // Unboxing (Integer to int)

ie.
Primitive Data Types:
These are the basic data types in Java such as 'int' , 'double', 'char', and 'boolean'. They
are not objects and do not belong to any class. They are stored efficiently and have a
lower memory footprint.

Wrapper Classes: for every primitive data type in Java, there is a corresponding
wrapper class, like 'Integer' for 'int', 'Double' for 'double', 'Character' for 'char', and
'Boolean' for 'boolean'. These classes encapsulate the primitive data type in an object
allowing them to be used in places where only objects can be utilized.

Auto Boxing - is the process where the Java compiler automatically converts the
primitive type into its corresponding wrapper class object. For example, when you type
int, to an Integer object, Java automatically converts the int to an Integer.

Unboxing the reverse process called unboxing, where the object of a wrapper class is
converted back to a primitive type

What is the potential negative about "auto boxing" in relation to Java?



CS326

,CS326


Think int -> Integer

(Lec 10.19.23) Subprograms 3 - Correct Ans-Has to be an object because Java weaves
it into the bytecode that way. Under the hood, when calling a generic, the generic is
called an object type. Thus, it has to be that way or the program does not work -
mathematically required. The problem is objects are generally bigger and slower.
Instead of using ALU - you have to make an object to put in a variable which all takes
time.. size of object + heap + field of actual 32 bits and something to access
(getter/setter/caller) which all takes up some space.




Generic is called

The syntax of a programming language is?'

ref ch 3 - Correct Ans-The form of its expressions, statements, and program units.

The semantics of a programming language is?

ref ch 3 - Correct Ans-The meaning of those expressions, statements, and programming
units.

Why are syntax and semantics closely related?

ref ch 3 - Correct Ans-A well-designed programming language, semantics should follow
directly from syntax; that is, the appearance of a statement should strongly suggest
what the statement is meant to accomplish.

Strings of a language are called? - Correct Ans-sentences or statements.

What are Lexemes?

ref ch 3 - Correct Ans-lowest-level of syntactical units. They include its numeric literals,
operators, and special words, etc.

One can think of programs as strings of lexemes rather than characters

What are Identifiers?

ref Ch 3 - Correct Ans-Identifiers - when partitioned into groups (ie. names of variables,
classes, etc)

What are Tokens?



CS326

, CS326


ref ch 3 - Correct Ans-Each lexeme group that is represented by a name or token. So, a
token of a language is a category of its lexemes.

What is a grammar?

ref ch 3 - Correct Ans-Grammars are formal language-generation mechanisms. They
commonly are used to describe the syntax of a programming language

Who created Context-Free Grammars?

ref ch 3 - Correct Ans-Noam Chomsky

Who created BNF?

ref ch 3 - Correct Ans-John Backus and Peter Naur

What is BNF?

ref ch 3 - Correct Ans-It is a natural notation for describing syntax.

What is a meta-language?

ref ch 3 - Correct Ans-A metalanguage is a language that is used to describe another
language. BNF is a metalanguage for programming languages.

<assign> -> <var> = <expression>

Define the LHS and RHS

ref ch3 - Correct Ans-LHS of arrow (->) is the abstraction being defined
RHS of arrow (->) is the definition of the LHS.

RHS consists of some mixture of tokens, lexemes, and references to other abstractions.
(Tokens are also abstractions)

In reference to the RHS, what is the definition called?

ref ch 3 - Correct Ans-definition is called a rule or production.

ie. a rule is just given, the abstraction <var> and <expression> obviously must be
defined for the <assign> definition to be useful.

This particular rule specified that the abstraction <assign> is defined as an instance of
the abstraction <var>, followed by the lexeme " = ", followed by an instance of the
abstraction <expression>



CS326

Document information

Uploaded on
May 12, 2025
Number of pages
19
Written in
2024/2025
Type
Exam (elaborations)
Contains
Questions & answers
$16.99

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
AlexScorer
2.5
(2)
Sold
11
Followers
0
Items
1800
Last sold
2 weeks ago



Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions