Week 12 Flashcards

1
Q

What does the c preprocessor do?

A

Makes changes to your program before code generation begins

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the typical uses of a c preprocessor?

A

Including other files like .h files

Defining constants

Defining macros

Selectively include or exclude some parts of a program

Give additional details to the compiler

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What do all preprocessor commands begin with?

A

#

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What does #include do?

A

Include the contents of one file directly into another file

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What does #define symbol value do?

A

Replace all occurences of symbol with the value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does #define do?

A

Can be used to make macros with parameters

The don’t fully behave like function calls

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Is it a good practice to hae parameters in parantheses?

A

Yes, it helps to make sure we get the result we expected.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What does FILE do?

A

the name of the file being compiled

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is LINE?

A

The line number where symbol was found.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is DATE and TIME

A

indicates when the compilation happened

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is FILE and LINE

A

Would most typically be used in other macros where you dn’t know immediately where the macro is being used.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What do #if, #else, #endif do?

A

LEts you use an expression to determine what to include in a compilation

Exclude temporary code with #if 0 …#endif

Include OS-specific code based on the expression

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the shorthand for #if defined(X)…#endif

A

Becomes #ifdef X….#endif

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the shorthand for #if_defined(x)…#endif

A

Becomes #ifndef X ….#endif

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How are compiler specific commands defined?

A

by #pragma statements

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What do #error and #warning do?

A

Lets you print messages at compile time

17
Q

What is the set L?

A

Called the language

18
Q

What are the elements of Chomsky Hierarchy?

A

Different levels of complexity for matching patterns of data.

Regular expressions
Context-free grammars
Context-sensitive grammars
Unrestricted grammars

19
Q

What are the elements of regular expressions?

A

Simplest of rules

Cannot match the numbe of pairs of things like matching parantheses

Can be handled by finite state machine

20
Q

What are the elements of context-free grammars?

A

Needs a non-deterministic pushdown automaton

21
Q

What are the elements of context-sensitive grammars?

A

Needs a non-deterministic Turing machine

22
Q

What are the elements of the unrestricted grammars?

A

Allows for the most complx rules

23
Q

What are some different symbols to represent the regular expressions in different tools?

A

Grep, sed

bash pathname expansion, find

perl

24
Q

Grep/sed syntax: What are the basic operations?

A

Character specification

Catenation

Repetition

Grouping

Alternation

25
Q

What is catenation?

A

The step of putting two strings or patterns in sequence to make a longer string or pattern.

26
Q

Does order of catenation matter?

A

Yes

27
Q

What are the repetition notation of grep/sed repetition?

A
  • matches 0 or more instances of the preceding character

+matches 1 or more instances of the preceding character

? Matches 0 or 1 instances of the preceding character

{n} matches n instances of the preceding character

{n,} matches n or more instances of the preceding character

{n,m} matches at least n and at most m instances of the preceding character

28
Q

If the catenation ab+ is used, what letter is affected?

A

asks for repetition of b, but not a

29
Q

What is egrep most commonly used for?

A

Most commonly used to apply repetition to a catenation

30
Q

How are alternatives separated in egrep/sed alternation?

A

by using the |

a|b|c| equivalent to [abcd]

31
Q

Are regex’s a part of standard c?

A

No, you just need to know that they’re available as the GNU posix regular expression library: regex.h

32
Q

What are the three steps to using the regular expressions?

A

1) Compile the expression into something usable with regcomp()
2) Use the compiled expression against 1 or more strings with regexec()
3) Release the compiled expression with regfree()

33
Q

What is regex_t?

A

The compiled pattern

34
Q

What are the two fields of regmatch_t?

A

rm_so - starting index of match

rm_eo - ending index of match