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 stricmp(*(char **)p1, *(char **)p2);
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 line, col, msg
print(line, col, msg)
exit(1)
exit(1)


Line 582: Line 581:


if tok == Integerk:
if tok == Integerk:
print "line %5d col %5d %-8s %8d" % (line, col, all_syms[tok], t[3])
print("line %5d col %5d %-8s %8d" % (line, col, all_syms[tok], t[3]))
elif tok == Ident:
elif tok == Ident:
print "line %5d col %5d %-8s %s" % (line, col, all_syms[tok], t[3])
print("line %5d col %5d %-8s %s" % (line, col, all_syms[tok], t[3]))
elif tok == Stringk:
elif tok == Stringk:
print 'line %5d col %5d %-8s "%s"' % (line, col, all_syms[tok], t[3])
print('line %5d col %5d %-8s "%s"' % (line, col, all_syms[tok], t[3]))
else:
else:
print "line %5d col %5d %-8s" % (line, col, all_syms[tok])
print("line %5d col %5d %-8s" % (line, col, all_syms[tok]))


if tok == EOI:
if tok == EOI: