COM2041 Lab 1-Lexical Analysis and Parsing Solved

30.00 $

Category: Tags: , , , , ,
Click Category Button to View Your Next Assignment | Homework

You'll get a download link with a: zip solution files instantly, after Payment

Securely Powered by: Secure Checkout

Description

5/5 - (1 vote)

Tutorial #1 && 2: “Lexical Analysis and Parsing”

Objective:

To learn the lexical and syntax analysis of context-free grammars using lex&yacc and to design a syntax analyzer for your own pogramming language.

Background Information:

Read “lexyacc.pdf” in the course homepage.

Implementation:

You will design a lexical and syntax analyzer for your own programming language. Give some rules for your programming language and call it as MPL (My Programming Language). For example, your rules may be as;

  • –  all programs must start with “begin” and end with “end”
  • –  all commands must be ended by “;”
  • –  all variables must be declared just after “begin” in the following format;

    int: i num;

    float: fl;

  • –  three types exist; “int”, “float”, “char”
  • –  variables names may be any alphanumeric string, but they must start with a letter
  • –  statements between “begin” and “end” can be either a variable declaration or an assignment
  • –  an assignment includes four type of operators; +,-,*,/.
  • –  the number of variables or constants in an expression is unlimited
  • –  the presedence of operators given as…………..
  • –  ……..
  • –  .etc

    The minimum requirements are: a well defined regular grammar for variable names, rules for variable declerations, at least 4 arithmetic, 2 logical and 2 comparison operators with their presedence and associativity rules, at least one conditional statement (like if, switch) and at least one loop structure (like for, while, do-while, repeat-until…). Instead of using the grammar for C langugae, try to bring new ideas for your language.

    After writing CFG rules for your language, design and implement a syntax analyzer for it. This analyzer will include a lex source (e.g mpl.l), a yacc source (e.g mpl.y) and example inputs (source codes written in your language, e.g myprog.mpl).

    To test your analyzer, follow the steps below;

         $ lex mpl.l
         $ yacc mpl.y
         $ gcc –o mpl y.tab.c –lfl
         $ mpl < myprog.mpl
    

    In the last step, if there is no syntax error in myprog.mpl, the program should give an “OK” message, otherwise, a “syntax error” message. Check your program for correct and wrong inputs.

    Note: Do not deal with any semantic rule, just give syntax rules!

    Report:

    Your report should include; (1) description of the rules which you designed (in your own words) (2)details of your grammar in BNF or EBNF notation, (3)code descriptions, (4)the

BİL240 PROGRAMMING LANGUAGES Tutorial #1 && 2: “Lexical Analysis and Parsing”

content of mpl.l, mpl.y files and an example myprog.mpl file, (5)any explanation which clarifies that you made your assingment with your own effort.

  • Lab-1-kbzfbz.zip