
Explore implementing parsers in C and C++, parsing mathematical and algebraic expressions, building expression trees, and extending to SQL queries with a math expression library.
Presentation for this Course.
By the end of this section, the Src code snapshot would be pointed to by this git hashcode : 09b5e974211fda2b61adf475aaa05d0f0e7f5331
How to setup this commit hashcode, pls follow the below steps :
Download git repo :
https://github.com/sachinites/MathExpressionParser
switch to branch Oops
git checkout Oops
Set the git head to above hash code
git reset --hard 09b5e974211fda2b61adf475aaa05d0f0e7f5331
To comeback to latest commit :
git pull
Now check files in MathExpressionParser/Course
I am attaching the fully fixed Parser.l and ParserExport.h file with the last lecture in this section, because we needed to fix a couple of bugs in these sections as those bugs went undetected and could not be found until very later stage in this course.
Therefore, pls download these attached files from the last lecture of this section, and ensure you have fully fixed files in your codes. Files are Parser.l and ParserExport.h files.
Regular expressions used in this lecture can be copy pasted from the attached text file.
Develop parser infrastructure for a Lex-style parser, enabling moving back and forth and jumping to input positions, and implement lexical stack, APIs, and checkpoint and restore checkpoint macros.
Set up the lexical stack to store lax data from lexer calls, including token code, wai wai text, and length, using a max-size 512 parser stack with push and pop.
Demonstrates writing a demo parser in C++ to recognize circle and ellipse equations, using lexical stack management, token validation, and debugging with GDB.
I am attaching the fully fixed Parser.l and ParserExport.h file here, because we needed to fix couple of bugs in these section as those bugs went undetected and could not be found until very later stage in this course.
Therefore, pls download these attach files and ensure you have fully fixed files in your codes.
Develop parsers in C++ for math expressions and SQL by implementing grammar G2 through an exercise, engaging practical grammar construction.
Explore list generation in context-free grammars, using recursive productions to build lists of identifiers or integers with separators, and apply this to select queries with comma separated columns.
Explain production rules for parsing SQL queries, focusing on generating a list of columns using nonterminal symbols, and implement the longer rule first before the shorter when rules overlap.
The lecture shows parsing mathematical expressions with grammars, a lexical stack, and infix-to-postfix conversion to build an expression tree, extending to plus, minus, multiply, divide, and nested brackets.
Add production rules to extend grammar: Q expands to E inequality E, and inequality expands to a comparison operator; implement functions q and inequality in the expression parser as homework.
Implement infix to postfix conversion in c++, converting a lexical stack in infix notation to a postfix array of pointers to data objects, with operator, parentheses, and inequality support.
Advance the infix to postfix algorithm by adding support for binary operators (max, min, pow, inequalities) and unary operators (square, square root) via grammar extensions and new parser functions.
See how a postfix expression is converted into an expression tree, with operator nodes and leaf operands like variables, integers, and doubles.
Add new data type classes to a C++ parser, enabling seamless handling of math expressions and SQL-like syntax.
Extend a C++ parser by adding new operator classes to support math expressions and SQL-style syntax.
Learn to add two virtual set value functions to the D type base class and implement them in derived operand classes, using the token value pointer from the postfix array.
Implement the postfix to expression tree algorithm using a stack to build operand and operator nodes, handling unary and binary operators, and assigning the root at completion.
Explore validating and evaluating expression trees via postorder traversal, handling mixed operand types and invalid operands, and learn to implement a virtual clone function for the node hierarchy.
Explore operand resolution in writing parsers in C++, defining data type variable operands, wiring a data source and read function, and evaluating expression trees only after all operands are resolved.
Demonstrates resolving datatype variable operand nodes by binding them to a memory cache and a lookup function, updating values per row, then evaluating the expression tree.
Learn to parse and evaluate logical expressions using and and or with correct precedence. See how expression trees reflect operator order in sql where clauses and http get requests.
Extend the C++ expression parser to parse logical expressions by implementing a left-recursion-free grammar with and/or operators and inequalities, and apply the prescribed pass functions.
This Section is Applicable only for those who are aiming to do RDBMS Project - the next project dependent on Mexpr Library
Have you ever thought about how front-end CLIs or command lines are written for various CLI-based devices?
for example, How to write a Parser for SQL Queries?
How to write a parser to parse mathematical expressions and evaluate them only when they are valid?
Then this is the course that promises implementation of Generic Parsers in C/CplusPlus.
In this course, we will be going to write OOPs-based C++ code to build the Parser a.k.a Mathematical Expression Library. This library helps the programmer to develop applications with ease that require the calculation of tedious mathematical expressions. Not only that, We will also cover how to parse Expressions representing Inequalities or logical expressions.
Once this project is fully ready and tested, we will import this project as a black box to solve even bigger projects such as the Implementation of RDBMS from Scratch.
So best of luck and Happy learning. This course is very interesting and I am sure you will going to enjoy it a lot in this course. This will be a sporty course!
Pre-requisite for this course
Basic Regular Expressions
OOPs basic concepts
Binary Search Tree Algorithms ( Post-Order )
Infix to postfix conversion
Agenda
Writer Parsers using Lex ( GNU Lexical analyzer )
Implement Grammars in C/CplusPlus
Construct and Build Expression Trees
Evaluate Expression Trees, Inequalities, and Logical Expressions
Case Study
Writing Parsers to Parse SQL Queries