Skip to content

rezmansouri/SynTAXI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SynTAXI 🚕

SynTAXI is a Syntax Analyzer for programming languages

It takes the grammar rules of a program, and a program as inputs and checks for syntax errors.

SynTAXI uses Version 1.1 of CoffeeLEX hosted at https://github.com/rezmansouri/CoffeeLEX

So The Lexical Rules is also an input for SynTAXI

Input Format:

For a simple grammar like this for the C language:

Program -> Int Keyword, Main Keyword, ParenthesesOpen, ParenthesesClose, BlockStatement

BlockStatement -> Accolade Open, Statement, Accolade Close

Statement -> Int Keyword, Identifier, Assignment, Number, Semicolon

The Input format for a JSON File named syntaxGrammar.json must be like this:

{
  "Program": [
    [
      "Int Keyword",
      "Main Keyword",
      "Parentheses Open",
      "Parentheses Close",
      "Block Statement"
    ]
  ],
  "Block Statement": [
    [
      "Accolade Open",
      "Statement",
      "Accolade Close"
    ]
  ],
  "Statement": [
    [
      "Int Keyword",
      "Identifier",
      "Assignment",
      "Number",
      "Semicolon"
    ]
  ]
}

The Grammar JSON Object Must Contain a key named "Program" which is the main term of the grammar

And The Lexical Rules for coffeeLEX must be in a file named lexicalRules.json in the following format:

[
  {
    "Int Keyword": "int",
    "Main Keyword": "main"
  },
  {
    "Identifier": "[A-Z_a-z]+",
    "Semicolon": ";",
    "Parentheses Open": "\\(",
    "Parentheses Close": "\\)",
    "Assignment": "=",
    "Accolade Open": "\\{",
    "Accolade Close": "\\}",
    "Number": "[+-]?([0-9]*[.])?[0-9]+"
  }
]

Output

SynTAXI top down parses the program input based on the tokens generated by CoffeeLEX and the program Input

So for a program input called program.c:

int main() {
    int x = 10;
}

The following output is generated if no syntax error is found:

CoffeeLEX Output: 
Value  Type               Row  Column  
-----  ----               ---  -----   
int    Int Keyword        1    1       
main   Main Keyword       1    5       
(      Parentheses Open   1    9       
)      Parentheses Close  1    10      
{      Accolade Open      1    11      
int    Int Keyword        2    5       
x      Identifier         2    9       
=      Assignment         2    11      
10     Number             2    13      
;      Semicolon          2    14      
}      Accolade Close     3    0       
_________________________________
SynTAXI Output: 
Program Compiled Successfully.
_________________________________
CoffeeLex © / SynTAXI © - 2021
Developed By Reza Mansouri

And If The Input has a Syntax Error like the lack of identifier:

int main() {
    int = 10;
}

The following output is generated:

Exception in thread "main" SynTAXI.TaxiException: Syntax Error: Expected Identifier At row: 2 Column: 9