# Just cant get my head around these FLEX questions!

• 03-12-2012
Sber
Just cant get my head around these FLEX questions!
Hey guys, noob here in dire need of help.

I am preparing for an exam on Compilers and I have serious trouble answering some --seemingly simple :frown:--- questions concerning the FLEX logical analyser.
I know, the first thing is for me is to go back to my notes and try harder, but sadly my lecturer just makes little sence to me (and others in the class, to that extent). I have read a few things on the Wikipedia article (doesn't help much) and I would like to ask any experts for help on these two questions.

Here's the questions:

1(i) In a programming language, we declare variables as follows:
Code:

```var name1,name2,.... : integer;       othername1,othername2,... : real;        otherothername1,...        :  boolean;     other4name1,...          : char;```
(a) Consider the declaration

Code:

```var number_of_attendants, sum: integer; ticket_price: real; symbols: char;```
(b) Construct the syntactic diagram (this is pretty frustrating, arrgh!)
(c) Define the variables in Backus-Naur form.
(d) Write the associated LEX program in C.
(e) Define the tokens, lexemes and patterns existing in this process.
(e) Define a formal expression regarding variable declaration in this language
and construct the relevant finite automaton.

Ok, and the second one goes...

2) A subset of a natural language contains these sentences:
1) Triangle ABC.
2) Line Segment AB.
3) Angle A.
In this set, names of triangles are formed by putting three letters together,
all drawn from the alphabet A,B,C,D,E. Line segment names are defined by
putting two letters together from the previous alphabet. And angle names are
(suprise!) given by any letter in that alphabet.

a) Write a LEX program (i know this is in C) that identifies words from the previous set of phrases, such that an input of the form "triangle BCD" returns:
-Triangle: a geometric entity (lol at that)
-BCD: name of a geometric entity
b) Define the tokens, lexemes and patterns to be found in formal expressions concerning these three sentences.
c) Construct the finite automaton that corresponds to the formal expressios to describe the names of geometric entities in that language. Use this to see if the name AYZ is recognizable.

Here they are. I would really appreciate any help... :frown:

• 03-12-2012
QuantumPete
Quote:

Here they are. I would really appreciate any help...
• 03-12-2012
Sber
Quote:

Originally Posted by QuantumPete

I only have my class notes to advise, and my lecturer makes little to no sense to me :( He doesn't explain much and makes me feel dumb when I ask a question (not just me, others in the class agree he is not helpful at all). So I just ask if someone knows how these are solved, so by "reverse engineering" I will be able understand just what's going on.