Triangle Manipulation Language TrML Language Reference Manual

Similar documents
Typescript on LLVM Language Reference Manual

CLIP - A Crytographic Language with Irritating Parentheses

TML Language Reference Manual

JME Language Reference Manual

The SPL Programming Language Reference Manual

VENTURE. Section 1. Lexical Elements. 1.1 Identifiers. 1.2 Keywords. 1.3 Literals

Language Reference Manual

Spoke. Language Reference Manual* CS4118 PROGRAMMING LANGUAGES AND TRANSLATORS. William Yang Wang, Chia-che Tsai, Zhou Yu, Xin Chen 2010/11/03

DaMPL. Language Reference Manual. Henrique Grando

Contents. Jairo Pava COMS W4115 June 28, 2013 LEARN: Language Reference Manual

c) Comments do not cause any machine language object code to be generated. d) Lengthy comments can cause poor execution-time performance.

DINO. Language Reference Manual. Author: Manu Jain

Language Reference Manual

Sketchpad Graphics Language Reference Manual. Zhongyu Wang, zw2259 Yichen Liu, yl2904 Yan Peng, yp2321

MATVEC: MATRIX-VECTOR COMPUTATION LANGUAGE REFERENCE MANUAL. John C. Murphy jcm2105 Programming Languages and Translators Professor Stephen Edwards

Full file at C How to Program, 6/e Multiple Choice Test Bank

GeoCode Language Reference Manual

flex is not a bad tool to use for doing modest text transformations and for programs that collect statistics on input.

Learning Language. Reference Manual. George Liao (gkl2104) Joseanibal Colon Ramos (jc2373) Stephen Robinson (sar2120) Huabiao Xu(hx2104)

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression

The pixelman Language Reference Manual. Anthony Chan, Teresa Choe, Gabriel Kramer-Garcia, Brian Tsau

Sprite an animation manipulation language Language Reference Manual

ASML Language Reference Manual

The PCAT Programming Language Reference Manual

Decaf Language Reference Manual

Mirage. Language Reference Manual. Image drawn using Mirage 1.1. Columbia University COMS W4115 Programming Languages and Translators Fall 2006

Triangle Manipulation Language TrML

MR Language Reference Manual. Siyang Dai (sd2694) Jinxiong Tan (jt2649) Zhi Zhang (zz2219) Zeyang Yu (zy2156) Shuai Yuan (sy2420)

Standard 11. Lesson 9. Introduction to C++( Up to Operators) 2. List any two benefits of learning C++?(Any two points)

Scheme Quick Reference

Lecture 2 FORTRAN Basics. Lubna Ahmed

BASIC ELEMENTS OF A COMPUTER PROGRAM

Petros: A Multi-purpose Text File Manipulation Language

CS 4240: Compilers and Interpreters Project Phase 1: Scanner and Parser Due Date: October 4 th 2015 (11:59 pm) (via T-square)

Chapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines.

PLT 4115 LRM: JaTesté

B E C Y. Reference Manual

Java Notes. 10th ICSE. Saravanan Ganesh

Expr Language Reference

GAWK Language Reference Manual

Ordinary Differential Equation Solver Language (ODESL) Reference Manual

SFPL Reference Manual

GBIL: Generic Binary Instrumentation Language. Language Reference Manual. By: Andrew Calvano. COMS W4115 Fall 2015 CVN

A Pascal program. Input from the file is read to a buffer program buffer. program xyz(input, output) --- begin A := B + C * 2 end.

IPCoreL. Phillip Duane Douglas, Jr. 11/3/2010

YOLOP Language Reference Manual

easel LANGUAGE REFERENCE MANUAL

1 Lexical Considerations

Language Reference Manual

Lexical Considerations

Full file at

SMURF Language Reference Manual Serial MUsic Represented as Functions

IT 374 C# and Applications/ IT695 C# Data Structures

4. Inputting data or messages to a function is called passing data to the function.

Creating a C++ Program

Chapter 2. Lexical Elements & Operators

Lecture 05 I/O statements Printf, Scanf Simple statements, Compound statements

SMPL - A Simplified Modeling Language for Mathematical Programming

FRAC: Language Reference Manual

CHIL CSS HTML Integrated Language

12/22/11. Java How to Program, 9/e. Help you get started with Eclipse and NetBeans integrated development environments.

Twister: Language Reference Manual

Lexical Considerations

Scheme Quick Reference

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved.

SIPL: Simple Image Processing Language

egrapher Language Reference Manual

CPS 506 Comparative Programming Languages. Syntax Specification

Introduction to TURING

DEPARTMENT OF MATHS, MJ COLLEGE

2.2 Syntax Definition

9/5/2018. Overview. The C Programming Language. Transitioning to C from Python. Why C? Hello, world! Programming in C

RTL Reference 1. JVM. 2. Lexical Conventions

COMP519 Web Programming Lecture 11: JavaScript (Part 2) Handouts

Decaf Language Reference

FORTRAN Basis. PROGRAM LAYOUT PROGRAM program name IMPLICIT NONE [declaration statements] [executable statements] END PROGRAM [program name]

The C Programming Language. (with material from Dr. Bin Ren, William & Mary Computer Science)

Language Reference Manual simplicity

Perdix Language Reference Manual

Project 2 Interpreter for Snail. 2 The Snail Programming Language

BoredGames Language Reference Manual A Language for Board Games. Brandon Kessler (bpk2107) and Kristen Wise (kew2132)

ML 4 A Lexer for OCaml s Type System

CSC 467 Lecture 3: Regular Expressions

Defining Program Syntax. Chapter Two Modern Programming Languages, 2nd ed. 1

BC An Arbitrary Precision Desk-Calculator Language. Lorinda Cherry Robert Morris Bell Laboratories Murray Hill, New Jersey ABSTRACT

L-System Fractal Generator: Language Reference Manual

for (i=1; i<=100000; i++) { x = sqrt (y); // square root function cout << x+i << endl; }

Lexical Analysis. Lexical analysis is the first phase of compilation: The file is converted from ASCII to tokens. It must be fast!

Template Language and Syntax Reference

Language Basics. /* The NUMBER GAME - User tries to guess a number between 1 and 10 */ /* Generate a random number between 1 and 10 */

COMS W4115 Programming Languages & Translators GIRAPHE. Language Reference Manual

do fifty two: Language Reference Manual

Crayon (.cry) Language Reference Manual. Naman Agrawal (na2603) Vaidehi Dalmia (vd2302) Ganesh Ravichandran (gr2483) David Smart (ds3361)

Compiler Techniques MN1 The nano-c Language

Differentiate Between Keywords and Identifiers

Ruby: Introduction, Basics

ARG! Language Reference Manual

The Warhol Language Reference Manual

VLC : Language Reference Manual

1. Lexical Analysis Phase

Transcription:

Triangle Manipulation Language TrML Language Reference Manual FENG XUECHEN (XF2120) CHEN QISHU (QC2166) WAN YU (YW2506) QU LIANHAO (LQ2140) ZHANG WANQIU (WZ2241) Oct 28 2012 1

Table of Content 1 Introduction... 3 2 Lexical Conventions... 4 2.1 Comments... 4 2.2 Identifiers... 4 2.3 Keywords... 4 2.4 Constants... 4 2.4.1 Value... 4 2.4.2 Triangle... 5 2.4.3 Boolean... 5 2.4.4 Sh-cat... 5 2.4.5 String... 5 3 Types... 6 4 Operators... 6 5 Expression and Statement... 7 5.1 expression... 7 5.1.1 Arithmetic Expression... 7 5.1.2 Logical Expression... 7 5.1.3 General Expression... 7 5.2 Statements... 7 5.2.1 Statements and Statement... 7 5.2.2 Assignment Statement... 8 5.2.3 Conditional Statement... 8 5.2.3 While Statement... 8 5.2.4 Built-in-Function... 8 6 Building Blocks... 9 6.1 Initialization... 9 6.2 Rules... 9 6.3 Operations... 9 7 Sample Code... 10 2

1 Introduction Trigonometry induction problem can be as simple as nai ve substitution and subtraction, yet sometimes it could drive people crazy with its subtle logic and hidden clues. We believe most science students share the painful process of solving trigonometry induction problems in high math classes. TrML is a programming language that allows user express trigonometry concept, and construct/solve complex trigonometry puzzles. The language could be use for educational purpose for both geometric class and entry level programming class. This manual provides a comprehensive description of the TrML language. 3

2 Lexical Conventions TrML has six kinds of tokens: keywords, identifiers, constants, string literals, operators, and separators. Whitespace such as blanks, tabs, and newlines are ignored except when they serve to separate tokens. Comments are also ignored. 2.1 Comments The character @ introduces a comment, which terminate with the new-line character \n. Comments do not nest, and they do not occur within string. 2.2 Identifiers An identifier is a series of alphabetical letters and digits; the first character must be alphabetic. 2.3 Keywords The following identifiers are reserved for the use as keywords, and may not be used otherwise: triangle true initialization false rule print operations while result string area if AND OR NOT sin cos tan arcsin arccos arctan sqrt V L print _ anglea angleb anglec sidea sideb sidec 2.4 Constants There are five constants in TrML: 2.4.1 Value Value constant consists of an integer part, a decimal point and a fraction part. No exponential part is supported. 4

2.4.2 Triangle Triangle constant can be either Vertex-constant starts with letter V followed by three tuples of values in square brackets. i.e. V[ (1.1, 2.2), (3.3, 4.4), (1.2, 4.2)] or Linesegment-constant starts with letter L followed by three values in square brackets. i.e. L[1.3, 4.2, 5.4] 2.4.3 Boolean The reserved Boolean constants are true and false. 2.4.4 Sh-cat The reserved Sh-cat constant is character _. As Schrödinger s cat means there is a field to be filled but the value in corresponding field is unknown. 2.4.5 String String constant is a sequence of characters surrounded by double quotes, as in. A string s value is initialized with the given characters. Only alphabet and number is allowed in string. 5

3 Types There are two data types in TrML Value Triangle A floating point number A Triangle in 2D plane 4 Operators TrML support most of the standard C Programming Language s arithmetic operations and inherit it s standard operator. Operators Precedence and order of evaluation Operators Associativity ( ) [ ] left to right cos sin tan arcsin arccos arctan sqrt left to right * / % left to right + - left to right >= <= > < left to right ==!= left to right NOT AND OR left to right 6

5 Expression and Statement 5.1 Expression Expression consists of arithmetic expression, logic expression and general expression 5.1.1 Arithmetic Expression Operators in arithmetic expressions group left to right arithmetic-expression : arithmetic-expression operator arithmetic-expression 5.1.2 Logical Expression Operators in Logical expressions group left to right logical-expression: logical-expression operator logical-expression 5.1.3 General Expression Operators in Logical expressions group left to right general-expression: general-expression operator general-expression 5.2 Statements A statement consists of while statement, conditional statement, assignment and built-in function calls. 5.2.1 Statements and Statement statements: { statement } statement: while-statement conditional-statement assignment-statement built-in-function 7

5.2.2 Assignment Statement assignment-statement: identifier = expression 5.2.3 Conditional Statement conditional-statement: if general-expression then statements 5.2.3 While Statement while-statement: while general-expression statements 5.2.4 Built-in-Function TrML has built-in print function. built-in-function: prints ( string-constant ) printv ( arithmetic-expression) 8

6 Building Blocks The program consists of three building blocks initialization, rules and operations 6.1 Initialization Initialization declares all variables used in the program. A variable may be a value or a triangle. All variable declarations end with semicolon. value-declaration: value-identifier value-constant triangle-declaration: triangle-identifier vertex-constant triangle-identifier line-segment-constant triangle-identifier vertex-constant line-segment-constant note a triangle with empty information could be created by using sh-cat. 6.2 Rules Trigonometry rules are defined in the rules section. Rule declaration starts with rule name followed by general expression as rules qualification and statements as rule definition. rule: identifier general-expression statements Note that the there are two different rules in trigonometry: judgment rule and calculation rule. Both rules can be expressed using the same rule expression: Judgment Rule: identifier general-expression true Calculation Rule: identifier true statements 6.3 Operations Operations invoke rules from previous block and variables from initialization block. Operations consist of a series of statements. A statement always ends with a semi-colon. No statement can return a value. A statement either calls a built-in function or making an assignment. operations: 9

statements 7 Sample Code @ keyword initialize: starts triangle initialization phase initialize: @ initialize triangle with 2-D vertex location triangle ABC V [(1.1, 2.2), (3.3, 4.4), (5.5, 6.6)]; @initialize triangle with line segment length triangle DEF L [4.2, 3.5, 3.6]; value agl 0.0; @ Keyword rules: starts rules construction phase rule: @ Explain regular triangle s meaning in terms of line length. @ This is a judgment rule identical_triangle (Tri_1, Tri_2) ( ((Tri_1.sideA == Tri_2.sideA ) AND (Tri_1. sideb == Tri_2. sideb) AND (Tri_1. sidec == Tri_2. sidec)) OR ((Tri_1. sidea == Tri_2. sideb) AND (Tri_1. sideb == Tri_2. sidec) AND (Tri_1. sidec == Tri_2. sidea)) OR ((Tri_1. sidea == Tri_2. sidec) AND (Tri_1. sideb == Tri_2. sidea) AND (Tri_1. sidec == Tri_2. sideb))) {true}; @ Explain right triangle s meaning in terms of angle regular_triangle (A) (A.sidea == A.sideb AND A.sideb == A.sidec) {true}; regular_triangle (A) (A.angleA == 60 AND A.angleB == 60) {true}; @ Explain what means of two triangles be equal equal_triangle (A, B) {A.sidea == B.sidea AND A.sideb == B.sibeb AND A.sidec == B.sidec}; @ Explain anglec in terms of sides @ This is a calculation rule 10

angle_c (A) (true) {arcos((a.sidea * A.sideA) + (A.sideB * A.sideB) (A.sideC * A.sideC) / 2 * A.sideA * A.sideB)}; @ keyword operation: starts operation and calculation phase operation: if (identical_triangle (ABC, DEF)) { prints ( ABC and DEF are identical ); } if (regular_triangle(abc)) print (ABC + is regular triangle ); while (agl < 180){ agl = agl + 5; prints ( value agl s valus is: ); printv ( agl ); } 11

Appendix: YACC parser generator grammar pseudo-code for TrML @ INITIALIZE 1. initialization -> INITIALIZE COLON initial-declarator 2. initial-declarator-list -> initial-declarator-list initial-declarator 3. initial-declarator-> value-declarator triangle-declarator 4. value-declarator -> VALUE VID FLOAT SEMICOLON 5. triangle-declarator -> TRIANGLE TID triangle-initializer SEMICOLON 6. triangle-initializer-> vertex-status line-status vertex-status line-state 7. line-status -> L LB line-initializer RB 8. line-initializer-> initial-value COMMA initial-value COMMA initial-value 9. vertex-status ->V LB vertex-initializer RB 10. vertex-initializer -> LP initial-value COMMA initial-value RP LP initialvalue COMMA initial-value RP LP initial-value COMMA initial-value RP 11. initial-value->float sh-toekn @ RULES 12. rules-def -> RULE COLON rule-declarator-list 13. rule-declarator-list -> rule-declarator-list SEMICOLON rule-declarator 12

rule-declarator 14. rule-declarator -> ID LP para-lst RP LP expr RP LP statement RP 15. para-lst -> para-lst COMMA parameter parameter 16. parameter -> TID 17. statement->numerical-expr 18. numerical-expr->numerical-expr MINUS numerical-expr numerical-expr ADD numerical-expr numerical-expr MULT numerical-expr numerical-expr DIVIDE numerical-expr SIN numerical-expr COS numerical-expr TAN numerical-expr ARCSIN numerical-expr ARCCOS numerical-expr ARCTAN numerical-expr I SQRT numerical-expr FLOAT VID TRUE LP numerical-expr RP tri-element 19. tri-element -> para-lst DOT element TID DOT element 20. element -> A B C SIDEA SIDEB SIDEC ANGLEA ANGLEB 13

ANGLEC AREA 21. comparison-expr-> comparison NEQ comparison comparison EQL comparison comparison GEQ comparison comparison SEQ comparison comparison GRTR comparison comparison SMLR comparison LP comparison RP 22. comparison -> numerical-expr 23. expr -> expr AND expr expr OR expr NOT expr LP expr RP comparison-expr 24. operations -> OPERATION COLON operation-list 25. operation-list -> operation SEMICOLON operation 26. operation -> print condition-statement while-statement assignment 27. print -> PRINT LP print-statement RP 28. print-statement ->expr STRING 29. condition-statement -> IF expr THEN operation-list 30. while-statement -> WHILE expr operation-list 14