@alu0100973914/infix2egg

1.1.0 • Public • Published

Practice 7 of PL: Infix to Egg (i2e)

BuildStatus npmversion

i2e is a little but powerfull language created for a practice of PL (Procesadores de Lenguajes) course of ULL (Universidad de La Laguna). It is based on a basic and conventional syntax, it doesn't have types and it is in development process. The Abstract Syntax Tree that the interpreter constructs are Egg AST.

Functionalities that the language supports

  • Declarations
  • Assignments
  • Functions
  • Function calls
  • Conditionals
  • While loops

Example programs

There are several example programs in the examples folder.

Language grammar

WHITES = XRegExp("(\\s|//.*|/\\*[^]*?\\*/)*", "y");
NEWLINE = XRegExp("\\r\\n|\\r|\\n");

STRING = XRegExp("[\"']((?:[^\"\\\\]|\\\\.)*)[\"']", "y");
NUM = XRegExp("([-+]?\\d*\\.?\\d+([eE][-+]?\\d+)?)", "y");
LOGICVALUE = XRegExp("(true|false)", "y");
LOGOP = XRegExp("(&&|\\|\\|)", "y");
COMPOP = XRegExp("(<|>|==|<=|>=)", "y");
ADDOP = XRegExp("([+-])", "y");
MULOP = XRegExp("([*/])", "y");
LP = XRegExp("([(])", "y");
RP = XRegExp("([)])", "y");
LB = XRegExp("([{])", "y");
RB = XRegExp("([}])", "y");
COMMA = XRegExp("(,)", "y");
SEMICOLON = XRegExp("(;)", "y");
WORD   = XRegExp("([^\\s(){},\"'?:;]+)", "y");

===============================================

STATEMENTS -> (STATEMENT)+

STATEMENT -> DECLARATION |
             ASSIGNMENT  |
             CONDITIONAL |
             FUNC_CALL   |
             LOOP        |
             FUNCTION

DECLARATION -> "var" ASSIGNMENT

ASSIGNMENT -> WORD "=" (EXPR ";" | ANONYMFUNCTION)

ANONYMFUNCTION -> "function" "(" (WORD ("," WORD)*)? ")" BLOCK

FUNCTION -> "function" WORD "(" (WORD ("," WORD)*)? ")" BLOCK

FUNC_CALL -> WORD "(" (EXPR ("," EXPR)*)? ")" ";"

BLOCK -> "{" STATEMENTS "}"

CONDITIONAL -> "if" "(" EXPR ")" BLOCK ("else" (CONDITIONAL | BLOCK))?

LOOP -> "while" "(" EXPR ")" BLOCK

EXPR -> COMP_EXPR (LOGOP COMP_EXPR)*         

COMP_EXPR -> AR_EXPR (COMPOP AR_EXPR)*

AR_EXPR -> PRODUCT (ADDOP PRODUCT)*
PRODUCT -> FINALEXPRESSION (MULOP FINALEXPRESSION)*
FINALEXPRESSION -> "(" EXPR ")"
         WORD |
         NUM  |
         LOGICVALUE |
         STRING

Readme

Keywords

Package Sidebar

Install

npm i @alu0100973914/infix2egg

Weekly Downloads

3

Version

1.1.0

License

ISC

Unpacked Size

32.5 kB

Total Files

35

Last publish

Collaborators

  • alu0100973914