// Returns NExprPrimary or any of subproduction nodes public Node ExprPrimary() { if (CurrentToken == TokenCategory.IDENTIFIER) { Token identifier = Expect(TokenCategory.IDENTIFIER); if (CurrentToken == TokenCategory.PARENTHESIS_LEFT) { NFunCall nFunCall = new NFunCall() { AnchorToken = identifier }; nFunCall.Add(FunCall()); return(nFunCall); } else { NExprPrimary nExprPrimary = new NExprPrimary(); nExprPrimary.AnchorToken = identifier; return(nExprPrimary); } } else if (firstOfLitAlt.Contains(CurrentToken)) { return(LitAlt()); } else if (CurrentToken == TokenCategory.PARENTHESIS_LEFT) { Expect(TokenCategory.PARENTHESIS_LEFT); Node resultingNode = Expr(); Expect(TokenCategory.PARENTHESIS_RIGHT); return(resultingNode); } return(new Node()); }
//----------------------------------------------------------- public void Visit(NFunCall node) { Console.WriteLine($"+++++++++++++++ NFunCall ++++++++++++++++"); if (pasones == 2) { errorFunctionCall = node.AnchorToken; llamadaFuncion = node.AnchorToken.Lexeme; if (!Table.Contains(node.AnchorToken.Lexeme)) { throw new SemanticError("function [" + node.AnchorToken.Lexeme + "] has not been declared", node.AnchorToken); } } if (pasones == 3) { Console.WriteLine($"aki va l {node}"); if (node.AnchorToken.Lexeme.StartsWith("println")) { imprimemela("", node.AnchorToken.Lexeme); return; } else if (node.AnchorToken.Lexeme.StartsWith("print")) { imprimemela(node[0][0].AnchorToken.Lexeme, node.AnchorToken.Lexeme); return; } } VisitChildren(node); }
public string Visit(NFunCall nFunCall) { string lexeme = nFunCall.AnchorToken.Lexeme; FunctionSym functionSym = semanticAnalyzer.GetFunctionSymbolByLexeme(lexeme); NExprList argumentList = (NExprList)nFunCall[0]; string argumentsPreparation = Visit(argumentList); string prefix = ""; if (functionSym.kind == FunctionSymKind.STANDARD) { prefix = "\t\tcall int64 class ['int64lib']'Int64'.'Utils'::"; } else { prefix = "\t\tcall int64 class 'Int64Program'::"; } string paramTypeList = ""; for (var i = 0; i < argumentList.children.Count; i++) { paramTypeList += "int64"; if (i != argumentList.children.Count - 1) { paramTypeList += ", "; } } if (lexeme == "new") { lexeme = "New"; } return(argumentsPreparation + prefix + "'" + lexeme + "'(" + paramTypeList + ")\n"); }
public void Visit(NFunCall nFunCall) { string lexeme = nFunCall.AnchorToken.Lexeme; FunctionSym functionSym = semanticAnalyzer.GetFunctionSymbolByLexeme(lexeme); NExprList argumentList = (NExprList)nFunCall[0]; if (functionSym != null && functionSym.GetArity() == argumentList.children.Count) { Visit(argumentList); } else { throw new SemanticError("Nonexistent function or signature mismatch", nFunCall.AnchorToken); } }
//----------------------------------------------------------- public void Visit(NFunCall node) { Console.WriteLine($"+++++++++++++++ NFunCall ++++++++++++++++"); if (pasones == 2) { errorFunctionCall = node.AnchorToken; llamadaFuncion = node.AnchorToken.Lexeme; if (!Table.Contains(node.AnchorToken.Lexeme)) { throw new SemanticError("function [" + node.AnchorToken.Lexeme + "] has not been declared", node.AnchorToken); } } VisitChildren(node); }
// Appends NStmt to nStmtList public void Stmt(NStmtList nStmtList) { switch (CurrentToken) { case TokenCategory.IDENTIFIER: { Token tokenForAnchor = Expect(TokenCategory.IDENTIFIER); if (CurrentToken == TokenCategory.ASSIGN) { NAssign nAssign = new NAssign() { AnchorToken = tokenForAnchor }; nAssign.Add(Assign()); nStmtList.Add(nAssign); } else if (CurrentToken == TokenCategory.PARENTHESIS_LEFT) { NFunCall nFunCall = new NFunCall() { AnchorToken = tokenForAnchor }; nFunCall.Add(FunCall()); nStmtList.Add(nFunCall); } else { throw new SyntaxError(new HashSet <TokenCategory>() { TokenCategory.ASSIGN, TokenCategory.PARENTHESIS_LEFT } , tokenStream.Current); } break; } case TokenCategory.IF: { Expect(TokenCategory.IF); nStmtList.Add(IfStmt()); break; } case TokenCategory.SWITCH: { nStmtList.Add(SwitchStmt()); break; } case TokenCategory.WHILE: { nStmtList.Add(WhileStmt()); break; } case TokenCategory.DO: { nStmtList.Add(DoWhileStmt()); break; } case TokenCategory.FOR: { nStmtList.Add(ForStmt()); break; } case TokenCategory.BREAK: { nStmtList.Add(new NBreak() { AnchorToken = Expect(TokenCategory.BREAK) }); Expect(TokenCategory.SEMICOLON); break; } case TokenCategory.CONTINUE: { nStmtList.Add(new NContinue() { AnchorToken = Expect(TokenCategory.CONTINUE) }); Expect(TokenCategory.SEMICOLON); break; } case TokenCategory.RETURN: { Expect(TokenCategory.RETURN); NReturn nReturn = new NReturn(); Node returnExpression = Expr(); if (returnExpression != null) { nReturn.Add(returnExpression); } nStmtList.Add(nReturn); Expect(TokenCategory.SEMICOLON); break; } case TokenCategory.SEMICOLON: { Expect(TokenCategory.SEMICOLON); break; } default: { throw new SyntaxError(firstOfStatement, tokenStream.Current); } } }