Just cant get my head around these FLEX questiions!

Discussion in 'C' started by Sber, Mar 12, 2012.

  1. Sber

    Sber New Member

    Joined:
    Mar 12, 2012
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    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 :(--- 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 (and hopefully I'll get it, the same way that Pavlov fed his dogs!)

    Here's the questions:

    1(i) In a programming languge, we declare variables as follows:
    var name1,name2,.... : integer;
    othername1,othername2,... : real;
    otherothername1,... : boolean;
    other4name1,... : char;

    (a) Write a real life example of a variable declaration in this language.
    (b) Construct the syntactic diagram (this is about circles,squares and arrows
    and 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. 1) a) i can do, so I would really appreciate any help with all the rest.
    :(
    Thanks in advance.
     
  2. Sber

    Sber New Member

    Joined:
    Mar 12, 2012
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    And also, my lectures uses "formal expressions" and "regular expressions" interchangeably. Is that right? :/
     
  3. Sber

    Sber New Member

    Joined:
    Mar 12, 2012
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Ok I see things more clearly now (mods please dont ban me for posting three times in my thread!)
    Here's my example for 1a):

    var number_of_attendants, sum: integer;
    ticket_price: real;
    symbols: char;

    and I have to answer all questions in 1) based on this.
     
  4. john_grammatidis

    john_grammatidis New Member

    Joined:
    Mar 7, 2016
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    So what did you do with your code? Any directions?
     
  5. Sber

    Sber New Member

    Joined:
    Mar 12, 2012
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0





    It's been years, dude :happy:Yeah I got it eventually.
    Email me for details
     
  6. john_grammatidis

    john_grammatidis New Member

    Joined:
    Mar 7, 2016
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Jolly news!! :D

    hmm.. I suppose that your contact info is not visible or I can't find it (new to forum). My email is johngrammatidis@gmail.com

    Thanks in advance
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice