public object DoForNum(NumAST num, object options = null) { ObjType ot = new ObjType(); switch (num.token.tokenType) { case TokenType.IntNum: ot = GetTypeFromName("int64"); break; case TokenType.FloatNum: ot = GetTypeFromName("float64"); break; } ObjExpr oe = new ObjExpr() { val = num.value, isSimplifiedToNum = true, isInt = (num.token.tokenType == TokenType.IntNum), objType = ot }; return(oe); }
public object DoForNum(NumAST num, object options = null) { PositionOutput(num.token.indent); ConsoleEx.WriteLine("{0}(Num) {1}{2}", ConsoleColor.DarkBlue, ConsoleColor.Gray, num.token.value); return(options); }
BlockAST Statments(int startIndent = 0) { List <AST> stmts = new List <AST>(); Token firstTok = tokens.current; do { string found = GetStmntMatch(tokens); switch (found) { case "Command": { AST stmtAST = null; switch (tokens.curTokenType) { case TokenType.Return: Token retTok = tokens.current; ExprAST expAST = ParseExpr(); stmtAST = new RetCmdAST(retTok, expAST); break; default: ShowError("Unknown command", tokens.current); break; } if (stmtAST != null) { stmts.Add(stmtAST); } break; } case "Main": { TypeAST typeAST = new TypeAST(tokens.current); Token mainTok = tokens.Next(); ArgAST[] argsAST = ParseArgs(); symbols.AddParent(typeAST, mainTok.value, argsAST); BlockAST stmtAST = Statments(startIndent + 1); symbols.RemParent(); AST functAST = new FuncDefAST(mainTok, typeAST, argsAST, stmtAST); stmts.Add(functAST); break; } case "Function": { TypeAST typeAST = new TypeAST(tokens.current); Token instTok = tokens.Next(); ArgAST[] argsAST = ParseArgs(); symbols.AddParent(typeAST, instTok.value, argsAST); BlockAST stmtAST = Statments(startIndent + 1); symbols.RemParent(); AST functAST = new FuncDefAST(instTok, typeAST, argsAST, stmtAST); stmts.Add(functAST); break; } case "ObjectDef": { // TokenType.Identifier, TokenType.Colon TypeAST typeAST = new TypeAST(tokens.current); tokens.Next(); symbols.AddParent(typeAST, "", null); tokens.Next(); BlockAST stmtAST = Statments(startIndent + 1); symbols.RemParent(); ObjDefAST odAST = new ObjDefAST(tokens.current, stmtAST); stmts.Add(odAST); break; } case "SimpleObjectInst": { // TokenType.AllTypes, TokenType.Identifier TypeAST typeAST = new TypeAST(tokens.current); tokens.Next(); symbols.Add(typeAST, tokens.current.value, null); ObjInstAST odAST = new ObjInstAST(tokens.current, typeAST, null); stmts.Add(odAST); break; } case "ObjectInst": { TypeAST typeAST = new TypeAST(tokens.current); tokens.Next(); symbols.Add(typeAST, tokens.current.value, null); ObjInstAST odAST = new ObjInstAST(tokens.current, typeAST, null); stmts.Add(odAST); break; } case "SimpleObjectInstAssigned": { TypeAST typeAST = new TypeAST(tokens.current); Token instTok = tokens.Next(); symbols.Add(typeAST, instTok.value, null); tokens.Next(); NumAST numAST = new NumAST(tokens.current, tokens.current.value, tokens.curTokenType); ObjInstAST odAST = new ObjInstAST(instTok, typeAST, numAST); stmts.Add(odAST); break; } case "ObjectInstAssigned": { TypeAST typeAST = new TypeAST(tokens.current); Token instTok = tokens.Next(); symbols.Add(typeAST, instTok.value, null); tokens.Next(); NumAST numAST = new NumAST(tokens.current, tokens.current.value, tokens.curTokenType); ObjInstAST odAST = new ObjInstAST(instTok, typeAST, numAST); stmts.Add(odAST); break; } default: ShowError("Unable to parse statement", tokens.current); break; } } while (tokens.Remaining() > 0); return(new BlockAST(firstTok, stmts.ToArray())); }