Skip to content

Wt dialect swahili#146

Open
PapePathe wants to merge 2 commits into
masterfrom
wt-dialect-swahili
Open

Wt dialect swahili#146
PapePathe wants to merge 2 commits into
masterfrom
wt-dialect-swahili

Conversation

@PapePathe
Copy link
Copy Markdown
Owner

@PapePathe PapePathe commented Mar 26, 2026

Support Swahili dialect

First program

lahaja:swahili;

anza() namba{
  rudisha 0;
}

Declaring variables

anza() namba{
  acha x : namba  = 25;
  acha y : float = 0.25; // need to translate to swahili
  acha y : maneno = "hello";

  rudisha 0;
}

Conditionals

anza() namba{
  kama(0 == 0) {
    chapisha("of course");
  } sivyo {
    chapisha("of course");
  }

  rudisha 0;
}

Functions

kazi divide(a: namba, b: namba) kosa {
    kama (b == 0) {
        rudisha kosa("dividend is zero"); 
    }
    rudisha zero(kosa); 
}

anza() namba {
    acha err: kosa = divide(100, 0);

    kama(err != zero(kosa)) {
      chapisha("Division by zero error (%s)\n", err);
    }

    err = divide(100, 10);
    kama(err == zero(kosa)) {
      chapisha("No division error");
    }

    rudisha 0;
}

Structs

muundo Person {
  Age:     namba,
  Height:  desimali,
  Name:    maneno,
}

kazi changeAge(person: *Person) namba {
  person.Age = person.Age + 20;
  person.Age = 20 + person.Age;
 

  rudisha person.Age;
}

kazi changeName(person: *Person) maneno {
  person.Name = "Pathe SENE";

  rudisha person.Name;
}

kazi changHeight(person: *Person) desimali {
  person.Height= 1.80;

  rudisha person.Height;
}

anza() namba {
  acha p : Person = Person{ Age: 0, Height: 0.0, Name: "Pathe", };
  acha myAge : namba = changeAge(p);
  acha myHeight : desimali = changHeight(p);
  acha myName: maneno = changeName(p);
 
  chapisha("age: %d, height: %.2f, name: %s", myAge, myHeight, myName);

  rudisha 0; 
}
`

@Harrisonkamau
Copy link
Copy Markdown

Harrisonkamau commented Mar 26, 2026

Support Swahili dialect

First program

lahaja:swahili;

anza() namba{
  rudisha 0;
}

Declaring variables

anza() namba{
  acha x : namba  = 25;
  acha y : float = 0.25; // need to translate to swahili
  acha y : maneno = "hello";

  rudisha 0;
}

Conditionals

anza() namba{
  kama(0 == 0) {
    chapisha("of course");
  } sivyo {
    chapisha("of course");
  }

  rudisha 0;
}

Functions

kazi divide(a: namba, b: namba) kosa {
    kama (b == 0) {
        rudisha kosa("dividend is zero"); 
    }
    rudisha zero(kosa); 
}

anza() namba {
    acha err: kosa = divide(100, 0);

    kama(err != zero(kosa)) {
      chapisha("Division by zero error (%s)\n", err);
    }

    err = divide(100, 10);
    kama(err == zero(kosa)) {
      chapisha("No division error");
    }

    rudisha 0;
}

Structs

muundo Person {
  Age:     namba,
  Height:  desimali,
  Name:    maneno,
}

kazi changeAge(person: *Person) namba {
  person.Age = person.Age + 20;
  person.Age = 20 + person.Age;
 

  rudisha person.Age;
}

kazi changeName(person: *Person) maneno {
  person.Name = "Pathe SENE";

  rudisha person.Name;
}

kazi changHeight(person: *Person) desimali {
  person.Height= 1.80;

  rudisha person.Height;
}

anza() namba {
  acha p : Person = Person{ Age: 0, Height: 0.0, Name: "Pathe", };
  acha myAge : namba = changeAge(p);
  acha myHeight : desimali = changHeight(p);
  acha myName: maneno = changeName(p);
 
  chapisha("age: %d, height: %.2f, name: %s", myAge, myHeight, myName);

  rudisha 0; 
}
`

Float is a challenging one. For instance, 0.25 is directly translated to sufuri (zero) nukta (decimal) mbili (two) tano (5)

Non-Mathetical float (not drowing) is translated to kuelea

"uongo": False,
"bool": TypeBool,
"baiti": TypeByte,
"desimali": TypeFloat,
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Harrisonkamau this is actually what I need to translate to Swahili. It's the concept of having data of type float.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@NdagiStanley how would you translate TypeFloat to Swhaili.

@NdagiStanley
Copy link
Copy Markdown

Following

}

func (m Swahili) Reserved() map[string]TokenKind {
return map[string]TokenKind{
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keyword translation for zero is missing

@@ -0,0 +1,46 @@
package lexer
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file does not belong here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants