Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 49bb728693
Fetching contributors…

Cannot retrieve contributors at this time

280 lines (242 sloc) 8.155 kb
//for c++ hllr
//must match order in .hlx
%token IDENT STRING REGEXP INTEGER FLOATER
%token MSCOPE MBRACK
%token LBRACE RBRACE LPAREN RPAREN COMMA
%token DOT SEMI ARROW SLASH DOLL
%token CONS
%token PACKAGE IMPORT DEFINE MIXIN EXPAND STR
%token GLOBAL FILE LOCAL OBJECT METHOD
%token NOISE
%{
#include <parser_obj.hpp>
struct RMIXIN {
/*Symbol*/int x;
std::vector</*Symbol*/int> y;
std::vector<ptr<State>> z;
RMIXIN() {}
RMIXIN(/*Symbol*/int x, const std::vector</*Symbol*/int>& y, const std::vector<ptr<State>>& z) {
this->x = x;
this->y = y;
this->z = z;
}
RMIXIN(/*Symbol*/int x, const std::vector<ptr<State>>& z) {
this->x = x;
this->z = z;
}
Dynamic build(const MSCOPE& scope) {
return StateMixin(dMacro(scope,x,y,z));
}
};
#define States std::vector<ptr<State>>
%}
%entry file
%ident %{ ptr<int> %} : IDENT %{ retval = ((Token&)%0).int_data; %} ;
%string %{ ptr<std::string> %} : STRING %{ retval = ((Token&)%0).string_data; %} ;
%regexp %{ ptr<std::string> %} : REGEXP %{ retval = ((Token&)%0).string_data; %} ;
%integer %{ ptr<std::string> %} : INTEGER %{ retval = ((Token&)%0).string_data; %} ;
%floater %{ ptr<std::string> %} : FLOATER %{ retval = ((Token&)%0).string_data; %} ;
%noise %{ ptr<std::string> %} : NOISE %{ retval = ((Token&)%0).string_data; %} ;
%file %{ Dynamic %}
: restex PACKAGE SEMI restex %{
States& x = (States&)%0;
States& y = (States&)%3;
for(auto i = y.begin(); i!=y.end(); i++) x.push_back(*i);
retval = Program("",x);
%}
| restex PACKAGE qname SEMI restex %{
retval = Program((std::string&)%2,(States&)%4);
%}
| restex %{
retval = Program("",(States&)%0);
%}
;
%qname %{ Dynamic %}
: qname DOT ident %{
std::string& x = (std::string&)%0;
x.append(".");
x.append(GetSymbol(*%2));
retval = %0;
%}
| ident %{
retval = GetSymbol(*%0);
%}
;
%rest %{ Dynamic %}
: rest state %{
States& x = (States&)%0;
x.push_back(ptr<State>(%1));
retval = %0;
%}
| %{
retval = States();
%}
;
%restex %{ Dynamic %}
: restex stateex %{
States& x = (States&) %0;
x.push_back(ptr<State>(%1));
retval = %0;
%}
| %{
retval = States();
%}
;
%state %{ Dynamic %}
: noise %{ retval = StateNoise(*%0); %}
| ident %{ retval = StateSymbol(*%0); %}
| CONS %{ retval = StateCons(); %}
| DOT %{ retval = StateNoise("."); %}
| SEMI %{ retval = StateNoise(";"); %}
| SLASH %{ retval = StateNoise("/"); %}
| ARROW %{ retval = StateNoise("->"); %}
| DOLL %{ retval = StateNoise("$"); %}
| DOLL ident %{
States list;
list.push_back(ptr<State>(StateSymbol(*%1)));
retval = StateMBrack(dMScopeBrack(list));
%}
| DOLL STR LPAREN restex RPAREN %{
retval = StateString(ptr<State>(new StateArgScope((States&)%3)));
%}
| string %{ retval = StateDatum(*%0); %}
| regexp %{ retval = StateDatum(*%0); %}
| integer %{ retval = StateNumber(*%0); %}
| floater %{ retval = StateNumber(*%0); %}
| IMPORT qname semi %{ retval = StateImport((std::string&)%1); %}
| LBRACE restex RBRACE %{ retval = StateScope((States&)%1); %}
| MSCOPE mscopeix ARROW restex RBRACE %{
retval = StateMScope(dMScopeBrack((std::vector<MIdent>&)%1, (States&)%3));
%}
| MBRACK mscopeix ARROW restex RPAREN %{
retval = StateMBrack(dMScopeBrack((std::vector<MIdent>&)%1, (States&)%3));
%}
| LOCAL %{ retval = StateSymbol(GetSymbol("local")); %}
| GLOBAL %{ retval = StateSymbol(GetSymbol("global")); %}
| FILE %{ retval = StateSymbol(GetSymbol("file")); %}
| OBJECT %{ retval = StateSymbol(GetSymbol("object")); %}
| METHOD %{ retval = StateSymbol(GetSymbol("method")); %}
| MIXIN %{ retval = StateSymbol(GetSymbol("mixin")); %}
| DEFINE %{ retval = StateSymbol(GetSymbol("define")); %}
| EXPAND %{ retval = StateSymbol(GetSymbol("expand")); %}
| STR %{ retval = StateSymbol(GetSymbol("str")); %}
| LPAREN args RPAREN %{ retval = StateCall((States&)%1); %}
| LPAREN RPAREN %{ retval = StateCall(); %}
| mimport RPAREN semi %{ retval = StateMImport(dMImport("")); %}
| mimport qname RPAREN semi %{ retval = StateMImport(dMImport((std::string&)%1)); %}
| mdefine access pre LPAREN eargs RPAREN restex RPAREN semi %{
States& pre = (States&) %2;
ptr<State> x = pre.back(); pre.pop_back();
int name = ptr<StateSymbol>(x)->data;
retval = StateDefine(dMacro((MSCOPE&)%1,pre,name,(std::vector</*Symbol*/int>&)%4, (States&)%6));
%}
| mdefine pre LPAREN eargs RPAREN restex RPAREN semi %{
States& pre = (States&) %1;
ptr<State> x = pre.back(); pre.pop_back();
int name = ptr<StateSymbol>(x)->data;
retval = StateDefine(dMacro(sLocal,pre,name,(std::vector</*Symbol*/int>&)%3, (States&)%5));
%}
| MBRACK EXPAND access ident LPAREN eargs RPAREN restex RPAREN semi %{
retval = StateExpand(dMacro((MSCOPE&)%2, *%3, (std::vector</*Symbol*/int>&)%5, (States&)%7));
%}
| MBRACK MIXIN access rmixin %{
RMIXIN& x = (RMIXIN&)%3;
retval = x.build((MSCOPE&)%2);
%}
;
%stateex %{ Dynamic %}
: state %{ retval = %0; %}
| COMMA %{ retval = StateNoise(","); %}
;
%mimport %{ Dynamic %} : MBRACK IMPORT %{%};
%mdefine %{ Dynamic %} : MBRACK DEFINE %{%};
%semi %{ Dynamic %} : SEMI %{%} | %{%} ;
%mscopeix %{ Dynamic %}
: mscopeix COMMA mscopei %{
std::vector<MIdent>& x = (std::vector<MIdent>&)%0;
x.push_back((MIdent&)%2);
retval = %0;
%}
| mscopei %{
std::vector<MIdent> x;
x.push_back((MIdent&)%0);
retval = x;
%}
| %{ retval = std::vector<MIdent>(); %}
;
%mscopei %{ Dynamic %}
: ident %{ retval = MIdent(*%0,0); %}
| ident SLASH integer %{
retval = MIdent(*%0, atoi((*%2).c_str()));
%}
;
%args %{ Dynamic %}
: %{ retval = States(); %}
| args2 %{ retval = %0; %}
;
%args2 %{ Dynamic %}
: args2 COMMA rest %{
States& x = (States&) %0;
x.push_back(ptr<State>(StateArgScope((States&)%2)));
retval = %0;
%}
| rest %{
States x;
x.push_back(ptr<State>(StateArgScope((States&)%0)));
retval = x;
%}
;
%eargs %{ Dynamic %}
: %{ retval = States(); %}
| eargs2 %{ retval = %0; %}
;
%eargs2 %{ Dynamic %}
: eargs2 COMMA ident %{
std::vector<int>& x = (std::vector<int>&)%0;
x.push_back(*%2);
retval = %0;
%}
| ident %{
std::vector<int> x;
x.push_back(*%0);
retval = x;
%}
;
%access %{ Dynamic %}
: %{ retval = sLocal; %}
| LOCAL %{ retval = sLocal; %}
| GLOBAL %{ retval = sGlobal; %}
| FILE %{ retval = sFile; %}
| OBJECT %{ retval = sObject; %}
| METHOD %{ retval = sMethod; %}
;
%pre %{ Dynamic %}
: ident %{
States x;
x.push_back(ptr<State>(StateSymbol(*%0)));
retval = x;
%}
| noise %{
States x;
x.push_back(ptr<State>(StateNoise(*%0)));
retval = x;
%}
| pre noise %{
States& x = (States&) %0;
x.push_back(ptr<State>(StateNoise(*%1)));
retval = %0;
%}
| pre ident %{
States& x = (States&) %0;
x.push_back(ptr<State>(StateSymbol(*%1)));
retval = %0;
%}
;
%rmixin %{ Dynamic %}
: ident LPAREN eargs RPAREN restex RPAREN semi %{
retval = RMIXIN(*%0, (std::vector<int>&)%2, (States&)%4);
%}
| ident restex RPAREN semi %{
retval = RMIXIN(*%0, (States&)%1);
%}
;
Jump to Line
Something went wrong with that request. Please try again.