-
Notifications
You must be signed in to change notification settings - Fork 0
russelldeguzman/111Project1
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
=========================================== By David Yang and Russell Deguzman UCLA ID: 404330995 and 804050308 =========================================== This is a skeleton for CS 111 Lab 1. Replace this README file with notes on your implementation. Mentions any special features or limitations. Stack Implementation: Generic stack data structure used in our algorithm based off of implementation found in a Stanford Lecture here: https://see.stanford.edu/materials/icsppcs107/stack-implementation.pdf Our command parsing approach: if encounters new command: put on command_stack if encounters new operator: if operator stack == NULL: push new operator to operator_stack else: if precedence(new operator) > precedence(operator_stack.top): push new operator to operator_stack else: while(operator_stack.top !='(' && precedence(new operator) <= precedence(operator_stack.top)): operator = operator_stack.pop second_command = command_stack.pop first_command = command_stack.pop new_command = combine(first_command, second_command, new operator) push new_command to command_stack top_operator = operator_stack.peek if top_operator == NULL: break; push new operator to operator_stack //process whater is left in the stacks... //TA NOTE: End condition: your algorithm will be done when: 1) The operator stack is empty 2) There is only one (fully complete) Node in the command stack (this node is your result) Input parsing ============= Converting the input to tokens first, to simplify the parsing process. Some important discussion notes: pipeline precedence is higher than semicolon a;b|c|d;e 1) b|c 2) (b|c)|d 3)a((b|c)|d) 4)a;b|c|d;e Rules: for syntax parsing a)A single new line is treated as a semicolon b) 2 or more new lines result in two different command trees (nodes in linked list) c)Special case of incomplete command where the right operand is missing: 2 or more '\n' have no effect a && \n \n \n b -->a&&b (This is an error) TUANS NEW ALGO (gonna implement this one) a)If a simple command, push to a command stack b)If it is a "(", push it onto an operator-stack c)If it is an Operator and operator stack is empty 1)push the operator onto the operator stack d)If it is an operator and the operator stack is NOT empty 1)Pop all operators with greator or equal precedence off the operator stack For each popped off Operator, Pop 2 commands off command stack combine them into a new command 2)Stop when you reach an operator with lower precedence or a "(" 3)Push the operator onto the stack e)If encounter ")", pop operators off the stack (for each operator, pop two commands, combine, push back on command stack) until you find a matching "(". then create a subshell command by popping out 1 command from command stack. f)Advance to next word (simple command, and, or) go to a) g)When all words are gone, pop each operator and combine them with 2 commands similar to d) I/O Implementation ================== Usage details on dup2 and the parameters used were obtained from sample code in lecture notes found here: http://www.cs.loyola.edu/~jglenn/702/S2005/Examples/dup2.html Input is set to read only. Output is set to write only, truncate, create if nonexistent, RW rights for user and group.
About
No description, website, or topics provided.
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published