YACC Program to Identify Function Declaration Syntax

Yacc program to identify function declaration syntax and semantics using regular expressions

Lex Program:
[cc lang=”c”]
%{
#include
#include “y.tab.h”
%}
%%
void|int|float|char return BUILTIN;
, return COMMA;
; return SC;
n return NL;
( return LP;
) return RP;
[a-zA-Z0-9]* return ID;
%%
[/cc]
YACC Program:
[cc lang=”c”]
%{
#include
#include “y.tab.h”
%}
%token COMMA ID BUILTIN SC NL RP LP
%%
var:datatype varlist LP FUNCT RP SC NL {printf(“VAlid declaration”);}
|
datatype: BUILTIN;
|
varlist: ID;
|
FUNCT: FUNCT COMMA ID|FUNCT COMMA BUILTIN|BUILTIN|ID;
%%
void yyerror(const char *str){printf(“error”);}
int yywrap(){return 1;}
main(){yyparse();}
[/cc]

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *