Skip to content

RishPoria/Function-Definition-Parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Parser for C++ Function Definition


Description

A basic parser for parsing C++ function definition using LEX and YACC


Syntax

Syntax of C++ function definition:

return_type function_name( parameter list ) {
   body of the function
}

Assumptions

  • Basic data types are supported (void, bool, char, int, float, double).
  • Default arguments are not supported.
  • Comments are not supported.
  • Variables have to be declared before initialization.
  • Basic arithmetic operators are supported (+, -, *, /, %).
  • Comparison operators are not supported (>, <, <=, >=, ==, !=).
  • Standard stream objects are not supported (cout, cin not supported).

Usage

Generate lex.yy.c file

flex fdef.l

Generate y.tab.c and y.tab.h files

bison -yd fdef.y

Compile the C files generated

gcc lex.yy.c y.tab.c

Run program using a.out file

./a.out

Examples

1.

float add(int a, float b){
  float ans;
  ans = a + b;
  return ans;
}

Output:

OUTPUT-1

2.

int ord(char c){
  return c + 0;
}

Output:

OUTPUT-2

3.

int (int b){
  return b;
}

Output:

OUTPUT-3

4.

function(){
  return 0;
}

Output:

OUTPUT-4


Reference links

About

Parser for C++ function defintion using Lex and Yacc

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published