#!/bin/bash
# Fibonacci numbers
# Writes an infinite series to stdout, one entry per line
function fib() {
local a=1
local b=1
while true ; do
echo $a
local tmp=$a
a=$(( $a + $b ))
b=$tmp
done
}
# output the 10th element of the series and halt
fib | head -10 | tail -1
#!/bin/bash
# Fibonacci numbers
# Writes an infinite series to stdout, one entry per line
function fib() {
local a=1
local b=1
while true ; do
echo $a
local tmp=$a
a=$(( $a + $b ))
b=$tmp
done
}
# output the 10th element of the series and halt
fib | /usr/bin/*head -10 | tail -1
#include <stdio.h>
/* the n-th fibonacci number.
*/
unsigned int fib(unsigned int n) {
unsigned int a = 1, b = 1;
unsigned int tmp;
while (--n >= 0) {
tmp = a;
a += b;
b = tmp;
}
return a;
}
main() {
printf("%u", fib(10));
}
#include <stdio.h>
/* the nth fibonacci number. */
unsigned int fib(unsigned int n) {
unsigned int a = 1, b = 1;
unsigned int tmp;
while (--n >= 0) {
tmp = a;
a += b;
b = tmp;
}
return a;
}
void main() {
printf("%u", fib(10));
}
#define ZERO 0 /* a
multiline comment */
#include <iostream>
using namespace std;
//! fibonacci numbers with gratuitous use of templates.
//! \param n an index into the fibonacci series
//! \param fib0 element 0 of the series
//! \return the nth element of the fibonacci series
template <class T>
T fib(unsigned int n, const T& fib0) {
T a(fib0), b(fib0);
for (; n; --n) {
T tmp(a);
a += b;
b = tmp;
}
return a;
}
int main(int argc, char **argv) {
cout << fib(10, 1U);
}
#include <iostream>
using namespace std;
//! fibonacci numbers with gratuitous use of templates.
//! \param n an index into the fibonacci series
//! \param fib0 element 0 of the series
//! \return the nth element of the fibonacci series
template <class T>
T fib(int n, const T& fib0) {
T a(fib0), b(fib0);
while (--n >= 0) {
T tmp(a);
a += b;
b = tmp;
}
return a;
}
int main(int argc, char **argv) {
cout << fib(10, 1U);
}
package foo;
import java.util.Iterator;
/**
* the fibonacci series implemented as an Iterable.
*/
public final class Fibonacci implements Iterable<Integer> {
/** the next and previous members of the series. */
private int a = 1, b = 1;
@Override
public Iterator<Integer> iterator() {
return new Iterator<Integer>() {
/** the series is infinite. */
public boolean hasNext() { return true; }
public Integer next() {
int tmp = a;
a += b;
b = tmp;
return a;
}
public void remove() { throw new UnsupportedOperationException(); }
};
}
/**
* the n<sup>th</sup> element of the given series.
* @throws NoSuchElementException if there are less than n elements in the
* given Iterable's {@link Iterable#iterator iterator}.
*/
public static <T>
T nth(int n, Iterable<T> iterable) {
Iterator<? extends T> it = iterable.iterator();
while (--n > 0) {
it.next();
}
return it.next();
}
public static void main(String[] args) {
System.out.print(nth(10, new Fibonacci()));
}
}
package foo;
import java.util.Iterator;
/**
* the fibonacci series implemented as an Iterable.
*/
public final class Fibonacci implements Iterable<Integer> {
/** the next and previous members of the series. */
private int a = 1, b = 1;
@Override
public Iterator<Integer> iterator() {
return new Iterator<Integer>() {
/** the series is infinite. */
public boolean hasNext() { return true; }
public Integer next() {
int tmp = a;
a += b;
b = tmp;
return a;
}
public void remove() { throw new UnsupportedOperationException(); }
};
}
/**
* the n<sup>th</sup> element of the given series.
* @throws NoSuchElementException if there are less than n elements in the
* given Iterable's {@link Iterable#iterator iterator}.
*/
public static <T>
T nth(int n, Iterable<T> iterable) {
Iterator<? extends T> in = iterable.iterator();
while (--n > 0) {
in.next();
}
return in.next();
}
public static void main(String[] args) {
System.out.print(nth(10, new Fibonacci()));
}
}
# not a java comment
# not keywords: static_cast and namespace
/**
* nth element in the fibonacci series.
* @param n >= 0
* @return the nth element, >= 0.
*/
function fib(n) {
var a = 1, b = 1;
var tmp;
while (--n >= 0) {
tmp = a;
a += b;
b = tmp;
}
return a;
}
document.write(fib(10));
/foo/; // a slash starting a line treated as a regexp beginning
"foo".match(/fo+$/);
// this line comment not treated as a regular expressions
"foo /bar/".test(/"baz"/); // test string and regexp boundaries
var division = /\b\d+\/\d+/g; // test char sets and escaping of specials
var allSpecials = /([^\(\)\[\]\{\}\-\?\+\*\.\^\$\/]+)\\/;
var slashInCharset = /[^/]/g, notCloseSq = /[^\]]/;
// test that slash used in numeric context treated as an operator
1 / 2;
1. / x;
x / y;
(x) / y;
1 /* foo */ / 2;
1 /* foo *// 2;
1/2;
1./x;
x/y;
(x)/y;
// test split over two lines. line comment should not fool it
1//
/2;
x++/y;
x--/y;
x[y] / z;
f() / n;
// test that slash after non postfix operator is start of regexp
log('matches = ' + /foo/.test(foo));
// test keyword preceders
return /a regexp/;
division = notreturn / not_a_regexp / 2; // keyword suffix does not match
// & not used as prefix operator in javascript but this should still work
&/foo/;
extends = /extends/;
/foo/; // a slash starting a line treated as a regexp beginning
"foo".match(/fo+$/);
// this line comment not treated as a regular expressions
"foo /bar/".test(/"baz"/); // test string and regexp boundaries
var division = /\b\d+\/\d+/g; // test char sets and escaping of specials
var allSpecials = /([^\(\)\[\]\{\}\-\?\+\*\.\^\$\/]+)\\/;
var slashInCharset = /[^/]/g, notCloseSq = /[^\]]/;
// test that slash used in numeric context treated as an operator
1 / 2;
1. / x;
x / y;
(x) / y;
1 /* foo */ / 2;
1 /* foo *// 2;
1/2;
1./x;
x/y;
(x)/y;
// test split over two lines. line comment should not fool it
1//
/2;
x++/y;
x--/y;
x[y] / z;
f() / n;
// test that slash after non postfix operator is start of regexp
log('matches = ' + /foo/.test(foo));
// test keyword preceders
return /a regexp/;
division = notreturn / not_a_regexp / 2; // keyword suffix does not match
// & not used as prefix operator in javascript but this should still work
&/foo/;
extends = /extends/;
#!/usr/bin/perl
use strict;
use integer;
# the nth element of the fibonacci series
# param n - an int >= 0
# return an int >= 0
sub fib($) {
my $n = shift, $a = 1, $b = 1;
($a, $b) = ($a + $b, $a) until (--$n < 0);
return $a;
}
print fib(10);
#!/usr/bin/python2.4
def fib():
'''
a generator that produces the elements of the fibonacci series
'''
a = 1
b = 1
while True:
a, b = a + b, a
yield a
def nth(series, n):
'''
returns the nth element of a series,
consuming the earlier elements of the series
'''
for x in series:
n = n - 1
if n <= 0: return x
print nth(fib(), 10)
#!/usr/bin/python2.4
def fib():
'''
a generator that produces the fibonacci series's elements
'''
a = 1
b = 1
while True:
a, b = a + b, a
yield a
def nth(series, n):
'''
returns the nth element of a series,
consuming the earlier elements of the series
'''
for x in series:
n -= 1
if n <= 0: return x
print nth(fib(), 10)
/* not a comment and not keywords: null char true */
/* A multi-line * comment */ 'Another string /* Isn\'t a comment', "A string */" -- A line comment SELECT * FROM users WHERE id IN (1, 2.0, +30e-1); -- keywords are case-insensitive. -- Note: user-table is a single identifier, not a pair of keywords select * from user-table where id in (x, y, z);
<!DOCTYPE series PUBLIC "fibonacci numbers"> <series base="1" step="s(n-2) + s(n-1)"> <element i="0">1</element> <element i="1">1</element> <element i="2">2</element> <element i="3">3</element> <element i="4">5</element> <element i="5">8</element> ... </series>
<html>
<head>
<title>Fibonacci number</title>
<style><!-- BODY { text-decoration: blink } --></style>
</head>
<body>
<noscript>
<dl>
<dt>Fibonacci numbers</dt>
<dd>1</dd>
<dd>1</dd>
<dd>2</dd>
<dd>3</dd>
<dd>5</dd>
<dd>8</dd>
…
</dl>
</noscript>
<script type="text/javascript"><!--
function fib(n) {
var a = 1, b = 1;
var tmp;
while (--n >= 0) {
tmp = a;
a += b;
b = tmp;
}
return a;
}
document.writeln(fib(10));
// -->
</script>
</body>
</html>
Fibonacci Numbers
<noscript>
<dl style="list-style: disc">
<dt>Fibonacci numbers</dt>
<dd>1</dd>
<dd>1</dd>
<dd>2</dd>
<dd>3</dd>
<dd>5</dd>
<dd>8</dd>
…
</dl>
</noscript>
<script type="text/javascript"><!--
function fib(n) {
var a = 1, b = 1;
var tmp;
while (--n >= 0) {
tmp = a;
a += b;
b = tmp;
}
return a;
}
document.writeln(fib(10));
// -->
</script>
<xhtml>
<head>
<title>Fibonacci number</title>
</head>
<body onload="alert(fib(10))">
<script type="text/javascript"><![CDATA[
function fib(n) {
var a = 1, b = 1;
var tmp;
while (--n >= 0) {
tmp = a;
a += b;
b = tmp;
}
return a;
}
]]>
</script>
</body>
</xhtml>
<html>
<head>
<title><?= 'Fibonacci numbers' ?></title>
<?php
// PHP has a plethora of comment types
/* What is a
"plethora"? */
function fib($n) {
# I don't know.
$a = 1;
$b = 1;
while (--$n >= 0) {
echo "$a\n";
$tmp = $a;
$a += $b;
$b = $tmp;
}
}
?>
</head>
<body>
<?= fib(10) ?>
</body>
</html>
<!-- Test elements and attributes with namespaces -->
<xsl:stylesheet xml:lang="en">
<xsl:template match=".">
<xsl:text>Hello World</xsl:text>
</xsl:template>
</xsl:stylesheet>
// ends with line comment token //
Javascript Snippets wrapped in HTML SCRIPT tags hides/destroys inner content
<script type="text/javascript">
var savedTarget=null; // The target layer (effectively vidPane)
var orgCursor=null; // The original mouse style so we can restore it
var dragOK=false; // True if we're allowed to move the element under mouse
var dragXoffset=0; // How much we've moved the element on the horozontal
var dragYoffset=0; // How much we've moved the element on the verticle
vidPaneID = document.getElementById('vidPane'); // Our movable layer
vidPaneID.style.top='75px'; // Starting location horozontal
vidPaneID.style.left='75px'; // Starting location verticle
<script>
The fact that the script tag was not closed properly was causing PR_splitSourceNodes to end without emitting the script contents.
If tabs are used to indent code inside <pre> IE6 and 7 won't honor them after the script runs. Code indented with tabs will be shown aligned to the left margin instead of the proper indenting shown in Firefox. I'm using Revision 20 of prettify.js, IE 6.0.29.00 in English and IE 7.0.5730.11 in Spanish.
one Two three Four five | Six seven Eight nine Ten | eleven Twelve thirteen Fourteen fifteen |
<br> as newline//comment
int main(int argc, char **argv) {}
<!-- There's an HTML comment in my comment --> <p>And another one inside the end tag</p>
<html> <head>
<html>
<head>
<title>Test</title>
</head>
</html>
To test this bug, disable overriding of _pr_isIE6 above, and copy and paste the above into Notepad.
01: // This is a line of code 02: /* Multiline comments can 03: * span over and around 04: * line markers And can even be interrupted by inline code annotations 05: */ 06: class MyClass extends Foo { 07: public static void main(String... argv) { 08: System.out.print("Hello World"); 09: } 10: }
os=require("os")
math=require("math")
-- Examples from the language reference
a = 'alo\n123"'
a = "alo\n123\""
a = '\97lo\10\04923"'
a = [[alo
123"]]
a = [==[
alo
123"]==]
3 3.0 3.1416 314.16e-2 0.31416E1 0xff 0x56
-- Some comments that demonstrate long brackets
double_quoted = "Not a long bracket [=["
--[=[ quoting out
[[ foo ]]
[==[does not end comment either]==]
]=]
past_end_of_comment
--]=]
-- Example code courtesy Joseph Harmbruster
#
do
local function ssgeneral(t, n, before)
for _, h in ipairs(incs) do
for i = h + 1, n do
local v = t[i]
for j = i - h, 1, -h do
local testval = t[j]
if not before(v, testval) then break end
t[i] = testval; i = j
end
t[i] = v
end
end
return t
end
function shellsort(t, before, n)
n = n or #t
if not before or before == "<" then return ssup(t, n)
elseif before == ">" then return ssdown(t, n)
else return ssgeneral(t, n, before)
end
end
return shellsort
end
Imports System
Class [class]
Shared Sub [shared](ByVal [boolean] As Boolean)
If [boolean] Then
Console.WriteLine("true")
Else
Console.WriteLine("false")
End If
End Sub
End Class
Module [module]
Sub Main()
[class].[shared](True)
' This prints out: ".
Console.WriteLine("""")
' This prints out: a"b.
Console.WriteLine("a""b")
' This prints out: a.
Console.WriteLine("a"c)
' This prints out: ".
Console.WriteLine(""""c)
End Sub
End Module
Dim d As Date
d = # 8/23/1970 3:45:39AM #
d = # 8/23/1970 #
d = # 3:45:39AM #
d = # 3:45:39 #
d = # 13:45:39 #
d = # 13:45:39PM #
Dim n As Float
n = (0.0, .99F, 1.0E-2D, 1.0E+3D, .5E4, 1E3R, 4D)
Dim i As Integer
i = (0, 123, 45L, &HA0I, &O177S)
-- A comment
Not(--"a comment")
Also.not(--(A.comment))
module Foo(bar) where
import Blah
import BlahBlah(blah)
import Monads(Exception(..), FIO(..),unFIO,handle,runFIO,fixFIO,fio,
write,writeln,HasNext(..),HasOutput(..))
{- nested comments
- don't work {-yet-} -}
instance Thingy Foo where
a = b
data Foo :: (* -> * -> *) -> * > * -> * where
Nil :: Foo a b c
Cons :: a b c -> Foo abc -> Foo a b c
str = "Foo\\Bar"
char = 'x'
Not.A.Char = 'too long' -- Don't barf. Show that 't is a lexical error.
(ident, ident', Fo''o.b'ar)
(0, 12, 0x45, 0xA7, 0o177, 0O377, 0.1, 1.0, 1e3, 0.5E-3, 1.0E+45)
(*
* Print the 10th fibonacci number
*)
//// A line comment
"A string";;
(0, 125, 0xa0, -1.0, 1e6, 1.2e-3);; // number literals
#if fibby
let
rec fib = function (0, a, _) -> a
| (n, a, b) -> fib(n - 1, a + b, a)
in
print_int(fib(10, 1, 1));;
#endif
Still TODO: handle nested (* (* comments *) *) properly.
; -*- mode: lisp -*-
(defun back-six-lines () (interactive) (forward-line -6))
(defun forward-six-lines () (interactive) (forward-line 6))
(global-set-key "\M-l" 'goto-line)
(global-set-key "\C-z" 'advertised-undo)
(global-set-key [C-insert] 'clipboard-kill-ring-save)
(global-set-key [S-insert] 'clipboard-yank)
(global-set-key [C-up] 'back-six-lines)
(global-set-key [C-down] 'forward-six-lines)
(setq visible-bell t)
(setq user-mail-address "foo@bar.com")
(setq default-major-mode 'text-mode)
(setenv "TERM" "emacs")
(c-set-offset 'case-label 2)
(setq c-basic-offset 2)
(setq perl-indent-level 0x2)
(setq delete-key-deletes-forward t)
(setq indent-tabs-mode nil)
;; Text mode
(add-hook 'text-mode-hook
'(lambda ()
(turn-on-auto-fill)
)
)
;; Fundamental mode
(add-hook 'fundamental-mode-hook
'(lambda ()
(turn-on-auto-fill)
)
)
throw new RuntimeException("Element [" + element.getName() +
"] missing attribute.");
variable++;
message SearchRequest {
required string query = 1;
optional int32 page_number = 2;
optional int32 result_per_page = 3 [default = 10];
enum Corpus {
UNIVERSAL = 0;
WEB = 1;
IMAGES = 2;
LOCAL = 3;
NEWS = 4;
PRODUCTS = 5;
VIDEO = 6;
}
optional Corpus corpus = 4 [default = UNIVERSAL];
}
#summary hello world
#labels HelloWorld WikiWord Hiya
[http://www.google.com/?q=WikiSyntax+site:code.google.com WikiSyntax]
Lorem Ipsum `while (1) print("blah blah");`
* Bullet
* Points
* NestedBullet
==DroningOnAndOn==
{{{
// Some EmbeddedSourceCode
void main() {
Print('hello world');
}
}}}
{{{
<!-- Embedded XML -->
<foo bar="baz"><boo /><foo>
}}}
<!--
@charset('UTF-8');
/** A url that is not quoted. */
@import(url(/more-styles.css));
HTML { content-before: 'hello\20'; content-after: 'w\6f rld';
-moz-spiff: inherit !important }
/* Test units on numbers. */
BODY { margin-bottom: 4px; margin-left: 3in; margin-bottom: 0; margin-top: 5% }
/** Test number literals and quoted values. */
TABLE.foo TR.bar A#visited { color: #001123; font-family: "monospace" }
/** bolder is not a name, so should be plain. !IMPORTANT is a keyword
* regardless of case.
*/
blink { text-decoration: BLINK !IMPORTANT; font-weight: bolder }
-->