1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00
jashkenas--coffeescript/vendor/jison/examples/classy_ast.json

126 lines
5.3 KiB
JSON

{
"comment": "ClassyLang grammar with AST-building actions. Very classy.",
"author": "Zach Carter",
"lex": {
"macros": {
"digit": "[0-9]",
"id": "[a-zA-Z][a-zA-Z0-9]*"
},
"rules": [
["//.*", "/* ignore comment */"],
["main\\b", "return 'MAIN';"],
["class\\b", "return 'CLASS';"],
["extends\\b", "return 'EXTENDS';"],
["nat\\b", "return 'NATTYPE';"],
["if\\b", "return 'IF';"],
["else\\b", "return 'ELSE';"],
["for\\b", "return 'FOR';"],
["printNat\\b", "return 'PRINTNAT';"],
["readNat\\b", "return 'READNAT';"],
["this\\b", "return 'THIS';"],
["new\\b", "return 'NEW';"],
["var\\b", "return 'VAR';"],
["null\\b", "return 'NUL';"],
["{digit}+", "return 'NATLITERAL';"],
["{id}", "return 'ID';"],
["==", "return 'EQUALITY';"],
["=", "return 'ASSIGN';"],
["\\+", "return 'PLUS';"],
["-", "return 'MINUS';"],
["\\*", "return 'TIMES';"],
[">", "return 'GREATER';"],
["\\|\\|", "return 'OR';"],
["!", "return 'NOT';"],
["\\.", "return 'DOT';"],
["\\{", "return 'LBRACE';"],
["\\}", "return 'RBRACE';"],
["\\(", "return 'LPAREN';"],
["\\)", "return 'RPAREN';"],
[";", "return 'SEMICOLON';"],
["\\s+", "/* skip whitespace */"],
[".", "throw 'Illegal character: '+yytext;"],
["$", "return 'ENDOFFILE';"]
]
},
"tokens": "MAIN CLASS EXTENDS NATTYPE IF ELSE FOR PRINTNAT READNAT THIS NEW VAR NUL NATLITERAL ID ASSIGN PLUS MINUS TIMES EQUALITY GREATER OR NOT DOT SEMICOLON LBRACE RBRACE LPAREN RPAREN ENDOFFILE",
"operators": [
["right", "ASSIGN"],
["left", "OR"],
["nonassoc", "EQUALITY", "GREATER"],
["left", "PLUS", "MINUS"],
["left", "TIMES"],
["right", "NOT"],
["left", "DOT"]
],
"bnf": {
"pgm": [["cdl MAIN LBRACE vdl el RBRACE ENDOFFILE",
"$$ = ['PROGRAM',{},$1,$4,$5]; return $$;"]],
"cdl": [["c cdl",
"$$ = prependChild($2, $1);"],
["",
"$$ = ['CLASS_DECL_LIST',{}];"]],
"c": [["CLASS id EXTENDS id LBRACE vdl mdl RBRACE",
"$$ = ['CLASS_DECL',{},$2,$4,$6,$7];"]],
"vdl": [["VAR t id SEMICOLON vdl",
"$$ = prependChild($5, ['VAR_DECL',{},$2,$3]);"],
["",
"$$ = ['VAR_DECL_LIST',{}];"]],
"mdl": [["t id LPAREN t id RPAREN LBRACE vdl el RBRACE mdl",
"$$ = prependChild($11, ['METHOD_DECL',{},$1,$2,$4,$5,$8,$9]);"],
["",
"$$ = ['METHOD_DECL_LIST',{}];"]],
"t": [["NATTYPE",
"$$ = ['NAT_TYPE',{}];"],
["id",
"$$ = $1"]],
"id": [["ID",
"$$ = ['AST_ID',{val:yytext}]"]],
"el": [["e SEMICOLON el",
"$$ = prependChild($3, $1);"],
["e SEMICOLON",
"$$ = ['EXPR_LIST',{},$1];"]],
"e": [["NATLITERAL", "$$ = ['NAT_LITERAL_EXPR',{val:parseInt(yytext)}];"],
["NUL", "$$ = ['NULL_EXPR',{}];"],
["id", "$$ = ['ID_EXPR',{},$1];"],
["NEW id", "$$ = ['NEW_EXPR',{},$2];"],
["THIS", "$$ = ['THIS_EXPR',{}];"],
["IF LPAREN e RPAREN LBRACE el RBRACE ELSE LBRACE el RBRACE",
"$$ = ['IF_THEN_ELSE_EXPR',{},$3,$6,$10];"],
["FOR LPAREN e SEMICOLON e SEMICOLON e RPAREN LBRACE el RBRACE",
"$$ = ['FOR_EXPR',{},$3,$5,$7,$10];"],
["READNAT LPAREN RPAREN",
"$$ = ['READ_EXPR',{}];"],
["PRINTNAT LPAREN e RPAREN",
"$$ = ['PRINT_EXPR',{},$3];"],
["e PLUS e", "$$ = ['PLUS_EXPR',{},$1,$3];"],
["e MINUS e", "$$ = ['MINUS_EXPR',{},$1,$3];"],
["e TIMES e", "$$ = ['TIMES_EXPR',{},$1,$3];"],
["e EQUALITY e", "$$ = ['EQUALITY_EXPR',{},$1,$3];"],
["e GREATER e", "$$ = ['GREATER_THAN_EXPR',{},$1,$3];"],
["NOT e", "$$ = ['NOT_EXPR',{},$2];"],
["e OR e", "$$ = ['OR_EXPR',{},$1,$3];"],
["e DOT id", "$$ = ['DOT_ID_EXPR',{},$1,$3];"],
["id ASSIGN e", "$$ = ['ASSIGN_EXPR',{},$1,$3];"],
["e DOT id ASSIGN e",
"$$ = ['DOT_ASSIGN_EXPR',{},$1,$3,$5];"],
["id LPAREN e RPAREN",
"$$ = ['METHOD_CALL_EXPR',{},$1,$3];"],
["e DOT id LPAREN e RPAREN",
"$$ = ['DOT_METHOD_CALL_EXPR',{},$1,$3,$5];"],
["LPAREN e RPAREN",
"$$ = $2;"]]
},
"actionInclude": "function prependChild(node, child){ node.splice(2,0,child); return node; }"
}