@alu0100973914/infix2egg
v1.1.0
Published
[![BuildStatus](https://travis-ci.com/ULL-ESIT-PL-1718/infix-to-egg-alu0100973914.svg?token=S9Gezg46GoVeGRv4GwA9&branch=master)](https://travis-ci.com/ULL-ESIT-PL-1718/infix-to-egg-alu0100973914) [![npmversion](https://badge.fury.io/js/%40alu0100973914%2F
Downloads
3
Readme
Practice 7 of PL: Infix to Egg (i2e)
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