parrotcode: implementation of the lexical analyzer of the PIR assembly language. | |
Contents | Compilers |
pir.l - implementation of the lexical analyzer of the PIR assembly language.
This file implements the lexical analyzer of the PIR assembly language. The macro layer is implemented here as well. Heredocs are processed by a different preprocessor.
Helper functions for macro expansion. These function are only used by the lexer, so keep them local to this file.
void init_scanner_state(yyscan_t yyscanner)
yyscanner
to the SPECIALSTART state,
which can then decide whether to scan PASM or PIR tokens.static macro_table *peek_macro_table(lexer_state *const lexer)
static char *munge_id(char const *const id, lexer_state *const lexer)
MACRO
refers to the macro name of the macro in which the .macro_local or .macro_label was defined; LABEL
refers to the runtime value of the label or local variable (this can be a macro's argument's value).
SCOPE
refers to the unique scope ID of this macro expansion.static macro_table *pop_macro_table(lexer_state *const lexer)
static void push_macro_table(lexer_state *const lexer, macro_table *const table)
table
onto the macro scope stack.
Any attempt to find a macro definition will start in table
.
If not found,
the stack will be walked down (recursing into older entries).static void update_unique_id(lexer_state *const lexer)
static void expand(yyscan_t yyscanner, macro_def *const macro, list *args, lexer_state *const lexer)
thismacro
field of the macro_table
structure.void *yyalloc(size_t bytes, yyscan_t yyscanner)
bytes
of memory; the yyscanner
argument is not used.void *yyrealloc(void *ptr, size_t bytes, yyscan_t yyscanner)
ptr
.
The new memory region is bytes
in size; the yyscanner
argument is not used.void yyfree(void *ptr, yyscan_t yyscanner)
ptr
.
The yyscanner
argument is not used,
but part of the signature as it is a Flex-generated function.
|