GithubHelp home page GithubHelp logo

mca401-compiler-design's Introduction

mca401-compiler-design

Coursework for mca401-compiler-design

We use GNU's flex bison for all the codes.

package requirements

  • gnu's lex yacc sudo apt-get install bison flex
  • make utility sudo apt-get install build-essential

Question Answers

How to compile lex yacc programs
Perform the following steps, in order to compile a demo program-
  • yacc -d demo.yacc Process the yacc grammar file using the -d flag (which tells the yacc command to create a file that defines the tokens used in addition to the C language source code)
  • Use ls to verify that the following files were created -
    • y.tab.c The C language source file that the yacc command created for the parser.
    • y.tab.h A header file containing define statements for the tokens used by the parser.
  • lex demo.lex Process the lex specification file
  • Use ls to verify that the following file was created -
    • lex.yy.c The C language source file that the lex command created for the lexical analyzer.
  • cc y.tab.c lex.yy.c -o demo Compile and link the two C language source files.
  • Use ls to verify that the following files were created -
    • demo The executable program file
Guide to writing a yacc program
  • Identify the Terminal and Non-Terminal Symbols from the BNF and Lex.
  • Try coding all the grammar rules in yacc with empty actions.
    • Compile,link it to Lex and check for conflicts.
    • This is an easy way of validating the BNF for reduce/reduce and shift/reduce conflicts.
  • Search for any reduce/reduce conflict. Resolve it in Lex. Resolve any shift/reduce conflicts.
  • Write rules for all possible syntax errors.Details on error handling are given later.
  • Code the yyerror function in subroutine section.
  • Design the Data Structure which can be easily integrated with the grammar rules for syntax directed translation.
  • From the Data Structures and Lex needs ,formulate the correct Stack.The stack must have pointers for all the data structures.
  • Do the appropiate type binding to all tokens and yacc variables (non-terminals).
  • Write all the data structures in a seperate file and inlude it in yacc.
  • Code all the actions.
  • Restrict the actions in case of error, i.e no data structure should be built but parsing should continue to get more errors.

Reference links

mca401-compiler-design's People

Contributors

jatin69 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.