public override Template Visit(ExprAlloc expr) { Template template = null; var type = expr.Type; string name_prefix = ""; string name_suffix = ""; while (true) { if (type is StarType) { name_prefix = "*" + name_prefix; type = ((StarType)type).Type; continue; } if (type is RefType) { name_prefix = "&" + name_prefix; type = ((RefType)type).Type; continue; } if (type is ArrayType) { Template tmp = new Template("<type_list>"); List<Template> type_list = new List<Template>(); foreach (var x in ((ArrayType)type).Args) { Template item = new Template("[<expr>]"); item.Add("expr", x.Accept(this)); type_list.Add(item); } tmp.Add("type_list", type_list); name_suffix = tmp.Render() + name_suffix; type = ((ArrayType)type).Type; continue; } break; } // Can declare inline if (expr.Style == AllocType.Declare) { template = new Template("<type> <name; separator=\", \">"); template.Add("type", type.Accept(this)); template.Add("name", expr.Name.Select(x => string.Format("{0}{1}{2}", name_prefix, x, name_suffix))); return template; } List<Template> list = new List<Template>(); foreach (var name in expr.Name) { switch (expr.Style) { case AllocType.Equal: { Template stmt = new Template("<type> <name> = <expr; separator=\", \">"); stmt.Add("type", type.Accept(this)); stmt.Add("name", string.Format("{0}{1}{2}", name_prefix, name, name_suffix)); stmt.Add("expr", expr.ExprList.Select(x => x.Accept(this))); list.Add(stmt); break; } case AllocType.Bracket: { Template stmt = new Template("<type> <name> { <expr; separator=\", \"> }"); stmt.Add("type", type.Accept(this)); stmt.Add("name", string.Format("{0}{1}{2}", name_prefix, name, name_suffix)); stmt.Add("expr", expr.ExprList.Select(x => x.Accept(this))); list.Add(stmt); break; } } } template = new Template("<list; separator=\";\n\">"); template.Add("list", list); return template; }
public override Template Visit(ExprAlloc expr) { string type = expr.Type; string name_prefix = ""; string name_suffix = ""; while (true) { if (type.EndsWith("*")) { type = type.Substring(0, type.Length - 1); name_prefix = "*" + name_prefix; continue; } if (type.EndsWith("&")) { type = type.Substring(0, type.Length - 1); name_prefix = "&" + name_prefix; continue; } if (type.EndsWith("[]")) { type = type.Substring(0, type.Length - 2); name_suffix = "[]" + name_suffix; continue; } break; } if (expr.ExprList.Count() > 0) { List<Template> list = new List<Template>(); foreach (var name in expr.Name) { if (expr.Type != "decltype") { Template stmt = null; if (expr.IsEqualSign) { stmt = new Template("<type> <name> = <expr; separator=\", \">"); } else { stmt = new Template("<type> <name>(<expr; separator=\", \">)"); } stmt.Add("type", type); stmt.Add("name", string.Format("{0}{1}{2}", name_prefix, name, name_suffix)); stmt.Add("expr", expr.ExprList.Select(x => x.Accept(this))); list.Add(stmt); } else { Template stmt = new Template("decltype(<expr>) <name> = <expr>"); stmt.Add("type", expr.Type); stmt.Add("name", name); stmt.Add("expr", expr.ExprList.First().Accept(this)); list.Add(stmt); } } Template template = new Template("<list; separator=\"\n\">"); template.Add("list", list); return template; } else { Template template = new Template("<type> <name; separator=\", \">"); template.Add("type", type); template.Add("name", expr.Name.Select(x => string.Format("{0}{1}{2}", name_prefix, x, name_suffix))); return template; } }
private Expr expr() { EnterRule_expr(); EnterRule("expr", 47); TraceIn("expr", 47); Expr value = default(Expr); CommonTree op = default(CommonTree); CommonTree text = default(CommonTree); ExprTuple tuple = default(ExprTuple); ExprAlloc alloc = default(ExprAlloc); MatchTuple match = default(MatchTuple); ExprCall call = default(ExprCall); ExprCall call_with = default(ExprCall); Expr dict = default(Expr); ExprLambda lambda = default(ExprLambda); ExprCast cast = default(ExprCast); ExprList list = default(ExprList); Expr expr_new = default(Expr); string ident_text = default(string); Expr a = default(Expr); Expr b = default(Expr); Expr c = default(Expr); Expr chain = default(Expr); string text_ident = default(string); try { DebugEnterRule(GrammarFileName, "expr"); DebugLocation(567, 1); try { // SugarWalker.g:568:5: (tuple= expr_tuple |alloc= alloc_expr |match= match_tuple |call= call_expr |call_with= call_with_expr |dict= dict_expr |lambda= lambda_expr |cast= cast_expr |list= list_expr |expr_new= new_expr | ^( Expr_Infix ident_text= ident a= expr b= expr ) | ^( Expr_Cond a= expr b= expr c= expr ) | ^( Expr_Cond_Not_Null a= expr b= expr ) | ^( Expr_Not_Null a= expr ) | ^( Expr_Access op= ( '.' | '::' | '->' | '->*' | '.*' ) a= expr ident_text= ident ) |chain= chain_expr | ^( Expr_Bin op= ( '+' | '-' | '*' | '/' | '%' | '<' | '<=' | '>' | '>=' | '==' | '!=' | '<<' | '>>' | '&' | '^' | '|' | '&&' | '||' | 'is' | 'isnt' | 'and' | 'or' ) a= expr b= expr ) | ^(op= ( '=' | '+=' | '-=' | '*=' | '/=' | '%=' | '&=' | '^=' | '|=' | '<<=' | '>>=' ) a= expr b= expr ) | ^( '@' text_ident= ident ) | ^( Expr_Bracket a= expr ) | ^( Expr_Suffix op= ( '++' | '--' ) a= expr ) | ^( Expr_Prefix op= ( '!' | '~' | '++' | '--' | '-' | '+' | '*' | '&' ) a= expr ) | ^( ':=' a= expr b= expr ) |text_ident= ident |text= ( NUMBER | DOUBLE ) |text= STRING ) int alt73=26; try { DebugEnterDecision(73, false); switch (input.LA(1)) { case Expr_Tuple: { alt73 = 1; } break; case Expr_Alloc_Bracket: case Expr_Alloc_Equal: { alt73 = 2; } break; case Match_Tuple: { alt73 = 3; } break; case Expr_Call: { alt73 = 4; } break; case Expr_Call_With: { alt73 = 5; } break; case Expr_Dict: { alt73 = 6; } break; case Expr_Lambda: { alt73 = 7; } break; case Expr_Cast: { alt73 = 8; } break; case Expr_List: { alt73 = 9; } break; case Expr_New_Array: case Expr_New_Type: { alt73 = 10; } break; case Expr_Infix: { alt73 = 11; } break; case Expr_Cond: { alt73 = 12; } break; case Expr_Cond_Not_Null: { alt73 = 13; } break; case Expr_Not_Null: { alt73 = 14; } break; case Expr_Access: { alt73 = 15; } break; case Expr_Chain: { alt73 = 16; } break; case Expr_Bin: { alt73 = 17; } break; case 75: case 78: case 82: case 85: case 89: case 95: case 102: case 104: case 110: case 117: case 150: { alt73 = 18; } break; case 113: { alt73 = 19; } break; case Expr_Bracket: { alt73 = 20; } break; case Expr_Suffix: { alt73 = 21; } break; case Expr_Prefix: { alt73 = 22; } break; case 98: { alt73 = 23; } break; case IDENT: { alt73 = 24; } break; case NUMBER: case DOUBLE: { alt73 = 25; } break; case STRING: { alt73 = 26; } break; default: { NoViableAltException nvae = new NoViableAltException("", 73, 0, input); DebugRecognitionException(nvae); throw nvae; } } } finally { DebugExitDecision(73); } switch (alt73) { case 1: DebugEnterAlt(1); // SugarWalker.g:568:7: tuple= expr_tuple { DebugLocation(568, 12); PushFollow(Follow._expr_tuple_in_expr2302); tuple=expr_tuple(); PopFollow(); DebugLocation(569, 2); value = tuple; } break; case 2: DebugEnterAlt(2); // SugarWalker.g:572:4: alloc= alloc_expr { DebugLocation(572, 9); PushFollow(Follow._alloc_expr_in_expr2312); alloc=alloc_expr(); PopFollow(); DebugLocation(573, 2); value = alloc; } break; case 3: DebugEnterAlt(3); // SugarWalker.g:576:4: match= match_tuple { DebugLocation(576, 9); PushFollow(Follow._match_tuple_in_expr2322); match=match_tuple(); PopFollow(); DebugLocation(577, 2); value = match; } break; case 4: DebugEnterAlt(4); // SugarWalker.g:580:4: call= call_expr { DebugLocation(580, 8); PushFollow(Follow._call_expr_in_expr2332); call=call_expr(); PopFollow(); DebugLocation(581, 2); value = call; } break; case 5: DebugEnterAlt(5); // SugarWalker.g:584:4: call_with= call_with_expr { DebugLocation(584, 13); PushFollow(Follow._call_with_expr_in_expr2342); call_with=call_with_expr(); PopFollow(); DebugLocation(585, 2); value = call_with; } break; case 6: DebugEnterAlt(6); // SugarWalker.g:588:4: dict= dict_expr { DebugLocation(588, 8); PushFollow(Follow._dict_expr_in_expr2352); dict=dict_expr(); PopFollow(); DebugLocation(589, 2); value = dict; } break; case 7: DebugEnterAlt(7); // SugarWalker.g:592:4: lambda= lambda_expr { DebugLocation(592, 10); PushFollow(Follow._lambda_expr_in_expr2362); lambda=lambda_expr(); PopFollow(); DebugLocation(593, 2); value = lambda; } break; case 8: DebugEnterAlt(8); // SugarWalker.g:596:4: cast= cast_expr { DebugLocation(596, 8); PushFollow(Follow._cast_expr_in_expr2372); cast=cast_expr(); PopFollow(); DebugLocation(597, 2); value = cast; } break; case 9: DebugEnterAlt(9); // SugarWalker.g:600:4: list= list_expr { DebugLocation(600, 8); PushFollow(Follow._list_expr_in_expr2382); list=list_expr(); PopFollow(); DebugLocation(601, 2); value = list; } break; case 10: DebugEnterAlt(10); // SugarWalker.g:604:4: expr_new= new_expr { DebugLocation(604, 12); PushFollow(Follow._new_expr_in_expr2392); expr_new=new_expr(); PopFollow(); DebugLocation(605, 2); value = expr_new; } break; case 11: DebugEnterAlt(11); // SugarWalker.g:608:4: ^( Expr_Infix ident_text= ident a= expr b= expr ) { DebugLocation(608, 4); DebugLocation(608, 6); Match(input,Expr_Infix,Follow._Expr_Infix_in_expr2401); Match(input, TokenTypes.Down, null); DebugLocation(608, 27); PushFollow(Follow._ident_in_expr2405); ident_text=ident(); PopFollow(); DebugLocation(608, 35); PushFollow(Follow._expr_in_expr2409); a=expr(); PopFollow(); DebugLocation(608, 42); PushFollow(Follow._expr_in_expr2413); b=expr(); PopFollow(); Match(input, TokenTypes.Up, null); DebugLocation(609, 2); value = new ExprInfix(ident_text, a, b); } break; case 12: DebugEnterAlt(12); // SugarWalker.g:612:4: ^( Expr_Cond a= expr b= expr c= expr ) { DebugLocation(612, 4); DebugLocation(612, 6); Match(input,Expr_Cond,Follow._Expr_Cond_in_expr2423); Match(input, TokenTypes.Down, null); DebugLocation(612, 17); PushFollow(Follow._expr_in_expr2427); a=expr(); PopFollow(); DebugLocation(612, 24); PushFollow(Follow._expr_in_expr2431); b=expr(); PopFollow(); DebugLocation(612, 31); PushFollow(Follow._expr_in_expr2435); c=expr(); PopFollow(); Match(input, TokenTypes.Up, null); DebugLocation(613, 2); value = new ExprCond(a, b, c); } break; case 13: DebugEnterAlt(13); // SugarWalker.g:616:4: ^( Expr_Cond_Not_Null a= expr b= expr ) { DebugLocation(616, 4); DebugLocation(616, 6); Match(input,Expr_Cond_Not_Null,Follow._Expr_Cond_Not_Null_in_expr2445); Match(input, TokenTypes.Down, null); DebugLocation(616, 26); PushFollow(Follow._expr_in_expr2449); a=expr(); PopFollow(); DebugLocation(616, 33); PushFollow(Follow._expr_in_expr2453); b=expr(); PopFollow(); Match(input, TokenTypes.Up, null); DebugLocation(617, 2); value = new ExprCond(new ExprBin("!=", a, new ExprConst("nullptr", ConstType.Ident)), a, b); } break; case 14: DebugEnterAlt(14); // SugarWalker.g:620:4: ^( Expr_Not_Null a= expr ) { DebugLocation(620, 4); DebugLocation(620, 6); Match(input,Expr_Not_Null,Follow._Expr_Not_Null_in_expr2463); Match(input, TokenTypes.Down, null); DebugLocation(620, 21); PushFollow(Follow._expr_in_expr2467); a=expr(); PopFollow(); Match(input, TokenTypes.Up, null); DebugLocation(621, 2); value = new ExprBin("!=", a, new ExprConst("nullptr", ConstType.Ident)); } break; case 15: DebugEnterAlt(15); // SugarWalker.g:624:4: ^( Expr_Access op= ( '.' | '::' | '->' | '->*' | '.*' ) a= expr ident_text= ident ) { DebugLocation(624, 4); DebugLocation(624, 6); Match(input,Expr_Access,Follow._Expr_Access_in_expr2477); Match(input, TokenTypes.Down, null); DebugLocation(624, 20); op=(CommonTree)input.LT(1); if ((input.LA(1)>=90 && input.LA(1)<=93)||input.LA(1)==97) { input.Consume(); state.errorRecovery=false; } else { MismatchedSetException mse = new MismatchedSetException(null,input); DebugRecognitionException(mse); throw mse; } DebugLocation(624, 57); PushFollow(Follow._expr_in_expr2503); a=expr(); PopFollow(); DebugLocation(624, 73); PushFollow(Follow._ident_in_expr2507); ident_text=ident(); PopFollow(); Match(input, TokenTypes.Up, null); DebugLocation(625, 2); value = new ExprAccess(a, op.Text, ident_text); } break; case 16: DebugEnterAlt(16); // SugarWalker.g:628:4: chain= chain_expr { DebugLocation(628, 10); PushFollow(Follow._chain_expr_in_expr2520); chain=chain_expr(); PopFollow(); DebugLocation(629, 2); value = chain; } break; case 17: DebugEnterAlt(17); // SugarWalker.g:632:4: ^( Expr_Bin op= ( '+' | '-' | '*' | '/' | '%' | '<' | '<=' | '>' | '>=' | '==' | '!=' | '<<' | '>>' | '&' | '^' | '|' | '&&' | '||' | 'is' | 'isnt' | 'and' | 'or' ) a= expr b= expr ) { DebugLocation(632, 4); DebugLocation(632, 6); Match(input,Expr_Bin,Follow._Expr_Bin_in_expr2529); Match(input, TokenTypes.Down, null); DebugLocation(632, 17); op=(CommonTree)input.LT(1); if ((input.LA(1)>=73 && input.LA(1)<=74)||(input.LA(1)>=76 && input.LA(1)<=77)||input.LA(1)==81||input.LA(1)==83||input.LA(1)==87||input.LA(1)==94||input.LA(1)==99||input.LA(1)==101||input.LA(1)==103||input.LA(1)==105||(input.LA(1)>=107 && input.LA(1)<=109)||input.LA(1)==116||input.LA(1)==119||(input.LA(1)>=133 && input.LA(1)<=134)||input.LA(1)==138||input.LA(1)==149||input.LA(1)==151) { input.Consume(); state.errorRecovery=false; } else { MismatchedSetException mse = new MismatchedSetException(null,input); DebugRecognitionException(mse); throw mse; } DebugLocation(639, 9); PushFollow(Follow._expr_in_expr2660); a=expr(); PopFollow(); DebugLocation(639, 16); PushFollow(Follow._expr_in_expr2664); b=expr(); PopFollow(); Match(input, TokenTypes.Up, null); DebugLocation(640, 2); value = new ExprBin(Alias(op.Text), a, b); } break; case 18: DebugEnterAlt(18); // SugarWalker.g:643:4: ^(op= ( '=' | '+=' | '-=' | '*=' | '/=' | '%=' | '&=' | '^=' | '|=' | '<<=' | '>>=' ) a= expr b= expr ) { DebugLocation(643, 4); DebugLocation(643, 8); op=(CommonTree)input.LT(1); if (input.LA(1)==75||input.LA(1)==78||input.LA(1)==82||input.LA(1)==85||input.LA(1)==89||input.LA(1)==95||input.LA(1)==102||input.LA(1)==104||input.LA(1)==110||input.LA(1)==117||input.LA(1)==150) { input.Consume(); state.errorRecovery=false; } else { MismatchedSetException mse = new MismatchedSetException(null,input); DebugRecognitionException(mse); throw mse; } Match(input, TokenTypes.Down, null); DebugLocation(643, 88); PushFollow(Follow._expr_in_expr2722); a=expr(); PopFollow(); DebugLocation(643, 95); PushFollow(Follow._expr_in_expr2726); b=expr(); PopFollow(); Match(input, TokenTypes.Up, null); DebugLocation(644, 2); value = new ExprBin(op.Text, a, b); } break; case 19: DebugEnterAlt(19); // SugarWalker.g:647:4: ^( '@' text_ident= ident ) { DebugLocation(647, 4); DebugLocation(647, 6); Match(input,113,Follow._113_in_expr2736); Match(input, TokenTypes.Down, null); DebugLocation(647, 20); PushFollow(Follow._ident_in_expr2740); text_ident=ident(); PopFollow(); Match(input, TokenTypes.Up, null); DebugLocation(648, 2); value = new ExprAccess(new ExprConst("this", ConstType.Ident), "->", text_ident); } break; case 20: DebugEnterAlt(20); // SugarWalker.g:651:4: ^( Expr_Bracket a= expr ) { DebugLocation(651, 4); DebugLocation(651, 6); Match(input,Expr_Bracket,Follow._Expr_Bracket_in_expr2750); Match(input, TokenTypes.Down, null); DebugLocation(651, 20); PushFollow(Follow._expr_in_expr2754); a=expr(); PopFollow(); Match(input, TokenTypes.Up, null); DebugLocation(652, 2); value = new ExprBracket(a); } break; case 21: DebugEnterAlt(21); // SugarWalker.g:655:4: ^( Expr_Suffix op= ( '++' | '--' ) a= expr ) { DebugLocation(655, 4); DebugLocation(655, 6); Match(input,Expr_Suffix,Follow._Expr_Suffix_in_expr2764); Match(input, TokenTypes.Down, null); DebugLocation(655, 20); op=(CommonTree)input.LT(1); if (input.LA(1)==84||input.LA(1)==88) { input.Consume(); state.errorRecovery=false; } else { MismatchedSetException mse = new MismatchedSetException(null,input); DebugRecognitionException(mse); throw mse; } DebugLocation(655, 36); PushFollow(Follow._expr_in_expr2778); a=expr(); PopFollow(); Match(input, TokenTypes.Up, null); DebugLocation(656, 2); value = new ExprSuffix(op.Text, a); } break; case 22: DebugEnterAlt(22); // SugarWalker.g:659:4: ^( Expr_Prefix op= ( '!' | '~' | '++' | '--' | '-' | '+' | '*' | '&' ) a= expr ) { DebugLocation(659, 4); DebugLocation(659, 6); Match(input,Expr_Prefix,Follow._Expr_Prefix_in_expr2788); Match(input, TokenTypes.Down, null); DebugLocation(659, 20); op=(CommonTree)input.LT(1); if (input.LA(1)==72||input.LA(1)==77||input.LA(1)==81||(input.LA(1)>=83 && input.LA(1)<=84)||(input.LA(1)>=87 && input.LA(1)<=88)||input.LA(1)==152) { input.Consume(); state.errorRecovery=false; } else { MismatchedSetException mse = new MismatchedSetException(null,input); DebugRecognitionException(mse); throw mse; } DebugLocation(659, 72); PushFollow(Follow._expr_in_expr2826); a=expr(); PopFollow(); Match(input, TokenTypes.Up, null); DebugLocation(660, 2); value = new ExprPrefix(op.Text, a); } break; case 23: DebugEnterAlt(23); // SugarWalker.g:663:4: ^( ':=' a= expr b= expr ) { DebugLocation(663, 4); DebugLocation(663, 6); Match(input,98,Follow._98_in_expr2836); Match(input, TokenTypes.Down, null); DebugLocation(663, 12); PushFollow(Follow._expr_in_expr2840); a=expr(); PopFollow(); DebugLocation(663, 19); PushFollow(Follow._expr_in_expr2844); b=expr(); PopFollow(); Match(input, TokenTypes.Up, null); DebugLocation(664, 2); if (!(a is ExprConst)) { throw new Exception("Assert failed."); } value = new ExprAlloc("auto", new List<string> { ((ExprConst)a).Text }, new List<Expr> { b }, true); } break; case 24: DebugEnterAlt(24); // SugarWalker.g:671:4: text_ident= ident { DebugLocation(671, 15); PushFollow(Follow._ident_in_expr2857); text_ident=ident(); PopFollow(); DebugLocation(672, 2); if (text_ident == "nil") text_ident = "nullptr"; value = new ExprConst(text_ident, ConstType.Ident); } break; case 25: DebugEnterAlt(25); // SugarWalker.g:676:4: text= ( NUMBER | DOUBLE ) { DebugLocation(676, 8); text=(CommonTree)input.LT(1); if (input.LA(1)==NUMBER||input.LA(1)==DOUBLE) { input.Consume(); state.errorRecovery=false; } else { MismatchedSetException mse = new MismatchedSetException(null,input); DebugRecognitionException(mse); throw mse; } DebugLocation(677, 5); value = new ExprConst(text.Text, ConstType.Number); } break; case 26: DebugEnterAlt(26); // SugarWalker.g:680:4: text= STRING { DebugLocation(680, 9); text=(CommonTree)Match(input,STRING,Follow._STRING_in_expr2888); DebugLocation(681, 2); value = new ExprConst(text.Text, ConstType.String); } break; } } catch (RecognitionException re) { ReportError(re); Recover(input,re); } finally { TraceOut("expr", 47); LeaveRule("expr", 47); LeaveRule_expr(); } DebugLocation(684, 1); } finally { DebugExitRule(GrammarFileName, "expr"); } return value; }
public override Template Visit(ExprListGeneration expr) { Template template = new Template("({\n <declare>;\n <for>\n <var>;\n})"); ExprAlloc delcare = new ExprAlloc(expr.Type, "_t_return_value", null, AllocType.Declare); template.Add("declare", delcare.Accept(this)); template.Add("var", "_t_return_value"); Stmt stmt = null; if (expr.Type is TemplateType && (((TemplateType)expr.Type).Type is IdentType)) { string type = ((IdentType)((TemplateType)expr.Type).Type).Type; if (type == "vector" || type == "list") { stmt = new StmtExpr(new ExprCall(new ExprAccess(new ExprConst("_t_return_value", ConstType.Ident), ".", "push_back"), null, new List<Expr> { expr.Expr })); } if (type == "forward_list" || type == "deque") { stmt = new StmtExpr(new ExprCall(new ExprAccess(new ExprConst("_t_return_value", ConstType.Ident), ".", "push_front"), null, new List<Expr> { expr.Expr })); } if (type == "queue" || type == "priority_queue" || type == "stack") { stmt = new StmtExpr(new ExprCall(new ExprAccess(new ExprConst("_t_return_value", ConstType.Ident), ".", "push"), null, new List<Expr> { expr.Expr })); } if (type == "set" || type == "multiset" || type == "unordered_set" || type == "unordered_multiset" || type == "map" || type == "multimap" || type == "unordered_map" || type == "unordered_multimap") { stmt = new StmtExpr(new ExprCall(new ExprAccess(new ExprConst("_t_return_value", ConstType.Ident), ".", "insert"), null, new List<Expr> { expr.Expr })); } } if (stmt == null) { string msg = string.Format("Type {0} is not supported in list generation.", expr.Type.Accept(this).Render()); throw new Exception(msg); } expr.For.Body = new StmtBlock(); expr.For.Body.StmtList.Add(stmt); template.Add("for", expr.For.Accept(this)); return template; }
public override Template Visit(FuncDef func_def) { string prefix = ""; if (func_def.Attribute.Find(x => x.Name == "inline") != null) { prefix += "inline "; } if (this.class_stack.Count() == 0) { if (func_def.Attribute.Find(x => x.Name == "static") != null) { prefix += "static "; } } string suffix = ""; if (func_def.Attribute.Find(x => x.Name == "const") != null) { suffix += " const"; } Template template = null; if (func_def.GenericParameter.Count() == 0) { if (func_def.Type == null) { template = new Template("<prefix><name>(<args; separator=\", \">)<suffix> {\n <list; separator=\"\n\">\n}"); } else { template = new Template("<prefix><type> <name>(<args; separator=\", \">)<suffix> {\n <list; separator=\"\n\">\n}"); template.Add("type", func_def.Type.Accept(this)); } } else { if (func_def.Type == null) { template = new Template("template \\<<generics; separator=\", \">>\n<prefix><name>(<args; separator=\", \">)<suffix> {\n <list; separator=\"\n\">\n}"); } else { template = new Template("template \\<<generics; separator=\", \">>\n<prefix><type> <name>(<args; separator=\", \">)<suffix> {\n <list; separator=\"\n\">\n}"); template.Add("type", func_def.Type.Accept(this)); } template.Add("generics", func_def.GenericParameter.Select(x => string.Format("typename {0}", x))); } template.Add("prefix", prefix); template.Add("suffix", suffix); if (func_def.Name == "this") { template.Add("name", NameInNameSpace(class_stack.First().Name)); } else if (func_def.Name == "~this") { template.Add("name", NameInNameSpace("~" + class_stack.First().Name)); } else { template.Add("name", NameInNameSpace(func_def.Name)); } List <Template> args_list = new List <Template>(); foreach (var x in func_def.Args) { ExprAlloc alloc = new ExprAlloc(x.Type, x.Name, null, AllocType.Declare); args_list.Add(alloc.Accept(this)); } template.Add("args", args_list); template.Add("list", func_def.Body.Accept(this)); return(template); }
private ExprAlloc alloc_expr() { EnterRule_alloc_expr(); EnterRule("alloc_expr", 35); TraceIn("alloc_expr", 35); ExprAlloc value = default(ExprAlloc); string a = default(string); List<string> b = default(List<string>); List<Expr> c = default(List<Expr>); try { DebugEnterRule(GrammarFileName, "alloc_expr"); DebugLocation(443, 1); try { // SugarWalker.g:444:2: ( ^( Expr_Alloc_Equal a= type_name b= ident_list (c= expr_list )? ) | ^( Expr_Alloc_Bracket a= type_name b= ident_list (c= expr_list )? ) ) int alt58=2; try { DebugEnterDecision(58, false); int LA58_0 = input.LA(1); if ((LA58_0==Expr_Alloc_Equal)) { alt58 = 1; } else if ((LA58_0==Expr_Alloc_Bracket)) { alt58 = 2; } else { NoViableAltException nvae = new NoViableAltException("", 58, 0, input); DebugRecognitionException(nvae); throw nvae; } } finally { DebugExitDecision(58); } switch (alt58) { case 1: DebugEnterAlt(1); // SugarWalker.g:444:4: ^( Expr_Alloc_Equal a= type_name b= ident_list (c= expr_list )? ) { DebugLocation(444, 4); DebugLocation(444, 6); Match(input,Expr_Alloc_Equal,Follow._Expr_Alloc_Equal_in_alloc_expr1752); Match(input, TokenTypes.Down, null); DebugLocation(444, 24); PushFollow(Follow._type_name_in_alloc_expr1756); a=type_name(); PopFollow(); DebugLocation(444, 36); PushFollow(Follow._ident_list_in_alloc_expr1760); b=ident_list(); PopFollow(); DebugLocation(444, 48); // SugarWalker.g:444:48: (c= expr_list )? int alt56=2; try { DebugEnterSubRule(56); try { DebugEnterDecision(56, false); int LA56_0 = input.LA(1); if (((LA56_0>=Expr_Access && LA56_0<=Expr_Tuple)||LA56_0==IDENT||LA56_0==Match_Tuple||LA56_0==NUMBER||LA56_0==STRING||LA56_0==75||LA56_0==78||LA56_0==82||LA56_0==85||LA56_0==89||LA56_0==95||LA56_0==98||LA56_0==102||LA56_0==104||LA56_0==110||LA56_0==113||LA56_0==117||LA56_0==150||LA56_0==DOUBLE)) { alt56 = 1; } } finally { DebugExitDecision(56); } switch (alt56) { case 1: DebugEnterAlt(1); // SugarWalker.g:444:49: c= expr_list { DebugLocation(444, 50); PushFollow(Follow._expr_list_in_alloc_expr1765); c=expr_list(); PopFollow(); } break; } } finally { DebugExitSubRule(56); } Match(input, TokenTypes.Up, null); DebugLocation(445, 2); value = new ExprAlloc(a, b, c, true); } break; case 2: DebugEnterAlt(2); // SugarWalker.g:448:4: ^( Expr_Alloc_Bracket a= type_name b= ident_list (c= expr_list )? ) { DebugLocation(448, 4); DebugLocation(448, 6); Match(input,Expr_Alloc_Bracket,Follow._Expr_Alloc_Bracket_in_alloc_expr1777); Match(input, TokenTypes.Down, null); DebugLocation(448, 26); PushFollow(Follow._type_name_in_alloc_expr1781); a=type_name(); PopFollow(); DebugLocation(448, 38); PushFollow(Follow._ident_list_in_alloc_expr1785); b=ident_list(); PopFollow(); DebugLocation(448, 50); // SugarWalker.g:448:50: (c= expr_list )? int alt57=2; try { DebugEnterSubRule(57); try { DebugEnterDecision(57, false); int LA57_0 = input.LA(1); if (((LA57_0>=Expr_Access && LA57_0<=Expr_Tuple)||LA57_0==IDENT||LA57_0==Match_Tuple||LA57_0==NUMBER||LA57_0==STRING||LA57_0==75||LA57_0==78||LA57_0==82||LA57_0==85||LA57_0==89||LA57_0==95||LA57_0==98||LA57_0==102||LA57_0==104||LA57_0==110||LA57_0==113||LA57_0==117||LA57_0==150||LA57_0==DOUBLE)) { alt57 = 1; } } finally { DebugExitDecision(57); } switch (alt57) { case 1: DebugEnterAlt(1); // SugarWalker.g:448:51: c= expr_list { DebugLocation(448, 52); PushFollow(Follow._expr_list_in_alloc_expr1790); c=expr_list(); PopFollow(); } break; } } finally { DebugExitSubRule(57); } Match(input, TokenTypes.Up, null); DebugLocation(449, 2); value = new ExprAlloc(a, b, c, false); } break; } } catch (RecognitionException re) { ReportError(re); Recover(input,re); } finally { TraceOut("alloc_expr", 35); LeaveRule("alloc_expr", 35); LeaveRule_alloc_expr(); } DebugLocation(452, 1); } finally { DebugExitRule(GrammarFileName, "alloc_expr"); } return value; }
public abstract Template Visit(ExprAlloc expr);
public override Template Visit(FuncDef func_def) { string prefix = ""; if (func_def.Attribute.Find(x => x.Name == "inline") != null) { prefix += "inline "; } if (this.class_stack.Count() == 0) { if (func_def.Attribute.Find(x => x.Name == "static") != null) { prefix += "static "; } } string suffix = ""; if (func_def.Attribute.Find(x => x.Name == "const") != null) { suffix += " const"; } Template template = null; if (func_def.GenericParameter.Count() == 0) { if (func_def.Type == null) { template = new Template("<prefix><name>(<args; separator=\", \">)<suffix> {\n <list; separator=\"\n\">\n}"); } else { template = new Template("<prefix><type> <name>(<args; separator=\", \">)<suffix> {\n <list; separator=\"\n\">\n}"); template.Add("type", func_def.Type.Accept(this)); } } else { if (func_def.Type == null) { template = new Template("template \\<<generics; separator=\", \">>\n<prefix><name>(<args; separator=\", \">)<suffix> {\n <list; separator=\"\n\">\n}"); } else { template = new Template("template \\<<generics; separator=\", \">>\n<prefix><type> <name>(<args; separator=\", \">)<suffix> {\n <list; separator=\"\n\">\n}"); template.Add("type", func_def.Type.Accept(this)); } template.Add("generics", func_def.GenericParameter.Select(x => string.Format("typename {0}", x))); } template.Add("prefix", prefix); template.Add("suffix", suffix); if (func_def.Name == "this") template.Add("name", NameInNameSpace(class_stack.First().Name)); else if (func_def.Name == "~this") template.Add("name", NameInNameSpace("~" + class_stack.First().Name)); else template.Add("name", NameInNameSpace(func_def.Name)); List<Template> args_list = new List<Template>(); foreach (var x in func_def.Args) { ExprAlloc alloc = new ExprAlloc(x.Type, x.Name, null, AllocType.Declare); args_list.Add(alloc.Accept(this)); } template.Add("args", args_list); template.Add("list", func_def.Body.Accept(this)); return template; }
private Expr expr() { EnterRule_expr(); EnterRule("expr", 60); TraceIn("expr", 60); Expr value = default(Expr); CommonTree op = default(CommonTree); CommonTree text = default(CommonTree); ExprTuple tuple = default(ExprTuple); ExprAlloc alloc = default(ExprAlloc); MatchTuple match = default(MatchTuple); ExprCall call = default(ExprCall); ExprCall call_with = default(ExprCall); Expr dict = default(Expr); Expr lambda = default(Expr); ExprCast cast = default(ExprCast); ExprList list = default(ExprList); ExprListGeneration list_generation = default(ExprListGeneration); Expr expr_new = default(Expr); Expr where = default(Expr); Expr expr_match = default(Expr); string ident_text = default(string); Expr a = default(Expr); Expr b = default(Expr); Expr c = default(Expr); Expr chain = default(Expr); string text_ident = default(string); try { DebugEnterRule(GrammarFileName, "expr"); DebugLocation(764, 1); try { // SugarWalker.g:765:5: (tuple= expr_tuple |alloc= alloc_expr |match= match_tuple |call= call_expr |call_with= call_with_expr |dict= dict_expr |lambda= lambda_expr |cast= cast_expr |list= list_expr |list_generation= list_generation_expr |expr_new= new_expr |where= where_expr |expr_match= match_expr | ^( Expr_Infix ident_text= ident a= expr b= expr ) | ^( Expr_Cond a= expr b= expr c= expr ) | ^( Expr_Cond_Not_Null a= expr b= expr ) | ^( Expr_Not_Null a= expr ) | ^( Expr_Access op= ( '.' | '::' | '->' | '->*' | '.*' ) a= expr ident_text= ident ) |chain= chain_expr | ^( Expr_Bin op= ( '+' | '-' | '*' | '/' | '%' | '<' | '<=' | '>' | '>=' | '==' | '!=' | '<<' | '>>' | '&' | '^' | '|' | '&&' | '||' | 'is' | 'isnt' | 'and' | 'or' ) a= expr b= expr ) | ^(op= ( '=' | '+=' | '-=' | '*=' | '/=' | '%=' | '&=' | '^=' | '|=' | '<<=' | '>>=' ) a= expr b= expr ) | ^( '@' text_ident= ident ) | ^( Expr_Bracket a= expr ) | ^( Expr_Suffix op= ( '++' | '--' ) a= expr ) | ^( Expr_Prefix op= ( '!' | '~' | '++' | '--' | '-' | '+' | '*' | '&' | 'not' ) a= expr ) | ^( ':=' a= expr b= expr ) |text_ident= ident |text= ( NUMBER | DOUBLE ) |text= STRING ) int alt90=29; try { DebugEnterDecision(90, false); switch (input.LA(1)) { case Expr_Tuple: { alt90 = 1; } break; case Expr_Alloc_Bracket: case Expr_Alloc_Equal: { alt90 = 2; } break; case Match_Tuple: { alt90 = 3; } break; case Expr_Call: { alt90 = 4; } break; case Expr_Call_With: { alt90 = 5; } break; case Expr_Dict: { alt90 = 6; } break; case Expr_Lambda: { alt90 = 7; } break; case Expr_Cast: { alt90 = 8; } break; case Expr_List: { alt90 = 9; } break; case Expr_List_Generation: { alt90 = 10; } break; case Expr_New_Array: case Expr_New_Type: { alt90 = 11; } break; case Expr_Where: { alt90 = 12; } break; case Match_Expr: { alt90 = 13; } break; case Expr_Infix: { alt90 = 14; } break; case Expr_Cond: { alt90 = 15; } break; case Expr_Cond_Not_Null: { alt90 = 16; } break; case Expr_Not_Null: { alt90 = 17; } break; case Expr_Access: { alt90 = 18; } break; case Expr_Chain: { alt90 = 19; } break; case Expr_Bin: { alt90 = 20; } break; case 89: case 92: case 96: case 99: case 104: case 110: case 118: case 121: case 128: case 135: case 183: { alt90 = 21; } break; case 131: { alt90 = 22; } break; case Expr_Bracket: { alt90 = 23; } break; case Expr_Suffix: { alt90 = 24; } break; case Expr_Prefix: { alt90 = 25; } break; case 113: { alt90 = 26; } break; case IDENT: { alt90 = 27; } break; case NUMBER: case DOUBLE: { alt90 = 28; } break; case STRING: { alt90 = 29; } break; default: { NoViableAltException nvae = new NoViableAltException("", 90, 0, input); DebugRecognitionException(nvae); throw nvae; } } } finally { DebugExitDecision(90); } switch (alt90) { case 1: DebugEnterAlt(1); // SugarWalker.g:765:7: tuple= expr_tuple { DebugLocation(765, 12); PushFollow(Follow._expr_tuple_in_expr3006); tuple=expr_tuple(); PopFollow(); DebugLocation(766, 2); value = tuple; } break; case 2: DebugEnterAlt(2); // SugarWalker.g:769:4: alloc= alloc_expr { DebugLocation(769, 9); PushFollow(Follow._alloc_expr_in_expr3016); alloc=alloc_expr(); PopFollow(); DebugLocation(770, 2); value = alloc; } break; case 3: DebugEnterAlt(3); // SugarWalker.g:773:4: match= match_tuple { DebugLocation(773, 9); PushFollow(Follow._match_tuple_in_expr3026); match=match_tuple(); PopFollow(); DebugLocation(774, 2); value = match; } break; case 4: DebugEnterAlt(4); // SugarWalker.g:777:4: call= call_expr { DebugLocation(777, 8); PushFollow(Follow._call_expr_in_expr3036); call=call_expr(); PopFollow(); DebugLocation(778, 2); value = call; } break; case 5: DebugEnterAlt(5); // SugarWalker.g:781:4: call_with= call_with_expr { DebugLocation(781, 13); PushFollow(Follow._call_with_expr_in_expr3046); call_with=call_with_expr(); PopFollow(); DebugLocation(782, 2); value = call_with; } break; case 6: DebugEnterAlt(6); // SugarWalker.g:785:4: dict= dict_expr { DebugLocation(785, 8); PushFollow(Follow._dict_expr_in_expr3056); dict=dict_expr(); PopFollow(); DebugLocation(786, 2); value = dict; } break; case 7: DebugEnterAlt(7); // SugarWalker.g:789:4: lambda= lambda_expr { DebugLocation(789, 10); PushFollow(Follow._lambda_expr_in_expr3066); lambda=lambda_expr(); PopFollow(); DebugLocation(790, 2); value = lambda; } break; case 8: DebugEnterAlt(8); // SugarWalker.g:793:4: cast= cast_expr { DebugLocation(793, 8); PushFollow(Follow._cast_expr_in_expr3076); cast=cast_expr(); PopFollow(); DebugLocation(794, 2); value = cast; } break; case 9: DebugEnterAlt(9); // SugarWalker.g:797:4: list= list_expr { DebugLocation(797, 8); PushFollow(Follow._list_expr_in_expr3086); list=list_expr(); PopFollow(); DebugLocation(798, 2); value = list; } break; case 10: DebugEnterAlt(10); // SugarWalker.g:801:4: list_generation= list_generation_expr { DebugLocation(801, 19); PushFollow(Follow._list_generation_expr_in_expr3096); list_generation=list_generation_expr(); PopFollow(); DebugLocation(802, 2); value = list_generation; } break; case 11: DebugEnterAlt(11); // SugarWalker.g:805:4: expr_new= new_expr { DebugLocation(805, 12); PushFollow(Follow._new_expr_in_expr3106); expr_new=new_expr(); PopFollow(); DebugLocation(806, 2); value = expr_new; } break; case 12: DebugEnterAlt(12); // SugarWalker.g:809:4: where= where_expr { DebugLocation(809, 9); PushFollow(Follow._where_expr_in_expr3116); where=where_expr(); PopFollow(); DebugLocation(810, 2); value = where; } break; case 13: DebugEnterAlt(13); // SugarWalker.g:813:4: expr_match= match_expr { DebugLocation(813, 14); PushFollow(Follow._match_expr_in_expr3126); expr_match=match_expr(); PopFollow(); DebugLocation(814, 2); value = expr_match; } break; case 14: DebugEnterAlt(14); // SugarWalker.g:817:4: ^( Expr_Infix ident_text= ident a= expr b= expr ) { DebugLocation(817, 4); DebugLocation(817, 6); Match(input,Expr_Infix,Follow._Expr_Infix_in_expr3135); Match(input, TokenTypes.Down, null); DebugLocation(817, 27); PushFollow(Follow._ident_in_expr3139); ident_text=ident(); PopFollow(); DebugLocation(817, 35); PushFollow(Follow._expr_in_expr3143); a=expr(); PopFollow(); DebugLocation(817, 42); PushFollow(Follow._expr_in_expr3147); b=expr(); PopFollow(); Match(input, TokenTypes.Up, null); DebugLocation(818, 2); value = new ExprInfix(ident_text, a, b); } break; case 15: DebugEnterAlt(15); // SugarWalker.g:821:4: ^( Expr_Cond a= expr b= expr c= expr ) { DebugLocation(821, 4); DebugLocation(821, 6); Match(input,Expr_Cond,Follow._Expr_Cond_in_expr3157); Match(input, TokenTypes.Down, null); DebugLocation(821, 17); PushFollow(Follow._expr_in_expr3161); a=expr(); PopFollow(); DebugLocation(821, 24); PushFollow(Follow._expr_in_expr3165); b=expr(); PopFollow(); DebugLocation(821, 31); PushFollow(Follow._expr_in_expr3169); c=expr(); PopFollow(); Match(input, TokenTypes.Up, null); DebugLocation(822, 2); value = new ExprCond(a, b, c); } break; case 16: DebugEnterAlt(16); // SugarWalker.g:825:4: ^( Expr_Cond_Not_Null a= expr b= expr ) { DebugLocation(825, 4); DebugLocation(825, 6); Match(input,Expr_Cond_Not_Null,Follow._Expr_Cond_Not_Null_in_expr3179); Match(input, TokenTypes.Down, null); DebugLocation(825, 26); PushFollow(Follow._expr_in_expr3183); a=expr(); PopFollow(); DebugLocation(825, 33); PushFollow(Follow._expr_in_expr3187); b=expr(); PopFollow(); Match(input, TokenTypes.Up, null); DebugLocation(826, 2); value = new ExprCond(new ExprBin("!=", a, new ExprConst("NULL", ConstType.Ident)), a, b); } break; case 17: DebugEnterAlt(17); // SugarWalker.g:829:4: ^( Expr_Not_Null a= expr ) { DebugLocation(829, 4); DebugLocation(829, 6); Match(input,Expr_Not_Null,Follow._Expr_Not_Null_in_expr3197); Match(input, TokenTypes.Down, null); DebugLocation(829, 21); PushFollow(Follow._expr_in_expr3201); a=expr(); PopFollow(); Match(input, TokenTypes.Up, null); DebugLocation(830, 2); value = new ExprBin("!=", a, new ExprConst("NULL", ConstType.Ident)); } break; case 18: DebugEnterAlt(18); // SugarWalker.g:833:4: ^( Expr_Access op= ( '.' | '::' | '->' | '->*' | '.*' ) a= expr ident_text= ident ) { DebugLocation(833, 4); DebugLocation(833, 6); Match(input,Expr_Access,Follow._Expr_Access_in_expr3211); Match(input, TokenTypes.Down, null); DebugLocation(833, 20); op=(CommonTree)input.LT(1); if ((input.LA(1)>=105 && input.LA(1)<=108)||input.LA(1)==112) { input.Consume(); state.errorRecovery=false; } else { MismatchedSetException mse = new MismatchedSetException(null,input); DebugRecognitionException(mse); throw mse; } DebugLocation(833, 57); PushFollow(Follow._expr_in_expr3237); a=expr(); PopFollow(); DebugLocation(833, 73); PushFollow(Follow._ident_in_expr3241); ident_text=ident(); PopFollow(); Match(input, TokenTypes.Up, null); DebugLocation(834, 2); value = new ExprAccess(a, op.Text, ident_text); } break; case 19: DebugEnterAlt(19); // SugarWalker.g:837:4: chain= chain_expr { DebugLocation(837, 10); PushFollow(Follow._chain_expr_in_expr3254); chain=chain_expr(); PopFollow(); DebugLocation(838, 2); value = chain; } break; case 20: DebugEnterAlt(20); // SugarWalker.g:841:4: ^( Expr_Bin op= ( '+' | '-' | '*' | '/' | '%' | '<' | '<=' | '>' | '>=' | '==' | '!=' | '<<' | '>>' | '&' | '^' | '|' | '&&' | '||' | 'is' | 'isnt' | 'and' | 'or' ) a= expr b= expr ) { DebugLocation(841, 4); DebugLocation(841, 6); Match(input,Expr_Bin,Follow._Expr_Bin_in_expr3263); Match(input, TokenTypes.Down, null); DebugLocation(841, 17); op=(CommonTree)input.LT(1); if ((input.LA(1)>=87 && input.LA(1)<=88)||(input.LA(1)>=90 && input.LA(1)<=91)||input.LA(1)==95||input.LA(1)==97||input.LA(1)==101||input.LA(1)==109||input.LA(1)==115||input.LA(1)==117||input.LA(1)==119||input.LA(1)==122||(input.LA(1)>=125 && input.LA(1)<=127)||input.LA(1)==134||input.LA(1)==137||(input.LA(1)>=153 && input.LA(1)<=154)||input.LA(1)==162||input.LA(1)==182||input.LA(1)==185) { input.Consume(); state.errorRecovery=false; } else { MismatchedSetException mse = new MismatchedSetException(null,input); DebugRecognitionException(mse); throw mse; } DebugLocation(848, 9); PushFollow(Follow._expr_in_expr3394); a=expr(); PopFollow(); DebugLocation(848, 16); PushFollow(Follow._expr_in_expr3398); b=expr(); PopFollow(); Match(input, TokenTypes.Up, null); DebugLocation(849, 2); value = new ExprBin(Alias(op.Text), a, b); } break; case 21: DebugEnterAlt(21); // SugarWalker.g:852:4: ^(op= ( '=' | '+=' | '-=' | '*=' | '/=' | '%=' | '&=' | '^=' | '|=' | '<<=' | '>>=' ) a= expr b= expr ) { DebugLocation(852, 4); DebugLocation(852, 8); op=(CommonTree)input.LT(1); if (input.LA(1)==89||input.LA(1)==92||input.LA(1)==96||input.LA(1)==99||input.LA(1)==104||input.LA(1)==110||input.LA(1)==118||input.LA(1)==121||input.LA(1)==128||input.LA(1)==135||input.LA(1)==183) { input.Consume(); state.errorRecovery=false; } else { MismatchedSetException mse = new MismatchedSetException(null,input); DebugRecognitionException(mse); throw mse; } Match(input, TokenTypes.Down, null); DebugLocation(852, 88); PushFollow(Follow._expr_in_expr3456); a=expr(); PopFollow(); DebugLocation(852, 95); PushFollow(Follow._expr_in_expr3460); b=expr(); PopFollow(); Match(input, TokenTypes.Up, null); DebugLocation(853, 2); value = new ExprBin(op.Text, a, b); } break; case 22: DebugEnterAlt(22); // SugarWalker.g:856:4: ^( '@' text_ident= ident ) { DebugLocation(856, 4); DebugLocation(856, 6); Match(input,131,Follow._131_in_expr3470); Match(input, TokenTypes.Down, null); DebugLocation(856, 20); PushFollow(Follow._ident_in_expr3474); text_ident=ident(); PopFollow(); Match(input, TokenTypes.Up, null); DebugLocation(857, 2); value = new ExprBracket(new ExprAccess(new ExprConst("this", ConstType.Ident), "->", text_ident)); } break; case 23: DebugEnterAlt(23); // SugarWalker.g:860:4: ^( Expr_Bracket a= expr ) { DebugLocation(860, 4); DebugLocation(860, 6); Match(input,Expr_Bracket,Follow._Expr_Bracket_in_expr3484); Match(input, TokenTypes.Down, null); DebugLocation(860, 20); PushFollow(Follow._expr_in_expr3488); a=expr(); PopFollow(); Match(input, TokenTypes.Up, null); DebugLocation(861, 2); value = new ExprBracket(a); } break; case 24: DebugEnterAlt(24); // SugarWalker.g:864:4: ^( Expr_Suffix op= ( '++' | '--' ) a= expr ) { DebugLocation(864, 4); DebugLocation(864, 6); Match(input,Expr_Suffix,Follow._Expr_Suffix_in_expr3498); Match(input, TokenTypes.Down, null); DebugLocation(864, 20); op=(CommonTree)input.LT(1); if (input.LA(1)==98||input.LA(1)==102) { input.Consume(); state.errorRecovery=false; } else { MismatchedSetException mse = new MismatchedSetException(null,input); DebugRecognitionException(mse); throw mse; } DebugLocation(864, 36); PushFollow(Follow._expr_in_expr3512); a=expr(); PopFollow(); Match(input, TokenTypes.Up, null); DebugLocation(865, 2); value = new ExprSuffix(op.Text, a); } break; case 25: DebugEnterAlt(25); // SugarWalker.g:868:4: ^( Expr_Prefix op= ( '!' | '~' | '++' | '--' | '-' | '+' | '*' | '&' | 'not' ) a= expr ) { DebugLocation(868, 4); DebugLocation(868, 6); Match(input,Expr_Prefix,Follow._Expr_Prefix_in_expr3522); Match(input, TokenTypes.Down, null); DebugLocation(868, 20); op=(CommonTree)input.LT(1); if (input.LA(1)==86||input.LA(1)==91||input.LA(1)==95||(input.LA(1)>=97 && input.LA(1)<=98)||(input.LA(1)>=101 && input.LA(1)<=102)||input.LA(1)==161||input.LA(1)==186) { input.Consume(); state.errorRecovery=false; } else { MismatchedSetException mse = new MismatchedSetException(null,input); DebugRecognitionException(mse); throw mse; } DebugLocation(868, 80); PushFollow(Follow._expr_in_expr3564); a=expr(); PopFollow(); Match(input, TokenTypes.Up, null); DebugLocation(869, 2); value = new ExprPrefix(Alias(op.Text), a); } break; case 26: DebugEnterAlt(26); // SugarWalker.g:872:4: ^( ':=' a= expr b= expr ) { DebugLocation(872, 4); DebugLocation(872, 6); Match(input,113,Follow._113_in_expr3574); Match(input, TokenTypes.Down, null); DebugLocation(872, 12); PushFollow(Follow._expr_in_expr3578); a=expr(); PopFollow(); DebugLocation(872, 19); PushFollow(Follow._expr_in_expr3582); b=expr(); PopFollow(); Match(input, TokenTypes.Up, null); DebugLocation(873, 2); if (!(a is ExprConst)) { throw new Exception("Assert failed."); } value = new ExprAlloc(new AutoType(), ((ExprConst)a).Text, b, AllocType.Equal); } break; case 27: DebugEnterAlt(27); // SugarWalker.g:880:4: text_ident= ident { DebugLocation(880, 15); PushFollow(Follow._ident_in_expr3595); text_ident=ident(); PopFollow(); DebugLocation(881, 2); if (text_ident == "nil") text_ident = "NULL"; value = new ExprConst(text_ident, ConstType.Ident); } break; case 28: DebugEnterAlt(28); // SugarWalker.g:885:4: text= ( NUMBER | DOUBLE ) { DebugLocation(885, 8); text=(CommonTree)input.LT(1); if (input.LA(1)==NUMBER||input.LA(1)==DOUBLE) { input.Consume(); state.errorRecovery=false; } else { MismatchedSetException mse = new MismatchedSetException(null,input); DebugRecognitionException(mse); throw mse; } DebugLocation(886, 5); value = new ExprConst(text.Text, ConstType.Number); } break; case 29: DebugEnterAlt(29); // SugarWalker.g:889:4: text= STRING { DebugLocation(889, 9); text=(CommonTree)Match(input,STRING,Follow._STRING_in_expr3626); DebugLocation(890, 2); value = new ExprConst(text.Text, ConstType.String); } break; } } catch (RecognitionException re) { ReportError(re); Recover(input,re); } finally { TraceOut("expr", 60); LeaveRule("expr", 60); LeaveRule_expr(); } DebugLocation(893, 1); } finally { DebugExitRule(GrammarFileName, "expr"); } return value; }
private ExprAlloc alloc_expr() { EnterRule_alloc_expr(); EnterRule("alloc_expr", 44); TraceIn("alloc_expr", 44); ExprAlloc value = default(ExprAlloc); SugarType a = default(SugarType); List<string> b = default(List<string>); List<Expr> c = default(List<Expr>); try { DebugEnterRule(GrammarFileName, "alloc_expr"); DebugLocation(584, 1); try { // SugarWalker.g:585:2: ( ^( Expr_Alloc_Equal a= type_name b= ident_list c= expr_list ) | ^( Expr_Alloc_Bracket a= type_name b= ident_list c= expr_list ) ) int alt69=2; try { DebugEnterDecision(69, false); int LA69_0 = input.LA(1); if ((LA69_0==Expr_Alloc_Equal)) { alt69 = 1; } else if ((LA69_0==Expr_Alloc_Bracket)) { alt69 = 2; } else { NoViableAltException nvae = new NoViableAltException("", 69, 0, input); DebugRecognitionException(nvae); throw nvae; } } finally { DebugExitDecision(69); } switch (alt69) { case 1: DebugEnterAlt(1); // SugarWalker.g:585:4: ^( Expr_Alloc_Equal a= type_name b= ident_list c= expr_list ) { DebugLocation(585, 4); DebugLocation(585, 6); Match(input,Expr_Alloc_Equal,Follow._Expr_Alloc_Equal_in_alloc_expr2233); Match(input, TokenTypes.Down, null); DebugLocation(585, 24); PushFollow(Follow._type_name_in_alloc_expr2237); a=type_name(); PopFollow(); DebugLocation(585, 36); PushFollow(Follow._ident_list_in_alloc_expr2241); b=ident_list(); PopFollow(); DebugLocation(585, 49); PushFollow(Follow._expr_list_in_alloc_expr2245); c=expr_list(); PopFollow(); Match(input, TokenTypes.Up, null); DebugLocation(586, 2); if (c != null && c.Count > 0) { value = new ExprAlloc(a, b, c, AllocType.Equal); } else { value = new ExprAlloc(a, b, c, AllocType.Declare); } } break; case 2: DebugEnterAlt(2); // SugarWalker.g:596:4: ^( Expr_Alloc_Bracket a= type_name b= ident_list c= expr_list ) { DebugLocation(596, 4); DebugLocation(596, 6); Match(input,Expr_Alloc_Bracket,Follow._Expr_Alloc_Bracket_in_alloc_expr2255); Match(input, TokenTypes.Down, null); DebugLocation(596, 26); PushFollow(Follow._type_name_in_alloc_expr2259); a=type_name(); PopFollow(); DebugLocation(596, 38); PushFollow(Follow._ident_list_in_alloc_expr2263); b=ident_list(); PopFollow(); DebugLocation(596, 51); PushFollow(Follow._expr_list_in_alloc_expr2267); c=expr_list(); PopFollow(); Match(input, TokenTypes.Up, null); DebugLocation(597, 2); value = new ExprAlloc(a, b, c, AllocType.Bracket); } break; } } catch (RecognitionException re) { ReportError(re); Recover(input,re); } finally { TraceOut("alloc_expr", 44); LeaveRule("alloc_expr", 44); LeaveRule_alloc_expr(); } DebugLocation(600, 1); } finally { DebugExitRule(GrammarFileName, "alloc_expr"); } return value; }