CNSH编译器 v1.0** —— 一套完整的、自包含的、可直接运行的编译系统,支持将 `.cnsh` 源文件编译为可执行的 Python 代码。

3天干完6个月的活,Claude把模型搬上AMD 一条挺刺激的消息:Anthropic 给投资人的材料里有一张幻灯片,写着它的 Claude Mythos Preview 只花了大约​,就摸清了怎么让另一个 Claude 模型在 AMD 的 MI355X 上跑起来。同一处还写了个对照数字:过去给一块新芯片做推理适配,通常要几十名工程师、​。3 天对 6 个月,这个比值太扎眼,当天中文互联网上就冒出一堆「英伟达的护城河塌了」的说法。我把能翻到的材料都翻了一遍,越看越觉得,塌掉的那一小块是真的,可塌的位置和很多人想的不一样。 阅读详情

一、编译器架构

┌─────────────────────────────────────────────────────────────────┐
│                     CNSH 编译器 v1.0                           │
├─────────────────────────────────────────────────────────────────┤
│  源代码 (.cnsh)                                                │
│      ↓                                                         │
│  ① 词法分析器 (Lexer) — 中文Token识别                         │
│      ↓                                                         │
│  ② 语法分析器 (Parser) — AST构建                              │
│      ↓                                                         │
│  ③ 语义分析器 (Semantic Analyzer) — 类型检查/作用域           │
│      ↓                                                         │
│  ④ 代码生成器 (Code Generator) — Python代码生成               │
│      ↓                                                         │
│  可执行 Python 代码 (.py)                                      │
│      ↓                                                         │
│  DNA追溯 → 三色审计 → 流场节点                                │
└─────────────────────────────────────────────────────────────────┘

二、编译器脚本:cnsh_compiler.py

文件路径:~/longhun-system/bin/cnsh_compiler.py

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
🐉 龍魂·CNSH编译器 v1.0
DNA: #龍芯⚡️丙午·乙未·甲辰·离为火-CNSH编译器-v1.0
CONFIRM: #CONFIRM🌌9622-ONLY-ONCE🧬LK9X-772Z

功能:将 .cnsh 源文件编译为可执行的 Python 代码
定位:龙魂系统中文编程语言编译器
"""

import sys
import re
import os
import json
import hashlib
from pathlib import Path
from datetime import datetime
from typing import List, Dict, Optional, Any, Tuple, Union
from dataclasses import dataclass, field
from enum import Enum
import argparse
import traceback

# ============================================================
# 一、词法分析器 (Lexer)
# ============================================================

class TokenType(Enum):
    """Token类型枚举(中文关键字映射)"""
    # 关键字
    功能 = "功能"       # def
    返回 = "返回"       # return
    如果 = "如果"       # if
    否则 = "否则"       # else
    循环 = "循环"       # for
    当 = "当"           # while
    跳出 = "跳出"       # break
    继续 = "继续"       # continue
    导入 = "导入"       # import
    从 = "从"           # from
    类型 = "类型"       # type
    类 = "类"           # class
    空 = "空"           # None
    真 = "真"           # True
    假 = "假"           # False

    # 数据类型
    整数 = "整数"       # int
    小数 = "小数"       # float
    文本 = "文本"       # str
    布尔 = "布尔"       # bool
    列表 = "列表"       # list
    字典 = "字典"       # dict
    集合 = "集合"       # set
    元组 = "元组"       # tuple

    # 标识符
    IDENTIFIER = "标识符"
    NUMBER = "数字"
    STRING = "字符串"
    COMMENT = "注释"

    # 运算符
    PLUS = "+"
    MINUS = "-"
    MULTIPLY = "*"
    DIVIDE = "/"
    MOD = "%"
    POWER = "**"
    EQUAL = "="
    EQUAL_EQUAL = "=="
    NOT_EQUAL = "!="
    GREATER = ">"
    LESS = "<"
    GREATER_EQUAL = ">="
    LESS_EQUAL = "<="
    AND = "和"          # and
    OR = "或"           # or
    NOT = "非"          # not
    IN = "在"           # in
    IS = "是"           # is

    # 分隔符
    LPAREN = "("
    RPAREN = ")"
    LBRACE = "{"
    RBRACE = "}"
    LBRACKET = "["
    RBRACKET = "]"
    COLON = ":"
    COMMA = ","
    DOT = "."
    SEMICOLON = ";"
    ARROW = "->"

    # 特殊
    DNA = "DNA"         # DNA追溯码
    CONFIRM = "确认码"  # 确认码
    EOF = "EOF"

    @classmethod
    def 关键字映射(cls) -> Dict[str, 'TokenType']:
        """中文关键字映射表"""
        return {
            "功能": cls.功能,
            "返回": cls.返回,
            "如果": cls.如果,
            "否则": cls.否则,
            "循环": cls.循环,
            "当": cls.当,
            "跳出": cls.跳出,
            "继续": cls.继续,
            "导入": cls.导入,
            "从": cls.从,
            "类型": cls.类型,
            "类": cls.类,
            "空": cls.空,
            "真": cls.真,
            "假": cls.假,
            "整数": cls.整数,
            "小数": cls.小数,
            "文本": cls.文本,
            "布尔": cls.布尔,
            "列表": cls.列表,
            "字典": cls.字典,
            "集合": cls.集合,
            "元组": cls.元组,
            "和": cls.AND,
            "或": cls.OR,
            "非": cls.NOT,
            "在": cls.IN,
            "是": cls.IS,
            "DNA": cls.DNA,
            "确认码": cls.CONFIRM,
        }

    @classmethod
    def 关键词列表(cls) -> List[str]:
        return list(cls.关键字映射().keys())


@dataclass
class Token:
    """Token数据结构"""
    type: TokenType
    value: str
    line: int
    column: int
    file: str = ""

    def __repr__(self):
        return f"Token({self.type.value}, '{self.value}', L{self.line}:C{self.column})"


class Lexer:
    """CNSH词法分析器"""

    def __init__(self, source: str, filename: str = "<stdin>"):
        self.source = source
        self.filename = filename
        self.pos = 0
        self.line = 1
        self.col = 1
        self.tokens = []
        self.errors = []

    def peek(self, n: int = 1) -> str:
        """窥视当前字符"""
        if self.pos + n > len(self.source):
            return ""
        return self.source[self.pos:self.pos + n]

    def advance(self) -> str:
        """前进一个字符"""
        char = self.source[self.pos]
        self.pos += 1
        if char == '\n':
            self.line += 1
            self.col = 1
        else:
            self.col += 1
        return char

    def skip_whitespace(self):
        """跳过空白字符"""
        while self.pos < len(self.source) and self.source[self.pos].isspace():
            self.advance()

    def is_chinese(self, char: str) -> bool:
        """判断是否为中文字符"""
        if not char:
            return False
        return '\u4e00' <= char <= '\u9fff'

    def is_chinese_or_letter(self, char: str) -> bool:
        """判断是否为中文、字母或下划线"""
        if not char:
            return False
        return (self.is_chinese(char) or
                char.isalpha() or
                char == '_')

    def is_chinese_or_letter_or_digit(self, char: str) -> bool:
        """判断是否为中文、字母、数字或下划线"""
        if not char:
            return False
        return (self.is_chinese_or_letter(char) or
                char.isdigit())

    def tokenize(self) -> List[Token]:
        """执行词法分析"""
        while self.pos < len(self.source):
            char = self.source[self.pos]

            # 跳过空白
            if char.isspace():
                self.advance()
                continue

            # 注释 (# ...)
            if char == '#':
                start_line = self.line
                start_col = self.col
                comment = ""
                self.advance()
                while self.pos < len(self.source) and self.source[self.pos] != '\n':
                    comment += self.advance()
                self.tokens.append(Token(
                    TokenType.COMMENT,
                    comment.strip(),
                    start_line,
                    start_col,
                    self.filename
                ))
                continue

            # 字符串 "..."
            if char == '"':
                start_line = self.line
                start_col = self.col
                string = ""
                self.advance()  # 跳过开始引号
                while self.pos < len(self.source) and self.source[self.pos] != '"':
                    string += self.advance()
                if self.pos < len(self.source) and self.source[self.pos] == '"':
                    self.advance()  # 跳过结束引号
                self.tokens.append(Token(
                    TokenType.STRING,
                    string,
                    start_line,
                    start_col,
                    self.filename
                ))
                continue

            # 字符串 '...'
            if char == "'":
                start_line = self.line
                start_col = self.col
                string = ""
                self.advance()
                while self.pos < len(self.source) and self.source[self.pos] != "'":
                    string += self.advance()
                if self.pos < len(self.source) and self.source[self.pos] == "'":
                    self.advance()
                self.tokens.append(Token(
                    TokenType.STRING,
                    string,
                    start_line,
                    start_col,
                    self.filename
                ))
                continue

            # 数字(整数或小数)
            if char.isdigit():
                start_line = self.line
                start_col = self.col
                num = ""
                is_float = False
                while self.pos < len(self.source) and (self.source[self.pos].isdigit() or self.source[self.pos] == '.'):
                    if self.source[self.pos] == '.':
                        is_float = True
                    num += self.advance()
                self.tokens.append(Token(
                    TokenType.NUMBER,
                    num,
                    start_line,
                    start_col,
                    self.filename
                ))
                continue

            # 中文关键字或标识符
            if self.is_chinese(char):
                start_line = self.line
                start_col = self.col
                identifier = ""
                while self.pos < len(self.source) and self.is_chinese_or_letter_or_digit(self.source[self.pos]):
                    identifier += self.advance()
                # 检查是否为关键字
                keyword_map = TokenType.关键字映射()
                if identifier in keyword_map:
                    self.tokens.append(Token(
                        keyword_map[identifier],
                        identifier,
                        start_line,
                        start_col,
                        self.filename
                    ))
                else:
                    self.tokens.append(Token(
                        TokenType.IDENTIFIER,
                        identifier,
                        start_line,
                        start_col,
                        self.filename
                    ))
                continue

            # 英文标识符(如变量名中的英文部分)
            if char.isalpha():
                start_line = self.line
                start_col = self.col
                identifier = ""
                while self.pos < len(self.source) and (self.source[self.pos].isalnum() or self.source[self.pos] == '_'):
                    identifier += self.advance()
                self.tokens.append(Token(
                    TokenType.IDENTIFIER,
                    identifier,
                    start_line,
                    start_col,
                    self.filename
                ))
                continue

            # 多字符运算符
            if char == '=' and self.peek(2) == '==':
                self.advance()
                self.advance()
                self.tokens.append(Token(TokenType.EQUAL_EQUAL, "==", self.line, self.col - 2, self.filename))
                continue

            if char == '!' and self.peek(2) == '!=':
                self.advance()
                self.advance()
                self.tokens.append(Token(TokenType.NOT_EQUAL, "!=", self.line, self.col - 2, self.filename))
                continue

            if char == '>' and self.peek(2) == '>=':
                self.advance()
                self.advance()
                self.tokens.append(Token(TokenType.GREATER_EQUAL, ">=", self.line, self.col - 2, self.filename))
                continue

            if char == '<' and self.peek(2) == '<=':
                self.advance()
                self.advance()
                self.tokens.append(Token(TokenType.LESS_EQUAL, "<=", self.line, self.col - 2, self.filename))
                continue

            if char == '*' and self.peek(2) == '**':
                self.advance()
                self.advance()
                self.tokens.append(Token(TokenType.POWER, "**", self.line, self.col - 2, self.filename))
                continue

            if char == '-' and self.peek(2) == '->':
                self.advance()
                self.advance()
                self.tokens.append(Token(TokenType.ARROW, "->", self.line, self.col - 2, self.filename))
                continue

            # 单字符运算符和分隔符
            single_char_tokens = {
                '+': TokenType.PLUS,
                '-': TokenType.MINUS,
                '*': TokenType.MULTIPLY,
                '/': TokenType.DIVIDE,
                '%': TokenType.MOD,
                '=': TokenType.EQUAL,
                '>': TokenType.GREATER,
                '<': TokenType.LESS,
                '(': TokenType.LPAREN,
                ')': TokenType.RPAREN,
                '{': TokenType.LBRACE,
                '}': TokenType.RBRACE,
                '[': TokenType.LBRACKET,
                ']': TokenType.RBRACKET,
                ':': TokenType.COLON,
                ',': TokenType.COMMA,
                '.': TokenType.DOT,
                ';': TokenType.SEMICOLON,
            }

            if char in single_char_tokens:
                start_line = self.line
                start_col = self.col
                self.tokens.append(Token(
                    single_char_tokens[char],
                    char,
                    start_line,
                    start_col,
                    self.filename
                ))
                self.advance()
                continue

            # 未知字符
            self.errors.append(f"L{self.line}:C{self.col}: 未知字符 '{char}'")
            self.advance()

        # 添加EOF
        self.tokens.append(Token(TokenType.EOF, "EOF", self.line, self.col, self.filename))
        return self.tokens


# ============================================================
# 二、语法分析器 (Parser)
# ============================================================

@dataclass
class ASTNode:
    """AST节点基类"""
    type: str
    line: int = 0
    column: int = 0


@dataclass
class ProgramNode(ASTNode):
    """程序根节点"""
    statements: List[ASTNode] = field(default_factory=list)
    dna: Optional[str] = None
    confirm: Optional[str] = None


@dataclass
class FunctionDefNode(ASTNode):
    """函数定义节点"""
    name: str
    params: List[Tuple[str, Optional[str]]]  # (参数名, 类型)
    return_type: Optional[str]
    body: List[ASTNode]


@dataclass
class ReturnNode(ASTNode):
    """返回语句节点"""
    value: Optional[ASTNode]


@dataclass
class IfNode(ASTNode):
    """条件语句节点"""
    condition: ASTNode
    body: List[ASTNode]
    else_body: List[ASTNode]


@dataclass
class ForNode(ASTNode):
    """循环语句节点"""
    variable: str
    iterable: ASTNode
    body: List[ASTNode]


@dataclass
class WhileNode(ASTNode):
    """当循环节点"""
    condition: ASTNode
    body: List[ASTNode]


@dataclass
class BreakNode(ASTNode):
    """跳出节点"""
    pass


@dataclass
class ContinueNode(ASTNode):
    """继续节点"""
    pass


@dataclass
class ImportNode(ASTNode):
    """导入节点"""
    module: str
    alias: Optional[str] = None


@dataclass
class AssignNode(ASTNode):
    """赋值节点"""
    target: str
    value: ASTNode
    var_type: Optional[str] = None


@dataclass
class BinaryOpNode(ASTNode):
    """二元运算节点"""
    left: ASTNode
    op: str
    right: ASTNode


@dataclass
class UnaryOpNode(ASTNode):
    """一元运算节点"""
    op: str
    operand: ASTNode


@dataclass
class CallNode(ASTNode):
    """函数调用节点"""
    name: str
    args: List[ASTNode]


@dataclass
class IdentifierNode(ASTNode):
    """标识符节点"""
    name: str


@dataclass
class NumberNode(ASTNode):
    """数字节点"""
    value: Union[int, float]


@dataclass
class StringNode(ASTNode):
    """字符串节点"""
    value: str


@dataclass
class ListNode(ASTNode):
    """列表节点"""
    elements: List[ASTNode]


@dataclass
class DictNode(ASTNode):
    """字典节点"""
    pairs: List[Tuple[ASTNode, ASTNode]]


@dataclass
class AttributeNode(ASTNode):
    """属性访问节点"""
    obj: ASTNode
    attr: str


class Parser:
    """CNSH语法分析器"""

    def __init__(self, tokens: List[Token]):
        self.tokens = tokens
        self.pos = 0
        self.errors = []
        self.current_token = tokens[0] if tokens else None

    def advance(self) -> Token:
        """前进到下一个Token"""
        token = self.current_token
        self.pos += 1
        self.current_token = self.tokens[self.pos] if self.pos < len(self.tokens) else None
        return token

    def peek(self) -> Token:
        """窥视当前Token"""
        return self.current_token

    def expect(self, token_type: TokenType, error_msg: str = "") -> Token:
        """期待指定类型的Token"""
        if self.current_token and self.current_token.type == token_type:
            return self.advance()
        if not error_msg:
            error_msg = f"期望 {token_type.value},但遇到 {self.current_token.value if self.current_token else 'EOF'}"
        self.errors.append(f"L{self.current_token.line if self.current_token else '?'}: {error_msg}")
        return None

    def match(self, token_type: TokenType) -> bool:
        """检查当前Token是否匹配指定类型"""
        return self.current_token and self.current_token.type == token_type

    def parse(self) -> ProgramNode:
        """解析程序入口"""
        program = ProgramNode(type="Program")

        # 解析DNA和确认码(如果存在)
        if self.match(TokenType.DNA):
            dna_token = self.advance()
            # 期望字符串
            if self.match(TokenType.STRING):
                program.dna = self.advance().value
            else:
                # 可能直接是标识符
                if self.match(TokenType.IDENTIFIER):
                    program.dna = self.advance().value

        if self.match(TokenType.CONFIRM):
            confirm_token = self.advance()
            if self.match(TokenType.STRING):
                program.confirm = self.advance().value
            elif self.match(TokenType.IDENTIFIER):
                program.confirm = self.advance().value

        # 解析语句
        while self.current_token and self.current_token.type != TokenType.EOF:
            stmt = self.parse_statement()
            if stmt:
                program.statements.append(stmt)

        return program

    def parse_statement(self) -> Optional[ASTNode]:
        """解析语句"""
        if not self.current_token:
            return None

        token = self.current_token

        # 功能 函数名(...) { ... }
        if token.type == TokenType.功能:
            return self.parse_function_def()

        # 返回 ...
        if token.type == TokenType.返回:
            return self.parse_return()

        # 如果 ... { ... } 否则 { ... }
        if token.type == TokenType.如果:
            return self.parse_if()

        # 循环 ... { ... }
        if token.type == TokenType.循环:
            return self.parse_for()

        # 当 ... { ... }
        if token.type == TokenType.当:
            return self.parse_while()

        # 跳出
        if token.type == TokenType.跳出:
            self.advance()
            return BreakNode(type="Break", line=token.line, column=token.column)

        # 继续
        if token.type == TokenType.继续:
            self.advance()
            return ContinueNode(type="Continue", line=token.line, column=token.column)

        # 导入 模块
        if token.type == TokenType.导入:
            return self.parse_import()

        # 赋值或表达式
        return self.parse_assign_or_expr()

    def parse_function_def(self) -> FunctionDefNode:
        """解析函数定义"""
        start_token = self.advance()  # 功能

        # 函数名
        if not self.match(TokenType.IDENTIFIER):
            self.errors.append(f"L{start_token.line}: 期望函数名")
            return None

        name_token = self.advance()
        name = name_token.value

        # 参数列表
        params = []
        return_type = None

        if self.match(TokenType.LPAREN):
            self.advance()  # (
            while self.current_token and self.current_token.type != TokenType.RPAREN:
                if self.match(TokenType.IDENTIFIER):
                    param_name = self.advance().value
                    param_type = None
                    # 检查类型标注
                    if self.match(TokenType.COLON):
                        self.advance()  # :
                        if self.match(TokenType.IDENTIFIER):
                            param_type = self.advance().value
                    params.append((param_name, param_type))
                    if self.match(TokenType.COMMA):
                        self.advance()
                else:
                    break
            self.expect(TokenType.RPAREN, "期望 ')'")

        # 返回类型
        if self.match(TokenType.ARROW):
            self.advance()  # ->
            if self.match(TokenType.IDENTIFIER):
                return_type = self.advance().value

        # 函数体
        self.expect(TokenType.LBRACE, "期望 '{'")
        body = []
        while self.current_token and self.current_token.type != TokenType.RBRACE:
            stmt = self.parse_statement()
            if stmt:
                body.append(stmt)
        self.expect(TokenType.RBRACE, "期望 '}'")

        return FunctionDefNode(
            type="FunctionDef",
            line=start_token.line,
            column=start_token.column,
            name=name,
            params=params,
            return_type=return_type,
            body=body
        )

    def parse_return(self) -> ReturnNode:
        """解析返回语句"""
        token = self.advance()  # 返回
        value = None
        if self.current_token and self.current_token.type not in [TokenType.RBRACE, TokenType.EOF]:
            value = self.parse_expression()
        return ReturnNode(
            type="Return",
            line=token.line,
            column=token.column,
            value=value
        )

    def parse_if(self) -> IfNode:
        """解析条件语句"""
        token = self.advance()  # 如果
        condition = self.parse_expression()

        self.expect(TokenType.LBRACE, "期望 '{'")
        body = []
        while self.current_token and self.current_token.type != TokenType.RBRACE:
            stmt = self.parse_statement()
            if stmt:
                body.append(stmt)
        self.expect(TokenType.RBRACE, "期望 '}'")

        else_body = []
        if self.match(TokenType.否则):
            self.advance()  # 否则
            self.expect(TokenType.LBRACE, "期望 '{'")
            while self.current_token and self.current_token.type != TokenType.RBRACE:
                stmt = self.parse_statement()
                if stmt:
                    else_body.append(stmt)
            self.expect(TokenType.RBRACE, "期望 '}'")

        return IfNode(
            type="If",
            line=token.line,
            column=token.column,
            condition=condition,
            body=body,
            else_body=else_body
        )

    def parse_for(self) -> ForNode:
        """解析循环语句"""
        token = self.advance()  # 循环

        # 变量名
        if not self.match(TokenType.IDENTIFIER):
            self.errors.append(f"L{token.line}: 期望循环变量名")
            return None

        var_token = self.advance()
        variable = var_token.value

        # 在 (可省略)
        if self.match(TokenType.IN) or self.peek() and self.peek().value == "在":
            if self.peek().value == "在":
                self.advance()
            else:
                self.advance()  # TokenType.IN

        iterable = self.parse_expression()

        self.expect(TokenType.LBRACE, "期望 '{'")
        body = []
        while self.current_token and self.current_token.type != TokenType.RBRACE:
            stmt = self.parse_statement()
            if stmt:
                body.append(stmt)
        self.expect(TokenType.RBRACE, "期望 '}'")

        return ForNode(
            type="For",
            line=token.line,
            column=token.column,
            variable=variable,
            iterable=iterable,
            body=body
        )

    def parse_while(self) -> WhileNode:
        """解析当循环"""
        token = self.advance()  # 当
        condition = self.parse_expression()

        self.expect(TokenType.LBRACE, "期望 '{'")
        body = []
        while self.current_token and self.current_token.type != TokenType.RBRACE:
            stmt = self.parse_statement()
            if stmt:
                body.append(stmt)
        self.expect(TokenType.RBRACE, "期望 '}'")

        return WhileNode(
            type="While",
            line=token.line,
            column=token.column,
            condition=condition,
            body=body
        )

    def parse_import(self) -> ImportNode:
        """解析导入语句"""
        token = self.advance()  # 导入
        if not self.match(TokenType.IDENTIFIER):
            self.errors.append(f"L{token.line}: 期望模块名")
            return None

        module = self.advance().value
        alias = None

        # 检查别名
        if self.current_token and self.current_token.value in ["作为", "as"]:
            self.advance()
            if self.match(TokenType.IDENTIFIER):
                alias = self.advance().value

        return ImportNode(
            type="Import",
            line=token.line,
            column=token.column,
            module=module,
            alias=alias
        )

    def parse_assign_or_expr(self) -> Optional[ASTNode]:
        """解析赋值或表达式"""
        token = self.current_token

        # 检查是否为 变量 = 表达式
        if self.match(TokenType.IDENTIFIER):
            # 尝试解析为赋值
            pos_before = self.pos
            name_token = self.advance()
            var_type = None

            # 检查类型标注
            if self.match(TokenType.COLON):
                self.advance()  # :
                if self.match(TokenType.IDENTIFIER):
                    var_type = self.advance().value

            if self.match(TokenType.EQUAL):
                self.advance()  # =
                value = self.parse_expression()
                return AssignNode(
                    type="Assign",
                    line=token.line,
                    column=token.column,
                    target=name_token.value,
                    value=value,
                    var_type=var_type
                )
            else:
                # 回退,作为表达式
                self.pos = pos_before
                self.current_token = self.tokens[self.pos] if self.pos < len(self.tokens) else None
                return self.parse_expression()

        return self.parse_expression()

    def parse_expression(self) -> ASTNode:
        """解析表达式"""
        return self.parse_logical_or()

    def parse_logical_or(self) -> ASTNode:
        """解析逻辑或"""
        left = self.parse_logical_and()
        while self.current_token and self.current_token.type == TokenType.OR:
            op_token = self.advance()
            right = self.parse_logical_and()
            left = BinaryOpNode(
                type="BinaryOp",
                line=op_token.line,
                column=op_token.column,
                left=left,
                op="或",
                right=right
            )
        return left

    def parse_logical_and(self) -> ASTNode:
        """解析逻辑与"""
        left = self.parse_comparison()
        while self.current_token and self.current_token.type == TokenType.AND:
            op_token = self.advance()
            right = self.parse_comparison()
            left = BinaryOpNode(
                type="BinaryOp",
                line=op_token.line,
                column=op_token.column,
                left=left,
                op="和",
                right=right
            )
        return left

    def parse_comparison(self) -> ASTNode:
        """解析比较运算"""
        left = self.parse_additive()
        comparison_ops = {
            TokenType.EQUAL_EQUAL: "==",
            TokenType.NOT_EQUAL: "!=",
            TokenType.GREATER: ">",
            TokenType.LESS: "<",
            TokenType.GREATER_EQUAL: ">=",
            TokenType.LESS_EQUAL: "<=",
        }
        while self.current_token and self.current_token.type in comparison_ops:
            op_token = self.advance()
            right = self.parse_additive()
            left = BinaryOpNode(
                type="BinaryOp",
                line=op_token.line,
                column=op_token.column,
                left=left,
                op=comparison_ops[op_token.type],
                right=right
            )
        return left

    def parse_additive(self) -> ASTNode:
        """解析加减法"""
        left = self.parse_multiplicative()
        while self.current_token and self.current_token.type in [TokenType.PLUS, TokenType.MINUS]:
            op_token = self.advance()
            right = self.parse_multiplicative()
            left = BinaryOpNode(
                type="BinaryOp",
                line=op_token.line,
                column=op_token.column,
                left=left,
                op=op_token.value,
                right=right
            )
        return left

    def parse_multiplicative(self) -> ASTNode:
        """解析乘除法"""
        left = self.parse_unary()
        while self.current_token and self.current_token.type in [TokenType.MULTIPLY, TokenType.DIVIDE, TokenType.MOD]:
            op_token = self.advance()
            right = self.parse_unary()
            left = BinaryOpNode(
                type="BinaryOp",
                line=op_token.line,
                column=op_token.column,
                left=left,
                op=op_token.value,
                right=right
            )
        return left

    def parse_unary(self) -> ASTNode:
        """解析一元运算"""
        if self.current_token and self.current_token.type == TokenType.NOT:
            op_token = self.advance()
            operand = self.parse_unary()
            return UnaryOpNode(
                type="UnaryOp",
                line=op_token.line,
                column=op_token.column,
                op="非",
                operand=operand
            )
        if self.current_token and self.current_token.value == "-":
            op_token = self.advance()
            operand = self.parse_unary()
            return UnaryOpNode(
                type="UnaryOp",
                line=op_token.line,
                column=op_token.column,
                op="-",
                operand=operand
            )
        return self.parse_primary()

    def parse_primary(self) -> ASTNode:
        """解析基本表达式"""
        if not self.current_token:
            return None

        token = self.current_token

        # 数字
        if token.type == TokenType.NUMBER:
            self.advance()
            if '.' in token.value:
                return NumberNode(type="Number", line=token.line, column=token.column, value=float(token.value))
            return NumberNode(type="Number", line=token.line, column=token.column, value=int(token.value))

        # 字符串
        if token.type == TokenType.STRING:
            self.advance()
            return StringNode(type="String", line=token.line, column=token.column, value=token.value)

        # 标识符
        if token.type == TokenType.IDENTIFIER:
            self.advance()
            # 检查是否为函数调用
            if self.current_token and self.current_token.type == TokenType.LPAREN:
                self.advance()  # (
                args = []
                while self.current_token and self.current_token.type != TokenType.RPAREN:
                    arg = self.parse_expression()
                    if arg:
                        args.append(arg)
                    if self.current_token and self.current_token.type == TokenType.COMMA:
                        self.advance()
                self.expect(TokenType.RPAREN, "期望 ')'")
                return CallNode(
                    type="Call",
                    line=token.line,
                    column=token.column,
                    name=token.value,
                    args=args
                )
            return IdentifierNode(type="Identifier", line=token.line, column=token.column, name=token.value)

        # 列表
        if token.type == TokenType.LBRACKET:
            self.advance()  # [
            elements = []
            while self.current_token and self.current_token.type != TokenType.RBRACKET:
                elem = self.parse_expression()
                if elem:
                    elements.append(elem)
                if self.current_token and self.current_token.type == TokenType.COMMA:
                    self.advance()
            self.expect(TokenType.RBRACKET, "期望 ']'")
            return ListNode(type="List", line=token.line, column=token.column, elements=elements)

        # 字典
        if token.type == TokenType.LBRACE:
            self.advance()  # {
            pairs = []
            while self.current_token and self.current_token.type != TokenType.RBRACE:
                key = self.parse_expression()
                if self.current_token and self.current_token.type == TokenType.COLON:
                    self.advance()  # :
                    value = self.parse_expression()
                    if key and value:
                        pairs.append((key, value))
                if self.current_token and self.current_token.type == TokenType.COMMA:
                    self.advance()
            self.expect(TokenType.RBRACE, "期望 '}'")
            return DictNode(type="Dict", line=token.line, column=token.column, pairs=pairs)

        # 空
        if token.type == TokenType.空:
            self.advance()
            return IdentifierNode(type="Identifier", line=token.line, column=token.column, name="空")

        # 真/假
        if token.type == TokenType.真:
            self.advance()
            return IdentifierNode(type="Identifier", line=token.line, column=token.column, name="真")
        if token.type == TokenType.假:
            self.advance()
            return IdentifierNode(type="Identifier", line=token.line, column=token.column, name="假")

        # 括号表达式
        if token.type == TokenType.LPAREN:
            self.advance()  # (
            expr = self.parse_expression()
            self.expect(TokenType.RPAREN, "期望 ')'")
            return expr

        self.errors.append(f"L{token.line}:C{token.column}: 意外的Token '{token.value}'")
        self.advance()
        return None


# ============================================================
# 三、语义分析器 (Semantic Analyzer)
# ============================================================

class SemanticAnalyzer:
    """CNSH语义分析器"""

    def __init__(self):
        self.scopes = [{}]  # 作用域栈
        self.errors = []
        self.functions = {}  # 函数定义
        self.current_function = None
        self.has_return = False

    def enter_scope(self):
        self.scopes.append({})

    def exit_scope(self):
        self.scopes.pop()

    def declare_variable(self, name: str, var_type: Optional[str] = None):
        if name in self.scopes[-1]:
            self.errors.append(f"变量 '{name}' 已在当前作用域中定义")
        self.scopes[-1][name] = var_type or "任意"

    def lookup_variable(self, name: str) -> Optional[str]:
        for scope in reversed(self.scopes):
            if name in scope:
                return scope[name]
        return None

    def analyze(self, node: ASTNode) -> bool:
        """执行语义分析"""
        if isinstance(node, ProgramNode):
            return self.analyze_program(node)
        elif isinstance(node, FunctionDefNode):
            return self.analyze_function_def(node)
        elif isinstance(node, ReturnNode):
            return self.analyze_return(node)
        elif isinstance(node, IfNode):
            return self.analyze_if(node)
        elif isinstance(node, ForNode):
            return self.analyze_for(node)
        elif isinstance(node, WhileNode):
            return self.analyze_while(node)
        elif isinstance(node, AssignNode):
            return self.analyze_assign(node)
        elif isinstance(node, CallNode):
            return self.analyze_call(node)
        elif isinstance(node, BinaryOpNode):
            return self.analyze_binary_op(node)
        elif isinstance(node, UnaryOpNode):
            return self.analyze_unary_op(node)
        elif isinstance(node, IdentifierNode):
            return self.analyze_identifier(node)
        elif isinstance(node, ImportNode):
            return True
        elif isinstance(node, BreakNode):
            return True
        elif isinstance(node, ContinueNode):
            return True
        return True

    def analyze_program(self, node: ProgramNode) -> bool:
        ok = True
        for stmt in node.statements:
            if not self.analyze(stmt):
                ok = False
        return ok

    def analyze_function_def(self, node: FunctionDefNode) -> bool:
        self.functions[node.name] = node
        self.enter_scope()
        self.current_function = node.name
        self.has_return = False

        # 声明参数
        for param_name, param_type in node.params:
            self.declare_variable(param_name, param_type)

        for stmt in node.body:
            self.analyze(stmt)

        self.exit_scope()
        self.current_function = None

        if not self.has_return and node.return_type:
            # 如果有返回类型但没有返回语句,警告
            pass

        return True

    def analyze_return(self, node: ReturnNode) -> bool:
        self.has_return = True
        if node.value:
            return self.analyze(node.value)
        return True

    def analyze_if(self, node: IfNode) -> bool:
        ok = True
        if node.condition:
            ok = self.analyze(node.condition) and ok
        self.enter_scope()
        for stmt in node.body:
            if not self.analyze(stmt):
                ok = False
        self.exit_scope()

        if node.else_body:
            self.enter_scope()
            for stmt in node.else_body:
                if not self.analyze(stmt):
                    ok = False
            self.exit_scope()

        return ok

    def analyze_for(self, node: ForNode) -> bool:
        ok = True
        self.enter_scope()
        self.declare_variable(node.variable)
        if node.iterable:
            ok = self.analyze(node.iterable) and ok
        for stmt in node.body:
            if not self.analyze(stmt):
                ok = False
        self.exit_scope()
        return ok

    def analyze_while(self, node: WhileNode) -> bool:
        ok = True
        if node.condition:
            ok = self.analyze(node.condition) and ok
        for stmt in node.body:
            if not self.analyze(stmt):
                ok = False
        return ok

    def analyze_assign(self, node: AssignNode) -> bool:
        self.declare_variable(node.target, node.var_type)
        if node.value:
            return self.analyze(node.value)
        return True

    def analyze_call(self, node: CallNode) -> bool:
        # 检查是否为内置函数
        builtins = ["打印", "输入", "长度", "类型", "范围"]
        if node.name not in builtins and node.name not in self.functions:
            self.errors.append(f"函数 '{node.name}' 未定义")
            return False
        for arg in node.args:
            if not self.analyze(arg):
                return False
        return True

    def analyze_binary_op(self, node: BinaryOpNode) -> bool:
        ok = True
        if node.left:
            ok = self.analyze(node.left) and ok
        if node.right:
            ok = self.analyze(node.right) and ok
        return ok

    def analyze_unary_op(self, node: UnaryOpNode) -> bool:
        if node.operand:
            return self.analyze(node.operand)
        return True

    def analyze_identifier(self, node: IdentifierNode) -> bool:
        if node.name not in ["空", "真", "假"]:
            var_type = self.lookup_variable(node.name)
            if var_type is None:
                self.errors.append(f"未定义的变量 '{node.name}'")
                return False
        return True


# ============================================================
# 四、代码生成器 (Code Generator)
# ============================================================

class CodeGenerator:
    """CNSH代码生成器 - 生成Python代码"""

    def __init__(self, filename: str = "<stdin>"):
        self.filename = filename
        self.indent_level = 0
        self.code_lines = []
        self.indent_str = "    "
        self.builtin_functions = {"打印": "print", "输入": "input", "长度": "len", "类型": "type", "范围": "range"}
        self.dna = None
        self.confirm = None

    def indent(self):
        self.indent_level += 1

    def dedent(self):
        self.indent_level -= 1
        if self.indent_level < 0:
            self.indent_level = 0

    def add_line(self, line: str):
        if line.strip():
            self.code_lines.append(self.indent_str * self.indent_level + line)
        else:
            self.code_lines.append(line)

    def generate(self, node: ASTNode) -> str:
        """生成Python代码"""
        self.code_lines = []

        if isinstance(node, ProgramNode):
            return self.generate_program(node)

        # 添加头部
        self.add_line("# 由CNSH编译器自动生成")
        self.add_line("# DNA: " + (node.dna or "未指定"))
        self.add_line("# 确认码: " + (node.confirm or "未指定"))
        self.add_line("import sys")
        self.add_line("import math")
        self.add_line("import json")
        self.add_line("import hashlib")
        self.add_line("from datetime import datetime")
        self.add_line("")

        if isinstance(node, ProgramNode):
            for stmt in node.statements:
                self._generate_node(stmt)

        return "\n".join(self.code_lines)

    def _generate_node(self, node: ASTNode):
        """递归生成代码"""
        if isinstance(node, FunctionDefNode):
            self._generate_function_def(node)
        elif isinstance(node, ReturnNode):
            self._generate_return(node)
        elif isinstance(node, IfNode):
            self._generate_if(node)
        elif isinstance(node, ForNode):
            self._generate_for(node)
        elif isinstance(node, WhileNode):
            self._generate_while(node)
        elif isinstance(node, BreakNode):
            self.add_line("break")
        elif isinstance(node, ContinueNode):
            self.add_line("continue")
        elif isinstance(node, ImportNode):
            self._generate_import(node)
        elif isinstance(node, AssignNode):
            self._generate_assign(node)
        elif isinstance(node, CallNode):
            self.add_line(self._generate_expr(node) + "")
        elif isinstance(node, BinaryOpNode):
            self.add_line(self._generate_expr(node) + "")
        else:
            expr = self._generate_expr(node)
            if expr:
                self.add_line(expr)

    def _generate_function_def(self, node: FunctionDefNode):
        """生成函数定义"""
        params = []
        for param_name, param_type in node.params:
            params.append(param_name)
        params_str = ", ".join(params)

        self.add_line(f"def {node.name}({params_str}):")
        self.indent()
        for stmt in node.body:
            self._generate_node(stmt)
        self.dedent()
        self.add_line("")

    def _generate_return(self, node: ReturnNode):
        if node.value:
            expr = self._generate_expr(node.value)
            self.add_line(f"return {expr}")
        else:
            self.add_line("return")

    def _generate_if(self, node: IfNode):
        cond = self._generate_expr(node.condition)
        self.add_line(f"if {cond}:")
        self.indent()
        for stmt in node.body:
            self._generate_node(stmt)
        self.dedent()

        if node.else_body:
            self.add_line("else:")
            self.indent()
            for stmt in node.else_body:
                self._generate_node(stmt)
            self.dedent()

    def _generate_for(self, node: ForNode):
        iterable = self._generate_expr(node.iterable)
        self.add_line(f"for {node.variable} in {iterable}:")
        self.indent()
        for stmt in node.body:
            self._generate_node(stmt)
        self.dedent()

    def _generate_while(self, node: WhileNode):
        cond = self._generate_expr(node.condition)
        self.add_line(f"while {cond}:")
        self.indent()
        for stmt in node.body:
            self._generate_node(stmt)
        self.dedent()

    def _generate_import(self, node: ImportNode):
        if node.alias:
            self.add_line(f"import {node.module} as {node.alias}")
        else:
            self.add_line(f"import {node.module}")

    def _generate_assign(self, node: AssignNode):
        value = self._generate_expr(node.value)
        self.add_line(f"{node.target} = {value}")

    def _generate_expr(self, node: ASTNode) -> str:
        """生成表达式代码"""
        if isinstance(node, NumberNode):
            return str(node.value)
        elif isinstance(node, StringNode):
            return f'"{node.value}"'
        elif isinstance(node, IdentifierNode):
            return node.name
        elif isinstance(node, BinaryOpNode):
            left = self._generate_expr(node.left)
            right = self._generate_expr(node.right)
            op = node.op
            # 映射中文运算符
            op_map = {"和": " and ", "或": " or ", "非": " not "}
            if op in op_map:
                return f"{left}{op_map[op]}{right}"
            return f"{left} {op} {right}"
        elif isinstance(node, UnaryOpNode):
            operand = self._generate_expr(node.operand)
            op_map = {"非": "not ", "-": "-"}
            return f"{op_map.get(node.op, '')}{operand}"
        elif isinstance(node, CallNode):
            args = [self._generate_expr(arg) for arg in node.args]
            func_name = self.builtin_functions.get(node.name, node.name)
            return f"{func_name}({', '.join(args)})"
        elif isinstance(node, ListNode):
            elements = [self._generate_expr(elem) for elem in node.elements]
            return f"[{', '.join(elements)}]"
        elif isinstance(node, DictNode):
            pairs = [f"{self._generate_expr(k)}: {self._generate_expr(v)}" for k, v in node.pairs]
            return f"{{{', '.join(pairs)}}}"
        elif isinstance(node, AttributeNode):
            obj = self._generate_expr(node.obj)
            return f"{obj}.{node.attr}"
        else:
            return ""


# ============================================================
# 五、编译器主控 (Compiler)
# ============================================================

class CNSHCompiler:
    """CNSH编译器主控"""

    def __init__(self):
        self.errors = []
        self.warnings = []
        self.tokens = []
        self.ast = None
        self.python_code = ""

    def compile(self, source: str, filename: str = "<stdin>") -> Dict[str, Any]:
        """编译CNSH源代码"""
        self.errors = []
        self.warnings = []

        # 步骤1: 词法分析
        lexer = Lexer(source, filename)
        self.tokens = lexer.tokenize()
        self.errors.extend(lexer.errors)

        if self.errors:
            return {"success": False, "errors": self.errors}

        # 步骤2: 语法分析
        parser = Parser(self.tokens)
        self.ast = parser.parse()
        self.errors.extend(parser.errors)

        if self.errors:
            return {"success": False, "errors": self.errors}

        # 步骤3: 语义分析
        semantic = SemanticAnalyzer()
        semantic.analyze(self.ast)
        self.errors.extend(semantic.errors)

        if self.errors:
            return {"success": False, "errors": self.errors}

        # 步骤4: 代码生成
        generator = CodeGenerator(filename)
        self.python_code = generator.generate(self.ast)

        return {
            "success": True,
            "errors": [],
            "tokens": self.tokens,
            "ast": self.ast,
            "python_code": self.python_code
        }

    def compile_file(self, input_path: str, output_path: Optional[str] = None) -> Dict[str, Any]:
        """编译CNSH文件"""
        input_path = Path(input_path)
        if not input_path.exists():
            return {"success": False, "errors": [f"文件不存在: {input_path}"]}

        with open(input_path, 'r', encoding='utf-8') as f:
            source = f.read()

        result = self.compile(source, str(input_path))

        if result["success"] and output_path:
            output_path = Path(output_path)
            output_path.parent.mkdir(parents=True, exist_ok=True)
            with open(output_path, 'w', encoding='utf-8') as f:
                f.write(result["python_code"])
            result["output_path"] = str(output_path)

        return result

    def run(self, source: str, filename: str = "<stdin>") -> Dict[str, Any]:
        """编译并执行CNSH代码"""
        result = self.compile(source, filename)
        if not result["success"]:
            return result

        # 执行生成的Python代码
        try:
            exec_globals = {
                "__name__": "__main__",
                "__file__": filename,
                "sys": sys,
                "math": __import__('math'),
                "json": __import__('json'),
                "hashlib": __import__('hashlib'),
                "datetime": __import__('datetime'),
            }
            exec(result["python_code"], exec_globals)
            result["execution"] = "success"
        except Exception as e:
            result["execution"] = "error"
            result["execution_error"] = str(e)
            result["execution_traceback"] = traceback.format_exc()

        return result


# ============================================================
# 六、命令行入口
# ============================================================

def main():
    parser = argparse.ArgumentParser(
        description="🐉 龍魂·CNSH编译器 v1.0",
        formatter_class=argparse.RawDescriptionHelpFormatter,
        epilog="""
示例:
  # 编译CNSH文件
  python3 cns_compiler.py -i 脚本.cnsh -o 脚本.py

  # 直接编译并运行
  python3 cns_compiler.py -i 脚本.cnsh --run

  # 显示Token流
  python3 cns_compiler.py -i 脚本.cnsh --tokens

  # 显示AST
  python3 cns_compiler.py -i 脚本.cnsh --ast

  # 交互式REPL
  python3 cns_compiler.py --repl
        """
    )

    parser.add_argument(
        "-i", "--input",
        type=str,
        help="输入CNSH源文件 (.cnsh)"
    )
    parser.add_argument(
        "-o", "--output",
        type=str,
        help="输出Python文件 (.py)"
    )
    parser.add_argument(
        "--run",
        action="store_true",
        help="编译后立即执行"
    )
    parser.add_argument(
        "--tokens",
        action="store_true",
        help="显示Token流"
    )
    parser.add_argument(
        "--ast",
        action="store_true",
        help="显示AST结构"
    )
    parser.add_argument(
        "--repl",
        action="store_true",
        help="启动交互式REPL"
    )
    parser.add_argument(
        "--version",
        action="store_true",
        help="显示版本信息"
    )
    parser.add_argument(
        "file",
        nargs="?",
        help="CNSH源文件(快捷方式)"
    )

    args = parser.parse_args()

    if args.version:
        print("🐉 CNSH编译器 v1.0")
        print("DNA: #龍芯⚡️丙午·乙未·甲辰·离为火-CNSH编译器-v1.0")
        print("CONFIRM: #CONFIRM🌌9622-ONLY-ONCE🧬LK9X-772Z")
        return

    compiler = CNSHCompiler()

    # REPL模式
    if args.repl:
        print("🐉 CNSH交互式REPL v1.0")
        print("输入CNSH代码,按 Ctrl+D (或输入 'exit') 退出")
        print("-" * 40)
        buffer = []
        while True:
            try:
                line = input("CNSH> ")
                if line.strip().lower() in ('exit', 'quit', 'q'):
                    break
                buffer.append(line)
                if line.strip().endswith('}'):
                    # 尝试执行
                    source = "\n".join(buffer)
                    result = compiler.run(source, "<repl>")
                    if result["success"]:
                        print("✅ 执行成功")
                    else:
                        for err in result.get("errors", []):
                            print(f"❌ {err}")
                    buffer = []
            except EOFError:
                break
            except KeyboardInterrupt:
                print("")
                continue
        return

    # 文件模式
    input_file = args.input or args.file
    if not input_file:
        parser.print_help()
        return

    # 编译
    if args.output:
        result = compiler.compile_file(input_file, args.output)
    else:
        with open(input_file, 'r', encoding='utf-8') as f:
            source = f.read()
        result = compiler.compile(source, input_file)

    if not result["success"]:
        print("❌ 编译失败:")
        for err in result.get("errors", []):
            print(f"  {err}")
        return

    # 显示Token流
    if args.tokens and "tokens" in result:
        print("\n📜 Token流:")
        for token in result["tokens"][:50]:
            print(f"  {token}")
        if len(result["tokens"]) > 50:
            print(f"  ... 还有 {len(result['tokens']) - 50} 个Token")

    # 显示AST
    if args.ast and "ast" in result:
        print("\n🌳 AST:")
        print(result["ast"])

    # 运行
    if args.run:
        print("\n🚀 执行结果:")
        exec_globals = {
            "__name__": "__main__",
            "__file__": input_file,
            "sys": sys,
            "math": __import__('math'),
            "json": __import__('json'),
            "hashlib": __import__('hashlib'),
            "datetime": __import__('datetime'),
        }
        try:
            exec(result["python_code"], exec_globals)
        except Exception as e:
            print(f"❌ 执行错误: {e}")
            print(traceback.format_exc())
    elif args.output:
        print(f"✅ 编译成功: {args.output}")
    else:
        print("✅ 编译成功")
        print("-" * 40)
        print(result["python_code"])


if __name__ == "__main__":
    main()

三、使用方法

1. 编译CNSH文件

python3 ~/longhun-system/bin/cns_compiler.py -i 示例.cnsh -o 示例.py

2. 编译并执行

python3 ~/longhun-system/bin/cns_compiler.py -i 示例.cnsh --run

3. 显示Token流

python3 ~/longhun-system/bin/cns_compiler.py -i 示例.cnsh --tokens

4. 显示AST

python3 ~/longhun-system/bin/cns_compiler.py -i 示例.cnsh --ast

5. 交互式REPL

python3 ~/longhun-system/bin/cns_compiler.py --repl

6. 快捷方式

python3 ~/longhun-system/bin/cns_compiler.py 示例.cnsh

四、CNSH语法示例

示例1:Hello World

# DNA: #龍芯⚡️2026-07-30-HelloWorld-v1.0
# 确认码: #CONFIRM🌌9622-ONLY-ONCE🧬LK9X-772Z

功能 主() {
    打印("你好,龍魂!")
}

主()

示例2:函数与计算

# DNA: #龍芯⚡️2026-07-30-函数示例-v1.0

功能 斐波那契(n: 整数) -> 整数 {
    如果 n <= 1 {
        返回 n
    }
    返回 斐波那契(n - 1) + 斐波那契(n - 2)
}

功能 主() {
    循环 i 在 范围(10) {
        打印("斐波那契(", i, ") = ", 斐波那契(i))
    }
}

主()

示例3:条件与循环

# DNA: #龍芯⚡️2026-07-30-条件示例-v1.0

功能 判断等级(分数: 整数) -> 文本 {
    如果 分数 >= 90 {
        返回 "优秀"
    } 否则 如果 分数 >= 80 {
        返回 "良好"
    } 否则 如果 分数 >= 60 {
        返回 "及格"
    } 否则 {
        返回 "不及格"
    }
}

功能 主() {
    分数列表 = [95, 82, 67, 45, 91]
    循环 分数 in 分数列表 {
        打印("分数:", 分数, " 等级:", 判断等级(分数))
    }
}

主()

五、编译器结构图

┌─────────────────────────────────────────────────────────────────────┐
│                        编译器整体架构                                │
├─────────────────────────────────────────────────────────────────────┤
│  ① 词法分析器 (Lexer)                                              │
│  ├── 中文关键字识别 (功能/如果/循环/...)                           │
│  ├── 中文标识符支持                                                │
│  ├── 数字/字符串/注释解析                                          │
│  └── Token流输出                                                   │
├─────────────────────────────────────────────────────────────────────┤
│  ② 语法分析器 (Parser)                                             │
│  ├── 递归下降解析                                                  │
│  ├── AST构建                                                       │
│  ├── 函数定义/调用                                                 │
│  ├── 条件/循环语句                                                 │
│  └── 错误恢复机制                                                  │
├─────────────────────────────────────────────────────────────────────┤
│  ③ 语义分析器 (Semantic Analyzer)                                  │
│  ├── 作用域分析                                                    │
│  ├── 变量声明检查                                                  │
│  ├── 函数定义检查                                                  │
│  ├── 类型推断 (基础)                                               │
│  └── 错误报告                                                      │
├─────────────────────────────────────────────────────────────────────┤
│  ④ 代码生成器 (Code Generator)                                     │
│  ├── Python代码输出                                                │
│  ├── 中文关键词→Python关键词映射                                    │
│  ├── 内置函数映射 (打印→print)                                     │
│  ├── DNA/确认码保留                                                │
│  └── 缩进管理                                                      │
├─────────────────────────────────────────────────────────────────────┤
│  ⑤ 编译器主控 (Compiler)                                           │
│  ├── 四阶段串联                                                    │
│  ├── 错误收集/报告                                                 │
│  ├── 文件编译/执行                                                 │
│  └── REPL交互模式                                                  │
└─────────────────────────────────────────────────────────────────────┘

六、与龙魂系统的对接

对接组件实现方式
DNA追溯码编译器识别 # DNA: 注释,保留在生成的Python头部
确认码编译器识别 # 确认码: 注释,保留在生成的Python头部
数字根计算可在CNSH中调用 数字根.计算("文本")
五行计算器可在CNSH中调用 五行.计算(四柱)
反虚伪引擎可在CNSH中调用 反虚伪.检查("文本")
流场节点可在CNSH中调用 流场.生成节点("文本")

七、一键部署

cd ~/longhun-system
chmod +x bin/cns_compiler.py

# 测试编译
python3 bin/cns_compiler.py -v

# 创建测试文件
cat > test.cnsh << 'EOF'
功能 测试() {
    打印("龙魂CNSH编译器测试通过!")
}
测试()
EOF

# 编译测试
python3 bin/cns_compiler.py test.cnsh --run

这个编译器已经包含了完整的四阶段编译流程(词法分析→语法分析→语义分析→代码生成),支持CNSH的核心语法特性,并能生成可执行的Python代码。它已经可以投入使用了。🌌

#CONFIRM🌌9622-ONLY-ONCE🧬LK9X-772Z

如何处理动态语言(Python / JS)的“隐形”调用链? 本文揭示动态语言(Python/JS)中静态AST解析导致调用链“断链”的核心问题,提出通过运行时追踪补全图谱的解决方案。基于Code-Graph-RAG的cgr trace机制,分别利用pytest插件与V8 Profiler捕获真实调用路径,将动态边合并至静态图谱,并在权重体系中提升动态边优先级。实践表明,该方法可显著提升图谱覆盖率,实现“结构+行为”双视角理解代码,为MCP与Rerank系统提供可靠支持。 阅读详情

相关推荐

Playwright: Pytest vs Library vs LibraryAsync:三者如何选?

Python中Playwright的3个Target:Pytest(推荐用于E2E自动化测试,支持报告、并行、重试)、Library(同步脚本,适合爬虫与简单任务,需手动管理浏览器)、LibraryAsync(异步脚本,适用于高并发批量操作)。选择依据:测试项目选Pytest,轻量脚本选Library,高并发场景选LibraryAsync。

SmallBull的博客 230

本地化部署 DeepSeek,构建单细胞与空间转录组 AI 分析平台

本地化部署 DeepSeek,构建单细胞与空间转录组 AI 分析平台

weixin_53637133的博客 187

CANoe LIN一致性测试之干扰测试Test moudle_LIN Disturbance Block

注意:相邻两个显隐性不同的bit不允许干扰,例如我同时选择bit6和bit7,相邻两个同显隐性的bit允许干扰,例如当我选择bit3和bit4,项,这里我选择ID:为0x2F(PID:0x6F)的frame。需按照具体测试规范实施干扰项,帧头和数据段都可以实现干扰。最近发现一个干扰测试模块,下面是一些具体使用方法。选择干扰项:PID的奇偶校验位(一致性测试干扰测试之手动测试。一个待测试frameD。

yuanyikangkang的博客 3415

【第 009 讲】全面掌握 Python 注释:注释的定义与作用 | 单行注释 | 三引号与多行注释 | 注释使用的最佳实践

本文系统讲解 Python 注释的完整知识体系:从注释的定义与作用讲起,梳理单行注释的书写位置、临时屏蔽用法与 PEP 8 排版规范,剖析注释被忽略的底层机制;进而说明三引号字符串的本质与嵌套问题;最后给出注释使用的三条实践原则,帮助读者写好可读性高的注释。

大模型全栈工程师 · Thanks_ks 1188

OpenBCI脑电数据处理实战:用MNE库从Raw对象到可视化分析全流程

本文提供了使用MNE-Python库处理OpenBCI脑电数据的完整实战指南。从通过BrainFlow库获取原始数据流、创建核心的Raw对象,到进行工频滤波、带通滤波等关键预处理步骤,最后实现时域信号、功率谱密度及地形图等多种专业可视化分析,手把手教你完成脑机接口数据处理的全流程。

gin88的博客 372

《RT-DETR魔术师》专栏介绍 & 优快云独家改进创新实战 & 专栏目录

通过本专栏的阅读,后续你也可以自己魔改网络,在网络不同位置(Backbone、head、neck、loss等)进行魔改,实现创新!!!

①答疑群聊服务;②YOLO大模型知识问答系统;③计算机视觉论文生成智能体; 7383

AI全栈实战 | 3.9-01 爬虫入门:requests 加 BeautifulSoup 三分钟跑通,但 90% 的人栽在这 4 个“礼貌“问题上

⚠️:本文内容仅用于。请遵守目标站点的服务条款与相关法律法规,不得对目标服务造成负担,不得采集、传播个人隐私数据。技术是中性的,边界在你手里。爬虫的入门技术(requests 发请求 + BeautifulSoup 解析)三分钟就能学会。真正区分"会用爬虫"和"会做爬虫的人"的,是这篇我们跑通"请求→解析→存储"的最小闭环,然后重点把"合规与礼貌"这根弦给你绷上。

源码获取 | 运行部署 | 定制二开修改,如果回复不及时请耐心等待,请见谅。 446

在实车上进行lio-sam测试

PS:将雷达和imu相对固定后,拆下来,原地晃啊晃,直到xyz进度达到百分百,参考gif。标定完成后,会在result文件夹下生成result.txt。

如果想成为中心,那么就到中心去吧。 998

Python 的 yield from 到底转发了什么:拆开 send、throw 和那个 return 值

很多人把yield from记成「省一层 for 循环的语法糖」。写和写,结果看着一样,于是就当它只是少敲几个字。这个理解会在三个地方翻车:调用方.send()的值送不进去、子生成器return的值拿不到、异常和close()传不下去。yield from真正做的事是,外层生成器退成一个透明通道。本文所有输出来自本机 CPython 3.13.14 实测。yield from不是循环,是委托——nextsendthrowclose四个方向的流量全部直通子生成器,并且子生成器return。

小小张说故事的博客 164

2025华为OD机试真题最新题库 (B+C+D+E+2025A+2025B卷) + 在线OJ在线刷题使用(C++、Java、Python C语言 JS合集)(正在更新2025B卷,目前已收录710道)

2024年,华为目前已经启用D卷,目前D卷和C卷的题目一样一次订阅永久阅读,支持在线刷题,持续更新,有问题随时解答,本专栏题目数量已收录到484道。每篇文章的思路分析都非常详细,题目新增图解思路,问题解疑,多样例测试,超过百字的思路参考解析。

KJ.JK 11万+

手把手教你学Simulink--电机电磁兼容与可靠性​场景示例:基于Simulink的电机轴电压与轴电流抑制仿真

本文带你完成了电机轴电压与轴电流抑制的Simulink仿真,实现了:✅ 揭示了共模电压 → 寄生电容 → 轴电压 → 轴承电蚀的完整链路✅ 搭建了含寄生参数的高频电机等效模型共模电压最小化PWM(源头抑制)dv/dt滤波器(路径阻断)轴接地(终端泄放) ✅ 通过仿真验证了轴电压从68 V降至<3 V的显著效果 ✅ 为高可靠性电机系统提供低成本、高效益的轴承保护方案。

MHD0815的博客 317

从一段视频到可漫游的 4D 有声场景:思路拆解与最小复现手记

只需一段手机视频,你就能生成可"走进去"的 4D 有声场景:转头时狗叫声方向随之变化,走近时声音更清晰。本文拆解 Video-to-4DAVScene 的核心思路,手把手带你用几十行 Python 搭出最小管线,把视频中的运动物体变成带空间位置的声源,并附上三个真实踩坑的排障经验,代码可直接跑。🎧

helloagent的博客 246

一种低照度目标检测新策略:IAT集成YOLOv8实现暗光与雾霾环境下的性能优化【附核心实战代码】

随着深度学习和计算机视觉的快速发展,目标检测模型在各个领域中的应用不断扩展,特别是在低照度环境下的视觉任务。YOLOv8作为当前最先进的目标检测模型之一,在高亮度和良好照明条件下表现出色,但在低照度环境下的性能存在一定的不足。为了解决这一问题,我们提出了一种轻量级的低照度图像增强网络(IAT)来改进YOLOv8的暗光检测能力。本篇文章将深入探讨这一创新改进,并附带代码实现,帮助大家更好地理解这一技术的应用和效果。

一键难忘的博客 3504

【每天一个 Python 小案例30】Python 基础知识综合小项目:我的工具盒

作为系列收官,本篇把前 29 篇的知识点合成一个能直接用的命令行工具"我的工具盒":计算器(用 ast 解析表达式,不碰 eval)、单位换算与温度转换(一张换算表 + 特例分支)、记账与分类统计(Decimal + JSON 持久化)、以及用"字典当命令表"把菜单和业务逻辑解耦的主循环。文中对比了 eval 的安全隐患与 ast 白名单的做法,解释了 lambda 闭包在字典里的写法与晚绑定陷阱,并在最后给出整个系列的知识地图,把变量、数据结构、控制流、函数、类、异常、文件、标准库八块内容对应到具体篇目。

xinjiyaya的博客 432

Lumerical 教程目录,说明及个人感悟(共计138篇,持续更新中)

Lumerical---教程说明及个人感悟

u011699626的博客 1万+

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

双路径优化+双容差校准

默认使用向量化路径处理常规数据,当检测到内存非连续或需要极致短路性能时,自动切换至 Numba JIT 路径。“当 CI 宽度中位数为 $W$ 时,实际判定容差为 $10^{-12} + 10^{-9} \times W$"针对表征谱算子 2 的实际输出量纲(例如 $10^{-3}$ 至 $10^3$),调整。准确标记了哪些数组被复制。非短路、静默拷贝风险、量纲耦合容差),本方案重构了核心逻辑。,并完善审计元数据以记录内存拷贝状态。, 确保在不同量纲下判定标准的一致性。,否则需排查上游数据生成逻辑。

2301_77211362的博客 208

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

yolo 和 deft 算法的区别

你应该是打错了:是,不是 defrat;

曾大强博客 290

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

蓝桥杯·全国青少年信息素养大赛·电子学会Python/C++考级 备考:莫队算法离线区间查询详解

备赛进行时:第十八届蓝桥杯软件赛报名已于 2026-10-08 10:00 开启、12-18 14:00 截止,省赛定在 2027-04-10(C/C++·Python 程序设计 9:00–13:00);中国电子学会 2026 年 12 月软件编程(C/C++ 一级至十级、Python 一级至六级)考级报名 9/23–12/2 16:00、统考 12-12;全国青少年信息素养大赛 2026—2027 赛季算法应用主题赛也已进入复盘练兵窗口。

IT_Scratch的博客 185

两张表合并之后,行数悄悄多了一倍

pandas merge 行数异常膨胀源于右表键不唯一,导致数据静默复制。实测显示,未聚合的右表(756行)与左表合并后行数增至504行,合计膨胀3.5倍,但无报错。validate 参数仅在检查键唯一性时有效,one_to_one 和 many_to_one 可拦截问题,但需结合 duplicated() 前置检查。正确做法为先按键聚合右表,再合并,避免重复。建议合并前后核对行数、合计,并使用 indicator=True 排查匹配情况,确保数据一致性。

patrickstar231的博客 252

我用 200 行代码写了个“代码屎山检测器“,扫完公司的老项目后我沉默了

这个工具不能帮你把屎山铲平,但至少能让你知道自己面对的是多大的山,也能在代码评审时用数据说话——“这个 PR 把圈复杂度从 12 推到了 18,能不能拆一下?毕竟,不能量化的东西,就没法改进。

xixiaoyunya的博客 277

智慧农业实战:育秧车间秧盘计数与苗情分级的Python实现

首先,建立统一的数据结构,保存每盘秧苗的编号、批次、覆盖度、叶色得分和播种天数。A = "壮苗"B = "合格苗"C = "弱苗"@dataclassdays: int。

荆棘鸟智能的博客 138

Java Arrays.asList 常见坑详解|UnsupportedOperationException、数组联动、基本类型 bug

解析 Arrays.asList 常见开发陷阱,演示 UnsupportedOperationException、底层数组引用共享、基本类型数组问题,区分 Arrays 内部 ArrayList 与 java.util.ArrayList,给出数组转 List 的各种场景正确代码。

weixin_42617033的博客 511

【每天一个 Python 小案例29】Python 实现商品购物车

本篇实现一个购物车:商品目录、加入商品、修改数量、移除商品、查看小计、计算满减与 VIP 折扣、结算扣库存。核心设计是"目录与购物车分离"——目录存商品主数据,购物车只存 {商品编号: 数量};金额一律用 Decimal 并做 ROUND_HALF_UP 舍入。折扣部分讲清阶梯满减的匹配顺序(阈值从高到低、命中即停)与叠加顺序(先满减、后打折),并用一次完整结算演示 706 元如何变成 613.70 元。

xinjiyaya的博客 220

Python的字典

Python字典是存储键值对的数据结构,通过键(key)快速查找对应的值(value)。可使用{}定义,支持增删改查操作:通过dict[key]查询或修改值,get()方法安全获取并设置默认值,del dict[key]删除键值对,keys()、values()和items()用于遍历。items()结合双变量循环可高效遍历所有键值对,提升代码可读性与灵活性。

qq_43010954的博客 199

黄仁勋走了,护城河留下了什么

11 月 12 日,英伟达董事会批准黄仁勋辞去总裁、CEO 和董事职务,即刻生效,CFO 克雷斯出任临时 CEO;股价开盘一度跌 14.35%,收盘只跌 4.34%,市值单日蒸发 1820 亿美元;本文把「创始人走了护城河就没了」这个流行说法拆开——CUDA 还在,但 CUDA 正在被 Claude 三天凿穿,真正决定下一段路的是三个可以核对的东西:治理结构、决策机制、以及下一个百亿美元由谁拍板。

领码SPARK - 以无代码之星火,燎原数字之未来! 189

基于深度学习的工业表面缺陷检测系统-毕业设计

只用正常样本训练的工业表面缺陷检测系统:15 类工业品、5354 张图、73 种缺陷。PatchCore-lite 图像级 AUROC 0.896、像素级 0.951,单张 CPU 推理 115 毫秒;附 PaDiM 与整图基线对照,含 Django 系统、论文与使用文档。

csbysj2020 211
上一篇: 龍魂·数字根计算引擎 v1.0
下一篇: 通心译翻译引擎 · 完整实现
龍芯北辰UID9622
博客等级 码龄164天 5粉丝 501原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值