Skip to content

Instantly share code, notes, and snippets.

View skymansandy's full-sized avatar
🤓

P Sandesh Baliga skymansandy

🤓
View GitHub Profile
DELAY PROC
PUSH CX
PUSH BX
MOV CX, 0FFFFH
B1: MOV BX, 0FFFFH
B2: DEC BX
JNZ B2
LOOP B1
POP BX
POP CX
%{
int cc=0;
%}
%x CMNT
%%
"/*" {BEGIN CMNT; }
<CMNT>. ;
<CMNT>\n ;
<CMNT>"*/" {BEGIN 0; cc++;}
.*//.* {BEGIN 0; cc++;}
%{
int a[]={0,0,0,0},i,valid=1,opnd=0;
%}
%x OPER
%%
[a-zA-Z0-9]+ { BEGIN OPER; opnd++;}
<OPER>"+" { if(valid) { valid=0;i=0;} else ext();}
<OPER>"-" { if(valid) { valid=0;i=1;} else ext();}
<OPER>"*" { if(valid) { valid=0;i=2;} else ext();}
<OPER>"/" { if(valid) { valid=0;i=3;} else ext();}
%{
int flag=0;
%}
%%
.+[ \t]+[Aa][Nn][Dd][ \t]+.+ {flag=1;}
.+[ \t]+[Oo][Rr][ \t]+.+ {flag=1;}
.+[ \t]+[Bb][Uu][Tt][ \t]+.+ {flag=1;}
.+[ \t]+[Bb][eE][Cc][Aa][Uu][Ss][Ee][ \t]+.+ {flag=1;}
.+[ \t]+[Nn][Ee][Vv][Ee][Rr][Tt][Hh][Ee][Ll][Ee][Ss][Ss][ \t]+.+ {flag=1;}
. ;
%{
#include<stdio.h>
#include<string.h>
int flag=0,cnt=0;
char str[50];
%}
%%
(int\ )|(char\ )|(float\ )|(double\ )(short\ )(long\ )(unsigned\ ) {flag=1;}
[a-zA-Z_][A-Za-z0-9_]*[,=\[;] {if(flag==1)
{ cnt++;
%{
/* 4a.l Yacc Program to check the validity of an arithmetic Expression that uses operators +, -, *, /
*/
#include "y.tab.h"
%}
%%
[0-9]+(\.[0-9]+)? { return NUM;}
[a-zA-Z_][_a-zA-Z0-9]* { return ID; }
[\t] ;
\n return 0;
%{
/* 4a.y Yacc Program to check the validity of an arithmetic Expression that uses operators +, -, *, /
*/
#include<stdio.h>
#include<stdlib.h>
%}
%token NUM ID
%left '+' '-'
%left '*' '/'
%%
%{
#include "y.tab.h"
%}
%%
[a-zA-z_] {return ALPHA;}
[0-9]+ {return NUMBER;}
"\n" { return ENTER;}
. {return ER;}
%%
yywrap()
%{
#include <stdio.h>
#include<stdlib.h>
%}
%token ALPHA NUMBER ENTER ER
%%
var:v ENTER {printf("Valid Variable\n");exit(0);}
v:ALPHA exp1
exp1:ALPHA exp1
|NUMBER exp1
%{
#include<stdlib.h>
#include "y.tab.h"
extern int yylval;
%}
%%
[0-9]+ { yylval=atoi(yytext); return NUM; }
[\t] ;
\n return 0;
. return yytext[0];