{"id":13780632,"url":"https://github.com/pmachapman/LittleC","last_synced_at":"2025-05-11T14:32:57.461Z","repository":{"id":84463496,"uuid":"54538583","full_name":"pmachapman/LittleC","owner":"pmachapman","description":"A modified version of the LittleC Interpreter from Herbert Schildt's C: The Complete Reference (4th Ed.)","archived":false,"fork":false,"pushed_at":"2023-12-15T01:01:15.000Z","size":101,"stargazers_count":24,"open_issues_count":1,"forks_count":18,"subscribers_count":11,"default_branch":"master","last_synced_at":"2024-11-17T15:48:58.254Z","etag":null,"topics":["c","interpreter","multi-platform"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pmachapman.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2016-03-23T07:10:05.000Z","updated_at":"2024-01-16T20:37:31.000Z","dependencies_parsed_at":"2023-12-15T02:23:56.920Z","dependency_job_id":"eae8a122-0144-4220-939f-ebf68fc1a395","html_url":"https://github.com/pmachapman/LittleC","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pmachapman%2FLittleC","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pmachapman%2FLittleC/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pmachapman%2FLittleC/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pmachapman%2FLittleC/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pmachapman","download_url":"https://codeload.github.com/pmachapman/LittleC/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253580116,"owners_count":21930885,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","interpreter","multi-platform"],"created_at":"2024-08-03T18:01:18.137Z","updated_at":"2025-05-11T14:32:57.103Z","avatar_url":"https://github.com/pmachapman.png","language":"C","funding_links":[],"categories":["C"],"sub_categories":[],"readme":"﻿# Little C \u003c!-- omit from toc --\u003e\nThe Little C Interpreter from Herbert Schildt's C: The Complete Reference (4th Ed.)\n\n## Table of Contents \u003c!-- omit from toc --\u003e\n\n- [Project Structure](#project-structure)\n- [Specifications](#specifications)\n- [Restrictions](#restrictions)\n- [Library Functions](#library-functions)\n- [Example Programs](#example-programs)\n\n## Project Structure\n\nThe files for this project are in the following directories:\n\n    .\n    ├── bcb3                  # Borland C++ Builder 3.0 Project Files\n    ├── bcc55                 # Borland C++ Compiler 5.5 Makefile\n    ├── clang                 # Clang C Compiler Makefile\n    ├── dev-cpp               # Dev-C++ 4.9 Project Files\n    ├── gcc                   # Gnu C Compiler Makefile\n    ├── qc25                  # Microsoft Quick C 2.5 Makefile\n    ├── src                   # Project Source Code\n    ├── vc152                 # Visual C++ 1.52 Project File\n    ├── vc2                   # Visual C++ 2.0 Project File\n    ├── vc42                  # Visual C++ 4.2 Project File\n    ├── vc5                   # Visual C++ 5.0 Project File\n    ├── vc6                   # Visual C++ 6.0 Project File\n    ├── vs2002                # Visual Studio .NET Project File\n    ├── vs2003                # Visual Studio .NET 2003 Project File\n    ├── vs2005                # Visual Studio 2005 Project File\n    ├── vs2008                # Visual Studio 2008 Project File\n    ├── vs2010                # Visual Studio 2010 Project File\n    ├── vs2012                # Visual Studio 2012 Project File\n    ├── vs2013                # Visual Studio 2013 Project File\n    ├── vs2015                # Visual Studio 2015 Project File\n    ├── vs2017                # Visual Studio 2017 Project File\n    ├── vs2019                # Visual Studio 2019 Project File\n    ├── vs2022                # Visual Studio 2022 Project File\n    ├── watcom                # Open Watcom 1.9 Project File\n    ├── xcode                 # Apple Xcode Project File\n    ├── LICENSE.md\n    └── README.md\n\n## Specifications\nThe following features are implemented:\n\n * Parameterized functions with local variables\n * Recursion\n * The **if** statement\n * The **do-while**, **while**, and **for** loops\n * Local and global variables of type **int** and **char**\n * Function parameters of type **int** and **char**\n * Integer and character constants\n * String constants (limited implementation)\n * The **return** statement, both with and without a value\n * The **break**, **continue** and **end** statements\n * A limited number of standard library functions\n * These operators: +, –, *, /, %, \u003c, \u003e, \u003c=, \u003e=, ==, !=, unary –, and unary +\n * These escaped characters: \\a, \\b, \\f, \\n, \\r, \\t, \\v, \\\\', \\\\\", and \\\\\\\\\n * Functions returning integers\n * /* ... */-style comments\n * C++ style comments\n\n## Restrictions\n\nThe 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:\n\n```C\nfor(a=0; a \u003c 10; a=a+1)\n  for(b=0; b \u003c 10; b=b+1)\n    for(c=0; c \u003c 10; c=c+1)\n      puts (\"hi\");\n\nif(a=c)\n  if(a=b) x = 10;\n```\n\nInstead, you must write the code like this:\n\n```C\nfor(a=0; a \u003c 10; a=a+1) {\n  for(b=0; b \u003c 10; b=b+1) {\n    for(c=0; c \u003c 10; c=c+1) {\n      puts(\"hi\");\n    }\n  }\n}\nif(a=c) {\n  if(a=b) {\n    x = 10;\n  }\n}\n```\n\nPrototypes 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.\n\nAll 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:\n\n```C\nint myfunc()\n{\n  int i; /* this is valid */\n  if(1) {\n    int i; /* this is not valid */\n    /*...*/\n  }\n}\n```\n\nAll functions must be preceded by either an **int** or **char** type specifier. For example, this declaration is valid:\n\n```C\nint main()\n{\n  /*...*/\n}\n```\n\nHowever, this one is not:\n\n```C\nmain ()\n{\n  /*...*/\n}\n```\n\n## Library Functions\n\nThe following library functions are implemented:\n\n```C\nint getche(void);    /* Read a character from keyboard and return its value */\nint putch(char ch);  /* Write a character to the screen */\nint puts(char *s);   /* Write a string to the screen */\nint getnum(void);    /* Read an integer from the keyboard and return its value */\nint print(char *s);  /* Write a string to the screen */\nint print(int i);    /* Write an integer to the screen */\n```\n\n## Example Programs\n\nA program demonstrating all of the features of Little C:\n\n```C\n/* Little C Demonstration Program #1.\n\n   This program demonstrates all features\n   of C that are recognized by Little C.\n*/\n\nint i, j;   /* global vars */\nchar ch;\n\nint main()\n{\n  int i, j;  /* local vars */\n\n  puts(\"Little C Demo Program.\");\n\n  print_alpha();\n\n  do {\n    puts(\"enter a number (0 to quit): \");\n    i = getnum();\n    if(i \u003c 0 ) {\n      puts(\"numbers must be positive, try again\");\n    }\n    else {\n      for(j = 0; j \u003c i; j=j+1) {\n        print(j);\n        print(\"summed is\");\n        print(sum(j));\n        puts(\"\");\n      }\n    }\n  } while(i!=0);\n\n  return 0;\n}\n\n/* Sum the values between 0 and num. */\nint sum(int num)\n{\n  int running_sum;\n\n  running_sum = 0;\n\n  while(num) {\n    running_sum = running_sum + num;\n    num = num - 1;\n  }\n  return running_sum;\n}\n\n/* Print the alphabet. */\nint print_alpha()\n{\n  for(ch = 'A'; ch\u003c='Z'; ch = ch + 1) {\n    putch(ch);\n  }\n  puts(\"\");\n\n  return 0;\n}\n```\n\nA program demonstrating nested loops:\n\n```C\n/* Nested loop example. */\nint main()\n{\n  int i, j, k;\n\n  for(i = 0; i \u003c 5; i = i + 1) {\n    for(j = 0; j \u003c 3; j = j + 1) {\n      for(k = 3; k ; k = k - 1) {\n        print(i);\n        print(j);\n        print(k);\n        puts(\"\");\n      }\n    }\n  }\n  puts(\"done\");\n\n  return 0;\n}\n```\n\nA program demonstrating the assignment operator:\n\n```C\n/* Assigments as operations. */\nint main()\n{\n  int a, b;\n\n  a = b = 10;\n\n  print(a); print(b);\n\n  while(a=a-1) {\n    print(a);\n    do {\n       print(b);\n    } while((b=b-1) \u003e -10);\n  }\n\n  return 0;\n}\n```\n\nA program demonstrating recursive functions:\n\n```C\n/* This program demonstrates recursive functions. */\n\n/* return the factorial of i */\nint factr(int i)\n{\n  if(i\u003c2) {\n    return 1;\n  }\n  else {\n     return i * factr(i-1);\n  }\n}\n\nint main()\n{\n  print(\"Factorial of 4 is: \");\n  print(factr(4));\n\n  return 0;\n}\n```\n\nA program demonstrating function arguments:\n\n```C\n/* A more rigorous example of function arguments. */\n\nint f1(int a, int b)\n{\n  int count;\n\n  print(\"in f1\");\n\n  count = a;\n  do {\n    print(count);\n  } while(count=count-1);\n\n  print(a); print(b);\n  print(a*b);\n  return a*b;\n}\n\nint f2(int a, int x, int y)\n{\n  print(a); print(x);\n  print(x / a);\n  print(y*x);\n\n  return 0;\n}\n\nint main()\n{\n  f2(10, f1(10, 20), 99);\n\n  return 0;\n}\n```\n\nA program demonstrating loop statements:\n\n```C\n/* The loop statements. */\nint main()\n{\n  int a;\n  char ch;\n\n  /* the while */\n  puts(\"\\aEnter a number: \");\n  a = getnum();\n  while(a) {\n    print(a);\n    print(a*a);\n    puts(\"\");\n    a = a - 1;\n  }\n\n  /* the do-while */\n  puts(\"enter characters, 'q' to quit\");\n  do {\n     ch = getche();\n  } while(ch !='q');\n\n  /* the for */\n  for(a=0; a\u003c10; a = a + 1) {\n     print(a);\n  }\n\n  return 0;\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpmachapman%2FLittleC","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpmachapman%2FLittleC","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpmachapman%2FLittleC/lists"}