User:Ed Davis: Difference between revisions
Content added Content deleted
No edit summary |
No edit summary |
||
Line 196: | Line 196: | ||
=={{header|C}}== |
=={{header|C}}== |
||
<lang C> |
<lang C> |
||
#include <stdlib.h> |
#include <stdlib.h> |
||
#include <stdio.h> |
#include <stdio.h> |
||
Line 204: | Line 203: | ||
#include <errno.h> |
#include <errno.h> |
||
#include <stdbool.h> |
#include <stdbool.h> |
||
#include <limits.h> |
|||
#define NELEMS(arr) (sizeof(arr) / sizeof(arr[0])) |
#define NELEMS(arr) (sizeof(arr) / sizeof(arr[0])) |
||
Line 308: | Line 308: | ||
static int kwd_cmp(const void *p1, const void *p2) { |
static int kwd_cmp(const void *p1, const void *p2) { |
||
return |
return strcmp(*(char **)p1, *(char **)p2); |
||
} |
} |
||
Line 430: | Line 430: | ||
=={{header|Python}}== |
=={{header|Python}}== |
||
<lang Python> |
<lang Python> |
||
import sys |
import sys |
||
Line 454: | Line 453: | ||
#*** show error and exit |
#*** show error and exit |
||
def error(line, col, msg): |
def error(line, col, msg): |
||
print |
print(line, col, msg) |
||
exit(1) |
exit(1) |
||
Line 582: | Line 581: | ||
if tok == Integerk: |
if tok == Integerk: |
||
print |
print("line %5d col %5d %-8s %8d" % (line, col, all_syms[tok], t[3])) |
||
elif tok == Ident: |
elif tok == Ident: |
||
print |
print("line %5d col %5d %-8s %s" % (line, col, all_syms[tok], t[3])) |
||
elif tok == Stringk: |
elif tok == Stringk: |
||
print |
print('line %5d col %5d %-8s "%s"' % (line, col, all_syms[tok], t[3])) |
||
else: |
else: |
||
print |
print("line %5d col %5d %-8s" % (line, col, all_syms[tok])) |
||
if tok == EOI: |
if tok == EOI: |