⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ctalk.html

📁 C-Talk is interpreted scripting language with C-like syntax and dynamic type checking. Variables in
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<HTML>
<BODY>

<H2>Introduction</H2>

C-Talk is interpreted scripting language with C-like syntax and dynamic type 
checking. Variables in C-Talk have no type. So there is no compile time type 
checking in C-Talk, all checking is performed at runtime. 
To preserve reference integrity, explicit memory deallocation is prohibited 
in C-Talk, unused objects are automatically deallocated by garbage collector.
<P>

C-Talk support integer, real, string, associative array, thread and mutex types.
There is no structures, classes, unions and pointers. Structures can be 
emulated by associative array, for example the expression <code>x.foo</code> is
equivalent to <code>x["foo"]</code> and access element of associative array with
key <code>"foo"</code>.
<P>

C-Talk provides very simple interface with C and C++. Programmer can easily 
define various primitives which can be called from the C-Talk as normal 
functions.<P>

C-Talk is intented to be used in the same area as Perl, VB-Script, Java-Script
languages. It is for the people who are familiar with C and prefer it's syntax
to something else. The other advantage of C-Talk is that it is open source free
software. It is distributed under MIT license - almost no restrictions on 
using this language in any project (unlike GPL). Also C-Talk is very 
simple and compact language, only - 6000 lines of code.
It very simple to extend the language with new primitives and types
needed for your application.<P>


<H2>Syntax</H2>
The syntax of C-Talk language is similar with C/Java.

<PRE>
program: import-list {stmt}
import-list: <B>"import"</B> module {<B>","</B> module}
module: identifier
func-def: <B>"function"</B> func-name <B>"("</B> params-list <B>")"</B> block-stmt
func-name: identifier
params-list: empty | intentifier { <B>","</B> intentifier }
stmt: <B>";"</B> | expr <B>";"</B> | block-stmt
      | while-stmt | do-while-stmt | for-stmt | if-stmt | break-stmt | continue-stmt 
      | return-stmt | throw-stmt | try-catch-stmt 
while-stmt: <B>"while"</B> <B>"("</B> condition <B>")"</B> stmt
do-while-stmt: <B>"do"</B> stmt <B>"while"</B> <B>"("</B> condition <B>")"</B> <B>";"</B>
for-stmt: <B>"for"</B> <B>"("</B> opt-expr <B>";"</B> opt-expr <B>";"</B> opt-expr <B>")"</B> stmt
if-stmt: <B>"if"</B> <B>"("</B> condition <B>")"</B> stmt [<B>"else"</B> stmt]
condition: expr
opt-expr: empty | expr
break-stmt: <B>"break"</B> <B>";"</B>
continue-stmt: <B>"continue"</B> <B>";"</B>
throw-stmt: <B>"throw"</B> expr <B>";"</B>
return-stmt: <B>"return"</B> opt-expr <B>";"</B>
try-catch-stmt: <B>"try"</B> stmt <B>"catch"</B> <B>"("</B> exception-var <B>")"</B> stmt
exception-var: identifier
block-stmt: <B>"{"</B> { stmt } <B>"}"</B>
expr: literal | func-call | start-thread  | binary-expr | unary-expr | 
      <B>"("</B> expr <B>")"</B> | | variable | index-expr | env-var
literal: string | integer | real | array-constructor
variable: identifier
index-expr: expr <B>"["</B> expr <B>"]"</B> | expr <B>"."</B> identifier
env-var: <B>"$"</B> identifier
array-constructor: <B>"["</B> empty | array-elem { <B>","</B> array-elem } <B>"]"</B> 
array-elem: expr [<B>":"</B>] 
func-call: expr <B>"("</B> expr-list <B>")"</B>
start-thread: <B>"par"</B> func-call
expr-list: empty | expr { <B>","</B> expr }
binary-expr: expr bin-op expr
unary-expr: unary-op expr
bin-op: <B>"+"</B> | <B>"-"</B> | <B>"/"</B> | <B>"*"</B> | <B>">>"</B> | <B>"<<"</B> | <B>">>>"</B> | <B>"|"</B> | <B>"&"</B> | <B>"^"</B> |
	| <B>"+="</B> | <B>"-="</B> | <B>"/="</B> | <B>"*="</B> | <B>">>="</B> | <B>"<<="</B> | <B>"|="</B> | <B>"&="</B> | <B>"^="</B> | <B>"="</B> 
        | <B>"=="</B> | <B>">"</B> | <B>">="</B> | <B>"<"</B> | <B>"<="</B> | <B>"!="</B> 
unary-op: <B>"~"</B> | <B>"!"</B> | <B>"-"</B> | <B>"+"</B> 

</PRE>

Syntax of identifiers, comments, string, integer and real
literals is the same as in C, with the exception that in C-Talk there is no 
difference between character and string literals.


The table below summarize differences between C and C-Talk syntax
<UL>
<LI>C-Talk has no preprocessor
<LI>C-Talk has <code>"function"</code> keyword
<LI>C-Talk treats &quot; and ' equally, so <code>"ok"</code> and <code>'ok'</code> means the same string character constant
<LI>C-Talk program consist of modules loaded by "import" construction
<LI>C-Talk expression <code>a.x</code> is syntax sugar for <code>a["x"]</code> and is treated as associative
   array access operation 
<LI>C-Talk variable has no types - so no function return type, formal parameter type or variable type should not (and can not) be specified.  
<LI>C-Talk has no goto construction
<LI>C-Talk has <code>"par"</code> construction for starting thread
</UL>

<H2>Types</H2>
C-Talk provides the following types
<UL>
<LI>Integer (32 bit signed integer type with operations similar to C, but shift right operation is unsigned - doesn't replicate the sign bit)
<LI>Real (32 bit ANSI double type)
<LI>String (+ operator)
<LI>Associative array (index of the array can be object of any type, for example a["foo"])
<LI>Raw pointer (used only by primitives, C-Talk can only store such value to variables 
and pass them to the functions, example is C FILE* type)
<LI>Thread type (with associated FIFO queue)
<LI>Function type (function is first class value and can assigned to variable 
and passed as parameter to other function)
</UL>


<H3>String operations</H3>
<TABLE BORDER>
<TR><TH>Example</TH><TH>Description</TH></TR>
<TR><TD><code>s = "ok"</code></TD><TD>relation operations</TD></TR>
<TR><TD><code>s + "cxx" </code></TD><TD>  concatenation of strings</TD></TR>
<TR><TD><code>indexOf(s, "xxx")</code></TD><TD>index of first occurrence of substring</TD></TR>
<TR><TD><code>lastIndexOf(s, "xxx")</code></TD><TD>index of first occurance of substring</TD></TR>
<TR><TD><code>substring(s, star</code></TD><TD>os, end-pos) - extract substring</TD></TR>
<TR><TD><code>toLower(s)</code></TD><TD>convert to lower case</TD></TR>
<TR><TD><code>toUpper(s)</code></TD><TD>convert to upper case</TD></TR>
<TR><TD><code>trim(s)</code></TD><TD>remove trailing spaces</TD></TR>
<TR><TD><code>startsWith(s, prefix)</code></TD><TD>check if string has specified prefix</TD></TR>
<TR><TD><code>endsWith(s, suffix)</code></TD><TD>check if string has specified suffix</TD></TR>
<TR><TD><code>string(x)</code></TD><TD>convert argument to string</TD></TR>
<TR><TD><code>integer("100")</code></TD><TD>convert string to integer</TD></TR>
<TR><TD><code>real("5.5")</code></TD><TD>convert string to real</TD></TR>
<TR><TD><code>length(x)</code></TD><TD>length of string</TD></TR>
</TABLE>

<H3>Arrays operations</H3>
<TABLE BORDER>
<TR><TD><code>a[x] = y</code></TD><TD>  store element</TD></TR>
<TR><TD><code>x = a[y]</code></TD><TD>  fetch element</TD></TR>
<TR><TD><code>x = [0:"red", 1:"green", 2:"blue"]</code></TD><TD>array constructor</TD></TR>
<TR><TD><code>x += ['one':1, 'two':2]</code></TD><TD>concatenate arrays</TD></TR>
<TR><TD><code>a - x </code></TD><TD> remove element(s) from the array, x can be array or key of element</TD></TR>
<TR><TD><code>length(a)       </code></TD><TD>length of array</TD></TR>
<TR><TD><code>cloneArray(a)   </code></TD><TD>create a copy of the array</TD></TR>
<TR><TD><code>deleteArray(a)  </code></TD><TD>deallocate array </TD></TR>
<TR><TD><code>clearArray(a)   </code></TD><TD>truncate array to size 0</TD></TR>
<TR><TD><code>getKeys(a)   </code></TD><TD>get array of keys</TD></TR>
</TABLE>

<H3>Mutex operations</H3>
<TABLE BORDER>
<TR><TD><code>m = createMutex()  </code></TD><TD>create mutex </TD></TR>
<TR><TD><code>lockMutex(m)       </code></TD><TD>lock mutex</TD></TR>
<TR><TD><code>unlockMutex(m)     </code></TD><TD>unlock mutex</TD></TR>
<TR><TD><code>deleteMutex(m)     </code></TD><TD>delete mutex</TD></TR>
</TABLE>

<H3>Thread operations</H3>
<TABLE BORDER>
<TR><TD><code>m = getMessage(t)  </code></TD><TD>get message from thread queue</TD></TR>
<TR><TD><code>putMessage(t, m)   </code></TD><TD>put message in thread queue</TD></TR>
<TR><TD><code>t = currentThread()</code></TD><TD>get reference to current thread</TD></TR>
</TABLE>

<H3>IO operations:</H3>
<TABLE BORDER>
<TR><TD><code>f = createFile("test.txt", "r")</code></TD><TD>create file with specified name and access mode</TD></TR>
<TR><TD><code>deleteFile(f)           </code></TD><TD>close file</TD></TR>
<TR><TD><code>flushFile(f)            </code></TD><TD>flush buffers</TD></TR>
<TR><TD><code>printFile(f, "x=", x)   </code></TD><TD>print varying number of arguments to the file</TD></TR>
<TR><TD><code>printlnFile(f, "x=", x) </code></TD><TD>the same as above but append '\n'</TD></TR>
<TR><TD><code>print("x=", x)          </code></TD><TD>print varying number of arguments to the console</TD></TR>
<TR><TD><code>println("x=", x)        </code></TD><TD>the same as above but append '\n'</TD></TR>
<TR><TD><code>input("> ")             </code></TD><TD>input string from console or specified file, the single optional argument of this function should be file or propmt string</TD></TR>
</TABLE>


<H3>Type check operations:</H3>
<TABLE BORDER>
<TR><TD><code>isString(x)</code></TD><TD>checks if argument is string</TD></TR>
<TR><TD><code>isArray(x)</code></TD><TD>checks if argument is array</TD></TR>
<TR><TD><code>isInteger(x)</code></TD><TD>checks if argument is integer</TD></TR>
<TR><TD><code>isReal(x)</code></TD><TD>checks if argument is real</TD></TR>
<TR><TD><code>isNull(x)</code></TD><TD>checks if argument is null</TD></TR>
<TR><TD><code>isFunction(x)</code></TD><TD>checks if argument is function</TD></TR>
<TR><TD><code>isPrimitive(x)</code></TD><TD>checks if argument is primitive</TD></TR>
<TR><TD><code>isMutex(x)</code></TD><TD>checks if argument is mutex</TD></TR>
<TR><TD><code>isFile(x)</code></TD><TD>checks if argument is file</TD></TR>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -