PageRenderTime 49ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/kate-4.8.97/part/tests/hl/highlight.4th

#
Forth | 187 lines | 147 code | 35 blank | 5 comment | 3 complexity | e076578728e1e22a8d5bd7705545960b MD5 | raw file
Possible License(s): LGPL-2.0
  1. (
  2. Example File for ANS Forth Syntax Highlighting
  3. 6th December 2011 Mark Corbin <mark@dibsco.co.uk>
  4. Version 1.0 06-12-11
  5. - Initial release.
  6. )
  7. \ This is a single line comment.
  8. ( This
  9. is
  10. a
  11. multi-line
  12. comment )
  13. \ Single Characters
  14. char A
  15. [char] B
  16. \ Strings
  17. ." Display this string."
  18. s" Compile this string."
  19. abort" This is an error message."
  20. word parsethisstring
  21. c" Compile another string."
  22. parse parsethisstringtoo
  23. .( Display this string too.)
  24. \ Constants and Variables
  25. variable myvar
  26. 2variable mydoublevar
  27. constant myconst
  28. 2constant mydoubleconst
  29. value myval
  30. 20 to myval
  31. fvariable myfloatvar
  32. fconstant myfloatconst
  33. locals| a b c d|
  34. \ Single Numbers
  35. 123
  36. -123
  37. \ Double Numbers
  38. 123.
  39. 12.3
  40. -123.
  41. -12.3
  42. \ Floating Point Numbers
  43. 1.2e3
  44. -1.2e3
  45. 12e-3
  46. +12e-3
  47. -12e-3
  48. +12e+3
  49. \ Keywords (one from each list)
  50. dup
  51. roll
  52. flush
  53. scr
  54. dnegate
  55. 2rot
  56. catch
  57. abort
  58. at-xy
  59. time&date
  60. file-size
  61. rename-file
  62. fround
  63. fsincos
  64. (local)
  65. locals| |
  66. allocate
  67. words
  68. assembler
  69. search-wordlist
  70. order
  71. /string
  72. \ Obsolete Keywords (one from each list)
  73. tib
  74. forget
  75. \ Simple Word Definition
  76. : square ( n1 -- n2 )
  77. dup \ Duplicate n1 on top of stack.
  78. * \ Multiply values together leaving result n2.
  79. ;
  80. \ Words that Define New Words or Reference Existing Words
  81. create newword
  82. marker newmarker
  83. [compile] existingword
  84. see existingword
  85. code newcodeword
  86. forget existingword
  87. \ Loop Constructs
  88. : squares ( -- )
  89. 10 0 do
  90. i
  91. dup
  92. *
  93. .
  94. loop
  95. ;
  96. : forever ( -- )
  97. begin
  98. ." This is an infinite loop."
  99. again
  100. ;
  101. variable counter
  102. 0 counter !
  103. : countdown ( -- )
  104. begin
  105. counter @ \ Fetch counter
  106. dup . \ Display count value
  107. 1- dup counter ! \ Decrement counter
  108. 0= \ Loop until counter = 0
  109. until
  110. ;
  111. : countup ( -- )
  112. begin
  113. counter @ \ Fetch counter
  114. dup . \ Display count value
  115. 10
  116. <
  117. while
  118. 1 counter +! \ Increment counter if < 10
  119. repeat
  120. ;
  121. \ Conditional Constructs
  122. : testnegative ( n -- )
  123. 0< if
  124. ." Number is negative"
  125. then
  126. ;
  127. variable flag
  128. 0 flag !
  129. : toggleflag ( -- )
  130. flag @ if \ Fetch flag and test
  131. ." Flag is true."
  132. 0 flag ! \ Set flag to false
  133. else
  134. ." Flag is false."
  135. 1 flag ! \ Set flag to true
  136. then
  137. ;
  138. : translatenumber ( n -- )
  139. case
  140. 1 of
  141. ." Eins"
  142. endof
  143. 2 of
  144. ." Zwei"
  145. endof
  146. 3 of
  147. ." Drei"
  148. endof
  149. ." Please choose a number between 1 and 3."
  150. endcase
  151. ;
  152. \ END OF FILE