본문 바로가기

3-2

(6)
[컴파일러개론 실습] 4. tinyPythonPrintListener import org.antlr.v4.runtime.tree.TerminalNode; public class tinyPythonPrintListener extends tinyPythonBaseListener { static int tab = 0; void printTab() { for (int i = 0; i < 4*tab; i++) { System.out.print(" "); } } @Override public void enterStmt(tinyPythonParser.StmtContext ctx) { printTab(); } @Override public void enterSuite(tinyPythonParser.SuiteContext ctx) { ++tab; } @Override public void..
[컴퓨터그래픽스] 4. OpenGL 실습 #include #include #include void reshape(int w, int h); void display(); int main(int argc, char** argv) { glutInit(&argc, argv); // GLUT_SINGLE: 단일 버퍼 창 glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(1000, 600); glutCreateWindow("201902648"); // color 버퍼를 검은색으로 초기화 후, 버퍼를 초기화하고, 앞으로 생성할 color는 흰색으로 glClearColor(0, 0, 0, 0); // 하나 이상의 버퍼를 제거 glClear(GL_COLOR_BUFFER_BIT); glColor3f..
[컴퓨터네트워크 실습] 5. TCP Proxy 전체 코드 #include #include #include #include #include #include #include #include #include using namespace std; namespace tcp_proxy { namespace ip = boost::asio::ip; namespace asio = boost::asio; namespace placeholders = boost::asio::placeholders; namespace syst = boost::system; class bridge : public boost::enable_shared_from_this { public: typedef ip::tcp::socket socket_type; typedef boost::shared_..
[컴퓨터네트워크 실습] 4. 에코 서버, 클라이언트 (TCP/UDP) socket() 소켓을 만들어주는 시스템콜 파라미터로는 domain, type, protocol을 넣고, 생성에 성공했으면 0을, 실패했으면 -1을 반환한다. TCP - server if ((sock = socket(PF_INET, SOCK_STREAM, 0)) == -1) { cerr
[기계학습 실습] 노트 make_moons (from sklearn.datasets) 초승달 모양 클러스터를 2개 생성하는 함수 X, y = make_moons(n_samples=2000, noise=0.1, random_state=925) 위처럼 사용 가능하다. noise에 따라서 분포가 달라지고, random_state는.. 솔직히 모르겠다. 튜플을 반환하는데, X는 점들의 좌표가 담긴 2차원 배열, y는 라벨을 의미한다. matplotlib 시각화 도구 import matplotlib.pyplot as plt plt.scatter 2차원 점들의 분포를 표현하는 함수 plt.scatter(x1, x2, c=y, marker='.', cmap='tab10') 제일 앞의 두 인자는 x, y좌표를 넣으면 된다. c는 색깔을 지정..
[컴파일러개론 실습] 1. 엄랭 to C 컴파일러 import java.io.*; public class Main { static String Calculate(String s, String var) { StringBuilder sb = new StringBuilder(); int N = s.length(); s += '#'; sb.append('(').append('0'); for (int i = 0; i < N; i++) { char c = s.charAt(i); if (c == '.') { sb.append("+1"); } else if (c == ',') { sb.append(-1); } else if (c == ' ') { sb.append(")*("); } else if (c == '식') { ++i; sb.append('+').append(..