728x90
반응형

CS/Programming Language 13

모호성

아래 세 개는 모두 같은 문법 각 규칙을 기반으로 a-b-c를 파싱하면 다음과 같다. G1의 경우 a-b부터 시작할지 b-c부터 시작할지 모호해진다 그러므로 파싱 트리는 중요하다 semantic(의미)를 결정하니까 Operator operand 개수에 따라 - unary : -1 - binary : 1+2 - ternary : a?b:c 위치에 따라 - infix : a+b - prefix : +ab - postfix : ab+ operator마다 parentheses를 기반으로 precedence level이 언어를 결정할 수 있지만 그래도 *이 +보다 먼저 계산되야하니까 규칙을 한 단계 내리면서 정할 수 있다 Associativity - Left associative: left to right - (..

Programming Syntax 2

프로그래밍을 명시할 때는 specification과 implementation을 담아내야 한다. specification에는 defenition, syntax, semantics를 명시해야 한다 implementation은 실행 방법에 대한 가이드라인(자바는 컴파일이 아닌 VM 기반에서)을 명시한다 syntax(formal grammer) : 프로그램의 구조와 형태 - token, expression, statement, Digit ... 문법의 작동방식 parse tree를 설계하여 문법의 규칙을 정한다 : 명사, : 동사, :sentence => -> Context Free Grammer (CFG) 문맥자유문법 왼쪽에 심볼 하나, 오른쪽에 심볼 하나 이상 terminal symbol = token, ..

Programming Syntax

Language Paradigm 다른 종류 : – Applicative, concurrent, constraint, declarative, definitional, procedural, scripting, single-assignment, … Imperative : 명령형 Assignment, Iteration, Order of execution is critical 프로그래밍의 상태와 이를 변경시키는 구문의 관점에서 연산을 설명 전역적인 상태가 없음. 그저 어떻게 계산되는지를 쭉 적어둠 C언어 int fact ( int n ) { int sofar = 1; while ( n > 0 ) sofar *= n-- ? return &ofar; } # Forth Factorial : stack-oriented ..

728x90
반응형