Skip to content

Instantly share code, notes, and snippets.

View blacksmithop's full-sized avatar
😁
Creating

Abhinav blacksmithop

😁
Creating
View GitHub Profile
import sys
if __name__ == "__main__":
sys.argv = sys.argv[1:]
w1 = sys.argv[0]
w2 = sys.argv[1]
print(True if sorted(list(w1)) == sorted(list(w2)) else False)
@blacksmithop
blacksmithop / pgm.l
Last active September 22, 2020 05:24
if-else with lex, yacc (ToDo: Add support for nested if-else)
%{
#include "y.tab.h"
%}
%%
"if" {return IF;}
"else" {return ELSE;}
"&&" {return AND;}
"||" {return OR;}
"<=" {return LE;}
">=" {return GE;}
@blacksmithop
blacksmithop / calc.l
Created September 22, 2020 05:00
Calculator with lex, yacc
%{
/* Definition section */
#include<stdio.h>
#include "y.tab.h"
extern int yylval;
%}
/* Rule Section */
%%
[0-9]+ {
@blacksmithop
blacksmithop / arith..y
Created September 22, 2020 05:23
Arithmetic Expression Evaluation with lex, yacc
%{
/* Definition section */
#include<stdio.h>
int yylex();
void yyerror();
%}
%token NUMBER ID
// setting the precedence
// and associativity of operators
@blacksmithop
blacksmithop / stack.l
Last active September 29, 2020 05:29
lex,yacc program for stack (has bugs) - current code
%{
#include "y.tab.h"
//extern char * yytext
%}
%%
[0-9]+ {return digit;}
[a-z]+ {return id;}
[\t] ;
[\n] {return 0;}
. {return yytext[0];}
@blacksmithop
blacksmithop / rdparser.c
Created October 20, 2020 04:07
Recursive Descent Parser in C
#include <stdio.h>
char input[100];
int i;
int T();
int F();
int TP();
int EP();
int E()
{
@blacksmithop
blacksmithop / q3.md
Last active November 11, 2020 05:27
Answer to C

Rasterisation

It is the task of taking an image described in a vector graphics format (shapes) and converting it into a raster image (a series of pixels, dots or lines, which, when displayed together, create the image which was represented via shapes). The rasterised image may then be displayed on a computer display, video display or printer, or stored in a bitmap file format. Rasterisation may refer to the technique of drawing 3D models, or the conversion of 2D rendering primitives such as polygons, line segments into a rasterized format.

Scan conversion

@blacksmithop
blacksmithop / icg.c
Created November 12, 2020 06:17
Intermediate Code -> Target Code
#include <stdio.h>
#include <string.h>
void main(){
char icode[10][30], str[30], opr[30];
int i=0;
printf("Enter Intermediate Code (terminated by exit):\n");
do{
scanf("%s", icode[i]);
import sqlite3
from pprint import pprint
class DB:
def __init__(self):
self.con = sqlite3.connect('newdb.db')
self.cur = self.con.cursor()
def view_table(self):
self.cur.execute("Select * from NEW")
@blacksmithop
blacksmithop / bot.py
Last active November 22, 2020 11:21
A basic Python discord Bot
from discord.ext import commands
from discord import Status, Game
from discord.errors import LoginFailure
bot = commands.Bot(command_prefix="?")
@bot.listen('on_ready')
async def bot_is_ready():
print(f"Logged in as: {bot.user}")
await bot.change_presence(status=Status.online, activity=Game(f"{bot.command_prefix}help"))