Sungwon Chunghttp://sungpi.postach.io/feed.xml2015-05-11T15:38:26.270000ZWerkzeugType Systems & Type Checkinghttps://sungpi.postach.io/post/type-systems-type-checking2015-05-11T15:38:26.270000Z2015-05-11T11:30:26ZSungwon Chung@sungpi<h2>Dynamic Type and Static Type</h2>
<ul>
<li>Runtime vs Compile time</li>
<li>Slow vs fast</li>
<li>flexible vs inflexible</li>
</ul>
<h2>Strong Typing</h2>
<ul>
<li><strong>Sound type system</strong>: guarantees that a no type errors can occur at runtime</li>
<li>cons<ul>
<li>Some checks can only be done dynamically (Array bounds checking)</li>
<li>Such checking can cause serious performance degradation</li>
<li>Even so-called strongly typed languages often have “holes" in the type system (e.g. variant records in Pascal)</li>
</ul>
</li>
</ul>
<h2>Type Equivalence</h2>
<ul>
<li>If types are required to match, the question of what types are considered to be “equivalent" arises</li>
<li><strong>Structural equivalence</strong> requires equivalent structures<ul>
<li>Identical basic types</li>
<li>Same type constructor applied to equivalent types</li>
</ul>
</li>
<li><strong>Name equivalence</strong> considered types to be equal only if the same names are used</li>
<li>C uses structural equivalence except for records</li>
</ul>
<h2>Type Signatures</h2>
<ul>
<li>The <strong>signature</strong> of a procedure is a description of the types of its arguments and type of its result. </li>
<li>i.e) sqrt : real -> real, mod: integer X integer -> integer</li>
</ul>
<h2>Polymorphic Procedures</h2>
<ul>
<li>A procedure that has multiple type signatures is called <strong>polymorphic</strong></li>
</ul>
<h2>Failure Of Type Checking Due To Aliasing, Variant Records, Subroutine Calls</h2>
<h4>Citation:</h4>
<ul>
<li>
<p>Aho, Lam, Sethi, & Ullman, Compilers: Principles, Techniques, and Tools</p>
</li>
<li>
<p>UT Austin CS375: Compilers by G.Novak. </p>
</li>
</ul>Record Structure Declarations and Referenceshttps://sungpi.postach.io/post/record-structure-declarations-and-references2015-05-11T15:38:17.482000Z2015-05-11T11:29:19ZSungwon Chung@sungpi<h2>What Information Is Stored In Symbol Table From Declaration</h2>
<ul>
<li>A record declaration has a form such as : <strong>record</strong> $field_1$, …, $field_n$ : $type_1$ ; … <strong>end</strong></li>
<li>
<ol>
<li>Initialize <strong>offset</strong> within the record to be 0.</li>
</ol>
</li>
<li>
<ol>
<li>For each entry group,</li>
<li>(a) Find the symbol table entry for the <strong>type</strong></li>
<li>(b) Allocate storage within the record using the storage allocation algorithm</li>
<li>(c) Make a symbol table entry for each field, filling in its print name, type, offset in the record, and size</li>
<li>(d) Link the entries for the fields to an entry for the record</li>
</ol>
</li>
<li>
<ol>
<li>The size of the record is the total size given by the storage allocation algorithm, rounded up to whole words, (e.g. multiple of 8)</li>
</ol>
</li>
<li>
<ol>
<li>Variant records simply restart the storage allocation at the place where the variant part begins. Total size is the maximum size of the variants</li>
</ol>
</li>
</ul>
<h2>Generation Of Intermediate Code For References To Records</h2>
<p>type date = record mo : 1..12;<br />
day : 1..31;<br />
year : integer end;<br />
person = record name : alfa;<br />
ss : integer;<br />
birth : date end;</p>
<p>var people : array[1..100] of person;</p>
<ul>
<li>people[i].birth.day </li>
<li>people[i] : (aref people (i-1)<em>32 ) = (aref people (+ -32 (</em> i 32) ) )</li>
</ul>
<h2>References Using Pointers</h2>
<h2>Records With Variant Parts</h2>
<h4>Citation:</h4>
<ul>
<li>
<p>Aho, Lam, Sethi, & Ullman, Compilers: Principles, Techniques, and Tools</p>
</li>
<li>
<p>UT Austin CS375: Compilers by G.Novak. </p>
</li>
</ul>Array References:https://sungpi.postach.io/post/array-references2015-05-11T15:38:11.769000Z2015-05-11T11:18:45ZSungwon Chung@sungpi<h2>Methods For Storing Arrays</h2>
<h2>Effect of Array Order and Loop Order On Efficiency</h2>
<h2>Computation Of Effective Address(Formula)</h2>
<h2>Why Optimization Of Array References Is Important</h2>
<h4>Citation:</h4>
<ul>
<li>
<p>Aho, Lam, Sethi, & Ullman, Compilers: Principles, Techniques, and Tools</p>
</li>
<li>
<p>UT Austin CS375: Compilers by G.Novak. </p>
</li>
</ul>Topics In Parsing Programming Language Constructs:https://sungpi.postach.io/post/topics-in-parsing-programming-language-constructs2015-05-11T15:38:07.773000Z2015-05-11T09:49:02ZSungwon Chung@sungpi<h2>Current Status Variable</h2>
<h2>Type Coercion</h2>
<ul>
<li>When a binary operator is reduced, it is necessary to check the types of the arguments, possibly to <strong>coerce</strong> an argument to the correct type, and to infer the result type.</li>
<li>char < int < float < double</li>
<li>For most operators, right-most type takes precedence</li>
<li>For assignment, left-most type takes precedence</li>
</ul>
<h2>Conversion of Names With Constant Compile-Time Values To Constants</h2>
<h2>Intermediate Code for Non-Arithmetic Statements</h2>
<h4>Citation:</h4>
<ul>
<li>
<p>Aho, Lam, Sethi, & Ullman, Compilers: Principles, Techniques, and Tools</p>
</li>
<li>
<p>UT Austin CS375: Compilers by G.Novak. </p>
</li>
</ul>Example Questions For Final Examhttps://sungpi.postach.io/post/example-questions-for-final-exam2015-05-11T15:38:06.178000Z2015-05-11T09:49:02ZSungwon Chung@sungpi<h2>Adderessing</h2>
<h2>From Midterm!</h2>
<h4>Show how an operator precedence parser would parse the string (ex. A-(B/C-D)/E+F)</h4>
<ul>
<li>Show the contents of the stacks at each step; produce a tree as output</li>
</ul>
<h4>Give one advantage and disadvantage of hashing as a method of symbol table organization</h4>
<h4>Consider the regular expression (a|b)<em>b+b</em>. What is the simplest regular expression that denotes the same language?</h4>
<h4>Give the allowable form of productions for a Regular grammar.</h4>
<h4>Consider the following grammar :</h4>
<ul>
<li>S -> a S</li>
<li>S -> S b</li>
<li>S -> b</li>
<li>What kind of grammar is this in the Chomsky hierarchy?</li>
<li>What kind of language does it denote?</li>
<li>Is there a simpler kind of grammar that denotes the same language? If so, give the grammar, if not, explain why not.</li>
</ul>
<h4>Briefly and clearly define the following terms : vocab</h4>
<h2>Other Questions</h2>
<h4>A robot moves on a square grid. The robot can go forward, turn left or turn right. Give a grammar to describe the language of all sequences of moves that leave the robot pointing in the same direction as when it started</h4>
<h4>What kind of grammar is the above(in the Chomsky hierarchy)?</h4>
<h4>Describe a kind of local optimization</h4>
<h4>Describe what it means for a subexpression to be (a) available (b) busy (c) killed</h4>
<h4>Describe sources of extra run-time overhead in (a) time and (b)space in an OOP language</h4>
<h4>Draw boxes around the following code to show the basic blocks:</h4>
<p>n := k*2;<br />
if n < j then write(‘less’) else begin k := k - 1; write(‘more’) end;<br />
writeln(k);</p>
<ul>
<li>Number the blocks and draw a flow graph; give the matrix form of the flow graph and its transitive closure</li>
</ul>
<h4>Give an advantage and a disadvantage for (a) call by reference (b) call by value</h4>
<h4>What are the most important things to optimize in a scientific program? Why?</h4>
<h4>Give three examples of computer architecture innovations that require compiler innovations to be effective</h4>
<h4>Briefly and clearly define the following terms: … 20 terms chosen from the vocabulary list on the study guide</h4>
<h4>Citation:</h4>
<ul>
<li>
<p>Aho, Lam, Sethi, & Ullman, Compilers: Principles, Techniques, and Tools</p>
</li>
<li>
<p>UT Austin CS375: Compilers by G.Novak. </p>
</li>
</ul>왜 항상 자바Java는 C++보다 느린가?https://sungpi.postach.io/post/wae-hangsang-jabajavaneun-c-boda-neuringa2015-04-15T07:26:01.785000Z2015-04-15T05:14:39ZSungwon Chung@sungpi<p>이 글은 Dejan Jelovic님의 글을 번역 한 글입니다. 수 많은 오역이 있을 수 있습니다. 피드백 부탁드립니다!</p>
<p>“자바Java는 높은 능률Performance을 가졌다. 그럭저럭 높은 능률. 그리고 그럭저럭 이란 느림을 뜻한다."<br />
Mr. Bunny( http://www.mrbunny.com/ )</p>
<p>자바Java 프로그래밍을 해본 사람이라면, 자바Java로 짜여진 프로그램들은 C++로 짜여진 프로그램보다 느린 걸 안다. 이것은 자바Java를 사용하는 사람들이 받아들여야 하는 인생의 진리이다.</p>
<p>그러나 많은 프로그래머들은 이 것이 임시적인 상황일 것이라고 자위하고, 남들을 설득하곤 한다. 그들은 자바Java가 느리게 만들어진 것이 아니라고 한다. 대신에 오늘날의 JIT는 상대적으로 나온지 얼마 안되었고, 최적화가 잘 안되었기 때문이라고.</p>
<p>그 말은 틀렸다. JIT가 얼마나 좋아지건 간에, Java는 <em>항상</em> C++보다 느릴 것이다.</p>
<h2>The Idea</h2>
<p>자바가 C++만큼 빠르거나 더 빠르다고 하는 사람들의 생각은 이렇다. 더 통제되는 프로그래밍 언어는 컴파일러가 최적화할 가능성을 더 열어준다. 그래서 모든 코드를 손으로 최적화 할 것이 아니라면, 전체적으로 컴파일러는 더 좋은 성능을 보여줄 것이다.</p>
<p>이 말은 옳다. Fortran은 더 통제되는 언어이기 때문에 계산에 있어서 C++을 완전히 발라버린다. Pointer Aliasing의 걱정 없이 컴파일러는 최적화를 더 잘 해준다. C++이 Fortran의 속도를 흉내낼 수 있는 방법은 영리하게 잘 만들어진 Blitz++같은 라이브러리를 이용하는 것 뿐이다.</p>
<p>그러나 이런 결과를 가져다 주기 위해서 애초에 프로그래밍 언어는 컴파일러에게 최적화의 가능성을 열어 줄 수있게 만들어 졌어야 한다. 공교롭게도 자바Java는 이런 방법으로 만들어지지 않았다. 그래서 컴파일러가 얼마나 똑똑해 지건 간에 자바Java는 C++의 속도를 절대 따라잡지 못할 것이다.</p>
<h2>The Benchmarks</h2>
<p>거꾸로, 자바Java가 C++ 만큼은 빠를 수 있는 분야는 전형적인 벤치마크를 할 때이다. 만약 N번째 피보나치 넘버를 계산하거나 Linpack(벤치마크 방법)을 돌려야 한다면, 자바가 C++보다 느릴 이유가 전혀 없다. 모든 계산이 한 클래스 안에서 이루어지고, int나 double같은 기본형Primitive 데이터만 다룬다면 자바는 C++의 발자국들을 따라 잡을 수 있다.</p>
<h2>The Real World</h2>
<p>프로그램에 오브젝트를 사용하는 순간부터 자바는 최적화를 할 가능성을 잃어버린다. 다음에서 그 이유들을 다룰 것이다.</p>
<h4>1. 모든 오브젝트는 힙Heap에 할당된다.</h4>
<p>자바는 int나 double같은 기본Primitive 자료형만 스택Stack에 할당한다. 모든 오브젝트는 힙Heap에 할당된다.</p>
<p>Identity semantic을 가지는 큰 오브젝트들의 경우에는 문제가 안된다. C++ 프로그래머들도 이런 오브젝트는 힙에 할당한다. 그러나 성능을 저하시키는 주요 이유는 단순 값만 들고 있는 (Value semantics) 작은 오브젝트들의 경우이다.</p>
<p>이런 작은 오브젝트가 무엇인가? 나에게 이것들은 이터레이터들이다. 나는 그들을 내 디자인(코드)에 많이 쓴다. 어떤 사람들은 복잡한 숫자를 쓸 수도 있다. 예로 3D 프로그래머들은 벡터Vector나 포인트Point 클래스를 쓴다. 시간에 연계된 자료를 다루는 사람들은 Time클래스를 쓴다. 이런 자료형들을 쓰는 사람들은 비용 0의 스택할당 보다 상수 시간이 걸리는 힙 할당을 쓴다. 이 것들로 루프를 돌리면 O(n)과 상수 0의 차이가 난다. 다른 루프를 추가하면 O($n^2$)과 상수 0의 차이가 난다.</p>
<h4>2. 엄청 많은 형변환Cast.</h4>
<p>템플릿Template의 등장으로, 뛰어난 C++ 프로그래머들은 high-level 프로그램에도 형변환Cast를 최대한 피할 수 있었다. 공교롭게도 자바는 템플릿Template이 없고, 자바 코드는 형변환Cast으로 넘쳐난다.</p>
<p>이 것은 성능에 무슨 영향을 끼칠까? 자바의 모든 형변환은 동적Dynamic 형변환이고, 비싼 비용을 지불해야 한다. 얼마나 비싼지 동적 형변환을 예로 들어 보겠다.</p>
<p>가장 쉬운 예는 클래스에 번호를 할당하고, 두 클래스가 연관되었는지를 판단하는 행렬을 만들고, 만약 그렇다면 offset은 형변환을 하기 위해 포인터에 추가되어야 될 것이다. 그 경우에, 형변환을 위한 수도코드는 다음과 같다 :</p>
<pre><code class=“language-java">
DestinationClass makeCast (Object o, Class destinationClass)
{
Class sourceClass = o.getClass(); // JIT compile-time
int sourceClassId = sourceClass.getId(); // JIT compile-time
int destinationId = destinationClass.getId();
int offset = ourTable [sourceClassId][destinationClassId];
if (offset != ILLEGAL_OFFSET_VALUE)
{
return ;
}else throw new IllegalCastException();
}
</code></pre>
<p>작은 형변환을 위해 너무 많은 코드를 쓴다. 그리고 여기에 장밋빛 그림이 있다 - 클래스의 관계를 나타내기 위해 행렬을 쓰는 것은 너무 많은 메모리를 잡아먹고 미치지 않은 컴파일러라면 이 짓을 할리가 없다. 대신에 그들은 Map이나 상속 계층을 뒤질 것이다. - 이 두 경우에는 계산이 더 느리다.</p>
<h4>3. 메모리 사용량의 증가</h4>
<p>자바 프로그램들은 C++ 프로그램들이 데이터를 저장하는 것의 거의 2배를 사용한다. 이는 다음과 같은 세 가지 이유가 있다.</p>
<ul>
<li>
<ol>
<li>GC를 켜놓은 프로그램들은 직접 손으로 메모리 관리를 하는 프로그램보다 메모리를 50% 정도 더 쓴다.</li>
</ol>
</li>
<li>
<ol>
<li>C++에선 많은 오브젝트들이 스택에 할당 될 때, 자바에서는 힙에 할당 된다.</li>
</ol>
</li>
<li>
<ol>
<li>자바의 오브젝트는 더 큰데, 모든 오브젝트가 virtual table을 가지는 데다가 synchronization primitive를 지원하기 때문이다.</li>
</ol>
</li>
</ul>
<p>큰 메모리를 사용하는 프로그램들은 프로그램이 디스크에서 스왑 아웃될 확률을 증가시킨다. 그리고 스왑 아웃이 된다면, 속도는 말할 것도 없다.</p>
<h4>4. 디테일을 다루는 컨트롤의 부재</h4>
<p>자바는 의도적으로 심플한 언어로 설계되었다. C++은 프로그래머에게 디테일을 다룰 수 있는 많은 기능들을 제공한다. 이 기능들은 자바에서 의도적으로 삭제되었다.</p>
<p>예를 들어 C++은 Locality of reference를 향상시킬 수 있는 기능을 제공한다. 많은 오브젝트들을 한 번에 할당하고, 해제하는 기능도 제공한다. 포인터로 멤버를 빠르게 접근할 수 있는 트릭도 제공한다...</p>
<p>하지만 이런 기능들을 자바에 없다.</p>
<h4>5. High-level 최적화의 부재</h4>
<p>프로그래머들은 high-level 개념들을 다룬다. 반대로 컴파일러는 low-level만을 다룬다. 프로그래머에게 Matrix라고 이름지어진 클래스는 Vector라고 이름 지어진 클래스와 다른 high-level 개념이다. 컴파일러에게 이들은 심볼 테이블Symbol Table의 일부일 뿐이다. 컴파일러가 신경쓰는 것은 그 클래스가 가지는 함수들과, 그 함수들 안의 구문들 뿐이다.</p>
<p>이제 이걸 생각해보자 : $x^y$를 반환하는 exp(double x, double y)라는 함수를 사용한다고 생각해보자. 컴파일러는 이 구문들을 들여다 보는 것만으로 exp(exp(x,2), 0.5)가 x로 최적화 될 수 있는 걸 알 수 있을까? 당연히 아니다.</p>
<p>컴파일러가 할 수 있는 모든 최적화는 구문 단계에서 이루어지며, 그들은 컴파일러 안에 쓰여져 있다. 위의 예제에서 가 exp(exp(x,2), 0.5)가 x와 같다는 것을 알거나 코드 안에서 함수를 부르는 순서가 잘못되었다는 걸 프로그래머는 안다. 하지만 컴파일러는 이걸 구문 레벨에서 뜯어낼 수 없기 때문에, (컴파일러가 구문 단계에서 이걸 뜯어 낼 수 있게 되기 전까지는) 최적화는 되지 않을 것이다.</p>
<p>그래서 만약 high-level 최적화가 되길 바란다면, 프로그래머가 컴파일러에게 high-level 최적화 조건들을 알려줄 수 있는 방법이 있어야 한다.</p>
<p>유명한 프로그래밍 언어와 시스템 중 이런 방법을 가진 것은 없다. 그러나 C++에서는 템플릿 메타프로그래밍으로 high-level 오브젝트들의 최적화를 해낼 수 있다. Temporary elimination, partial evaluation, symmetric function call removal 그리고 더 많은 다른 최적화들은 템플릿을 이용함으로써 구현할 수 있다. 당연히 모든 high-level최적화가 이런 방식으로 되는 것은 아니다. 그리고 이런 것들을 사용하는 것은 어렵고 귀찮다. 그러나 상당히 많은 수가 해결될 수 있으며, 사람들을 이미 이런 기술을 이용해 snazzy libraries를 구현 했다.</p>
<p>다시 한 번 공교롭게도, 자바에는 메타프로그래밍 설비가 되어있지 않다. 그러므로 (이를 이용한) high-level 최적화는 자바에서 불가능하다. </p>
<h4>So...</h4>
<p>지금까지의 기능을 볼 때 자바는 결코 C++처럼 빠를 수 없다. 이 것은 곧 자바가 고성능 소프트웨어나 COTS arena에 적당하지 않다는 것을 의미한다. 그러나 자바는 배우고 쉽고, 관대하고, 이용하기 쉬운 방대한 라이브러리가 있어서 작거나 중간 정도의 크기의 프로그램을 만드는 데 적당하다.</p>
<h4>역주</h4>
<p>정확한 번역보다 읽기 쉽게 의역하려고 노력 했습니다. </p>
<p>번역 : 정성원(sungpia@me.com)</p>
<h4>Citation</h4>
<ul>
<li>Jevolic, D. (n.d.). Why Java Will Always Be Slower than C. Retrieved April 15, 2015, from http://www.jelovic.com/articles/why_java_is_slow.htm</li>
</ul>OOP 인터뷰 질문 정리https://sungpi.postach.io/post/oop-inteobyu-jilmun-jeongri2015-04-15T12:35:34.155000Z2015-04-14T04:38:45ZSungwon Chung@sungpi<h2>What are the basic concepts of OOP?</h2>
<ul>
<li>Abstraction</li>
<li>Polymorphism</li>
<li>Inheritance</li>
<li>Encapsulation</li>
</ul>
<h2>What is dynamic or run time polymorphism?</h2>
<h2>Object와 Class의 차이</h2>
<p>Class를 인스턴트화(Instantiation)하면 Object(Instance)가 된다.<br />
객체는 클래스의 인스턴스다.<br />
객체 간의 링크는 클래스 간의 연관관계의 인스턴스다.<br />
실행 프로세스는 실행 프로그램의 인스턴스다.</p>
<p>추상적인 컨셉에서 논할 때는 클래스와 객체로 이야기 한다.<br />
프로그램 컴파일 레벨의 아래 쪽에서 논할 때는 클래스와 인스턴스로 이야기 한다.</p>
<p>Object has states and behaviors. An object is an instance of class.<br />
Class can be defined as a template/blue print that describes the behaviors/states that object of its type support.</p>
<h4>오브젝트</h4>
<p>오브젝트는 실 세계와 연관이 깊다. ‘개’라는 오브젝트를 우리는 실 생활에서 쉽게 찾을 수 있다. </p>
<h4>클래스</h4>
<p>클래스는 각 각의 오브젝트들을 만들기 위한 청사진이다.<br />
Local variable, Instance variable, class variable.<br />
$1 : </p>
<h2>Instantiation</h2>
<p>자바에서는 new 키워드를 사용하면 인스턴스화가 된다.<br />
(declaration class_name var_name = instantiation class_name(initialization);</p>
<h2>Method</h2>
<p>메소드는 오브젝트와 오브젝트의 통신을 하는 방법이다.<br />
오브젝트의 상태를 나타내는 것은 인스턴스 변수이다. </p>
<h2>Abstract Class</h2>
<h2>Class/Static Method</h2>
<h2>Static/Class Initializer</h2>
<h2>Constructor</h2>
<h2>Destructor/Finalizer</h2>
<h2>Superclass /Baseclass</h2>
<h2>Subclass/Derived Class</h2>
<h2>Inheritance</h2>
<h2>Encapsulation</h2>
<h2>Polymorphism (예시 없이)</h2>
<h2>Multiple Inheritance</h2>
<h2>Delegation</h2>
<h2>Composition /Aggregation</h2>
<h2>Interface /Abstract class</h2>
<h2>Interface /Protocol</h2>
<h2>Method Overriding</h2>
<h2>Method Overloading</h2>
<h2>IS-A 와 HAS-A</h2>
<h2>Method Signatures</h2>
<h2>Method Visibility</h2>HTTPS and SSL Certificatehttps://sungpi.postach.io/post/https-and-ssl-certificate2015-04-04T07:03:53.107000Z2015-04-04T06:51:20ZSungwon Chung@sungpi<h2>HTTPS vs HTTP</h2>
<p>HTTP stands for Hypertext Transfer Protocol. Which means, it is a protocol that we can use for transferring Hypertext datas. “S" in HTTPS stands for Over Secure Socket Layer. Intuitively, it’s secured HTTP protocol. HTTP sends data without encryption; hackers can easily eavesdrop data flowing between server and client.</p>
<h2>HTTPS and SSL</h2>
<p>HTTPS and SSL are not same concept as Internet and Web are not same. SSL protocol is more broad concept; HTTPS works on the SSL protocol.</p>
<h2>SSL and TLS</h2>
<p>Netscape developed SSL, but this term was redefined by IETF to TLS. However, no one cares and it is stilled called by SSL.</p>
<h2>SSL Digital Certificate</h2>
<p>Communication between client and server can be guaranteed by third person, and documented to SSL certificate. Right after client approaches server, server sends this certificate to client. Client examines whether is certificate is trustable and safe, then client processes next procedures. There we can earn benefits by SSL.</p>
<ul>
<li>Hide information from eavesdropper</li>
<li>Client can determine if server is trustable or not</li>
<li>Both can assure if communication was changed in the middle or not</li>
</ul>
<h2></h2>
<h2>Citation</h2>
<p>http://opentutorials.org/course/228</p>Setting AWS for Who’s Hungry?https://sungpi.postach.io/post/setting-aws-for-whos-hungry2015-04-04T06:51:31.194000Z2015-04-04T06:17:31ZSungwon Chung@sungpi<p>1 Load Balancer<br />
1 Web/App Server with Passenger<br />
1 DB server ( postgreSQL )</p>Description of methodshttps://sungpi.postach.io/post/description-of-methods2015-04-13T09:45:21.270000Z2015-03-27T22:10:49ZSungwon Chung@sungpi<h2>Phone</h2>
<h4>Send Verification Message to User</h4>
<ul>
<li>method : POST</li>
<li>version : v1</li>
<li>URL : /v1/phone/sendsms</li>
</ul>
<h6>Description</h6>
<p>You can use this method for sending verification SMS to user, with 6 random digit code</p>
<h6>Parameters</h6>
<ul>
<li>contact</li>
</ul>
<h6>Constraints</h6>
<ul>
<li>contact : should be “+15129994336" form</li>
</ul>
<h6>Response</h6>
<p>Simple text, “SENT"</p>
<h4>Verify 6 digit number from SMS</h4>
<ul>
<li>method : POST</li>
<li>version : v1</li>
<li>URL : /v1/phone/verify</li>
</ul>
<h6>Description</h6>
<p>You can use this method to verify SMS from our server.</p>
<h6>Parameters</h6>
<ul>
<li>contact</li>
<li>code</li>
</ul>
<h6>Constraints</h6>
<ul>
<li>contact should be “+15129994336" form.</li>
</ul>
<h6>Response</h6>
<p>“OK" if right, or “Wrong" if wrong.</p>
<h2>User</h2>
<h4>Creates User</h4>
<ul>
<li>method : POST</li>
<li>version : v1</li>
<li>URL : /v1/users</li>
</ul>
<h6>Description</h6>
<p>You can register user, using parameters above. This is exactly same as “Sign Up" that you can see everywhere on the website. You’ll use user_id from response for every single actions for Who’s Hungry? server</p>
<h6>Parameters :</h6>
<ul>
<li>name : name of the user from facebook</li>
<li>picture : url of the profile picture from facebook</li>
<li>contact : user’s contact number</li>
<li>email : user’s email address</li>
<li>fb_id : facebook id of the user</li>
<li>access_token : access_token from Facebook login</li>
<li>os_type : iOS / android</li>
<li>push_id : push id of the device</li>
</ul>
<h6>Constraints</h6>
<ul>
<li>contact <br />
should be <strong>unique</strong>. If you try to make user with existing contact number, server will not allow any actions. you can use <strong>put</strong> method existing below.</li>
</ul>
<h6>Response</h6>
<ul>
<li>id : this is <strong>user_id</strong></li>
<li>name </li>
<li>picture </li>
<li>contact</li>
<li>email</li>
<li>fb_id</li>
<li>created_at</li>
<li>updated_at</li>
<li>devices<ul>
<li>id : this is <strong>device_id</strong></li>
<li>user_id</li>
<li>os_type</li>
<li>push_id</li>
<li>created_at</li>
<li>updated_at</li>
</ul>
</li>
</ul>
<h4>Show One User</h4>
<ul>
<li>method : GET</li>
<li>version : v1</li>
<li>URL : v1/{token}/user/{user_id}</li>
</ul>
<h6>Description</h6>
<h6>Parameter</h6>
<h6>Constraint</h6>
<h6>Response</h6>
<p>see apiary</p>
<h4>Update User</h4>
<ul>
<li>method : PUT</li>
<li>version : v1</li>
<li>URL : v1/{token}/users</li>
</ul>
<h6>Description</h6>
<h6>Parameter</h6>
<h6>Constraint</h6>
<h6>Response</h6>
<ul>
<li>id : this is <strong>user_id</strong></li>
<li>name </li>
<li>picture </li>
<li>contact</li>
<li>email</li>
<li>fb_id</li>
<li>created_at</li>
<li>updated_at</li>
<li>devices<ul>
<li>id : this is <strong>device_id</strong></li>
<li>user_id</li>
<li>os_type</li>
<li>push_id</li>
<li>created_at</li>
<li>updated_at</li>
</ul>
</li>
</ul>
<h2>Auth</h2>
<h4>login to the server</h4>
<ul>
<li>method : POST</li>
<li>version : v1</li>
<li>URL : /v1/auth</li>
</ul>
<h6>Descriptions</h6>
<p>If access_token from the Facebook is expired, you should update user cause Who’s Hungry? server will never allow you to login. (It will never match data from the server)<br />
Response <strong>token</strong> will allow you every single authorization towards the server.</p>
<h6>Parameters</h6>
<ul>
<li>user_id : user_id of Who’s Hungry? server</li>
<li>access_token : access_token from facebook</li>
</ul>
<h6>Constraints</h6>
<p>none</p>
<h6>Response</h6>
<ul>
<li>user_id</li>
<li>id </li>
<li>login_type</li>
<li>token</li>
<li>created_at</li>
<li>updated_at</li>
</ul>
<h2>Group</h2>
<h4>Create Group</h4>
<ul>
<li>method : POST</li>
<li>version : v1</li>
<li>URL : /v1/{token}/groups</li>
</ul>
<h6>Descriptions</h6>
<p>Creates group according to invitation. We invite through contact number, and </p>
<h6>Parameters</h6>
<ul>
<li>invitation<ul>
<li>fb_id or contact</li>
<li>fb_id or contact</li>
<li>fb_id or contact … (at least one contact number)</li>
</ul>
</li>
</ul>
<h6>Constraints</h6>
<ul>
<li>token<br />
We need <strong>token</strong> to authorize user</li>
<li>contact<br />
Contact number should contain country code, ex : “+15129994336".</li>
</ul>
<h6>Response</h6>
<ul>
<li>id : id of group</li>
<li>user_id : admin user_id</li>
<li>name : name of the group</li>
<li>created_at</li>
<li>updated_at</li>
<li>users<ul>
<li>id</li>
<li>fb_id</li>
<li>name</li>
<li>picture</li>
<li>contact</li>
<li>email</li>
<li>created_at</li>
<li>updated_at</li>
<li>devices<ul>
<li>id : this is <strong>device_id</strong></li>
<li>user_id</li>
<li>os_type</li>
<li>push_id</li>
<li>created_at</li>
<li>updated_at</li>
</ul>
</li>
</ul>
</li>
</ul>
<h4>Show groups where you belongs</h4>
<ul>
<li>method: GET</li>
<li>version: v1</li>
<li>url: v1/{token}/groups</li>
</ul>
<h6>Description</h6>
<p>Get the list of groups that you’re belonging to</p>
<h6>Parameters</h6>
<p>none</p>
<h6>Constraints</h6>
<p>none</p>
<h6>Responses</h6>
<p>see apiary</p>
<h4>Show one group</h4>
<ul>
<li>method: GET</li>
<li>version: v1</li>
<li>url: v1/{token}/group/{group_id}</li>
</ul>
<h6>Description</h6>
<h6>Parameters</h6>
<h6>Constraints</h6>
<h6>Responses</h6>
<h2>Vote</h2>
<h4>Create Vote</h4>
<ul>
<li>method : POST</li>
<li>version : v1</li>
<li>URL : /v1/{token}/{group_id}/votes</li>
</ul>
<h6>Description</h6>
<p>Create “Vote" with information of votes, and known information with restaurants. Automatically creates “Choices" in the vote, and restaurants are automatically registered in the servers so you can use it.</p>
<h6>Parameters</h6>
<ul>
<li>vote_type : vote type such as “lunch", “dinner" ...</li>
<li>name : name of the vote</li>
<li>expires_in : integer minute, which is, vote will expire in 10 minute => 10</li>
<li>expires_at : Datetime of expiring time of the vote </li>
<li>restaurants : JSON array of restaurants<ul>
<li>place_id : id of restaurant(from google place API, yelp …)</li>
<li>name : name of restaurant</li>
<li>picture : url of profile pic of restaurant</li>
<li>lat : latitude</li>
<li>lng : longitude</li>
<li>rating : official rating</li>
</ul>
</li>
</ul>
<h6>Constraints</h6>
<h6>Response</h6>
<ul>
<li>id : id of vote</li>
<li>group_id : id of group</li>
<li>vote_type</li>
<li>name</li>
<li>expires_in </li>
<li>expires_at</li>
<li>created_at</li>
<li>updated_at</li>
<li>choices<ul>
<li>id</li>
<li>vote_id</li>
<li>restaurant_id</li>
<li>count</li>
<li>created_at</li>
<li>updated_at</li>
</ul>
</li>
</ul>
<h4>Show one Vote</h4>
<ul>
<li>method: GET</li>
<li>version: v1</li>
<li>URL: v1/{token}/vote/{vote_id}</li>
</ul>
<h6>Description</h6>
<p>show one vote</p>
<h6>Parameters</h6>
<p>none</p>
<h6>Constraints</h6>
<p>none</p>
<h6>Response</h6>
<h2>Choices</h2>
<h4>View all the choices in the vote</h4>
<ul>
<li>method: GET</li>
<li>version: v1</li>
<li>URL: v1/{token}/{vote_id}/choices</li>
</ul>
<h6>Description</h6>
<p>Look up all the choices that belongs to certain {vote_id}.</p>
<h6>Parameters</h6>
<p>none</p>
<h6>Constraints</h6>
<p>none</p>
<h6>Response</h6>
<ul>
<li>choices <ul>
<li>id</li>
<li>vote_id</li>
<li>restaurant_id</li>
<li>count</li>
<li>created_at</li>
<li>updated_at</li>
</ul>
</li>
</ul>
<h4>Create new choice in the vote</h4>
<ul>
<li>method: POST</li>
<li>version: v1</li>
<li>URL: v1/{token}/{vote_id}/choices</li>
</ul>
<h6>Description</h6>
<p>Create single choice under certain {vote_id}, which is adding a restaurant to vote.</p>
<h6>Parameters</h6>
<ul>
<li>place_id</li>
<li>name</li>
<li>picture</li>
<li>lat</li>
<li>lng</li>
<li>rating</li>
</ul>
<h6>Constraints</h6>
<h6>Response</h6>
<ul>
<li>id</li>
<li>vote_id</li>
<li>restaurant_id</li>
<li>count</li>
<li>created_at</li>
<li>updated_at</li>
</ul>
<h4>Make a choice (make a vote)</h4>
<ul>
<li>method: PUT</li>
<li>version: v1</li>
<li>URL: v1/{token}/choice/{choice_id}</li>
</ul>
<h6>Description</h6>
<p>Make a vote, with the count with given {choice_id} from other APIS.</p>
<h6>Parameters</h6>
<ul>
<li>count : up vote? down vote?</li>
</ul>
<h6>Constraints</h6>
<ul>
<li>count<br />
should be {-1, 1}, one can remain in state {upvote, not voted, down vote }</li>
</ul>
<h6>Response</h6>
<ul>
<li>id</li>
<li>vote_id</li>
<li>restaurant_id</li>
<li>count</li>
<li>created_at</li>
<li>updated_at</li>
</ul>
<h2>Rsvp</h2>
<h4>Make a RSVP</h4>
<ul>
<li>method: POST</li>
<li>version: v1</li>
<li>URL: v1/{token}/{vote_id}/rsvps</li>
</ul>
<h6>Description</h6>
<p>Make a Rsvp, and send push notification between devices so RSVP of the vote can remain updated.</p>
<h6>Parameters</h6>
<ul>
<li>rsvp : integer (1: going, -1: not going, 0: default)</li>
</ul>
<h6>Constraints</h6>
<h6>Response</h6>
<ul>
<li>id </li>
<li>vote_id</li>
<li>user_id</li>
<li>rsvp</li>
<li>created_at</li>
<li>updated_at</li>
</ul>
<h4>Get one vote’s RSVP list</h4>
<ul>
<li>method: GET</li>
<li>version: v1</li>
<li>URL: v1/{token}/{vote_id}/rsvps</li>
</ul>
<h6>Description</h6>
<p>Get all RSVPs from Vote</p>
<h6>Parameters</h6>
<p>none</p>
<h6>Constraints</h6>
<h6>Response</h6>
<ul>
<li>rsvps : JSON array of rsvps<ul>
<li>id</li>
<li>vote_id</li>
<li>user_id</li>
<li>rsvp</li>
<li>created_at</li>
<li>updated_at</li>
</ul>
</li>
</ul>
<h2>Restaurant</h2>
<h4>Show one restaurant’s information</h4>
<ul>
<li>method: GET</li>
<li>version: v1</li>
<li>URL: v1/{token}/restaurant/{restaurant_id}</li>
</ul>
<h6>Description</h6>
<p>Get all the information about the restaurant. {restaurant_id} either can be Who’s Hungry? server’s id or place_id</p>
<h6>Parameter</h6>
<p>none</p>
<h6>Constraints</h6>
<h6>Response</h6>
<ul>
<li>id</li>
<li>place_id</li>
<li>name</li>
<li>picture</li>
<li>lat</li>
<li>lng </li>
<li>rating</li>
<li>created_at</li>
<li>updated_at</li>
</ul>
<h2>Location</h2>
<h4>Update user’s location</h4>
<ul>
<li>method: POST</li>
<li>version: v1</li>
<li>URL: v1/{token}/locations</li>
</ul>
<h6>Description</h6>
<p>Update user’s location</p>
<h6>Parameters</h6>
<ul>
<li>lat : latitude of the user</li>
<li>lng : longitude of the user</li>
<li>pickup : {1: “I want to be picked up", 2: “I am driving", 3: “I’m inviting you to my home"}</li>
</ul>
<h6>Constraints</h6>
<h6>Response</h6>
<ul>
<li>id</li>
<li>user_id</li>
<li>lat</li>
<li>lng</li>
<li>pickup</li>
<li>updated_at</li>
<li>created_at</li>
</ul>
<h4>Get Vote's location</h4>
<ul>
<li>method: GET</li>
<li>version: v1</li>
<li>URL: v1/{token}/{vote_id}/locations</li>
</ul>
<h6>Description</h6>
<p>Get group’s location</p>
<h6>Parameters</h6>
<p>none</p>
<h6>Constraints</h6>
<p>“ I have a question :: Do we have to filter users that who RSVPed?"</p>
<h6>Response</h6>
<ul>
<li>locations<ul>
<li>id</li>
<li>user_id</li>
<li>lat</li>
<li>lng</li>
<li>pickup</li>
<li>updated_at</li>
<li>created_at</li>
</ul>
</li>
</ul>
<h2>Lobby</h2>
<h4>See Lobby</h4>
<ul>
<li>method : POST</li>
<li>version : v1</li>
<li>URL: v1/{token}/lobbies</li>
</ul>
<h6>Description</h6>
<p>Get lobby</p>
<h6>Parameters</h6>
<ul>
<li>limit : limit of lobby {should send default :: 40}</li>
<li>offset : starting point {should send default :: 0}</li>
</ul>
<h6>Constraint</h6>
<p>please send limit and offset</p>
<h6>Response</h6>
<p>JSON array of votes : chk document for vote</p>
<h2>Chat</h2>
<h4>upload your chat</h4>
<ul>
<li>method : POST</li>
<li>version: v1</li>
<li>URL: v1/{token}/{vote_id}/chat</li>
</ul>
<h6>Description</h6>
<p>Upload chat from the user to the server</p>
<h6>Parameters</h6>
<ul>
<li>text </li>
</ul>
<h6>Constraint</h6>
<h6>Response</h6>
<h4>See all Chats</h4>
<ul>
<li>method : GET</li>
<li>version: v1</li>
<li>URL: v1/{token}/{vote_id}/chat</li>
</ul>
<h6>Description</h6>
<p>See all the chats</p>
<h6>Parameters</h6>
<p>none</p>
<h6>Contraint</h6>
<h6>Response</h6>
<h2>Overlap</h2>
<h4>Show one overlap</h4>
<ul>
<li>method : GET</li>
<li>version : v1</li>
<li>URL: v1/{token}/{choice_id}/overlap</li>
</ul>
<h2></h2>
<h2></h2>
<h2></h2>
<h2></h2>Type Latticehttps://sungpi.postach.io/post/type-lattice2015-03-27T21:59:41.102000Z2015-03-27T21:45:20ZSungwon Chung@sungpi<h4>C++ 에서의 자료형type 을 크게 네 가지로 생각해 보면 다음과 같다:</h4>
<ul>
<li>bool</li>
<li>char</li>
<li>int</li>
<li>double </li>
</ul>
<p>이 네 가지 자료형Type 에는 우선 순위가 있다. 이를 Type Lattice라고 한다.<br />
자료형 변환Cast을 할 때나, 연산을 할 때 이 우선 순위가 적용된다:</p>
<p>bool to char<br />
bool to int<br />
bool to double<br />
char to int<br />
char to double<br />
int to double<br />
위와 같은 경우는 자료형을 변환할 때 안전하다고 한다. (Safe conversion)<br />
이 외의 경우에는 안전하지 않다고 한다. 이는 자료형Type안의 값Value가 파괴될 수 있기 때문이다. C++에서는 변수를 선언할 때나 변환할 때, { } 를 사용함으로써 컴파일 단계에서 이 안전하지 않은 변환에서 에러를 낼 수 있다. 그리고 이 에러를 Narrowing이라고 한다.</p>
<pre><code class=“language-cpp">
int a{4.2};
int b = 4.2;
1 + 2.5;
</code></pre>
<p>이 코드는 int a에 double 값인 4.2가 들어감으로써 narrow error를 발생시킨다.<br />
반면, int b = 4.2는 b에 4를 넣어주는 강제 형변환이 된다. </p>
<h4>연산</h4>
<p>연산 시에는 Type Lattice에 따라, 안전하게 변환이 되게 컴파일러가 계산을 한다. <br />
예를 들어 1 + 2.5 는 int와 double의 +연산이다. 이 경우에 int + int로 계산하거나, double + double로 계산하는 두 가지 경우가 있다. 전자는 int + double->int의 연산이고, 후자는 int->double + double의 연산이다. 전자는 double->int가 unsafe conversion이고, 후자는 int->double이 safe conversion이므로 컴파일러는 자동으로 후자를 택해서 연산을 하게 된다.</p>Testcodehttps://sungpi.postach.io/post/testcode2015-03-27T21:52:51.034000Z2015-03-13T13:12:26ZSungwon Chung@sungpi<pre><code class=“language-cpp">
int a;
std::cout << a;
</code></pre>
<p>dho dkseh</p>
<p>int a;<br />
std::cout << a;</p>
<p>왜??</p>
<p>import urllib</p>
<p>print ‘Hello World'</p>Other Conceptshttps://sungpi.postach.io/post/other-terminologies2015-03-12T15:02:57.096000Z2015-03-12T12:36:54ZSungwon Chung@sungpi<h4>Synthesized Translation</h4>
<p>The term <em>synthesized translation</em> includes two ideas:</p>
<ul>
<li>A complex expression is constructed from subexpressions</li>
<li>The translation of a complex expression is constructed in a mechanical way form the translations of its subexpressions<br />
if x > max then max := x <br />
is constructed of (x > max) and (max := x), therefore, ( if (> x max) (:= max x) )</li>
</ul>
<h4>Controllability and Observability</h4>
<p>These are central concepts from control theory. We will define them as :</p>
<ul>
<li>Controllability: the ability to chance the behavior of a system by changing its parameters.</li>
<li>Observability: the ability to observe the behavior of a system well enough to control it.</li>
</ul>
<p>In order to control a system, both controllability and observability are required.</p>
<h6>The implications For Large Software Systems</h6>
<ul>
<li>Aspects of software that cannot easily be observed will never be debugged</li>
<li>All Large Software Systems must have observability built in</li>
<li>Observability is a requirement, not a luxury. The time spent building in observability will be well repaid.</li>
<li>In-process traces can be turned on by setting bits in a bit vector.</li>
</ul>
<h4>Comparison of Parsing Techniques</h4>
<h5>Recursive Descent and Operator Precedence</h5>
<h6>Advantages:</h6>
<ul>
<li>easy to control, understand</li>
<li>Good error messages can be produced</li>
</ul>
<h6>Disadvantages:</h6>
<ul>
<li>More code to write</li>
<li>Grammar not as clear</li>
</ul>
<h5>Parser Generator (yacc)</h5>
<h6>Advantages</h6>
<ul>
<li>Less code to write</li>
<li>Grammar is clear and easy to change</li>
</ul>
<h6>Disadvantages:</h6>
<ul>
<li>The programmer may get stuck on grammar errors that are hard to understand</li>
<li>Error messages during compilation may be unhelpful and far from the actual error</li>
</ul>
<h4>Lexical Scoping</h4>
<p>Scope is the region of program text over which a symbol can be referenced.</p>
<p>With lexical scoping, a name is defined when it can be looked up in the lexicon at the point of use.</p>
<h4>Structure References</h4>
<ul>
<li>Every expression has type</li>
<li>Types from a tree structure (a graph when pointers to types are included, but still treated as a tree)</li>
<li>The structure references in source code specify a traversal down the type tree</li>
<li>A reference to a part of a structure depends on the type of the structure; the results of the reference are:<ul>
<li>An address expression for the substructure</li>
<li>A new type for the substructure</li>
</ul>
</li>
</ul>
<h4>Citation:</h4>
<ul>
<li>Aho, Lam, Sethi, & Ullman, Compilers: Principles, Techniques, and Tools</li>
<li>UT Austin CS375: Compilers by G.Novak. </li>
</ul>Address Calculationshttps://sungpi.postach.io/post/address-calculations2015-03-12T14:17:50.421000Z2015-03-12T12:32:39ZSungwon Chung@sungpi<h4>For Array References (Know the Fomulars)</h4>
<p>A simple array declaration has a form such as:<br />
* array[ $low_1$ .. $high_1$] of type</p>
<ul>
<li>Find the symbol table entry for type</li>
<li>Make a symbol table entry for the array type. The total size of the array is: ($high_1$ - $low_1$ + 1) * size(type)</li>
</ul>
<h4>Address Calculations for Access to Fields of a Record</h4>
<h4>Determining Types of Accesses To Parts of a Structure</h4>
<h4>Be Able to Calculate the Size of An Array Records</h4>
<h4>Be Able to Calculate the Address Offsets For Access to an Array Element and Record Field</h4>
<h4>Citation:</h4>
<ul>
<li>Aho, Lam, Sethi, & Ullman, Compilers: Principles, Techniques, and Tools</li>
<li>UT Austin CS375: Compilers by G.Novak. </li>
</ul>Data Area and Base-Offset Addressinghttps://sungpi.postach.io/post/data-area-and-base-offset-addressing2015-03-12T14:16:38.987000Z2015-03-12T12:31:42ZSungwon Chung@sungpi<h4>Storage Allocation Algorithm</h4>
<p>Data area is contiguous region of storage specified by its <strong>base address</strong> and <strong>size</strong>.<br />
Two kinds of data are are arrays and records. </p>
<h4>Allocation of Data in Records</h4>
<p>Allocation of storage is done as an offset to a base address, which is associated with a block of storage. Assignment of storage locations is done sequentially by a simple algorithm:</p>
<ul>
<li>next = 0</li>
</ul>
<pre><code>offset = next;
next = next + n;
return offset;
</code></pre>
<ul>
<li>Finally, next gives the total size of the block.</li>
</ul>
<h4>Word Alignment and Padding</h4>
<p><strong>storage alignment</strong>: Certain items must be allocated at restricted locations.<br />
In such cases, next is advanced to next available boundary if needed, and the intervening(사이에 오는) storage is wasted; this is called <strong>padding</strong></p>
<pre><code>wordaddress(next, m) = ( (next + m - 1) / m) *m
</code></pre>
<h4>Variant Records</h4>
<p>A record declaration has a form such as : <strong> record $field_1$, …, $field_n$ : $type_1$ ; .. end </strong>*<br />
Such a declaration is processed as follows :</p>
<ul>
<li>Initialize <strong>offset</strong> within the record to be 0.</li>
<li>For each entry group, <ul>
<li>find the symbol table entry for the type</li>
<li>allocate storage within the record using the storage allocation algorithm and size of type</li>
<li>make a symbol table entry for each field, filling in its print name, type, offset in the record, and size.</li>
<li>link the entries for the field to an entry for the record</li>
</ul>
</li>
<li>The size of the record is the total size given by the storage allocation algorithm, rounded up to whole words.</li>
<li>Variant records simply restart the storage allocation at the place where the variant part begins. Total size is the maximum size of the variants.</li>
</ul>
<h4>Citation:</h4>
<ul>
<li>Aho, Lam, Sethi, & Ullman, Compilers: Principles, Techniques, and Tools</li>
<li>UT Austin CS375: Compilers by G.Novak. </li>
</ul>Symbol Tableshttps://sungpi.postach.io/post/symbol-tables2015-03-12T13:45:43.408000Z2015-03-12T12:28:26ZSungwon Chung@sungpi<h4>Definition</h4>
<p>Symbol table is a data structure that associates names with information about the objects that are denoted by the names.<br />
<strong>Must be well organized</strong>: </p>
<ul>
<li>For fast lookup of symbols</li>
<li>To reflect the organization of the program (block structure)<br />
쉽게 생각하면, Lexicon = dictionary = symbol table.</li>
</ul>
<p>Operations : insert / search / search-insert</p>
<h4>Method of Organization</h4>
<ul>
<li>Think of key-value dictionary.</li>
<li>Linear, unsorted: Symbols are stored in an array; new symbols are inserted at the end.</li>
<li>Linear, sorted: Symbols are stored in an array that is sorted.</li>
<li>Hash table: typical hash table :: do you remember collision and rehash?</li>
<li>Indexed Buckets: hashed with buckets / alphabetized buckets</li>
<li>Tree of symbol table</li>
<li>Stack symbol table<br />
Tree and stack formats both have concepts of scoping: inheritance.</li>
</ul>
<h6>Speed</h6>
<ul>
<li>Linear, unsorted: Insert O(1) Search O(n)</li>
<li>Linear, sorted: Insert: O(n) Search(log n) <em>binary search</em></li>
<li>Hash table: Insert: O(1) Search(1)</li>
</ul>
<h6>Advantages</h6>
<ul>
<li>Binary tree symbol tables have log n search time, so build AVL trees.</li>
<li>Hash tables are super fast, don’t have to sort!</li>
</ul>
<h6>Disadvantages</h6>
<ul>
<li>AVL tree is bit complicated.</li>
<li>Hash Table is more complex, and hard to find hashing function, also complexity of rehashing.</li>
</ul>
<h6>Comparison</h6>
<h4>Be Able to select a method for a particular application.</h4>
<h4>Search is More Frequent than Insertion</h4>
<h4>Symbol Tables for Block-Structured Languages</h4>
<p>Tree, Stack structure</p>
<h4>What Things Are Put in Symbol Tables?</h4>
<p>Symbols: statement labels, variables, constants, subprogram names</p>
<ul>
<li>Symbolic constants</li>
<li>Enumerated types</li>
<li>Subrange types</li>
<li>Scalar types</li>
<li>Variables</li>
<li>Arrays</li>
<li>Records</li>
<li>Functions and procedures</li>
<li>Labels</li>
<li>Objects </li>
</ul>
<h4>Examples of Symbols in a Compiler</h4>
<p>|variable|description|<br />
|:———:|:—————:|<br />
|link|link to next symbol|<br />
|name string|name of symbol|</p>
<h4>Deletion of Symbols</h4>
<h5>When it is needed</h5>
<h5>Relation to Table Organization Methods</h5>
<h4>Methods of Strong Identifier Names</h4>
<h4>User of Indirection or Auxiliary Table Structures</h4>
<h4>Citation:</h4>
<ul>
<li>Aho, Lam, Sethi, & Ullman, Compilers: Principles, Techniques, and Tools</li>
<li>UT Austin CS375: Compilers by G.Novak. </li>
</ul>Shift-Reduce Parserhttps://sungpi.postach.io/post/shift-reduce-parser2015-03-12T12:45:20.051000Z2015-03-12T09:27:05ZSungwon Chung@sungpi<h4>Use of Stack</h4>
<p>Use stack to save statements</p>
<h4>Four Actions of Shift-Reduce Parser</h4>
<ul>
<li>Shift : Shift the current input onto the stack and go to the specified next state <strong>s</strong>.</li>
<li>Reduce : Given the production <strong>r</strong> : A -> b, remove enough items from the stack to match b, produce output structure from those items, and put the resulting structure A back on the stack. The next state is found from the goto table.</li>
<li>Accept : Parsing is completed! return top of stack as result.</li>
<li>Error : The input cannot be parsed according to the grammar; call an error recovery routine. Error entries are denoted by blanks in the parsing table.</li>
</ul>
<h4>Relationship to Canonical Derivation</h4>
<p>x</p>
<h4>How Parse Tree is Constructed Using Shift-Reduce Parser</h4>
<h4>Conflicts</h4>
<ul>
<li>Reduce/reduce: resolved by choosing the first listed production</li>
<li>Shift/reduce: resolved in favor of shift<br />
Reduce if the precedence of the production is greater than that of the terminal or if they are equal and the associativity of the production is left.</li>
<li>reduce의 결과가 터미널의 결과보다 우선순위가 높을 때.</li>
<li>만약 그 결과들이 같으면 associativity는 왼 쪽.<br />
Shift otherwise.</li>
</ul>
<h4>Citation:</h4>
<ul>
<li>Aho, Lam, Sethi, & Ullman, Compilers: Principles, Techniques, and Tools</li>
<li>UT Austin CS375: Compilers by G.Novak. </li>
</ul>Top-down Parsinghttps://sungpi.postach.io/post/top-down-parsing2015-03-12T12:53:43.181000Z2015-03-12T09:25:27ZSungwon Chung@sungpi<h4>Definition</h4>
<p>Parser begins with the Sentence symbol <strong>S</strong>, expands a production for <strong>S</strong>, and so on recursively until words are reached. (Terminals) If the string of words matches the input, a parsing has been found.</p>
<h4>Why Backup May Be Required</h4>
<p>This approach to parsing might seem hopelessly inefficient. However, top-down filtering, that is testing whether the next word in the input string could begin the phrase about to be tried, can prune many failing paths early.</p>
<h4>For What Kinds of Languages Does It Work Well</h4>
<p>Languages with keywords, such as programming languages or natural language application. Easy to program.</p>
<h4>Recursive Descent Parser</h4>
<p>A parse for some context-free languages can be written using the technique of recursive descent. The basic idea is to write a procedure to parse each kind of statement or expression in the grammar. When such procedures are written in a recursive language, they can call each other as needed.<br />
It works well for a well-structured language such as Pascal. In Pascal each statement other than assignment statements begin with a unique reserved word; thus, it is easy for a “big switch" program to determine which statement parser to call.</p>
<h4>Problems with Left Recursion</h4>
<p>It may be necessary to restructure a grammar to avoid left recursion, which can cause a recursive descent parser to go into a loop.</p>
<h4>Left Factoring</h4>
<p>A method of modifying a grammar to eliminate left recursion</p>
<h4>Implementation of Top-down Parser by A Recursive Program</h4>
<p>be able to write a procedure for a construct such as an IF statement</p>
<h5>Avoiding Ambiguity while keeping the syntax</h5>
<p>Pascal and C follows this convention.</p>
<ul>
<li>If parser is SLR, LR(1), or LALR LR parser generator, the programmer will often rely on the generated parser feature of preferring shift over reduce whenever there is a conflict.</li>
<li>If the parser is produced by a pruning and deep pruning LR generator, one can issue directives that prune away the ambiguities completely.</li>
<li>If the parser is hand-written, the programmer may use a non-ambiguous context-free grammar. Alternatively, one may rely on a non-context-free grammar or a parsing expression grammar.</li>
</ul>
<h5>Avoiding Ambiguity By Changing the Syntax</h5>
<ul>
<li>Have a “end if" statement.</li>
<li>Disallow following then to be if.</li>
<li>Require a bracelet when else follows if </li>
<li>Require every if to be paired with an else</li>
</ul>
<h4>Citation:</h4>
<ul>
<li>Aho, Lam, Sethi, & Ullman, Compilers: Principles, Techniques, and Tools</li>
<li>UT Austin CS375: Compilers by G.Novak. </li>
</ul>Operator Precedence Grammar and Parserhttps://sungpi.postach.io/post/operator-precedence-grammar-and-parser2015-03-12T10:49:07.957000Z2015-03-12T09:24:23ZSungwon Chung@sungpi<h4>Definitions</h4>
<p>Expressions could be written in an unambiguous, fully parenthesized form. However, this is less convenient for the programmer.</p>
<h6>Precedence numbers</h6>
<p>Precedence specifies which operations in a flat expression are to be performed first.<br />
Usually, </p>
<ul>
<li>.</li>
<li>^</li>
<li>unary -</li>
<li>* /</li>
<li>
<ul>
<li>-</li>
</ul>
</li>
<li>= <> >= > <= <</li>
<li>not</li>
<li>and</li>
<li>or </li>
<li>:=</li>
</ul>
<h6>Associativity</h6>
<p>Associativity specifies which operations are to be performed first when adjacent operators have the same precedence.</p>
<h4>How operator precedence parser works(give example)</h4>
<p>Shift & Reduce</p>
<ul>
<li>Operands </li>
<li>Operator</li>
<li>(</li>
<li>)</li>
<li>End</li>
</ul>
<h4>Citation:</h4>
<ul>
<li>Aho, Lam, Sethi, & Ullman, Compilers: Principles, Techniques, and Tools</li>
<li>UT Austin CS375: Compilers by G.Novak. </li>
</ul>Derivation From a Context-Free Grammarhttps://sungpi.postach.io/post/derivation-from-a-context-free-grammar2015-03-12T10:41:05.848000Z2015-03-12T09:21:05ZSungwon Chung@sungpi<p>Derivation is the process of deriving a sentence from the start symbol S according to a grammar.</p>
<h4>Relationship to Parse Tree</h4>
<h4>Notations for a Derivation</h4>
<p>Symbol => is used to denote a derivation step.<br />
=>* is used to denote derivation in zero or more steps.<br />
=>+ is used to denote derivation in one or more steps.</p>
<h4>Definition of a language in Terms of Derivations</h4>
<p>Leftmost derivation : the leftmost nonterminal is replaced in each step. If S=>*(lm) a then a is called a left-sentential form of the grammar G. A leftmost derivation is traced by a predictive, top-down parser.<br />
Rightmost derivation <strong>canonical derivation</strong> : the right most nonterminal is replaced in each step. A shift-reduce parser traces a rightmost derivation “backwards"</p>
<h4>Citation:</h4>
<ul>
<li>Aho, Lam, Sethi, & Ullman, Compilers: Principles, Techniques, and Tools</li>
<li>UT Austin CS375: Compilers by G.Novak. </li>
</ul>Context-free Languageshttps://sungpi.postach.io/post/context-free-languages2015-03-12T10:21:00.485000Z2015-03-12T09:11:44ZSungwon Chung@sungpi<h4>Grammar Definition</h4>
<p>A - a<br />
A $\in$ N<br />
a $\in$ V*</p>
<p>Since left-hand-side of each production is a single nonterminal, every derivation is a tree.</p>
<h4>Memory Needed for Parsing.</h4>
<p>Recursive program = a stack for temporary storage</p>
<h4>Notations for defining the syntax of a language :</h4>
<h6>BNF</h6>
<h6>Pascal-style transition diagrams.</h6>
<h4>Ambiguous grammars VS unambiguous grammars</h4>
<p><em>Ambiguous</em> : grammar for which some sentence has more than one parse tree is ambiguous. There’s two way to deal with this. <em>Re-write the grammar</em> and <em>User disambiguating rules to guide the parser</em>.</p>
<h4>Augmented transition network;Yacc</h4>
<ul>
<li>Arbitrary tests : can be added to the arcs. </li>
<li>Structure-building actions : can be added to the arcs. These actions may save information in registers to be used later by the parser, or to build the representation of the meaning of the sentence. Transformations, can also be handled.</li>
<li>Phrase names : as well as part-of-speech names, may appear on arcs. This allows a grammar to be called as a subroutine.</li>
</ul>
<h4>What kinds of language constructs are context-free?</h4>
<p>Arithmetic expressions, noun pharses.<br />
Any language that requires counting must be at least context free.</p>
<h4>Citation:</h4>
<ul>
<li>Aho, Lam, Sethi, & Ullman, Compilers: Principles, Techniques, and Tools</li>
<li>UT Austin CS375: Compilers by G.Novak. </li>
</ul>Floating Pointhttps://sungpi.postach.io/post/floating-point2015-03-12T09:02:19.268000Z2015-03-12T08:19:49ZSungwon Chung@sungpi<p>[http://steve.hollasch.net/cgindex/coding/ieeefloat.html]</p>Lexical Analyzerhttps://sungpi.postach.io/post/lexical-analyzer2015-03-12T09:11:25.653000Z2015-03-12T08:10:37ZSungwon Chung@sungpi<h4>What constructs are parsed</h4>
<h4>Type of grammar used</h4>
<p>Use regular expressions.</p>
<h4>Need for speed?</h4>
<p>NFA to DFA, and converted to tables to control a table-driven parser.</p>
<h4>lex</h4>
<h4>Citation:</h4>
<ul>
<li>Aho, Lam, Sethi, & Ullman, Compilers: Principles, Techniques, and Tools</li>
<li>UT Austin CS375: Compilers by G.Novak. </li>
</ul>Regular Expressionhttps://sungpi.postach.io/post/regular-expression2015-03-12T09:10:01.147000Z2015-03-12T08:08:24ZSungwon Chung@sungpi<h4>Definition</h4>
<p>Regular expresssions are a more convenient way(than a regular grammar) to specify a regular language. </p>
<h4>Construct a Regular Expression for a Language</h4>
<p>in <strong>lex</strong> rule.<br />
<em> [chars] : Any number of the set of characters chars<br />
</em> [c1-c2] : Any character from c1 through c2<br />
<em> [^chars] : not chars<br />
</em> {category} : An instance of a previously named category<br />
<em> “string" : Exactly the specified string.<br />
</em> s1 | s2 : s1 or s2<br />
<em> a</em> : zero or more a<br />
<em> a+ : one or more a<br />
</em> a? : zero or one a<br />
* a{2,5} : 2 to 5 a</p>
<h4>Construct the Language Denoted by a Regular Expression</h4>
<p>Follow the rule.</p>
<h4>Relation Between Regular Expression and Finite Automata</h4>
<p>Always can change into DFA.</p>
<h4>Automatic Construction of Finite Automata from Regular Expressions</h4>
<h4>Citation:</h4>
<ul>
<li>Aho, Lam, Sethi, & Ullman, Compilers: Principles, Techniques, and Tools</li>
<li>UT Austin CS375: Compilers by G.Novak. </li>
</ul>Regular Languages 정규 언어https://sungpi.postach.io/post/regular-languages2015-03-12T15:58:51.859000Z2015-03-12T07:57:19ZSungwon Chung@sungpi<h2>Grammar?</h2>
<h4>Formal Definition of a Grammar</h4>
<p>Grammar specifies the legal syntax of a language. A grammar specifies a set of productions; non-terminal symbols. A grammar describes the structure of the sentences of a language in terms of components or phrases. The mathematical description of phrase structure grammars is due to Chomsky.<br />
문법은 언어의 syntax(the rules by which legitimate statements can be constructed)를 나타내는 규칙이다. 문법은 production으로 이루어져 있다.</p>
<p>Formally, a <strong>Grammar</strong> is a four-tuple G = (T, N, S, P) where:</p>
<ul>
<li><strong>T</strong> is the set of terminal symbols or words of the language.</li>
<li><strong>N</strong> is the set of nonterminal symbols or phrase names that are used in specifying the grammar. We say V = T $\cup$ N is the vocabulary of the grammar.</li>
<li><strong>S</strong> is a distinguished element of N called the start symbol.</li>
<li><strong>P</strong> is a set of productions, P $\subseteq V^<em>NV^</em> \texttimes V^*$. We write productions in the form a $\textrightarrow$ b where a is a string of symbols from V containing at lest one nonterminal and b is any string of symbols from V.</li>
<li>V = Vocabulrary<br />
문법은 언어의 구조가 올바른지를 판단하는 거다.</li>
</ul>
<h4>Chart about Grammar Classes.</h4>
<ul>
<li>General Phrase-structure</li>
<li>Context Sensitive</li>
<li>Context Free <strong>pushdown stack</strong> O($n^3$)</li>
<li>Regular <strong>finite storage</strong> O(n)<br />
We’ll focus on Context-Free and Regular Language. </li>
</ul>
<h2>Regular Languages</h2>
<h4>Grammar definitions</h4>
<p>A - xB.<br />
A - x.<br />
A, B $\in$ N<br />
x $\in T^*$<br />
Only one nonterminal can appear in any derived string, and it must appear at the rightmost.</p>
<h4>Uses</h4>
<p>In compilers, we use to parse the stream of characters into tokens. Cause parser never has to back up or do search. O(n); Linear parsing time. <strong>Indentifiers, numbers, word forms</strong>.</p>
<h4>Local Ambiguity</h4>
<h5>Examples</h5>
<p>A - xB<br />
B - x</p>
<h5>Way to Handle</h5>
<p>Make test cases to pre-process it.</p>
<h4>Relationship of finite automata and regular grammars</h4>
<p>Equivalent to a deterministic finite automaton</p>
<h4>Linear nature of a derivation from a regular grammar</h4>
<p>Since only one nonterminal can appear in any derived string, and the rightmost end, parse tree has only one step to evaluate it, produces right-biased tree.</p>
<h4>Citation:</h4>
<ul>
<li>Aho, Lam, Sethi, & Ullman, Compilers: Principles, Techniques, and Tools</li>
<li>UT Austin CS375: Compilers by G.Novak. </li>
</ul>Major Phases of a Compiler 컴파일러의 주요 단계들https://sungpi.postach.io/post/major-phases-of-a-compiler2015-03-12T08:19:05.234000Z2015-03-12T07:50:54ZSungwon Chung@sungpi<h4>What the phases do 각 단계는 무엇을 하나?</h4>
<h5>Lexical Analyzer</h5>
<p>or <strong>scanning</strong><br />
Reads the stream of characters and group the characters into meaningful sequences called <strong>lexemes</strong>.<br />
글자들을 읽어서 글자들에 의미를 부여하는 단계; 문장에서 단어를 잘라준다고 생각하면 편하다.<br />
<strong>ex</strong> a = 1 + 2 는 a,=,1,+,2 5개의 token이 된다.</p>
<h5>Syntax Analyzer</h5>
<p>or <strong>parsing</strong> <br />
The parser uses the first components of the tokens produced by the lexical analyzer to produce a tree-like intermediate representation that describes the grammatical structure of the token stream.<br />
Parser는 lexer가 만들어준 토큰을 가지고, 문장에 의미를 부여하기 시작한다. (컴퓨터 과학에서는 tree로 token을 엮어낸다.) </p>
<h5>Semantic Analyzer</h5>
<p>Semantic analyzer uses the syntax tree and the information in the symbol table to check the source program for semantic consistency with the language definition.<br />
Parser가 만들어준 트리로, 이 것이 과연 문법적으로 맞는 놈인지 문법을 검사한다.</p>
<h5>Intermediate Code Generator</h5>
<h5>Machine-independent Code optimizer</h5>
<h5>Code Generator</h5>
<h5>Machine-dependent Code Optimizer</h5>
<h4>Data flow between phases 각 단계별 데이터의 흐름</h4>
<ul>
<li>Character Stream : Before lexical analysis ; lexer는 character들을 받아서</li>
<li>Token : Before syntax analysis ; token을 생성하고</li>
<li>Syntax Tree : before intermediate code generation ; parser는 syntax tree를 만들며</li>
<li>Intermediate representation : before code generation ; 코드 제네레이터는 중간 코드를 생성하고</li>
<li>Target Machine Code : after code generation ; 코드 제네레이터는 컴퓨터가 읽을수 있는 형태로 뽑아준다.</li>
</ul>
<h4>Citation:</h4>
<ul>
<li>Aho, Lam, Sethi, & Ullman, Compilers: Principles, Techniques, and Tools</li>
<li>UT Austin CS375: Compilers by G.Novak. </li>
</ul>Lexical Analysishttps://sungpi.postach.io/post/untitled2015-03-09T07:54:40.109000Z2015-03-09T07:27:50.725000ZSungwon Chung@sungpi<h5>Lexical Analysis</h5>
<h5>3.1 The Role of the Lexical Analyzer</h5>
<ol>
<li>
<p>To read the input characters of the source program</p>
</li>
<li>
<p>Group them into lexemes</p>
</li>
<li>
<p>Produce as output a sequence of tokens for each lexeme in the source program</p>
</li>
</ol>
<p><em>Scanning</em> and <em>Lexical analysis</em></p>
<h5>3.1.1 Lexical Analysis Versus Parsing</h5>
<p>Why do we separate lexer and parser?</p>
<ol>
<li>
<p>Simplicity of design is the most important consideration</p>
</li>
<li>
<p>Compiler efficiency is improved</p>
</li>
<li>
<p>Compiler portability is enhanced<br />
(only lexer has to deal with device-input)</p>
</li>
</ol>
<h5>3.1.2 Tokens, Patterns, and Lexemes</h5>
<p><em>ex</em> printf(“Hello World!");</p>
<p><em>printf</em> and <em>score</em> are <strong>lexemes</strong> matching the <strong>pattern</strong> for <strong>token</strong> <strong>id</strong>.</p>미국의 해커톤https://sungpi.postach.io/post/migugyi-haekeoton2015-03-12T12:12:48.482000Z2015-03-06T08:08:35ZSungwon Chung@sungpi<h5>MLB ( Major League Hacking) 에 속해있는 HackDFW를 다녀와서.</h5>
<ol>
<li>수상한 팀들은 거의 모두가 기계 장비와 관련 있었다.</li>
<li>자기 아이디어를 설명하는게 더 중요한 것 같다.</li>
<li>똑똑한 친구들 정말 많다.</li>
</ol>DB Scheme for Who’s Hungry?https://sungpi.postach.io/post/db-scheme2015-03-15T05:26:13.360000Z2015-02-26T07:30:04ZSungwon Chung@sungpi<p>There’s two strong entity, <strong>User, Restaurant</strong>.<br />
Any other tables are weak entities.</p>
<h5>Abstract</h5>
<p><strong>User</strong> table hold data of user, including it’s Facebook id, name, profile picture, contact number. <strong>Device</strong> table belongs to <strong>User</strong> table, and saves User’s device data in case user has many devices, mainly exists for push notification. <strong>Session</strong> table exists for security issue, belongs to <strong>User</strong> table. <strong>Location</strong> table exists for saving user’s location, reason this table is separated is, for encrypting issue. <strong>Group</strong> table exists to re-use the group that people made. <strong>Crew</strong> table exists holding data between <strong>User</strong> and <strong>Group</strong>, for N to N relationship. <strong>Vote</strong> table is for every single information of votes besides information of restaurant. <strong>Choice</strong> table holds data between <strong>Restaurant</strong> and <strong>Vote</strong> table, for counting issue. (to be updated)</p>
<p>User<br />
Device<br />
Restaurant<br />
Group <br />
Vote<br />
Location<br />
Auth<br />
Subscription<br />
Crew<br />
Rsvp<br />
Chat<br />
Choice<br />
Rating</p>
<h4>User</h4>
<ul>
<li>id : <strong>PK</strong></li>
<li>fb_id : <strong>string</strong> <em>indexed</em><em> </em>Facebook_id* </li>
<li>name : <strong>string</strong> <em>Name of the user</em></li>
<li>picture : <strong>string</strong> <em>URL of the user’s profile picture</em></li>
<li>contact : <strong>string</strong> <strong>indexed</strong> <em>Phone number of the user</em>* </li>
<li>created_at : <strong>datetime</strong></li>
<li>updated_at : <strong>datetime</strong></li>
</ul>
<h4>Device</h4>
<p>Belongs to User</p>
<ul>
<li>id : <strong>PK</strong> <em>id of device in our server</em></li>
<li>os_type : <strong>string</strong> <em>{ios, android, web} default : web</em></li>
<li>push_id : <strong>string</strong> <em>push_id</em></li>
<li>(user_id)</li>
<li>created_at</li>
<li>updated_at</li>
</ul>
<h4>Restaurant</h4>
<ul>
<li>id : <strong>PK</strong> <em>id of restaurant in our server, not Google Place API</em></li>
<li>place_id : <strong>string</strong> <strong>indexed</strong> <em>id of restaurant in Google Place API</em></li>
<li>lat : <strong>float</strong> <em>Latitude of the restaurant location</em></li>
<li>lng : <strong>float</strong> <em>Longitude of the restaurant location</em></li>
<li>name : <strong>string</strong> <em>Name of the restaurant</em></li>
<li>rating : <strong>float</strong> <em>Rating of the restaurant</em></li>
<li>created_at </li>
<li>updated_at</li>
</ul>
<h4>Group</h4>
<ul>
<li>id : <strong>PK</strong> </li>
<li>lead_user_id : <strong>user_id</strong> <em>Leader of the group</em></li>
<li>name : <strong>string</strong> NULL</li>
<li>created_at</li>
<li>updated_at</li>
</ul>
<h4>Vote</h4>
<ul>
<li>id : <strong>PK</strong></li>
<li>(group_id) :</li>
<li>type : <strong>string</strong> <em>{lunch, dinner, cafe, bar}</em></li>
<li>name : <strong>string</strong> <em>Name of the vote</em></li>
<li>expires_in : <strong>integer</strong> <em>Expires in # minute</em></li>
<li>winner: <strong>restaurant_id</strong> <em>FK to restaurant(id)</em></li>
<li>expires_at : <strong>datetime</strong></li>
<li>created_at</li>
<li>updated_at</li>
</ul>
<h4>Location</h4>
<ul>
<li>id : <strong>PK</strong></li>
<li>(user_id)</li>
<li>lat : <strong>float</strong></li>
<li>lng : <strong>float</strong></li>
</ul>
<h4>Auth</h4>
<p>Belongs to <strong>User</strong></p>
<ul>
<li>user_id</li>
<li>login_type</li>
<li>token </li>
<li>created_at</li>
<li>updated_at</li>
</ul>
<h4>Subscription (User-User)</h4>
<p>Use to look up mutual friends, invitation, etc..<br />
Recursive relations between <strong>User</strong></p>
<ul>
<li>id : <strong>PK</strong></li>
<li>friend_from : <strong>user_id</strong> <strong>indexed</strong></li>
<li>friend_to : <strong>user_id</strong></li>
</ul>
<h4>Crew (User- Group)</h4>
<p>Belongs to <strong>User</strong> and <strong>Group</strong></p>
<ul>
<li>id</li>
<li>user_id</li>
<li>group_id</li>
</ul>
<h4>Rsvp (User-Vote)</h4>
<p>Belongs to <strong>User</strong> and <strong>Vote</strong></p>
<ul>
<li>id</li>
<li>user_id</li>
<li>vote_id</li>
<li>rsvp : <strong>integer</strong> {1: going, -1: not going, 0: Dunno}</li>
</ul>
<h4>Chat (User-Vote)</h4>
<p>Belongs to <strong>User</strong> and <strong>Vote</strong></p>
<p><em>user_id<br />
</em>vote_id<br />
<em>chat : <strong>text</strong><br />
</em>created_at<br />
*updated_at</p>
<h4>Choice (Vote-Restaurant)</h4>
<p>Belongs to <strong>User</strong> and <strong>Restaurant</strong></p>
<ul>
<li>restaurant_id</li>
<li>user_id</li>
<li>count</li>
</ul>
<h4>Rating (User-Restaurant)</h4>
<p>Belongs to <strong>User</strong> and <strong>Restaurant</strong></p>
<ul>
<li>restaurant_id</li>
<li>user_id</li>
<li>rating</li>
</ul>Development Environment for Who’s Hungry?https://sungpi.postach.io/post/development-environment-for-whos-hungry2015-03-12T12:12:48.261000Z2015-02-26T06:21:15ZSungwon Chung@sungpi<h4>1. Setting up Ruby</h4>
<p>visit</p>
<p>http://rvm.io</p>
<p>and install RVM through curl.<br />
‘’'bash</p>
<p>$ \curl -sSL https://get.rvm.io | bash -s stable</p>
<p>‘''<br />
Then, you enable bash_profile for later install.</p>
<p>$ source .bash_profile</p>
<p>We’re currently using Ruby 2.2.0 version, therefore</p>
<p>$ rvm install 2.2.0</p>
<h4>2. Setting up Rails</h4>
<p>Install rails 4.2.0 , with command (with out documentations, and two “-“s in front of no)<br />
‘’’bash<br />
gem install rails —no-ri —nordoc<br />
‘''</p>
<h4>3. Install PostgreSQL</h4>
<p>brew install postgresql</p>
<h5>To have launchd start postgresql at login:</h5>
<p>ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents</p>
<h5>Then to load postgresql now:</h5>
<p>launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist</p>
<h5>Or, if you don't want/need launchctl, you can just run:</h5>
<p>postgres -D /usr/local/var/postgres</p>What is Load Balancerhttps://sungpi.postach.io/post/test2015-03-12T12:12:48.026000Z2015-02-17T05:40:25ZSungwon Chung@sungpi<p>This article is for deciding server stacks, for Who's Hungry?, and to help other startup backend developers if possible.</p>
<h1>Cipher Block Chaining Mode</h1>
<h1>CBC</h1>
<p>To encrypt using this mode, a uniform initialization vector (IV) of length $n$ is first chosen. Then, cipher text blocks are generated by applying the block cipher to XOR of the current plaintext block and the previous ciphertext block. That is, set $c_0$ := IV and then for i = 1 to $l$, set $c_i$ := $F_k$ ($c_{i-1} \xor m_i$). The final</p>