How pablomlago/multifunction_bison_calculator works
Project Purpose and Type
• This is a compiler/interpreter project with a command-line interface. It reads and evaluates mathematical expressions, implements a symbol table using a binary tree, and supports additional commands (e.g., "clean", "echo", "help", "load", "read", and "workspace").
Main Components
a. Lexical Analyzer:
• Files: mfcalc.l, lex.yy.c, lex.yy.h.
• Role: Tokenizes input from the command line or files.
b. Parser:
• Files: mfcalc.y, mfcalc.tab.c, mfcalc.tab.h, mfcalc.output.
• Role: Uses Bison to analyze the syntax based on the mathematical expression grammar.
c. Symbol Table:
• Files: abb.c, abb.h.
• Role: Implements a binary tree to store variables, constants, and function information.
d. Command Module:
• Files: commands.c, commands.h.
• Role: Extends basic calculator functionality with additional commands.
e. Error Handling Module:
• Files: errors.c, errors.h.
• Role: Defines and manages error messages across the application.
f. Initialization Module:
• Files: initialization.c, initialization.h.
• Role: Pre-populates the symbol table with predefined functions, commands, and constants.
g. Parameter Extraction:
• Files: params.c, params.h.
• Role: Extracts and validates parameters for commands.
h. Stack Implementation:
• Files: pila.c, pila.h.
• Role: Implements a stack that may be used internally for parsing or expression evaluation.
i. Dynamic Function Library Loader:
• Files: sampleLibrary.c, sampleLibrary.h.
• Role: Demonstrates dynamic loading of external functions (via the "load" command).
j. Utility & Execution:
• Files: launch.sh, instructions1, instructions2.
• Role: The shell script builds the executable; instruction files provide sample usage.
Relationships and Interactions
• User Input (CLI) feeds the raw commands and expressions.
• The Lexical Analyzer (Flex-generated from mfcalc.l) processes this input and sends tokens to the Parser.
• The Parser (Bison-generated from mfcalc.y) builds the parsed structure (or possibly an abstract syntax tree) and then interacts with:
• The Symbol Table (for storing variables, constants, or function references).
• The Commands Module (to detect and execute commands such as load, workspace, etc.).
• The Error Handling Module (to manage and signal parsing or evaluation errors).
• The Initialization Module pre-loads the symbol table at startup.
• The Parameter Extraction module assists the Commands Module in processing user command parameters.
• The Stack module might be used internally within parsing/evaluation or when processing nested expressions.
• When a command like "load" is executed, the Dynamic Function Library Loader is invoked to load an external library function.
• Finally, the results (or errors) are output back to the CLI.
Architectural Patterns and Design Principles
• Modularity: Each major function is encapsulated in its own module (e.g., parsers, symbol table, error handling).
• Separation of Concerns: Lexical analysis, parsing, error management, command processing, and dynamic loading are clearly separated.
• Layered Design: There’s a clear data flow from user input → lexical analysis → parsing → execution/evaluation with support modules.
• From CLI to Lexical Analyzer.
• From Lexical Analyzer to Parser.
• Between Parser and the Symbol Table, Commands Module, and Error Handler.
• From Commands Module to Dynamic Loader when executing a "load" command.