char* fpos;
} LexFile;
+typedef struct {
+ enum {
+ VAL_I8, VAL_I16, VAL_I32, VAL_I64, VAL_REAL, VAL_STRING
+ } type;
+ union {
+ long long integer;
+ double floating;
+ char* text;
+ } value;
+} Value;
+
+typedef struct Symbol {
+ struct Symbol* next;
+ char* name;
+ enum{
+ SYM_CONST, SYM_VAR, SYM_TYPE, SYM_PROC
+ } type;
+} Symbol;
+
typedef struct {
LexFile* done;
LexFile* file;
Tok tok;
+ int valstack_idx;
+ Value valstack[1024];
} Parser;
void lexfile(Parser* ctx, char* path);
--- /dev/null
+#include <stdint.h>
+
+const int8_t A1 = 42;
+const int16_t A2 = 42;
+const int32_t A3 = 42;
+const int64_t A4 = 42;
+
+const uint8_t B1 = 42;
+const uint16_t B2 = 42;
+const uint32_t B3 = 42;
+const uint64_t B4 = 42;
+
+const float C1 = 42.0;
+const double C2 = 42.0;
+
+const char* D1 = "this is a string";
+const char D2[] = "this is another string";
\ No newline at end of file
--- /dev/null
+#!/bin/sh
+cc -c -S -o - "$@" | sed -e 's/^\s*\.globl.*$/\n\n&/'
return strdup(expect_val(p, type)->text);
}
-static int consume(Parser* p)
+static int consume(Parser* p)
{
int type = peek(p)->type;
if (!accept(p, type))
}
/*
-factor = number
- | string
- | "nil"
- | "true"
- | "false"
- | designator [ActualParameters]
- | "(" expression ")"
+factor = number
+ | string
+ | "nil"
+ | "true"
+ | "false"
+ | designator [ActualParameters]
+ | "(" expression ")"
| "not" factor.
*/
parse_rule(const_decl,
"FOO = -1");
parse_rule(const_decl,
- "FOO = 1 + 1");
+ "FOO = 1 + 2 + 3");
parse_rule(const_decl,
"FOO = 1 + 2 * 4");
}