[ Prev ]
2021-10-11

-- Practice Midterm Solution Thread
Arun Murugan, Luksawee Q: 11 Early basic: the scope is the single global scope; x1, x2
Fortran: The scope is both global and local scope
Ex. For the global
Ex. For the local
Rust: Let introduce the scope that visible on the stack unless another let call with the same variable name appear on the stack before the previous one. The newest call with that variable name is token. The another let call with that the same variable name will be showdown
Ex.
 let a = 1
 let b = 2; β€”> this will be showdown with 5
 let b = 5; 
 println!(β€œ{}”, b) β€”> It should get the 5
borrowing ru, it will be able to get the refernce, but it will not get the ownership.
fn main() {
	let I = 5;
	print_i(&i);
} fn print_i(i:: i32) {
	println!(β€œi = {} β€œ, i);
}
(Edited: 2021-10-11)
Arun Murugan, Luksawee Q: 11 Early basic: the scope is the single global scope; x1, x2 Fortran: The scope is both global and local scope Ex. For the global Ex. For the local Rust: Let introduce the scope that visible on the stack unless another let call with the same variable name appear on the stack before the previous one. The newest call with that variable name is token. The another let call with that the same variable name will be showdown Ex. let a = 1 let b = 2; β€”> this will be showdown with 5 let b = 5; println!(β€œ{}”, b) β€”> It should get the 5 borrowing ru, it will be able to get the refernce, but it will not get the ownership. fn main() { let I = 5; print_i(&i); } fn print_i(i:: i32) { println!(β€œi = {} β€œ, i); }

-- Practice Midterm Solution Thread
Tyler Beshearse, Raymond Lin, Angela Pham
 Question 8: (a) What is LL parsing versus LR parsing?
 LL (left-to-right leftmost) derivation expands on each step based on 
 the leftmost non-terminal, LR (left-to-right rightmost) expands each
 step based on the rightmost non-terminal 
 
 (b)What is First(A) vs. Follow(A)? 
 First(A) is the set of all tokens that could be the first token in A,
 Follow(A) is everything that could come after A in a valid program.
 
 (c) How do you associate a lex file to be used with a yacc file?
 First you define the accepted tokens in the lex file and the grammar 
 in the yacc file. The lexer will pass tokens to the yacc portion which
 will try to match them to the grammar rules. Then you compile them together
 into a C program with the following commands:
 lex lex_file_name.l
 //this produces a lex file, by default named "lex.yy.c"
 bison yacc_file_name.y
 //this produces yacc files, by default named "yacc_file_name.tab.c" and
 //"yacc_file_name.tab.h"
 gcc -o name_of_program yacc_file_name.tab.c lex.yy.c -ly -ll
 //compiles into an executable
 
 (d)How do you tell yacc to parse a string?
 In the main() function in the yacc file, you call the yyparse() function after 
 loading the program into yyin.
(Edited: 2021-10-11)
Tyler Beshearse, Raymond Lin, Angela Pham Question 8: (a) What is LL parsing versus LR parsing? LL (left-to-right leftmost) derivation expands on each step based on the leftmost non-terminal, LR (left-to-right rightmost) expands each step based on the rightmost non-terminal (b)What is First(A) vs. Follow(A)? First(A) is the set of all tokens that could be the first token in A, Follow(A) is everything that could come after A in a valid program. (c) How do you associate a lex file to be used with a yacc file? First you define the accepted tokens in the lex file and the grammar in the yacc file. The lexer will pass tokens to the yacc portion which will try to match them to the grammar rules. Then you compile them together into a C program with the following commands: lex lex_file_name.l //this produces a lex file, by default named "lex.yy.c" bison yacc_file_name.y //this produces yacc files, by default named "yacc_file_name.tab.c" and //"yacc_file_name.tab.h" gcc -o name_of_program yacc_file_name.tab.c lex.yy.c -ly -ll //compiles into an executable (d)How do you tell yacc to parse a string? In the main() function in the yacc file, you call the yyparse() function after loading the program into yyin.
X