Notes, summaries, assignments, exams, and problems for Computers

Sort by
Subject
Level

Implementing Lexical and Syntax Analysis with Lex and Yacc

Posted by Comunidad Wikiteka and classified in Computers

Written on in English with a size of 2.73 KB

Lexer Implementation (lexer.l)

%{ #include "y.tab.h" %} %%% "+" { return PLUS; } "-" { return MINUS; } "*" { return MULTIPLY; } "/" { return DIVIDE; } "%" { return MODULUS; } "(" { return LPAREN; } ")" { return RPAREN; } [0-9]+ { yylval.num = atoi(yytext); return NUMBER; } [a-zA-Z][a-zA-Z0-9]* { yylval.id = strdup(yytext); return IDENTIFIER; } [ \t\n] { /* ignore whitespace */ } . { return yytext[0]; } %%%

Parser Implementation (parser.y)

%{ #include <stdio.h> #include <stdlib.h> #include <string.h> void yyerror(const char *s); int yylex(); int temp_count = 0; int label_count = 0; void gen(char op, int arg1, int arg2, int result) { printf("%d: %c, %d, %d, %d\n", label_count++, op, arg1, arg2, result); } int new_temp() { return
... Continue reading "Implementing Lexical and Syntax Analysis with Lex and Yacc" »

Essential Data Structure Operations and Java Implementations

Posted by Comunidad Wikiteka and classified in Computers

Written on in English with a size of 3.95 KB

Inserting the First Element into a Tree Structure

Method to add the first element (root) to a Tree Structure:

public void insertFirstNode(Object item)
{
    // If the tree is empty, the new node becomes the root of the tree
    if (theRoot == null)
    {
        Node theNewNode = new Node(item);
        theRoot = theNewNode;
    }
}

Deleting an Element from a Linked List

Method to remove an element at a specific index in a Linked List:

public void remove(int index) {
    // Special case: removing at the head of the list
    if (index == 1) {
        head = head.getNext();
    } else {
        // Find the previous and current node
        setCurrent(index);
        prev.setNext(curr.getNext());
    }
    size = size - 1;
}

Steps for Inserting an Element

... Continue reading "Essential Data Structure Operations and Java Implementations" »

Implementando 4x4 Matriz Transposta em Linguagem C

Posted by Comunidad Wikiteka and classified in Computers

Written on in English with a size of 2.66 KB

Implementação da Transposição de Matriz 4x4 em C

Este programa em C demonstra como calcular e exibir a matriz transposta (B) de uma matriz quadrada de ordem 4 (A). A transposição é realizada trocando as linhas pelas colunas, ou seja, o elemento na posição A[i][j] é copiado para B[j][i].

Código Fonte em C para Transposição de Matriz

O código utiliza as bibliotecas padrão stdio.h para entrada/saída e conio.h (comum em ambientes legados) para controle de console.

#include <stdio.h>
#include <conio.h>

int main()
{
    int i, j, A[4][4], B[4][4];

    // 1. Entrada de Dados
    printf("Insira os elementos da Matriz A (4x4):\n");
    for(i = 0; i < 4; i++)
    {
        for(j = 0; j < 4; j++)
        {
            printf(
... Continue reading "Implementando 4x4 Matriz Transposta em Linguagem C" »

Operating Systems Kernel, Processes, Sockets, Pipes and Signals Explained

Posted by Comunidad Wikiteka and classified in Computers

Written on in English with a size of 3.77 KB

Kernel Fundamentals

Kernel = FLIH (interrupt controller) + dispatcher + communication, synchronization and mutual exclusion.

Process States

States: Ready, Running, Blocked

Transitions:

  • Creation → Ready (OS creates it)
  • Ready → Running (dispatcher gives it the CPU)
  • Running → Ready (time slice ends)
  • Running → Blocked (waits for I/O)
  • Blocked → Ready (awaited event happens)
  • Running → Finished

Process Control Block (PCB)

PCB: PID, state, context (PC, flags, general registers, memory access registers) + scheduling info (priority).

Interrupt Handling

FLIH: store context → find which device interrupted (poll devices by priority) → run ISR.

Chain: hardware stores PC → FLIH → ISR → dispatcher

The Dispatcher

Dispatcher: called after an interrupt changes... Continue reading "Operating Systems Kernel, Processes, Sockets, Pipes and Signals Explained" »

Essential PHP Programming: Forms, Databases, and Sessions

Posted by Anonymous and classified in Computers

Written on in English with a size of 2.37 KB

PHP Form Validation

To create a PHP form and perform server-side validation for user input such as name, email, and password:

<?php
$name = $email = $password = "";
$nameErr = $emailErr = $passwordErr = "";

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // Name Validation
    if (empty($_POST["name"])) { $nameErr = "Name is required"; } else { $name = $_POST["name"]; }
    // Email Validation
    if (empty($_POST["email"])) { $emailErr = "Email is required"; } else { $email = $_POST["email"];
        if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $emailErr = "Invalid email format"; } 
    }
    // Password Validation
    if (empty($_POST["password"])) { $passwordErr = "Password is required"; } else { $password = $_POST["password"];
... Continue reading "Essential PHP Programming: Forms, Databases, and Sessions" »

Essential Kubectl Commands: The Ultimate Kubernetes Cheat Sheet

Posted by Anonymous and classified in Computers

Written on in English with a size of 7.76 KB

Key Takeaways

  • kubectl is the core tool for managing Kubernetes clusters, enabling you to inspect, deploy, troubleshoot, and scale workloads from the command line. Mastering flags like -n, -o, and --dry-run is essential.
  • Use a consistent workflow for debugging: get → describe → logs. This structured approach surfaces issues faster and reduces downtime.
  • Favor declarative over imperative commands by using YAML manifests with kubectl apply to promote version control and repeatability.

Kubernetes (K8s) is the industry standard for orchestrating containerized applications, but managing it can be complex. At the center of every Kubernetes workflow is kubectl, the command-line utility used to interact with clusters, deploy applications, and troubleshoot

... Continue reading "Essential Kubectl Commands: The Ultimate Kubernetes Cheat Sheet" »

JDBC Drivers, JSP Tags, and ResultSet Implementation

Posted by Anonymous and classified in Computers

Written on in English with a size of 2.86 KB

JDBC Driver Types

Type 1: JDBC-ODBC Bridge

  • Converts JDBC calls to ODBC
  • ❌ Slow, platform dependent, and obsolete

Type 2: Native API Driver

  • Uses database-specific native libraries
  • ⚠️ Faster than Type 1 but platform dependent

Type 3: Network Protocol Driver

  • Uses middleware server to connect
  • 🌐 Platform independent but slower due to network

Type 4: Thin Driver

  • Directly connects to database using pure Java
  • ✅ Fast, platform independent, and most used

Tags in JSP

1. Directive Tags

  • Provide instructions to the JSP container
  • Syntax: <%@ ... %>
  • Example: page, include, taglib

2. Scripting Tags

  • Scriptlet Tag: Write Java code <% ... %>
  • Expression Tag: Display output <%= ... %>
  • Declaration Tag: Declare variables or methods <%! ... %>

3. Action

... Continue reading "JDBC Drivers, JSP Tags, and ResultSet Implementation" »

Android and iOS Mobile App Development Solutions

Posted by Anonymous and classified in Computers

Written on in English with a size of 11.74 KB

RecyclerView Features and GridView Implementation

1. List and explain any three features of RecyclerView. Develop an Android application to display any five programming languages in GridView.

  • View Recycling: Reuses views to improve performance and reduce memory usage.
  • ViewHolder Pattern: Stores item views to avoid repeated findViewById() calls.
  • Flexible Layout: Supports LinearLayoutManager, GridLayoutManager, and StaggeredGridLayoutManager.

Example: XML and Java

Java Code:

GridView gridView = findViewById(R.id.gridView);
String[] languages = {"C", "C++", "Java", "Python", "Kotlin"};
ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, languages);
gridView.setAdapter(adapter);

API Types and Data Passing

... Continue reading "Android and iOS Mobile App Development Solutions" »

FCFS and SJF CPU Scheduling C Program Example

Posted by Anonymous and classified in Computers

Written on in English with a size of 3.03 KB

FCFS and SJF CPU Scheduling C Program Example

Corrected and formatted C source code for FCFS and SJF scheduling.

FCFS Scheduling C Implementation

#include <stdio.h>

int FCFS() {
    int bt[15], n, i, wt[15];
    float twt = 0, tat = 0, att, awt;
    printf("\nTHE FCFS SCHEDULING\n");
    printf("Enter the number of processes: ");
    scanf("%d", &n);
    printf("Enter burst time of all the processes:\n");
    for (i = 0; i < n; i++) {
        printf("P%d: ", i + 1);
        scanf("%d", &bt[i]);
    }

    wt[0] = 0;
    // for calculating waiting time of each process
    for (i = 1; i < n; i++)
        wt[i] = bt[i - 1] + wt[i - 1];

    printf("ProcessID\tBurstTime\tWaitingTime\tTurn Around Time\n");
    for (i = 0; i <
... Continue reading "FCFS and SJF CPU Scheduling C Program Example" »

Assembly Language Programming: Code Analysis and Solutions

Posted by Anonymous and classified in Computers

Written on in English with a size of 4.63 KB

Assembly Language Code Analysis and Solutions

Section 1: Instruction Correctness Check

.data

calculate WORD 100
wVal DWORD 2

Instructions:

  1. mov bl, calculate
  2. mov ax, wVal

Question 1: Are the above two instructions correct? If not, justify your claim. [2 marks]

Answer:

Both instructions are incorrect.

  • For the mov operation, the operands must generally be of the same size.
  • In instruction 1, bl is 8 bits (1 byte), but calculate is defined as a WORD (16 bits or 2 bytes). The operand sizes do not match.
  • In instruction 2, ax is 16 bits (2 bytes), but wVal is defined as a DWORD (32 bits or 4 bytes). The operand sizes do not match.

Section 2: Loop Pseudo-code

Question 2: Write the pseudo-code for the loop that calculates the sum of the integers 3 + 2 + 1. [2 marks]

... Continue reading "Assembly Language Programming: Code Analysis and Solutions" »