Skip to content

Stack-oriented programming language that feels like JSX

Notifications You must be signed in to change notification settings

Mohammad-Al-Refai/jsx-language

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

83 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jsx-language

Overview

Have you ever wondered how programming languages actually work under the hood? Do you believe that languages are just magical entities?

In this project, I set out to create a simple stack-oriented programming language and its syntax looks like JSX (because I love react js 😊) and all of that using the Go programming language with 0 dependencies. Inspired by my curiosity and desire to understand the inner workings of languages, this project served as an educational endeavor to demystify the magic behind programming languages, even it just an interpreted language not a compiled language but it worth it.

Getting Started

Download jsx-language from the releases then create a file and run:

./jsx-language [file path]

How it works?

image

Comment

start with #

Variables

Math operations: + & - & * & / & %

Supported values:

  • string

  • number

  • array

  • boolean

  • object member call


<App>
   <Let id={"name"} value={"Mohammad"}/>
<App/>

<App>
   <Let id={"num"} value={1 1 +}/>
<App/>

<App>
   <Let id={"data"} value={[1,"hi",false]}/>
<App/>

<App>
   <Let id={"data"} value={[1,"hi",false]}/>
   <Let id={"dataLength"} value={data array.length()}/>
<App/>

If statement

Logical operators:

  • ==

  • !=

  • greater like >

  • smaller like <

<App>
   <If condition={1 2 greater}>
    ...
    <If/>
<App/>

Loop

<App>
   <For var={"i"} from={0} to={10}>
     <Print value={i}/>
    <For/>
<App/>

Break

<App>
   <For var={"i"} from={0} to={10}>
      <If condition={i 2 greater}>
         <Print value={i}>
         <Break/>
      <If/>
    <For/>
<App/>

Continue

<App>
   <For var={"i"} from={0} to={10}>
      <If condition={i 2 ==}>
         <Continue/>
      <If/>
      <Print value={i}>
    <For/>
<App/>

Function

<App>
   <Function id={"Sum"} args={"x","y"}>
        <Print value={x y +}>
    <Function/>
<App/>

Function call

<App>
  <Sum x={1} y={2}/>
<App/>

Array

// [array] array.length()

<App>
   <Let id={"data"} value={[1,2,"hello",false,423]}/>
   <Print value={data array.length()}/>
<App/>
// [array] [index] array.at()

<App>
   <Let id={"data"} value={[1,2,"hello",false,423]}/>
   <Print value={0 data array.at()}/>
<App/>
// [array] [value] array.push()

<App>
   <Let id={"data"} value={[]}>
   <Print value={"hello" data array.push()}/>
<App/>
// [array] array.pop()

<App>
   <Let id={"data"} value={[1,2,3]}>
   <Print value={data array.pop()}/>
   <Print value={data}/>
<App/>

Examples

Recurses I learnt from

About

Stack-oriented programming language that feels like JSX

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages