mirror of
https://github.com/Alvin-Zilverstand/femcode.git
synced 2026-03-06 02:56:56 +01:00
16 KiB
16 KiB
Femcode Development Log
This log details the features implemented and significant changes made to the Femcode programming language.
Project Context and Structure
This project, femboy-coding-language, is located at the root directory /home/k1tty/dev/gemini-cli/femboy-coding-language.
femboy-terminoligy.txt: A text file containing the custom keywords and their meanings used in Femcode.femcode/: This is the main project directory for the Femcode interpreter.femcode/femterpreter: A shell script located in thefemcode/directory that acts as a wrapper to run compiled Femcode programs. It executes the compiled Linux executable (femcode/dist/femcode_linux).femcode/src/: Contains the core source code for the Femcode interpreter.femcode/src/lexer.py: Responsible for lexical analysis, breaking down the source code into tokens.femcode/src/parser.py: Responsible for syntactic analysis, building an Abstract Syntax Tree (AST) from the tokens.femcode/src/interpreter.py: Responsible for semantic analysis and execution of the AST.femcode/src/main.py: The entry point for the interpreter, handling file input and orchestrating the lexing, parsing, and interpretation process.
femcode/docs/: Contains documentation for the Femcode language.femcode/docs/README.md: Comprehensive documentation of the Femcode language, including syntax, features, and usage instructions.
femcode/examples/: Contains example Femcode programs demonstrating various language features.femcode/build/: Directory created by PyInstaller during the build process, containing intermediate build files.femcode/dist/: Directory created by PyInstaller, containing the compiled standalone executables.femcode/dist/femcode_linux: The compiled Linux executable of the Femcode interpreter.
femcode/venv/: A Python virtual environment used for managing project dependencies (e.g., PyInstaller).
Implemented Features & Changes
1. Core Language Setup
- Description: Established the foundational lexical analysis, parsing, and interpretation framework for Femcode. This involved defining basic token types, parsing simple expressions and statements, and setting up a rudimentary execution environment.
- Technical Details:
lexer.py: Initial implementation ofTokenclass andLexerwithget_next_tokenfor basic token recognition (integers, strings, basic operators, keywords).parser.py: Defined core AST nodes (Number,String,BinOp,Print,Assign,Variable,Block,IfStatement,WhileStatement,FunctionDefinition,FunctionCall,ReturnStatement). Implemented recursive descent parsing methods (expression,term,factor,parse_statement, etc.).interpreter.py: ImplementedInterpreterclass withvisit_*methods for each AST node, defining their runtime behavior. Introducedscope_stackfor variable management andReturnValueexception for function returns.
- Files Modified:
femcode/src/lexer.pyfemcode/src/parser.pyfemcode/src/interpreter.py
2. Dictionaries and Property Access
- Description: Added support for creating dictionary (object) data structures and accessing their properties using dot notation. This allows for more complex data representation.
- Keywords/Syntax:
{}(dictionary literal),.(property access) - Technical Details:
lexer.py: Added token patterns forLBRACE({),RBRACE(}),COLON(:), andDOT(.).parser.py:- New AST nodes:
Dictionary(to represent dictionary literals) andPropertyAccess(to represent accessing a property of an object). parse_dictionary_literal()method: Parses key-value pairs within{}. It consumesLBRACE, then iteratively parsesexpression(for key),COLON,expression(for value), andCOMMAuntilRBRACEis encountered.factor()method: Modified to recognizeLBRACEfor dictionary literals andDOTfor property access. It now correctly dispatches toparse_dictionary_literal()andparse_property_access().parse_property_access(target_node)method: ConsumesDOT, then anIDtoken for the property name, creating aPropertyAccessAST node.
- New AST nodes:
interpreter.py:visit_Dictionary(node): Evaluates key and value expressions for each pair and constructs a Python dictionary.visit_PropertyAccess(node): Evaluates thetargetnode (expected to be a dictionary) and retrieves the property usingtarget.get(property_name). Includes type checking to ensure the target is a dictionary.
- Files Modified:
femcode/src/lexer.pyfemcode/src/parser.pyfemcode/src/interpreter.pyfemcode/examples/dictionaries.fem
3. Input/Output (ask built-in function)
- Description: Introduced a built-in function
askto prompt the user for input, enhancing interactivity. This allows Femcode programs to receive data from the user. - Keywords/Syntax:
ask(prompt_string) - Technical Details:
interpreter.py:- Added
_ask_builtin(prompt)method: This method directly uses Python'sinput()function to get user input. - Modified
Interpreter.__init__: Registered_ask_builtinas a callable function under the name "ask" in theself.functionsdictionary. - Modified
visit_FunctionCall(node): Added logic to check iffunc_infois a callable (i.e., a built-in function). If so, it calls the function directly with evaluated arguments. Otherwise, it proceeds with the logic for user-defined functions.
- Added
- Files Modified:
femcode/src/interpreter.pyfemcode/examples/io.fem
4. Built-in Functions (len, type)
- Description: Added utility built-in functions
lenfor getting the length of strings/lists andtypefor determining the type of a value. These functions provide basic introspection and data manipulation capabilities. - Keywords/Syntax:
len(value),type(value) - Technical Details:
interpreter.py:- Added
_len_builtin(obj)method: Uses Python's built-inlen()function. Marked as@staticmethod. - Added
_type_builtin(obj)method: Uses Python'stype(obj).__name__to get the type string. Marked as@staticmethod. - Modified
Interpreter.__init__: Registered_len_builtinand_type_builtinin theself.functionsdictionary.
- Added
- Files Modified:
femcode/src/interpreter.pyfemcode/examples/built_ins.fem
5. femterpreter Wrapper Script
- Description: Created a standalone executable wrapper script to run Femcode programs directly from the command line, simplifying execution and removing the need to specify
python3 main.py. This greatly improves the user experience. - Technical Details:
femcode/femterpreter(new file): A bash script that calls the compiled Python executable (femcode/dist/femcode_linux) with the provided arguments. It handles path resolution to ensure the executable is found.femcode/src/main.py: Modified to accept the Femcode file path as a command-line argument usingsys.argv. Includes basic error handling for missing files.- Build Process: Instructions were provided for creating a virtual environment, installing
pyinstaller, and compiling the Linux executable (femcode/dist/femcode_linux).
- Files Modified:
femcode/femterpreter(new file)femcode/src/main.py
6. Enhanced Data Types
Floating-Point Numbers
- Description: Extended numerical support to include decimal values, allowing for more precise calculations.
- Technical Details:
lexer.py: Modified theisdigit()block to check for a decimal point (.) and subsequent digits, tokenizing them asFLOAT. Thetoken_patternslist was updated to includeFLOATregex.parser.py: Thefactor()method was updated to recognizeFLOATtokens and createNumberAST nodes (reusing the existingNumberAST node, as the interpreter can handle bothintandfloatPython types).
- Files Modified:
femcode/src/lexer.pyfemcode/src/parser.py
Null/None Type
- Description: Introduced a specific keyword (
Ghosted) to represent the absence of a value, similar tonullorNonein other languages. - Keywords/Syntax:
Ghosted - Technical Details:
lexer.py: Added a regex pattern to recognize theGhostedkeyword and tokenize it asNULL. This pattern was added to thetoken_patternslist.parser.py:- New AST node:
Null(a simple placeholder AST node). factor()method: Modified to recognizeNULLtokens and createNullAST nodes.
- New AST node:
interpreter.py:visit_Null(node): Returns Python'sNonewhen aNullAST node is visited.
- Files Modified:
femcode/src/lexer.pyfemcode/src/parser.py
7. Advanced Control Flow
for Loops
- Description: Implemented iteration over sequences (lists and strings), enabling more flexible looping constructs.
- Keywords/Syntax:
Tomgirl(for loop keyword) - Technical Details:
lexer.py: Added a regex pattern to recognizeTomgirland tokenize it asFOR. This pattern was added to thetoken_patternslist.parser.py:- New AST node:
ForStatement(stores the loop variable name, the iterable expression, and the loop body). parse_statement(): Modified to recognizeFORand dispatch toparse_for_statement().parse_for_statement(): Parses the loop variable (ID), theASSIGNtoken (acting as 'in' for now, a more specific 'IN' token could be introduced later), the iterable expression, and the loop body (block).
- New AST node:
interpreter.py:visit_ForStatement(node): Evaluates theiterable. It then iterates through each item, creates a new scope for each iteration, assigns the item to the loop variable in that scope, and then visits the loop body. Includes type checking to ensure the iterable is a list or string.
- Files Modified:
femcode/src/lexer.pyfemcode/src/parser.pyfemcode/src/interpreter.pyfemcode/examples/loops_advanced.fem
break and continue Statements
- Description: Added statements to provide more granular control over loop execution, allowing early exit (
Break) or skipping to the next iteration (Continue). - Keywords/Syntax:
Break,Continue - Technical Details:
lexer.py: Added regex patterns to recognizeBreakandContinuekeywords, tokenizing them asBREAKandCONTINUErespectively. These patterns were added to thetoken_patternslist.parser.py:- New AST nodes:
BreakStatementandContinueStatement(simple marker nodes). parse_statement(): Modified to recognizeBREAKandCONTINUEtokens and create the corresponding AST nodes.
- New AST nodes:
interpreter.py:- New exception classes:
BreakLoop(Exception)andContinueLoop(Exception). These are custom exceptions raised byvisit_BreakStatementandvisit_ContinueStatementrespectively. visit_BreakStatement(node): RaisesBreakLoop.visit_ContinueStatement(node): RaisesContinueLoop.visit_WhileStatement(node)andvisit_ForStatement(node): Wrapped their loop body execution intry-exceptblocks to catchBreakLoopandContinueLoopexceptions, implementing the desired loop control flow. Thescope_stackis properly managed (popped) when abreakorcontinueoccurs.
- New exception classes:
- Files Modified:
femcode/src/lexer.pyfemcode/src/parser.pyfemcode/src/interpreter.pyfemcode/examples/loops_advanced.fem
8. Error Handling (try-except)
- Description: Implemented basic error handling mechanisms to gracefully manage runtime errors and prevent program crashes. This allows Femcode programs to define blocks of code that can "catch" and respond to errors.
- Keywords/Syntax:
Twink(try block),Bimboy(except block) - Technical Details:
lexer.py: Added regex patterns to recognizeTwinkandBimboykeywords, tokenizing them asTRYandEXCEPTrespectively. These patterns were added to thetoken_patternslist.parser.py:- New AST node:
TryExceptStatement(stores thetry_blockandexcept_block). parse_statement(): Modified to recognizeTRYand dispatch toparse_try_except_statement().parse_try_except_statement(): Parses theTRYkeyword,FEMBOYCORE, thetry_block(aBlockof statements),PERIODT, thenEXCEPT,FEMBOYCORE, theexcept_block(anotherBlockof statements), andPERIODT. It ensures proper block termination.
- New AST node:
interpreter.py:visit_TryExceptStatement(node): Wraps the execution ofnode.try_blockin a Pythontry-except Exceptionblock. If any PythonExceptionoccurs during the execution of thetry_block, it catches the exception and then executesnode.except_block. This provides a basic catch-all error handling mechanism.
- Files Modified:
femcode/src/lexer.pyfemcode/src/parser.pyfemcode/src/interpreter.pyfemcode/examples/error_handling.fem
9. Syntactic Sugar
Compound Assignment Operators
- Description: Added shorthand operators for common arithmetic assignments, improving code conciseness and readability.
- Keywords/Syntax:
+=,-=,*=,/= - Technical Details:
lexer.py: Added token patterns forPLUS_ASSIGN,MINUS_ASSIGN,MUL_ASSIGN, andDIV_ASSIGN. These are matched as two-character operators and placed before single-character operators intoken_patternsto ensure correct precedence.parser.py:parse_assignment_statement(): Modified to check for these new compound assignment token types (PLUS_ASSIGN,MINUS_ASSIGN, etc.). If a compound assignment is found, it transforms it into a standardAssignAST node where the right-hand side is aBinOprepresenting the equivalent arithmetic operation (e.g.,count += 3is parsed ascount = count + 3). This simplifies interpreter logic.
interpreter.py: Thevisit_Assignmethod implicitly handles the compound assignments because the parser transforms them into standardAssignandBinOpnodes, requiring no special handling in the interpreter itself.
- Files Modified:
femcode/src/lexer.pyfemcode/src/parser.pyfemcode/src/interpreter.pyfemcode/examples/syntactic_sugar.fem
Increment/Decrement Operators
- Description: Introduced operators for easily increasing or decreasing numerical variables by one, providing a more concise syntax for common operations.
- Keywords/Syntax:
++,-- - Technical Details:
lexer.py: Added token patterns forINCREMENT(++) andDECREMENT(--). These are matched as two-character operators and placed before single-character operators intoken_patternsto ensure correct precedence.parser.py:- New AST nodes:
IncrementandDecrement(each storing theVariablenode to be modified). factor()method: Modified to recognizeINCREMENTandDECREMENTtokens immediately following anID(variable name). It creates the correspondingIncrementorDecrementAST node.parse_statement(): Modified to handleIncrementandDecrementAST nodes as standalone statements.
- New AST nodes:
interpreter.py:visit_Increment(node): Retrieves the current value of the variable (fromnode.var_name), increments it by 1, and updates the variable in the current scope. Includes type checking to ensure the variable is numeric.visit_Decrement(node): Retrieves the current value of the variable, decrements it by 1, and updates the variable in the current scope. Includes type checking for numeric values.
- Files Modified:
femcode/src/lexer.pyfemcode/src/parser.pyfemcode/src/interpreter.pyfemcode/examples/syntactic_sugar.fem
10. Documentation Updates
- Description: Continuously updated the
README.mddocumentation to accurately reflect all new features, syntax, and usage instructions, including thefemterpreterscript. This ensures that users have up-to-date information on how to use the language. - Files Modified:
femcode/docs/README.md