summaryrefslogtreecommitdiff
path: root/Homework/cs5300/homework-three/compilers_assn_3.org
blob: 0d4028ee61ff6d32c76a835dac6402c003279973 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#+TITLE: Assignment Three
#+AUTHOR: Logan Hunt
#+STARTUP: entitiespretty fold inlineimages
#+LATEX_HEADER: \notindent \notga \usepackage{ dsfont } \usepackage{amsmath}
#+LATEX: \setlength\parindent{0pt}
#+OPTIONS: toc:nil

* Question One
\begin{verbatim}
<void> <id, cube> <(> <float> <id, y> <)> <{>
  <if> <(> <id, y> <comparison, >> <number, 3.14159> <)> \\
      <return> <id, y> <mult_op> <id, y> <mult_op> <id, y>
  <return> <number, -1>
<}>
\end{verbatim}

* Question Two
#+attr_latex: :width 250px
[[./2.png]]

The first buffer is filled twice. The second is filled once, and the last contains three elements.
* Question Three
Strings starting and ending with "x" with any number of x or y's in between.

* Question Four
** a
\begin{verbatim}
col(o|ou)r
\end{verbatim}
** b
\begin{verbatim}
m(o|u)m
\end{verbatim}
** c
\begin{verbatim}
analy(z|s)e
\end{verbatim}

* Question Five
** a
1. bbbaa
2. bbbcc
3. bbbac
4. bbbca
** b
1. bbb
2. aa
3. cc
4. ac
5. ca
** c
1. bbb
2. acac
** d
1. bbbacac

* Question Six
** a
\begin{verbatim}
In [1]: ["aggie"[0:n] for n in range(0, len("aggie")+1)]
Out[1]: ['', 'a', 'ag', 'agg', 'aggi', 'aggie']
\end{verbatim}

** b
\begin{verbatim}
In [3]: ["aggie"[n:len("aggie")] for n in range(0, len("aggie")+1)]
Out[3]: ['aggie', 'ggie', 'gie', 'ie', 'e', '']
\end{verbatim}

** c
\begin{verbatim}
In [4]: ["aggie"[0:n] for n in range(1, len("aggie"))]
Out[4]: ['a', 'ag', 'agg', 'aggi']
\end{verbatim}

** d
\begin{verbatim}
In [8]: def subs(s):
    ...:     proper_substrings = set()
    ...:     for i in range(len(s)+1):
    ...:         for j in range(len(s)+1):
    ...:             if (i <= j):
    ...:                 sub = s[i:j]
    ...:                 if (sub != "" and sub != s):
    ...:                     proper_substrings.add(sub)
    ...:     return proper_substrings
    ...:

In [9]: subs("aggie")
Out[9]:
{'a',
 'ag',
 'agg',
 'aggi',
 'e',
 'g',
 'gg',
 'ggi',
 'ggie',
 'gi',
 'gie',
 'i',
 'ie'}
\end{verbatim}

* Question Seven
\begin{verbatim}
(u|U)(n|N)(i|I)(o|O)(n|N)
\end{verbatim}

* Question Eight
$\textdollar([0-9]|[0-9]^2|[0-9]^3)(,[0-9]^3)^*.[0-9][0-9]$

* Question Nine
nonzeroDigit \Rightarrow 1|2|3|4|5|6|7|8|9|A|B|C|D|E|F

hex \Rightarrow nonzeroDigit^{+}(0|nonzeroDigit)^{*}

* Question Ten
** a
\begin{verbatim}
(0011)*|(1100)*
\end{verbatim}
** b
[[./10b.png]]

\begin{verbatim}
((00)|(0(11)*0?))|((11)|(1(00)*1?))
\end{verbatim}
** c
\begin{verbatim}
a?b?c?d?
\end{verbatim}

* Question Eleven
** a
\begin{verbatim}
(\t| )+
\end{verbatim}
** b
\begin{verbatim}
(/\*)[^(*/)]*(\*/)
\end{verbatim}
** c
\begin{verbatim}
"[^"]*"
\end{verbatim}

* Question Twelve

nonVowelPart \Rightarrow [\textasciicircum aeiou]^{*}

aPart \Rightarrow a^{+}[\textasciicircum eiou]^{*}

ePart \Rightarrow e^{+}[\textasciicircum aiou]^{*}

iPart \Rightarrow i^{+}[\textasciicircum aeou]^{*}

oPart \Rightarrow o^{+}[\textasciicircum aeiu]^{*}

uPart \Rightarrow u^{+} [\textasciicircum aeio]^{*}

str \Rightarrow (nonVowelPart)(aPart)(ePart)(iPart)(oPart)(uPart)