|
CS456 - Systems Programming
| Displaying exercises/e6/files/lex.c
#include "lex.h"
char *input; // Input string
int pos = 0; // Position within the string
void startlex(char *s)
{
input = s;
pos = 0;
}
// Gets the next character, or a -1 on end of input.
int get(void)
{
if (input[pos] == '\0') return -1;
return input[pos++];
}
// Unget a character (as long as it is not the end of input):
int unget(int c)
{
if (pos > 0 && c != -1) pos--;
}
/**
* If the next character is c, then move past it and return TRUE, otherwise
* do nothing and return FALSE. You will likely not need this function for this
* assignment.
*/
bool next(int c)
{
if (input[pos] == c) {
pos++;
return TRUE;
}
return FALSE;
}
// Keywords, true, false and null defined for you, if you choose to use this
// structure.
static struct keyword {
char *name;
token_t tval;
} keywords[] = {
{"true", T_TRUE},
{"false", T_FALSE},
{"null", T_NULL},
{NULL, T_UNKNOWN}
};
/**
* JSON strings are always double-quoted and may contain 0 or more characters
* with the following allowed for characters:
* char : any-Unicode-character-except-"-or-\-or-control-character
* | \" | \\ | \/ | \b | \f | \n | \r | \t| \u four-hex-digits
* For this assignment you do not need to support \u hex sequences, although
* you may.
*/
static token_t lexstring(char *word)
{
}
/**
* Returns the next token. Place strings and numbers in the word buffer.
*/
token_t lex(char *word)
{
}
|