{"id":19819562,"url":"https://github.com/syedzawwarahmed/lavascript","last_synced_at":"2025-02-28T15:47:35.199Z","repository":{"id":186305660,"uuid":"670709717","full_name":"SyedZawwarAhmed/LavaScript","owner":"SyedZawwarAhmed","description":"Our very own programming language.","archived":false,"fork":false,"pushed_at":"2023-12-12T16:24:14.000Z","size":173,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-11T08:26:14.037Z","etag":null,"topics":["compiler","intermediate-code-generation","lexical-analysis","parsing","python","semantic-analysis"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SyedZawwarAhmed.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-07-25T16:49:06.000Z","updated_at":"2023-12-18T11:18:05.000Z","dependencies_parsed_at":"2023-12-12T18:25:18.232Z","dependency_job_id":null,"html_url":"https://github.com/SyedZawwarAhmed/LavaScript","commit_stats":null,"previous_names":["syedzawwarahmed/lavascript"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SyedZawwarAhmed%2FLavaScript","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SyedZawwarAhmed%2FLavaScript/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SyedZawwarAhmed%2FLavaScript/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SyedZawwarAhmed%2FLavaScript/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SyedZawwarAhmed","download_url":"https://codeload.github.com/SyedZawwarAhmed/LavaScript/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241176622,"owners_count":19922732,"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":["compiler","intermediate-code-generation","lexical-analysis","parsing","python","semantic-analysis"],"created_at":"2024-11-12T10:19:23.711Z","updated_at":"2025-02-28T15:47:35.159Z","avatar_url":"https://github.com/SyedZawwarAhmed.png","language":"Python","readme":"\u003ch1\u003eLavaScript\u003c/h1\u003e\n\u003cp\u003e\n  \u003cb\u003eLavaScript is a language inspired by JavaScript.\u003c/b\u003e\n\u003c/p\u003e\n\n\u003ch3\u003eGroup Members:\u003c/h3\u003e\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd\u003eSheikh Abdullah\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003eSyed Zawwar Ahmed\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003eMuhammad Annas Baig\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n\u003cbr\u003e\n\u003ch2\u003eLanguage Specification\u003c/h2\u003e\n\n\u003ch3\u003eVariables\u003c/h3\u003e\n\u003cp\u003eVariables can be declared using \u003ccode\u003edynamic\u003c/code\u003e and \u003ccode\u003estatic\u003c/code\u003e.\ndynamic variables are changeable while static variable is unchangeable like \u003ccode\u003econst\u003c/code\u003e.\u003c/p\u003e\n\n```\n  dynamic a = 10;\n  static b = \"two\";\n  a = false;\n  a = a + 3;\n```\n\n\u003ch3\u003eOperators\u003c/h3\u003e\n\u003cp\u003eLavaScript has 2 types of operators.\u003c/p\u003e\n  \u003ch4\u003eMathematical Operators:\u003c/h4\u003e\n  \u003ccode\u003e +, -, *, /, ^, %\u003c/code\u003e\n  \u003ch4\u003eLogical Operators:\u003c/h4\u003e\n  \u003ccode\u003e ==, !=, \u003e, \u003c, \u003e=, \u003c=, \u0026\u0026, ||\u003c/code\u003e\n\n\u003ch3\u003eData Types\u003c/h3\u003e\n\u003cp\u003eWe have 3 datatypes in LavaScript. Namely: string, number and boolean.\u003c/p\u003e\n\n```\n  dynamic a = 10;\n  dynamic b = 2 - 3;\n  dynamic c = \"Sheikh Abdullah\";\n  static d = true;\n  dynamic e = false \u0026\u0026 true;\n```\n\n\u003ch3\u003eBuilt-ins\u003c/h3\u003e\n\u003cp\u003eUse \u003ccode\u003elog\u003c/code\u003e to print anything to console.\u003c/p\u003e\n\n```\n  log \"Hello World\";\n  static foo = \"I'm a Ubitian\";\n  log foo;\n```\n\n\u003ch3\u003eConditionals\u003c/h3\u003e\n\u003cp\u003eLavaScript supports if-else construct, \u003ccode\u003eif\u003c/code\u003e block will execute if condition is \u003ccode\u003etrue\u003c/code\u003e, \u003ccode\u003eelse\u003c/code\u003e block will execute if the above conditions is \u003ccode\u003efalse\u003c/code\u003e. if-else blocks can be nested.\n\n```\n  dynamic = 10;\n  if (a \u003c 20) {\n    log \"a is less than 20\";\n  } else {\n    if (a \u003e 20) {\n      log \"a is greater than 20\";\n    } else {\n      log \"a is equals to 20\";\n    }\n  }\n```\n\n\u003ch3\u003eLoops\u003c/h3\u003e\n\u003cp\u003eStatements inside \u003ccode\u003euntil\u003c/code\u003e blocks are executed as long as a specified condition evaluates to true. If the condition becomes \u003ccode\u003efalse\u003c/code\u003e, statement within the loop stops executing and control passes to the statement following the loop. Use \u003ccode\u003eexit\u003c/code\u003e to break the loop and \u003ccode className=\"language-cpp\"\u003eskip\u003c/code\u003e to continue within loop.\u003c/p\u003e\n\n```\n  dynamic i = 0;\n  until (i \u003c 10) {\n    log \"Let's study Automata\";\n    if (i == 5) {\n      exit;\n    } else {\n      skip;\n    }\n    i = i + 1;\n  }\n```\n\n\u003ch3\u003eFunctions\u003c/h3\u003e\n\u003cp\u003eFunction can be decalared using \u003ccode\u003eproc\u003c/code\u003e. A function can accept 0 to n parameters separated by comma. \u003ccode\u003ereturn\u003c/code\u003e keyword can be used in the body to exit from function with or without a value. You can optionally specify the return type of a function\u003c/p\u003e\n\n```\n  proc isEven(a, b): string {\n    static rem = a % 2;\n    if (rem == 0) {\n      return \"Number is even\";\n    } else {\n      return \"Number is odd\";\n    }\n  }\n\n  log isEven(23);\n```\n\n\u003ch3\u003eComments\u003c/h3\u003e\n\u003cp\u003eWhile code is for computer to understand, the comments are for humans. LavaScript supports two types of comments i.e single-line comment, starts with \u003ccode\u003e?\u003c/code\u003e and multi-line comment, wrapped by \u003ccode\u003e@...@\u003c/code\u003e.\u003c/p\u003e\n\n```\n? This is a variable\nstatic f = 4;\n\n@\n  This function is used to calculate age\n  from date of birth.\n@\nproc calcAge(dob) {\n  ...\n}\n```\n\n\u003ch3\u003eData Structures\u003c/h3\u003e\n\n\u003ch4\u003eArrays\u003c/h4\u003e\n\u003cp\u003eLavaScript supports the array data structure. Arrays can be defined by using brackets \u003ccode\u003e[]\u003c/code\u003e with the collection of values inside of the brackets separated by commas. Arrays can be multi-dimensional as well.\u003c/p\u003e\n\n```\ndynamic myArray = [1, 3.8, \"Hello\"];\n\ndynamic multiArray = [\n  [\n    ['a', 'b', 'c'],\n    ['A', 'B', 'C']\n  ],\n  [1, 2, 3]\n];\n```\n\n\u003ch3\u003eObject Oriented Programing (OOP)\u003c/h2\u003e\n\u003cp\u003eLavaScript also supports Object Oriented Programming. One can create classes of their own and then create instances namely objects of the classes created.\u003c/p\u003e\n\u003ch4\u003eClasses\u003c/h3\u003e\n\u003cp\u003eClasses can be created using \u003ccode\u003eclass\u003c/code\u003e keyword.\u003c/p\u003e\n\n```\nclass Employee {\n  ...\n}\n```\n\n\u003cp\u003ePublic attributes can be added by writing their identifier in the class definition. Private attributes can also be added by writing a \u003ccode\u003e#\u003c/code\u003e followed by their identifier in the class definition.\u003c/p\u003e\n\n```\nclass Employee {\n  name;\n  #SSN;\n}\n```\n\n\u003cp\u003eIn the above code block, the Employee class has two attributes, \u003ccode\u003ename\u003c/code\u003e is a public attribute, \u003ccode\u003eSSN\u003c/code\u003e is a private attribute.\u003c/p\u003e\n\n\u003cp\u003eA constructor is a function which is called at the time of creation of an object of the class. The constructor method can be added by using the \u003ccode\u003econstructor\u003c/code\u003e keyword.\u003c/p\u003e\n\n```\nclass Employee {\n  name;\n  #SSN;\n\n  constructor(name, SSN) {\n    this.name = name;\n    this.SSN = SSN;\n  }\n}\n```\n\n\u003cp\u003eThe \u003ccode\u003ethis\u003c/code\u003e keyword refers to the current instace of the class.\u003c/p\u003e\n\n\u003cp\u003eFurthermore, simple methods can also be introduced by defining a function in the class definition with the \u003ccode\u003emethod\u003c/code\u003e keyword. Again, class methods can also be made private by adding a # before the identifier.\u003c/p\u003e\n\n```\nclass Employee {\n  name;\n  #SSN;\n  #salary;\n\n  constructor(name, SSN, salary) {\n    this.name = name;\n    this.SSN = SSN;\n    this.salary = salary;\n  }\n\n  method #fire() {\n    log \"Good bye! You've been promoted to a customer.\";\n  }\n\n  method evalutate(performance) {\n    if (performance == 'good') {\n      this.salary = this.salary + 10000;\n    } else {\n      this.fire();\n    }\n  }\n}\n```\n\n\u003cp\u003eIn this example, \u003ccode\u003eevaluate\u003c/code\u003e is a public method while \u003ccode\u003efire\u003c/code\u003e is a private method. Note that private methods can only be called inside of a class.\u003c/p\u003e\n\n\u003ch4\u003eObjects\u003c/h4\u003e\n\u003cp\u003eObjects are instances of any LavaScript class. They can be created by using the \u003ccode\u003einit\u003c/code\u003e keyword followed by the name of the class, and passing the respective arguements as the parameters of the class constructor.\u003c/p\u003e\n\n```\ndynamic employee1 = init Employee(\"Sheikh Abdullah\", 123456789, 250000);\n```\n\n\u003cp\u003eIn the above line of code,  an instance of the class Employee is created and then assigned to a dynamic variable employee 1.\u003c/p\u003e\n\nThe object attributes and methods can be accessed using the \u003ccode\u003edot(.)\u003c/code\u003e operator.\n\n```\nlog employee1.name;\n```\n\nThis line of code will dislay the name of the \u003ccode\u003eemployee1\u003c/code\u003e object in the terminal, in this case \"Sheikh Abdullah\".\n\n```\nemployee1.evaluate(\"good\");\n```\n\nThis will call the \u003ccode\u003eevaluate\u003c/code\u003e method of the \u003ccode\u003eEmployee\u003c/code\u003e class for this object.\n\n\u003ch4\u003eInheritance\u003c/h4\u003e\n\u003cp\u003eIn LavaScript, it is possible to inherit attributes and methods from one class to another.\nTo inherit from a class, use the \u003ccode\u003eextends\u003c/code\u003e keyword.\u003c/p\u003e\n\n```\nclass SoftwareEngineer extends Employee {\n  level;\n\n  constructor(level, name, SSN) {\n    this.level = level;\n    super(name, SSN, this.level * 75000);\n  }\n}\n\nstatic emp = init SoftwareEngineer(3, \"Sheikh Abdullah\", 123456789, 74000);\nlog emp.name; // prints: Sheikh Abdullah\n```\n\n\u003cp\u003eThe \u003ccode\u003esuper\u003c/code\u003e keyword is a reference variable which is used to refer immediate parent class object.\u003c/p\u003e\n\u003cp\u003eIf you don't want a class to be extended, you can mark it with \u003ccode\u003esealed\u003c/code\u003e keyword.\u003c/p\u003e\n\n```\nsealed class Employee {\n  ...\n}\n```\n\n\u003ch4\u003eInterfaces\u003c/h4\u003e\n\u003cp\u003eInterface is a blueprint of a class. It is used to achieve abstraction in LavaScript.\nIn interfaces you can only define the method headers. The body will be described by the class that implements it. \u003c/p\u003e\n\n```\ninterface IShape {\n    method GetArea(): number;\n}\n\nclass Rectangle implements IShape {\n    #length;\n    #breadth;\n\n    method GetArea(): number {\n      return this.length * this.breadth;\n    }\n}\n```\n\n\u003cp\u003eMulti-Inheritance is supported in LavaScript through the use of interfaces.\u003c/p\u003e\n\n```\ninterface IShape {\n    method GetArea(): number;\n}\n\ninterface IColor {\n    method GetColor(): string;\n}\n\nclass Rectangle implements IShape, IColor {\n    #length;\n    #breadth;\n    #color;\n\n    method GetArea(): number {\n      return this.length * this.breadth;\n    }\n\n    method GetColor(): string {\n      return this.color;\n    }\n}\n```\n\n\u003ch2\u003eClassification of Keywords\u003c/h2\u003e\n\u003cp\u003eThe keywords can be classified as follows:\u003c/p\u003e\n\u003cul\u003e\n\u003cli\u003e\u003cb\u003eInitializers\u003c/b\u003e\u003c/li\u003e\n\u003cul\u003e\n\u003cli\u003estatic\u003c/li\u003e\n\u003cli\u003edynamic\u003c/li\u003e\n\u003c/ul\u003e\n\u003cli\u003e\u003cb\u003eSpecial Identifiers\u003c/b\u003e\u003c/li\u003e\n\u003cul\u003e\n\u003cli\u003elog\u003c/li\u003e\n\u003c/ul\u003e\n\u003cli\u003e\u003cb\u003einit\u003c/b\u003e\u003c/li\u003e\n\u003cli\u003e\u003cb\u003eif\u003c/b\u003e\u003c/li\u003e\n\u003cli\u003e\u003cb\u003eelse\u003c/b\u003e\u003c/li\u003e\n\u003cli\u003e\u003cb\u003euntil\u003c/b\u003e\u003c/li\u003e\n\u003cli\u003e\u003cb\u003eproc\u003c/b\u003e\u003c/li\u003e\n\u003cli\u003e\u003cb\u003ereturn\u003c/b\u003e\u003c/li\u003e\n\u003cli\u003e\u003cb\u003eclass\u003c/b\u003e\u003c/li\u003e\n\u003cli\u003e\u003cb\u003emethod\u003c/b\u003e\u003c/li\u003e\n\u003cli\u003e\u003cb\u003ethis\u003c/b\u003e\u003c/li\u003e\n\u003cli\u003e\u003cb\u003einterface\u003c/b\u003e\u003c/li\u003e\n\u003cli\u003e\u003cb\u003eextends\u003c/b\u003e\u003c/li\u003e\n\u003cli\u003e\u003cb\u003eimplements\u003c/b\u003e\u003c/li\u003e\n\u003cli\u003e\u003cb\u003esuper\u003c/b\u003e\u003c/li\u003e\n\u003cli\u003e\u003cb\u003esealed\u003c/b\u003e\u003c/li\u003e\n\u003c/ul\u003e\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyedzawwarahmed%2Flavascript","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsyedzawwarahmed%2Flavascript","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyedzawwarahmed%2Flavascript/lists"}