All Projects β†’ pmachapman β†’ Littlec

pmachapman / Littlec

Licence: mit
A modified version of the LittleC Interpreter from Herbert Schildt's C: The Complete Reference (4th Ed.)

Programming Languages

c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to Littlec

Springboot Learning
πŸš• spring bootε­¦δΉ ζ‘ˆδΎ‹οΌŒζ–ΉδΎΏspring boot εˆε­¦θ€…εΏ«ι€ŸζŽŒζ‘η›Έε…³ηŸ₯θ―†
Stars: ✭ 724 (+7140%)
Mutual labels:  interpreter
Poop
A new perspective on programming
Stars: ✭ 19 (+90%)
Mutual labels:  interpreter
Androidfancydrawable
Android animation interpolator based on bezier curve.
Stars: ✭ 26 (+160%)
Mutual labels:  interpreter
Openspades
Compatible client of Ace of Spades 0.75
Stars: ✭ 769 (+7590%)
Mutual labels:  multi-platform
Celiagg
🎨Anti-Grain Geometry for Python 3 with Cython
Stars: ✭ 17 (+70%)
Mutual labels:  multi-platform
Avalonia.gamestudio
Stride GameStudio running on Avalonia UI
Stars: ✭ 24 (+140%)
Mutual labels:  multi-platform
Xeus
Implementation of the Jupyter kernel protocol in C++
Stars: ✭ 693 (+6830%)
Mutual labels:  interpreter
Cfl
a Compileable statically typed Functional programming Language
Stars: ✭ 7 (-30%)
Mutual labels:  interpreter
Mico
Mico ("Monkey" in catalan). Monkey language implementation done with C++. https://interpreterbook.com/
Stars: ✭ 19 (+90%)
Mutual labels:  interpreter
Jasl
Just another scripting language
Stars: ✭ 25 (+150%)
Mutual labels:  interpreter
Trinitycore
TrinityCore Open Source MMO Framework (master = 9.1.5.41488, 3.3.5 = 3.3.5a.12340)
Stars: ✭ 7,074 (+70640%)
Mutual labels:  multi-platform
Ligo
ligo language interpreter
Stars: ✭ 17 (+70%)
Mutual labels:  interpreter
Blink Lexer
Starting code of the first challenge in the Let's Build a Programming Language series.
Stars: ✭ 24 (+140%)
Mutual labels:  interpreter
Reaktive
Kotlin multi-platform implementation of Reactive Extensions
Stars: ✭ 760 (+7500%)
Mutual labels:  multi-platform
Mpssh Py
Mass Parallel Secure Shell command execution
Stars: ✭ 7 (-30%)
Mutual labels:  multi-platform
Bic
A C interpreter and API explorer.
Stars: ✭ 719 (+7090%)
Mutual labels:  interpreter
Hpnl
High Performance Network Library for RDMA
Stars: ✭ 23 (+130%)
Mutual labels:  multi-platform
Cpp redis
C++11 Lightweight Redis client: async, thread-safe, no dependency, pipelining, multi-platform - NO LONGER MAINTAINED - Please check https://github.com/cpp-redis/cpp_redis
Stars: ✭ 855 (+8450%)
Mutual labels:  multi-platform
Openhmd
Free and Open Source API and drivers for immersive technology.
Stars: ✭ 837 (+8270%)
Mutual labels:  multi-platform
Moonsharp
An interpreter for the Lua language, written entirely in C# for the .NET, Mono, Xamarin and Unity3D platforms, including handy remote debugger facilities.
Stars: ✭ 926 (+9160%)
Mutual labels:  interpreter

Little C

The Little C Interpreter from Herbert Schildt's C: The Complete Reference (4th Ed.)

Table of Contents

Project Structure

The files for this project are in the following directories:

.
β”œβ”€β”€ bcb3                  # Borland C++ Builder 3.0 Project Files
β”œβ”€β”€ bcc55                 # Borland C++ Compiler 5.5 Makefile
β”œβ”€β”€ clang                 # Clang C Compiler Makefile
β”œβ”€β”€ dev-cpp               # Dev-C++ 4.9 Project Files
β”œβ”€β”€ gcc                   # Gnu C Compiler Makefile
β”œβ”€β”€ qc25                  # Microsoft Quick C 2.5 Makefile
β”œβ”€β”€ src                   # Project Source Code
β”œβ”€β”€ vc152                 # Visual C++ 1.52 Project File
β”œβ”€β”€ vc2                   # Visual C++ 2.0 Project File
β”œβ”€β”€ vc42                  # Visual C++ 4.2 Project File
β”œβ”€β”€ vc5                   # Visual C++ 5.0 Project File
β”œβ”€β”€ vc6                   # Visual C++ 6.0 Project File
β”œβ”€β”€ vs2002                # Visual Studio .NET Project File
β”œβ”€β”€ vs2003                # Visual Studio .NET 2003 Project File
β”œβ”€β”€ vs2005                # Visual Studio 2005 Project File
β”œβ”€β”€ vs2008                # Visual Studio 2008 Project File
β”œβ”€β”€ vs2010                # Visual Studio 2010 Project File
β”œβ”€β”€ vs2012                # Visual Studio 2012 Project File
β”œβ”€β”€ vs2013                # Visual Studio 2013 Project File
β”œβ”€β”€ vs2015                # Visual Studio 2015 Project File
β”œβ”€β”€ vs2017                # Visual Studio 2017 Project File
β”œβ”€β”€ vs2019                # Visual Studio 2019 Project File
β”œβ”€β”€ watcom                # Open Watcom 1.9 Project File
β”œβ”€β”€ xcode                 # Apple Xcode Project File
β”œβ”€β”€ LICENSE.md
└── README.md

Specifications

The following features are implemented:

  • Parameterized functions with local variables
  • Recursion
  • The if statement
  • The do-while, while, and for loops
  • Local and global variables of type int and char
  • Function parameters of type int and char
  • Integer and character constants
  • String constants (limited implementation)
  • The return statement, both with and without a value
  • The break, continue and end statements
  • A limited number of standard library functions
  • These operators: +, –, *, /, %, <, >, <=, >=, ==, !=, unary –, and unary +
  • These escaped characters: \a, \b, \f, \n, \r, \t, \v, \', \", and \\
  • Functions returning integers
  • /* ... */-style comments
  • C++ style comments

Restrictions

The targets of if, while, do, and for must be blocks of code surrounded by beginning and ending curly braces. You cannot use a single statement. For example, code such as this will not correctly interpreted:

for(a=0; a < 10; a=a+1)
  for(b=0; b < 10; b=b+1)
    for(c=0; c < 10; c=c+1)
      puts ("hi");

if(a=c)
  if(a=b) x = 10;

Instead, you must write the code like this:

for(a=0; a < 10; a=a+1) {
  for(b=0; b < 10; b=b+1) {
    for(c=0; c < 10; c=c+1) {
      puts("hi");
    }
  }
}
if(a=c) {
  if(a=b) {
    x = 10;
  }
}

Prototypes are not supported. All functions are assumed to return an integer type (char return types are allowed, but elevated to int), and no parameter type checking is performed.

All local variables must be declared at the start of a function, immediately after the opening brace. Local variables cannot be declared within any other block. The following function is invalid:

int myfunc()
{
  int i; /* this is valid */
  if(1) {
    int i; /* this is not valid */
    /*...*/
  }
}

All functions must be preceded by either an int or char type specifier. For example, this declaration is valid:

int main()
{
  /*...*/
}

However, this one is not:

main ()
{
  /*...*/
}

Library Functions

The following library functions are implemented:

int getche(void);    /* Read a character from keyboard and return its value */
int putch(char ch);  /* Write a character to the screen */
int puts(char *s);   /* Write a string to the screen */
int getnum(void);    /* Read an integer from the keyboard and return its value */
int print(char *s);  /* Write a string to the screen */
int print(int i);    /* Write an integer to the screen */

Example Programs

A program demonstrating all of the features of Little C:

/* Little C Demonstration Program #1.

   This program demonstrates all features
   of C that are recognized by Little C.
*/

int i, j;   /* global vars */
char ch;

int main()
{
  int i, j;  /* local vars */

  puts("Little C Demo Program.");

  print_alpha();

  do {
    puts("enter a number (0 to quit): ");
    i = getnum();
    if(i < 0 ) {
      puts("numbers must be positive, try again");
    }
    else {
      for(j = 0; j < i; j=j+1) {
        print(j);
        print("summed is");
        print(sum(j));
        puts("");
      }
    }
  } while(i!=0);

  return 0;
}

/* Sum the values between 0 and num. */
int sum(int num)
{
  int running_sum;

  running_sum = 0;

  while(num) {
    running_sum = running_sum + num;
    num = num - 1;
  }
  return running_sum;
}

/* Print the alphabet. */
int print_alpha()
{
  for(ch = 'A'; ch<='Z'; ch = ch + 1) {
    putch(ch);
  }
  puts("");

  return 0;
}

A program demonstrating nested loops:

/* Nested loop example. */
int main()
{
  int i, j, k;

  for(i = 0; i < 5; i = i + 1) {
    for(j = 0; j < 3; j = j + 1) {
      for(k = 3; k ; k = k - 1) {
        print(i);
        print(j);
        print(k);
        puts("");
      }
    }
  }
  puts("done");

  return 0;
}

A program demonstrating the assignment operator:

/* Assigments as operations. */
int main()
{
  int a, b;

  a = b = 10;

  print(a); print(b);

  while(a=a-1) {
    print(a);
    do {
       print(b);
    } while((b=b-1) > -10);
  }

  return 0;
}

A program demonstrating recursive functions:

/* This program demonstrates recursive functions. */

/* return the factorial of i */
int factr(int i)
{
  if(i<2) {
    return 1;
  }
  else {
     return i * factr(i-1);
  }
}

int main()
{
  print("Factorial of 4 is: ");
  print(factr(4));

  return 0;
}

A program demonstrating function arguments:

/* A more rigorous example of function arguments. */

int f1(int a, int b)
{
  int count;

  print("in f1");

  count = a;
  do {
    print(count);
  } while(count=count-1);

  print(a); print(b);
  print(a*b);
  return a*b;
}

int f2(int a, int x, int y)
{
  print(a); print(x);
  print(x / a);
  print(y*x);

  return 0;
}

int main()
{
  f2(10, f1(10, 20), 99);

  return 0;
}

A program demonstrating loop statements:

/* The loop statements. */
int main()
{
  int a;
  char ch;

  /* the while */
  puts("\aEnter a number: ");
  a = getnum();
  while(a) {
    print(a);
    print(a*a);
    puts("");
    a = a - 1;
  }

  /* the do-while */
  puts("enter characters, 'q' to quit");
  do {
     ch = getche();
  } while(ch !='q');

  /* the for */
  for(a=0; a<10; a = a + 1) {
     print(a);
  }

  return 0;
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].