Giter VIP home page Giter VIP logo

c48's Introduction

c48

Contact: [email protected]

Getting started

  1. c48/src$ cd src
  2. c48/src$ make

Now that you have built the interpreter you can start writing programs.

Open up a file call hello.c48 and write this

//This is how functions are defined, the main function is the first function that the interpreter calls
fun main(){

//The following line calls the print function "Hello World" as the parameter
print("Hello World");
}

Now you can run this program through the interpreter to execute it

$ ./c48 hello.c48

You should see

$ Hello World

Congratulations on running your first C48 program!

Conditionals

Conditionals allow the programmer to specify one more condititons to be evaluated or tested by the program including the expressions to be executed if the condition is true or if the condition is false.

The following program prints that a is less than 10 because the if statement evaluated to true.

a = 5;

if(a < 10){
  print("A is less than 10");
 }
 else{
   print("A is more than 10");
 }

Recursion

Recursion is when a functions is defined in terms of itself. It is when a function calls itself. One recursive program is called the factorial. Here is the factorial in C48

fun factorial(i){
   if(i == 1) {
      return 1;
   }
   return i * factorial(i - 1);
}

fun main() { 
   i = 5;
   print (factorial(i));
}

This should give you the factorial of 5, which is 120.

c48's People

Contributors

bmathur avatar hzey avatar ztech35 avatar ztwild avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

bmathur

c48's Issues

Get values from a token list that was assigned to a void pointer (Due before we meet tommorrow)

We are trying to cast the value of the void pointer to a token_list, but it is giving a segfault.

  object1.value = "(";
  token_list = cons1(object1, token_list);

  object1.type = "identifier";
  object1.value = "+";
  token_list = cons1(object1, token_list);

  object1.type = "num";
  object1.value = "137";
  token_list = cons1(object1, token_list);

  object1.type = "num";
  object1.value = "349";
  token_list = cons1(object1, token_list);

  object1.type = "right_paren";
  object1.value = ")";
  token_list = cons1(object1, token_list);

  void *ptr1 = &token_list;
  token_list2 = (struct token_list*)ptr1;
  printf("%s\n", token_list2->val.value);

Add simple operator validation

if the input entered doesn't match the correct format or the operator isn't supported alert the user and exit back to user entry

Lexer can't handle spaces

If you insert a space between left parenthesis and operator for example : ( + 137 349)
The test will fail.
Also if you have tab after operator for example: (+ 137 349)
the test will fail.

Lexer Part 1

lexer(" (set position (* 60 (+ initial rate)))") should return a linked list that looks like this:
[identifier, closed_paren] -> [identifier, closed_paren] ->[identifier, closed_paren] -> [variable, rate] -> [variable, initial] -> [operator, +] -> [identifier, open_paren] -> [indentifier, 60] -> [operator, *] -> [identifier, open_paren] -> [variable, position] ->[operator, set] -> [identifier, open_paren]

Make Lexer handle the correct data types

List of data types that the Lexer should tag in the type variable of it's struct:

  1. Booleans "#t" and "#f" means True and False
  2. Numbers "34", "56" ... means numbers
  3. Characters "#\a", "#\c" e.t.c means characters
  4. Everything else is a symbol, open_paren, or closed_paren.

Add more tests to lexer_tests.c

The test() function is called in repl.c This test() function is in the tests directory in a file called test.c. The test() function calls lexer_tests().

lexer_tests() is in lexer_tests.c which is also in the tests directory. This file also contains a function called assert(). assert takes two strings. An input, and the expected output. If these two strings are equal, this function returns 0. If they are not, it returns 1. assert() increments a "passed" variable if assert() returns 0, and it does nothing if assert() returns 1.

The run variable keeps track of the number of tests run. If the number of tests run is equal to the number of tests passed, then all the tests pass.

Update Comments across all files in the master branch

With the addition of bison/flex we need to update the c style comment "//" to "/* ... */" to compile so if someone can take the time to update the files in the master branch so we all have a consistent place and aren't repeating this process

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.