CSCE 3600 FINAL EXAM QUESTIONS & ANSWERS
Compilation Process - Answers - Preprocessor -> Compiler -> Assembler -> Linker ->
Loader
Preprocessor Directive - Answers - lines begin with # (like #include or #define)
Preprocessing - Answers - before a program is compiled, definition of constants and
macros, conditional compilation of program code
#include - Answers - copy of a specified file included, used for programs with multiple
source files compiled together or libraries
#define - Answers - when program compiled, all occurrences of symbolic constant
replaced with replacement text
#undef - Answers - undefines a symbolic constant or macro (#define WIDTH 80
........#undef WIDTH)
gcc - Answers - GNU Compiler Collection, standard Linux C compiler, translates C to
assembly
Assembler - Answers - assembles, but doesn't link, source code to generate relocatable
object code
Linker - Answers - combines compiled and assembled object code to make executable
file
Loader - Answers - ensures that object programs are placed in memory in executable
form
Only Compiling: - Answers - gcc -c hello.c
Only Linking: - Answers - gcc hello.o -o hello
Compiling and Linking: - Answers - gcc hello.c -o hello
To Run: - Answers - ./hello
Compiler - Answers - system software that translates high level language to machine
language
Static Semantics - Answers - semantics rules that can be checked at compile time
, Runtime Semantics - Answers - semantics rules that can be checked only at runtime
Compilation Stages - Answers - lexical analysis (scanner) -> syntax analysis (parser) ->
semantic analysis -> intermediate code generation -> machine independent
improvement (optional) -> target code generation -> machine specific improvement
(optional)
Lexical Analysis (Scanner) - Answers - recognizes tokens (keywords, operators,
identifiers, numbers) of a program, outputs sequence of tokens to syntax analyzer
Lexical Analysis Process - Answers - 1. discard blanks, tabs
2. put characters together
3. repeat step 2 until end of token
4. classify and save token
5. repeat steps 1-4 until end of statement
6. repeat steps 1-5 until end of source code
x* - Answers - zero or more occurrence of x. i.e., it can generate { e, x, xx, xxx, xxxx, ...
}
x+ - Answers - one or more occurrence of x. i.e., it can generate { x, xx, xxx, xxxx ... } or
x.x*
x? - Answers - at most one occurrence of x i.e., it can generate either {x} or {e}.
Write all strings of 1s and 0s in regex - Answers - ( 0 | 1 )*
Write all strings of 1s and 0s beginning with a 1 in regex - Answers - 1 ( 0 | 1 )*
Write all strings of 0s and 1s containing at least two consecutive 1s in regex - Answers -
( 0 | 1 )* 1 1( 0 | 1 )*
Write all strings of alternating 0s and 1s in regex - Answers - ( e | 1 ) ( 0 1 )* ( e | 0 )
x+= x x* - Answers - denotes L(x)+
x? = x | e - Answers - denotes L(x) U {e}
[abc] = a | b | c - Answers - matches one character in the square bracket
a-z = a | b | c | ... | z - Answers - range
[^abc] - Answers - ^ means negation
. - Answers - (dot) matches any character except the newline
Compilation Process - Answers - Preprocessor -> Compiler -> Assembler -> Linker ->
Loader
Preprocessor Directive - Answers - lines begin with # (like #include or #define)
Preprocessing - Answers - before a program is compiled, definition of constants and
macros, conditional compilation of program code
#include - Answers - copy of a specified file included, used for programs with multiple
source files compiled together or libraries
#define - Answers - when program compiled, all occurrences of symbolic constant
replaced with replacement text
#undef - Answers - undefines a symbolic constant or macro (#define WIDTH 80
........#undef WIDTH)
gcc - Answers - GNU Compiler Collection, standard Linux C compiler, translates C to
assembly
Assembler - Answers - assembles, but doesn't link, source code to generate relocatable
object code
Linker - Answers - combines compiled and assembled object code to make executable
file
Loader - Answers - ensures that object programs are placed in memory in executable
form
Only Compiling: - Answers - gcc -c hello.c
Only Linking: - Answers - gcc hello.o -o hello
Compiling and Linking: - Answers - gcc hello.c -o hello
To Run: - Answers - ./hello
Compiler - Answers - system software that translates high level language to machine
language
Static Semantics - Answers - semantics rules that can be checked at compile time
, Runtime Semantics - Answers - semantics rules that can be checked only at runtime
Compilation Stages - Answers - lexical analysis (scanner) -> syntax analysis (parser) ->
semantic analysis -> intermediate code generation -> machine independent
improvement (optional) -> target code generation -> machine specific improvement
(optional)
Lexical Analysis (Scanner) - Answers - recognizes tokens (keywords, operators,
identifiers, numbers) of a program, outputs sequence of tokens to syntax analyzer
Lexical Analysis Process - Answers - 1. discard blanks, tabs
2. put characters together
3. repeat step 2 until end of token
4. classify and save token
5. repeat steps 1-4 until end of statement
6. repeat steps 1-5 until end of source code
x* - Answers - zero or more occurrence of x. i.e., it can generate { e, x, xx, xxx, xxxx, ...
}
x+ - Answers - one or more occurrence of x. i.e., it can generate { x, xx, xxx, xxxx ... } or
x.x*
x? - Answers - at most one occurrence of x i.e., it can generate either {x} or {e}.
Write all strings of 1s and 0s in regex - Answers - ( 0 | 1 )*
Write all strings of 1s and 0s beginning with a 1 in regex - Answers - 1 ( 0 | 1 )*
Write all strings of 0s and 1s containing at least two consecutive 1s in regex - Answers -
( 0 | 1 )* 1 1( 0 | 1 )*
Write all strings of alternating 0s and 1s in regex - Answers - ( e | 1 ) ( 0 1 )* ( e | 0 )
x+= x x* - Answers - denotes L(x)+
x? = x | e - Answers - denotes L(x) U {e}
[abc] = a | b | c - Answers - matches one character in the square bracket
a-z = a | b | c | ... | z - Answers - range
[^abc] - Answers - ^ means negation
. - Answers - (dot) matches any character except the newline