This repository has been archived on 2025-11-10. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
ovm/asm/parser.h
Aryadev Chavali 4990d93a1c Created a preprocessing unit presult_t and a function to process them
Essentially a presult_t contains one of these:

1) A label construction, which stores the label symbol into
`label` (PRES_LABEL)

2) An instruction that calls upon a label, storing the instruction
in `instruction` and the label name in `label` (PRES_LABEL_ADDRESS)

3) An instruction that uses a relative address offset, storing the
instruction in `instruction` and the offset wanted into
`relative_address` (PRES_RELATIVE_ADDRESS)

4) An instruction that requires no further processing, storing the
instruction into `instruction` (PRES_COMPLETE_INSTRUCTION)

In the processing stage, we resolve all calls by iterating one by one
and maintaining an absolute instruction address.  Pretty nice, lots
more machinery involved in parsing now.
2023-11-02 20:31:55 +00:00

55 lines
1.1 KiB
C

/* Copyright (C) 2023 Aryadev Chavali
* You may distribute and modify this code under the terms of the
* GPLv2 license. You should have received a copy of the GPLv2
* license with this file. If not, please write to:
* aryadev@aryadevchavali.com.
* Created: 2023-10-24
* Author: Aryadev Chavali
* Description: Parser for assembly language
*/
#ifndef PARSER_H
#define PARSER_H
#include "./lexer.h"
#include <lib/inst.h>
typedef enum
{
PERR_OK = 0,
PERR_INTEGER_OVERFLOW,
PERR_NOT_A_NUMBER,
PERR_EXPECTED_UTYPE,
PERR_EXPECTED_TYPE,
PERR_EXPECTED_SYMBOL,
PERR_EXPECTED_OPERAND,
PERR_UNKNOWN_OPERATOR,
PERR_INVALID_RELATIVE_ADDRESS,
PERR_UNKNOWN_LABEL,
} perr_t;
const char *perr_as_cstr(perr_t);
typedef struct
{
inst_t instruction;
char *label;
s_word relative_address;
enum PResult_Type
{
PRES_LABEL = 0,
PRES_LABEL_ADDRESS,
PRES_RELATIVE_ADDRESS,
PRES_COMPLETE_RESULT,
} type;
} presult_t;
perr_t parse_next(token_stream_t *, presult_t *);
perr_t process_presults(presult_t *, size_t, inst_t **, size_t *);
perr_t parse_stream(token_stream_t *, inst_t **, size_t *);
#endif