Skip to content

Commit

Permalink
Added examples and fixed makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
chaser92 committed May 4, 2015
1 parent 4af5561 commit 5d35658
Show file tree
Hide file tree
Showing 28 changed files with 3,390 additions and 66 deletions.
123 changes: 123 additions & 0 deletions Absmyjs.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@


module Absmyjs where

-- Haskell module generated by the BNF converter




newtype Ident = Ident String deriving (Eq,Ord,Show,Read)
data Program =
Progr [Stmt]
deriving (Eq,Ord,Show,Read)

data MaybeIdent =
NoIdent
| JustIdent Ident
deriving (Eq,Ord,Show,Read)

data Decl =
VarDecl Ident
| VarDeclAssign Ident Expr
| FunDecl FunExpr
deriving (Eq,Ord,Show,Read)

data CompoundStmt =
CS [Stmt]
deriving (Eq,Ord,Show,Read)

data Stmt =
CSS CompoundStmt
| ExprStmt Expr
| DeclStmt Decl
| EmptyStmt
| IfStmt Expr Stmt ElseClause
| WhileStmt Expr Stmt
| ThrowStmt Expr
| TryCatchStmt CompoundStmt Ident CompoundStmt
| ReturnStmt Expr
| EmptyReturnStmt
deriving (Eq,Ord,Show,Read)

data Lvalue =
QIdent [QIdentPart]
deriving (Eq,Ord,Show,Read)

data QIdentPart =
IdentPart IIdent
deriving (Eq,Ord,Show,Read)

data IIdent =
IIdentBare Ident
| IIdentIndexed Ident Expr
deriving (Eq,Ord,Show,Read)

data ParamNames =
ParamNameList [Ident]
deriving (Eq,Ord,Show,Read)

data Params =
ParamList [Param]
deriving (Eq,Ord,Show,Read)

data Param =
ParamExpr Expr
deriving (Eq,Ord,Show,Read)

data KeyValuePair =
KVP Key Expr
deriving (Eq,Ord,Show,Read)

data Key =
KeyIdent Ident
| KeyString String
deriving (Eq,Ord,Show,Read)

data Literal =
IntLiteral Integer
| StringLiteral String
| TrueLiteral
| FalseLiteral
| UndefinedLiteral
| ObjectLiteral [KeyValuePair]
| ArrayLiteral [Param]
deriving (Eq,Ord,Show,Read)

data FunExpr =
Fun MaybeIdent ParamNames CompoundStmt
deriving (Eq,Ord,Show,Read)

data Expr =
FunExpression FunExpr
| AssignExpr Lvalue Expr
| LOrExpr Expr Expr
| LAndExpr Expr Expr
| EqExpr Expr Expr
| NeqExpr Expr Expr
| LessExpr Expr Expr
| GreaterExpr Expr Expr
| LeqExpr Expr Expr
| GeqExpr Expr Expr
| PlusExpr Expr Expr
| MinusExpr Expr Expr
| TimesExpr Expr Expr
| DivExpr Expr Expr
| PreincExpr Lvalue
| PredecExpr Lvalue
| PreopExpr UnaryOp Expr
| ParenExpr Expr
| CallExpr Lvalue Params
| LiteralExpr Literal
| EvalExpr Lvalue
deriving (Eq,Ord,Show,Read)

data UnaryOp =
NegOp
deriving (Eq,Ord,Show,Read)

data ElseClause =
Else Stmt
| ElseEmpty
deriving (Eq,Ord,Show,Read)

149 changes: 149 additions & 0 deletions Docmyjs.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
The Language myjs
BNF Converter


%This txt2tags file is machine-generated by the BNF-converter
%Process by txt2tags to generate html or latex



This document was automatically generated by the //BNF-Converter//. It was generated together with the lexer, the parser, and the abstract syntax module, which guarantees that the document matches with the implementation of the language (provided no hand-hacking has taken place).

==The lexical structure of myjs==
===Identifiers===
Identifiers //Ident// are unquoted strings beginning with a letter,
followed by any combination of letters, digits, and the characters ``_ '``
reserved words excluded.


===Literals===
String literals //String// have the form
``"``//x//``"``}, where //x// is any sequence of any characters
except ``"`` unless preceded by ``\``.


Integer literals //Integer// are nonempty sequences of digits.




===Reserved words and symbols===
The set of reserved words is the set of terminals appearing in the grammar. Those reserved words that consist of non-letter characters are called symbols, and they are treated in a different way from those that are similar to identifiers. The lexer follows rules familiar from languages like Haskell, C, and Java, including longest match and spacing conventions.

The reserved words used in myjs are the following:
| ``catch`` | ``else`` | ``false`` | ``function``
| ``if`` | ``return`` | ``throw`` | ``true``
| ``try`` | ``undefined`` | ``var`` | ``while``

The symbols used in myjs are the following:
| ; | = | { | }
| . | [ | ] | (
| ) | , | : | ||
| && | === | !== | <
| > | <= | >= | +
| - | * | / | ++
| -- | ! | return; |

===Comments===
Single-line comments begin with //.Multiple-line comments are enclosed with /* and */.

==The syntactic structure of myjs==
Non-terminals are enclosed between < and >.
The symbols -> (production), **|** (union)
and **eps** (empty rule) belong to the BNF notation.
All other symbols are terminals.

| //Program// | -> | //[Stmt]//
| //[Stmt]// | -> | **eps**
| | **|** | //Stmt//
| | **|** | //Stmt// //[Stmt]//
| //MaybeIdent// | -> | **eps**
| | **|** | //Ident//
| //Decl// | -> | ``var`` //Ident// ``;``
| | **|** | ``var`` //Ident// ``=`` //Expr// ``;``
| | **|** | //FunExpr//
| //CompoundStmt// | -> | ``{`` //[Stmt]// ``}``
| //Stmt// | -> | //CompoundStmt//
| | **|** | //Expr// ``;``
| | **|** | //Decl//
| | **|** | ``;``
| | **|** | ``if`` ``(`` //Expr// ``)`` //Stmt// //ElseClause//
| | **|** | ``while`` ``(`` //Expr// ``)`` //Stmt//
| | **|** | ``throw`` //Expr//
| | **|** | ``try`` //CompoundStmt// ``catch`` ``(`` //Ident// ``)`` //CompoundStmt//
| | **|** | ``return`` //Expr// ``;``
| | **|** | ``return;``
| //Lvalue// | -> | //[QIdentPart]//
| //QIdentPart// | -> | //IIdent//
| //[QIdentPart]// | -> | //QIdentPart//
| | **|** | //QIdentPart// ``.`` //[QIdentPart]//
| //IIdent// | -> | //Ident//
| | **|** | //Ident// ``[`` //Expr// ``]``
| //ParamNames// | -> | ``(`` //[Ident]// ``)``
| //[Ident]// | -> | **eps**
| | **|** | //Ident//
| | **|** | //Ident// ``,`` //[Ident]//
| //Params// | -> | ``(`` //[Param]// ``)``
| //Param// | -> | //Expr//
| //[Param]// | -> | **eps**
| | **|** | //Param//
| | **|** | //Param// ``,`` //[Param]//
| //KeyValuePair// | -> | //Key// ``:`` //Expr//
| //Key// | -> | //Ident//
| | **|** | //String//
| //[KeyValuePair]// | -> | **eps**
| | **|** | //KeyValuePair//
| | **|** | //KeyValuePair// ``,`` //[KeyValuePair]//
| //Literal// | -> | //Integer//
| | **|** | //String//
| | **|** | ``true``
| | **|** | ``false``
| | **|** | ``undefined``
| | **|** | ``{`` //[KeyValuePair]// ``}``
| | **|** | ``[`` //[Param]// ``]``
| //FunExpr// | -> | ``function`` //MaybeIdent// //ParamNames// //CompoundStmt//
| //Expr// | -> | //FunExpr//
| | **|** | //Lvalue// ``=`` //Expr//
| | **|** | //Expr1//
| //Expr2// | -> | //Expr2// ``||`` //Expr3//
| | **|** | //Expr3//
| //Expr3// | -> | //Expr3// ``&&`` //Expr4//
| | **|** | //Expr4//
| //Expr4// | -> | //Expr4// ``===`` //Expr5//
| | **|** | //Expr4// ``!==`` //Expr5//
| | **|** | //Expr5//
| //Expr5// | -> | //Expr5// ``<`` //Expr6//
| | **|** | //Expr5// ``>`` //Expr6//
| | **|** | //Expr5// ``<=`` //Expr6//
| | **|** | //Expr5// ``>=`` //Expr6//
| | **|** | //Expr6//
| //Expr6// | -> | //Expr6// ``+`` //Expr7//
| | **|** | //Expr6// ``-`` //Expr7//
| | **|** | //Expr6// ``*`` //Expr7//
| | **|** | //Expr6// ``/`` //Expr7//
| | **|** | //Expr7//
| //Expr7// | -> | ``++`` //Lvalue//
| | **|** | ``--`` //Lvalue//
| | **|** | //Expr8//
| //Expr8// | -> | //UnaryOp// //Expr9//
| | **|** | //Expr9//
| //Expr9// | -> | ``(`` //Expr// ``)``
| | **|** | //Expr10//
| //Expr10// | -> | //Lvalue// //Params//
| | **|** | //Expr11//
| //Expr11// | -> | //Literal//
| | **|** | //Expr12//
| //Expr12// | -> | //Lvalue//
| | **|** | //Expr13//
| //UnaryOp// | -> | ``!``
| //ElseClause// | -> | ``else`` //Stmt//
| | **|** | **eps**
| //Expr1// | -> | //Expr2//
| //Expr13// | -> | //Expr14//
| //Expr14// | -> | //Expr15//
| //Expr15// | -> | //Expr16//
| //Expr16// | -> | //Expr17//
| //Expr17// | -> | //Expr18//
| //Expr18// | -> | ``(`` //Expr// ``)``


380 changes: 380 additions & 0 deletions Lexmyjs.hs

Large diffs are not rendered by default.

Loading

0 comments on commit 5d35658

Please sign in to comment.