aboutsummaryrefslogtreecommitdiff
path: root/include/cps/Parser.h
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-07-26 17:21:14 +0000
committer_ov4 <ov4@ov4.org>2026-07-26 17:21:14 +0000
commit3366a2e0fae05d9e792169e74471c7282bf18681 (patch)
tree0cc4cacdac7d32ee7671d6799c52f74953c2007e /include/cps/Parser.h
parent0fef2986daa2945c9e3d050c0f750d56792b30bd (diff)
feat: TYPE-system front end — tokens, designators, ParamDecl grammar
- Reserve TYPE/ENDTYPE/SET/DEFINE (-600 token block); SET/DEFINE parse to dedicated not-implemented errors (RANDOM precedent). - New TypeAST.h: enum/pointer/record decl nodes, designator chain (DesignatorExprAST + Index/Field/Deref accessors), AddrOfExprAST, DesignatorAssignStmtAST. Bare-name and single-index shapes degrade to their legacy nodes, so existing programs produce identical ASTs. - ParserType.cc: TYPE declarations (top-level only, enforced via a ParseBlock depth counter), DECLARE-only record bodies with local field-level error recovery. - Postfix [ ] . ^ chain in ParseIdentifierExpr; prefix ^ (address-of, designator operand only) in ParseUnary; assignment targets rebuilt on the same suffix parser. - Parameters: ParamDecl{name, type, mode, array rank/bounds} replaces the (name, type, byref) tuple. Pass mode is sticky across parameters and BYREF is rejected in FUNCTIONs, both per guide §8.3 (the old per-param reset made the guide's own SWAP example pass Y by value). ARRAY OF T / ARRAY[l:u,...] OF T parameter syntax parses; codegen rejects it until the parameter-passing phase lands. - CodeGen stubs report clear not-implemented errors for the new nodes so nothing is silently ignored. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Diffstat (limited to 'include/cps/Parser.h')
-rw-r--r--include/cps/Parser.h13
1 files changed, 11 insertions, 2 deletions
diff --git a/include/cps/Parser.h b/include/cps/Parser.h
index 0ecb7f9..49f418c 100644
--- a/include/cps/Parser.h
+++ b/include/cps/Parser.h
@@ -1,12 +1,14 @@
#pragma once
#include "cps/Lexer.h"
#include "cps/AST.h"
+#include "cps/TypeAST.h"
+#include "cps/FunctionAST.h"
+#include <cstdint>
#include <vector>
#include <initializer_list>
#include <memory>
#include <map>
#include <optional>
-#include <tuple>
#include <string>
namespace cps {
@@ -15,6 +17,7 @@ class Parser {
Lexer &Lex;
int CurTok;
unsigned NumErrors = 0;
+ unsigned BlockDepth = 0; // ParseBlock nesting; 1 = top level
std::map<int, int> BinopPrecedence;
@@ -42,12 +45,18 @@ class Parser {
std::unique_ptr<StmtAST> ParseForStmt();
std::unique_ptr<StmtAST> ParseDeclare();
+ std::unique_ptr<StmtAST> ParseAssignStmt();
+ bool ParseDesignatorSuffix(std::vector<DesignatorAccess> &Out);
+
+ std::unique_ptr<StmtAST> ParseTypeDecl();
+ bool ParseRecordField(std::vector<RecordFieldDecl> &Out);
std::unique_ptr<StmtAST> ParseFunction();
std::unique_ptr<StmtAST> ParseProcedure();
std::unique_ptr<StmtAST> ParseCallStmt();
std::unique_ptr<StmtAST> ParseReturnStmt();
- std::optional<std::vector<std::tuple<std::string, std::string, bool>>> ParsePrototypeArgs();
+ std::optional<std::vector<ParamDecl>> ParsePrototypeArgs(bool AllowByRef);
+ bool ParseSignedIntBound(int64_t &Out);
std::unique_ptr<StmtAST> ParseOpenFile();
std::unique_ptr<StmtAST> ParseReadFile();