v6502
The MOS 6502 Virtual Machine and Toolchain Infrastructure
token.h
Go to the documentation of this file.
1 
4 /*
5  * Copyright (c) 2013 Daniel Loffgren
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a copy
8  * of this software and associated documentation files (the "Software"), to
9  * deal in the Software without restriction, including without limitation the
10  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
11  * sell copies of the Software, and to permit persons to whom the Software is
12  * furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included in
15  * all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
23  * IN THE SOFTWARE.
24  */
25 
26 #ifndef as6502_token_h
27 #define as6502_token_h
28 
29 #include <stddef.h>
30 #include <stdio.h> // Required for dot output
31 
34 typedef enum {
35  as6502_token_type_other,
36  as6502_token_type_value
38 
41 typedef struct _as6502_token {
43  char *text;
45  size_t loc;
47  size_t len;
49  struct _as6502_token *next;
52 } as6502_token;
53 
57 as6502_token *as6502_tokenCreate(const char *text, size_t loc, size_t len);
65 int as6502_tokenIsEqualToString(as6502_token *token, const char *string, size_t len);
67 #define as6502_tokenIsEqualToStringLiteral(token, string) as6502_tokenIsEqualToString(token, string, sizeof(string) - 1)
68 
69 void as6502_stringForTokenList(char *output, size_t len, as6502_token *head);
77 size_t as6502_lengthOfToken(const char *start, size_t len);
78 
80 size_t as6502_valueLengthInChars(const char *string, size_t len);
82 as6502_token *as6502_lex(const char *line, size_t len);
88 as6502_token *as6502_tokenListFindToken(as6502_token *token, const char *text, size_t len);
90 #define as6502_tokenListFindTokenLiteral(token, literal) as6502_tokenListFindToken(token, literal, sizeof(literal) - 1)
91 
98 void as6502_printDotForList(FILE *stream, as6502_token *head);
100 void as6502_printDotRankForList(FILE *stream, as6502_token *head);
103 #endif /* defined(as6502_token_h) */
size_t loc
The token&#39;s column location in the line.
Definition: token.h:45
void as6502_tokenDestroy(as6502_token *token)
Destroys a single token object.
Definition: token.c:54
void as6502_showDotForLinkedList(as6502_token *head)
Generates and opens a full dot graph of a given list (This is a super convenience function for fully ...
int as6502_tokenIsEqualToString(as6502_token *token, const char *string, size_t len)
Does a quick token comparison to a string.
Definition: token.c:69
An individual token which will often be a part of a linked list of tokens.
Definition: token.h:41
as6502_token * as6502_tokenListFindToken(as6502_token *token, const char *text, size_t len)
Searches through a linked list of tokens to find a token matching a given string of a given length...
Definition: token.c:233
as6502_token * as6502_lex(const char *line, size_t len)
Lexes a line of text into a linked list of tokens for later parsing.
Definition: token.c:139
void as6502_printDotForList(FILE *stream, as6502_token *head)
Generates a full dot graph of a given linked list of as6502_token&#39;s (one entire source file) ...
Definition: token.c:262
size_t as6502_lengthOfToken(const char *start, size_t len)
Finds the first non-token character encountered, and returns it&#39;s location relative to the start poin...
Definition: token.c:119
as6502_token * as6502_tokenCopy(as6502_token *original)
Creates a single token object that is identical to the passed in object, but in a different location...
Definition: token.c:48
size_t as6502_valueLengthInChars(const char *string, size_t len)
Finds the first thing that isn&#39;t the value literal pointed to by string, and returns the length of th...
Definition: token.c:108
void as6502_stringForTokenList(char *output, size_t len, as6502_token *head)
Outputs a flat string for a given token list.
Definition: token.c:77
as6502_token_type type
Significant type information to help identify this token during parsing.
Definition: token.h:51
char * text
The raw text of a token.
Definition: token.h:43
void as6502_printDotRankForList(FILE *stream, as6502_token *head)
Generates the dot code for a given rank of as6502_token&#39;s (one line of assembly)
Definition: token.c:244
as6502_token_type
A simple enumeration type to differentiate values from other types of tokens. This could...
Definition: token.h:34
as6502_token * as6502_tokenCreate(const char *text, size_t loc, size_t len)
Creates a single token object. Text is copied up to length indicated by len.
Definition: token.c:34
size_t len
The token&#39;s character length.
Definition: token.h:47
void as6502_tokenListDestroy(as6502_token *token)
Destroys a token and all tokens attached to it by traversing the linked list of tokens.
Definition: token.c:60
as6502_token * as6502_firstTokenOfTypeInList(as6502_token *head, as6502_token_type type)
Searches through a token list and returns the first token whose type matches the specified as6502_tok...
Definition: token.c:90
struct _as6502_token * next
The next token in the linked list.
Definition: token.h:49