Compiler/lexical analyzer: Difference between revisions

Content added Content deleted
(template "introheader" was renamed to "task heading")
(Unfortunately, the <lang> tag treats the first and last newline as significant)
Line 207: Line 207:
|-
|-
| style="vertical-align:top" |
| style="vertical-align:top" |
<lang c>
<lang c>/*
/*
Hello world
Hello world
*/
*/
print("Hello, World!\n");
print("Hello, World!\n");</lang>
</lang>


| style="vertical-align:top" |
| style="vertical-align:top" |
Line 226: Line 224:
|-
|-
| style="vertical-align:top" |
| style="vertical-align:top" |
<lang c>
<lang c>/*
/*
Show Ident and Integers
Show Ident and Integers
*/
*/
phoenix_number = 142857;
phoenix_number = 142857;
print(phoenix_number, "\n");
print(phoenix_number, "\n");</lang>
</lang>


| style="vertical-align:top" |
| style="vertical-align:top" |
Line 252: Line 248:
|-
|-
| style="vertical-align:top" |
| style="vertical-align:top" |
<lang c>
<lang c>/*
/*
All lexical tokens - not syntactically correct, but that will
All lexical tokens - not syntactically correct, but that will
have to wait until syntax analysis
have to wait until syntax analysis
Line 271: Line 266:
/* character literal */ '\n'
/* character literal */ '\n'
/* character literal */ '\\'
/* character literal */ '\\'
/* character literal */ ' '
/* character literal */ ' '</lang>
</lang>


| style="vertical-align:top" |
| style="vertical-align:top" |
Line 316: Line 310:
=={{header|C}}==
=={{header|C}}==
Tested with gcc 4.81 and later, compiles warning free with -Wall -Wextra
Tested with gcc 4.81 and later, compiles warning free with -Wall -Wextra
<lang C>
<lang C>#include <stdlib.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdio.h>
#include <stdarg.h>
#include <stdarg.h>
Line 537: Line 530:
run();
run();
return 0;
return 0;
}</lang>
}
</lang>


Output from test case 3:
Output from test case 3:
Line 577: Line 569:
=={{header|Euphoria}}==
=={{header|Euphoria}}==
Tested with Euphoria 4.05.
Tested with Euphoria 4.05.
<lang euphoria>
<lang euphoria>include std/io.e
include std/io.e
include std/map.e
include std/map.e
include std/types.e
include std/types.e
Line 791: Line 782:
end procedure
end procedure


main(command_line())
main(command_line())</lang>
</lang>


Output from test case 3:
Output from test case 3:
Line 831: Line 821:
=={{header|Flex}}==
=={{header|Flex}}==
Tested with Flex 2.5.4.
Tested with Flex 2.5.4.
<lang C>
<lang C>%{
%{
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
Line 994: Line 983:
} while (tok != tk_EOI);
} while (tok != tk_EOI);
return 0;
return 0;
}</lang>
}
</lang>


Output from test case 3:
Output from test case 3:
Line 1,034: Line 1,022:
=={{header|FreeBASIC}}==
=={{header|FreeBASIC}}==
Tested with FreeBASIC 1.05
Tested with FreeBASIC 1.05
<lang FreeBASIC>
<lang FreeBASIC>enum Token_type
enum Token_type
tk_EOI
tk_EOI
tk_Mul
tk_Mul
Line 1,301: Line 1,288:


main()
main()
system
system</lang>
</lang>


Output from test case 3:
Output from test case 3:
Line 1,567: Line 1,553:
=={{header|Python}}==
=={{header|Python}}==
Tested with Python 2.7 and 3.x
Tested with Python 2.7 and 3.x
<lang Python>
<lang Python>from __future__ import print_function
from __future__ import print_function
import sys
import sys


Line 1,734: Line 1,719:


if tok == tk_EOI:
if tok == tk_EOI:
break
break</lang>
</lang>


Output from test case 3:
Output from test case 3: