Skip to content

Instantly share code, notes, and snippets.

View utkarshsingh99's full-sized avatar
🏹
Greatness adores the relentless

Utkarsh Singh utkarshsingh99

🏹
Greatness adores the relentless
View GitHub Profile
@utkarshsingh99
utkarshsingh99 / lexical_analyzer.lex
Last active November 26, 2019 16:10
A Lex Program to detect errors in a C/C++ program
%{
int n = 0, limit = 0, cursor = 0;
char identifiers[100][100];
int identify = 0;
%}
%%
"while"|"if"|"else"|"for" {n++;printf("\t keywords : %s\n", yytext);}
%{
/* Definition Section */
/* You define certain variables in here which you might need to manipulate your code */
%}
%%
/* Rules Section */
/* Pattern Actions begin */
/* This is a section where you define certain patterns of string (just like RegEx) */
@utkarshsingh99
utkarshsingh99 / Find First & Follow in CPP
Last active December 1, 2019 18:02
A short program to find the First & Follow of a Grammar in CPP (82 Lines of Code)
#include<bits/stdc++.h>
using namespace std;
int main() {
string a[5];
for(int i = 0; i < 5; i++) cin>>a[i];
map <char, string> s;
unordered_map <char, vector <char>> first, follow, t;
for(int i = 0; i < 5; i++) {
cout<<a[i]<<endl;
string h="";
@utkarshsingh99
utkarshsingh99 / sequoia-hierarchy.rb
Created April 17, 2024 14:26
Updated gist that fixes the problematic code for robot hierarchy
# The ReadingRobot class incorrectly attempts to implement
# the clean_room method, which is specific to CleaningRobot
# and not applicable to ReadingRobot.
# This violates the principle of inheritance, where subclasses
# should override methods only when they are meant to provide a
# different implementation.
# To fix this, we can redesign the class hierarchy to separate
# the common behavior from the specific behavior more clearly.
# One approach is to use composition instead of inheritance,
CREATE TABLE authors (
author_id INT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
birth_date DATE
);
CREATE TABLE books (
book_id INT PRIMARY KEY,
title VARCHAR(255) NOT NULL,
publication_year INT,
proc mergeSort[T](arr: var seq[T]) =
# Check if the array has more than one element
if arr.len <= 1:
return
# Calculate mid index
let mid = arr.len div 2
# Split the array into two halves
var leftHalf = arr[0 ..< mid]