Compiler Construction Tool - ANTLR

ANTLR


  • A set of language translation tools (formerly PCCTS).     
  • It is one of the "Compiler Construction Tool for Programming languages".
  • Includes scanner/parser generators for C, C++, and Java.

  • Terence Parr is the maniac behind ANTLR and has been working on language tools since 1989. He is a professor of computer science at the University of San Francisco.

  • ANTLR(ANother Tool for Language Recognition) is a powerful parser generator for reading, processing, executing, or translating structured text or binary files. 
  • It's widely used to build languages, tools, and frameworks. 
  • From a grammar, ANTLR generates a parser that can build and walk parse trees. 

Example

grammer Expr;  

prog : (expr NEWLINE)*;

expr  : expr('*'|'/')

expr 
   |
     expr('+'|'-')

expr   |
     int
   |
    '('expr')' ;

NEWLINE : [\r\n]+;

int : [0-9]+;


Compile  : $ javac Expr.java

Run         : $ grun expr prog -gui 100+2*34


ASP .NET Real time process program

ONLINE QUIZ APPLICATION













ONLINE VOTING APPLICATION
























ONLINE SHOPPING















C# Real time process program

1.STRING MANIPULATIONS

AIM:
            To implement a String Manipulation using C#.

CODING:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace string_fun
{
    class Program
    {
        static void Main(string[] args)
        {
            String fn;
            String ln;
            fn = "Bhuvana";
            ln = "Devi";
            int ch;
            Console.WriteLine("*******String Function********");
            Console.WriteLine("\n");
            Console.WriteLine("\t\t1.HashCode");
            Console.WriteLine("\n");
            Console.WriteLine("GetHashCode  :"+fn.GetHashCode());
            Console.WriteLine("\n");
            Console.WriteLine("\t\t2.GetType");
            Console.WriteLine("\n");
            Console.WriteLine("GetType      :" + fn.GetTypeCode());
            Console.WriteLine("\n");
            Console.WriteLine("\t\t3.SubString");
            Console.WriteLine("\n");
            Console.WriteLine("SubString    :" + fn.Substring(2,5));
            Console.WriteLine("\n");
            Console.WriteLine("\t\t4.Split");
            Console.WriteLine("\n");
            String[] split = fn.Split(new Char[] { 'a' });
            Console.WriteLine("Split        :" + split[0]);
             Console.WriteLine("Split       :" + split[1]);
             Console.WriteLine("\n");
             Console.WriteLine("\t\t5.GetTypeCode");
             Console.WriteLine("\n");
             Console.WriteLine("GetTypeCode :"+fn.GetTypeCode());
             Console.WriteLine("\n");
             Console.WriteLine("\t\t6.Contains");
             Console.WriteLine("\n");
             Console.WriteLine("Contains     :" + fn.Contains("vana"));
             Console.WriteLine("\n");
             Console.WriteLine("\t\t7.Equals");
             Console.WriteLine("\n");
             Console.WriteLine("Equals       :"+fn.Equals(ln));
             Console.WriteLine("\n");
             Console.WriteLine("\t\t8.TOUppper & TOLower");
             Console.WriteLine("\n");
             Console.WriteLine("UpperCase   :" +fn.ToUpper());
             Console.WriteLine("LowerCase   :" + ln.ToLower());
             Console.WriteLine("\n");
             Console.WriteLine("\t\t9.StartsWith & EndsWith");
             Console.WriteLine("\n");
             Console.WriteLine("StartsWith  :"+fn.StartsWith("Bhu"));
             Console.WriteLine("EndsWith  :" + ln.EndsWith("i"));
             Console.WriteLine("\n");
             Console.WriteLine("\t\t10.Insert & Remove");
             Console.WriteLine("\n");
             Console.WriteLine("Insert      :"+fn.Insert(0,"R."));
             Console.WriteLine("Remove      :"+fn.Remove(1));
             Console.WriteLine("****************************************");
             Console.ReadKey();           
        }
    }
}

 OUTPUT:
                                                
2. Inheritence
Date:
AIM:
            To implement Inheritence using VB .NET.

CODING:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Inheritance
{
public class add 
{
public String name,clas,roll;
public Decimal no,efee,tfee;
public int[][] a = new int[5][];
public  void adddetails()
{
Console.Write("Enter Student Name:");
name = Console.ReadLine ();
Console.Write("Enter Roll No:");
 roll = Console.ReadLine();
Console.Write("Enter Class Name:");
clas = Console.ReadLine();
Console.Write("Enter Bill No:");
no = Convert.ToDecimal(Console.ReadLine());
Console.Write("Enter Exam Fee:");
efee = Convert.ToDecimal(Console.ReadLine());
Console.Write("Enter Tution Fee:");
tfee = Convert.ToDecimal(Console.ReadLine());}}
public class formatebill : add{
public void bill(){
Console.WriteLine("|--------------------------------------------|");
Console.WriteLine("|\t\tArasan Ganesan Polytechnic                   College\n|\t\t\tSivakasi\t\t\t\n|\t\t\tReceipt\t\t\t");
Console.WriteLine("|--------------------------------------------|");
Console.WriteLine("|Name: "+name+"\t\t\t\t\t\tBill No: "+no);
Console.WriteLine("|Roll No: "+roll);
Console.WriteLine("|Class: "+clas+"\t\t\t\t\t\tDate:29/01/2018|");
Console.WriteLine("|-------------------------------------------|");
 Console.WriteLine("|S.No|\t\t\tParticulars\t\t\t|\tAmount|");
Console.WriteLine("|-------------------------------------------|");
Console.WriteLine("|1.  |\t\t\tExam Fees\t\t\t|\t"+efee+"  ");
Console.WriteLine("|2.  |\t\t\tTution Fees\t\t\t|\t"+tfee+"  ");
Console.WriteLine("|---------------------------------------------|");
Console.WriteLine("|\t\t\t\t\t\tTotal   |\t"+(efee+tfee)+"      ");
Console.WriteLine("|------------------------------------------|");
Console.WriteLine("|Signature: |");                                         
Console.WriteLine("|-------------------------------------------|");
 Console.WriteLine("");
}
}
public  class bill
{
static void Main(String [] args)
{
formatebill fm = new formatebill();
fm.adddetails();
fm.bill();
Console.ReadKey();
}
}
}

Output:






























                                       3, Interface

Aim:
          To implement bank transaction using interface
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Interface
{
 interface TMBACCOUNT
{
void deposit(Decimal amount);
void withdraw(Decimal amount);
Decimal balanceknow();
}
public class savingaccount : TMBACCOUNT
{
private Decimal balance;
private Decimal perdaylimit;
public void deposit(Decimal amount)
{
 balance += amount;
 }
 public void withdraw(Decimal amount)
  { if (balance < amount)
Console.WriteLine("Insufficiend Balanace");
else if ((perdaylimit + amount) > 5000)
Console.WriteLine("Withdraw Failed Your Daily Limite is outed");
else
{
balance -= amount;
perdaylimit += amount;
}
}
public Decimal balanceknow()
{
return balance;
}
static void Main(String[] args)
{
Decimal amount1;
String s;
 do
{
Console.WriteLine("1:Deposit\n2:Withdraw\n3:Balance Check");
int a = Convert.ToInt32(Console.ReadLine());
savingaccount sa = new savingaccount();
if (a == 1)
{
Console.WriteLine("Enter the Deposit  Amount");
amount1 = Convert.ToInt32(Console.ReadLine());
sa.deposit(amount1);
}
 if (a == 2)
{
Console.WriteLine("Enter the Withdraw  Amount");
amount1 = Convert.ToInt32(Console.ReadLine());
sa.withdraw(amount1);
}
if (a == 3)
{
 amount1 = sa.balanceknow();
Console.WriteLine("Enter the Balance :{0}",amount1 );
}
Console.Write("\nThanks For Using TMB Bank\nDo You Want to Continue this transaction(y/n): ");
s=Console.ReadLine();
while(s.Equals("y"));
Console.ReadKey();
}
}
}Output:


                                           4. EXCEPTION

Aim:
            To handle exception using console application.
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int n,a,b,i;
int[] c=new int[5];
do{
Console.Write("1.DivideByZeroException\n2.IndexOutOfRangeException\n3.OverFlowException\n4.FormatException\nEnter Your Choice: ");
                n = int.Parse(Console.ReadLine());
switch (n) {
case 1:
        Console.Write("Enter A: ");
        a=int.Parse(Console.ReadLine());
        Console.Write("Enter B: ");
        b=int.Parse(Console.ReadLine());
        try
       {
       Console.WriteLine(a+" / "+b+" = " + (a / b));
       }
       catch(DivideByZeroException e) {
       Console.WriteLine(e); }
       break;
case 2:
        Console.Write("Enter Count: ");
         a = int.Parse(Console.ReadLine());
         try
        {
        for (i = 0; i < a; i++) {
        c[i] = int.Parse(Console.ReadLine());
        } }
        catch (IndexOutOfRangeException e) {
        Console.WriteLine(e);                }
       break;
case 3:
          Console.Write("Enter Value: ");
          try
         {
          a = int.Parse(Console.ReadLine());
          }
          catch (OverflowException e) {
          Console.WriteLine(e);
          }
          break;
case 4:
          Console.Write("Enter Value: ");
          try
         {
         a = int.Parse(Console.ReadLine());
         }
        catch (FormatException e) {
        Console.WriteLine(e);
        }
        break;
        }
        Console.Write("Do You Want to Continue(y/n): ");
        }while(Console.ReadLine().Equals("y"));
        Console.WriteLine("Press Any Key To Exit");
        Console.ReadKey();
        }  }}

Output:





Compiler Construction Tool - ANTLR

ANTLR A set of language translation tools (formerly PCCTS).       It is one of the "Compiler Construction Tool for Programming l...