Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // /*-------------------------------------------------------------------*\
- // | Concrete Template : Program_Parse_1
- // \*-------------------------------------------------------------------*/
- #ifndef CT_PROGRAM_PARSE_1
- #define CT_PROGRAM_PARSE_1 1
- ///------------------------------------------------------------------------
- /// Global Context --------------------------------------------------------
- ///------------------------------------------------------------------------
- #include "AT/Program/Parse.h"
- #include "CI/BL_Tokenizing_Machine/1.h"
- #include "CT/BL_Tokenizing_Machine/Get_1.h"
- ///------------------------------------------------------------------------
- /// Interface -------------------------------------------------------------
- ///------------------------------------------------------------------------
- concrete_template <
- concrete_instance class Statement,
- /*!
- implements
- abstract_instance Statement_Kernel <Statement>,
- implements
- abstract_instance Statement_Parse <
- Statement,
- Tokenizing_Machine
- >
- !*/
- concrete_instance class Program_Base,
- /*!
- implements
- abstract_instance Program_Kernel <Statement>
- !*/
- concrete_instance class Tokenizing_Machine =
- BL_Tokenizing_Machine_Get_1 <
- BL_Tokenizing_Machine_1
- >
- /*!
- implements
- abstract_instance BL_Tokenizing_Machine_Kernel,
- implements
- abstract_instance BL_Tokenizing_Machine_Get
- !*/
- >
- class Program_Parse_1 :
- implements
- concrete_instance Program_Parse <Statement>,
- extends
- concrete_instance Program_Base
- {
- private:
- local_procedure_body Parse_Instruction_Definition (
- alters Character_IStream& str,
- alters Tokenizing_Machine& m,
- alters Text& token_text,
- alters Integer& token_kind,
- produces Text& name,
- produces Statement& body
- )
- /*!
- requires
- str.is_open = true and
- token_text = "INSTRUCTION" and
- token_kind = KEYWORD and
- m.ready_to_dispense = false
- ensures
- if there exists x, y: string of character,
- i: IDENTIFIER, s: STATEMENT
- (#token_text * #m.buffer * #str.content = x * y and
- INSTRUCTION_TO_STRING_OF_TOKENS (i, s) =
- REMOVE_SEPARATORS (TOKENIZE_PROGRAM_TEXT (x)))
- then
- str.is_open = true and
- str.ext_name = #str.ext_name and
- there exists z: string of character
- (#token_text * #m.buffer * #str.content =
- z * token_text * m.buffer * str.content and
- INSTRUCTION_TO_STRING_OF_TOKENS (name, body) =
- REMOVE_SEPARATORS (TOKENIZE_PROGRAM_TEXT (z)) and
- token_kind = WHICH_TOKEN (token_text) and
- m.ready_to_dispense = false)
- !*/
- {
- // Students to fill this in
- object Statement_Parse_1 temp;
- assert((token_text == "INSTRUCTION"), "Expecting INSTRUCTION");
- m.Get_Next_Non_Seperator_Token(str, token_text, token_kind);
- name = token_text;
- m.Get_Next_Non_Seperator_Token(str, token_text, token_kind);
- assert((token_text == "IS"), "Expecting IS");
- while(count < self.Length_Of_Block())
- {
- self.Add_To_Block(count, temp);
- count++;
- }
- temp.Parse(str);
- Parse_Block(str, m, token_text, token_kind);
- m.Get_Next_Non_Seperator_Token(str, token_text, token_kind);
- }
- public:
- procedure_body Parse (
- alters Character_IStream& str
- )
- {
- // Students to fill this in
- object Tokenizing_Machine m;
- object Text token_text, input, name, p_name;
- object Integer token_kind;
- object Character ch;
- object Statement body;
- while (not str.At_EOS())
- {
- str << input;
- while (input.Length() > 0)
- {
- input.Remove(0, ch);
- m.Insert(ch);
- }
- }
- //get PROGRAM
- m.Get_Next_Non_Seperator_Token(str, token_text, token_kind);
- assert ((token_text == "PROGRAM"), "Expecting PROGRAM");
- //get name
- m.Get_Next_Non_Seperator_Token(str, token_text, token_kind);
- token_text = p_name;
- // get IS
- m.Get_Next_Non_Seperator_Token(str, token_text, token_kind);
- assert((token_text == "IS"), "Expecting IS");
- //get CONTEXT
- m.Get_Next_Non_Seperator_Token(str, token_text, token_kind);
- // assert((token_text == "{"), "Expecting {");
- while(token_text == "INSTRUCTION")
- {
- Parse_Instruction_Definition(str, m, token_text, token_kind, name, body);
- }
- // m.Get_Next_Non_Seperator_Token(str, token_text, token_kind);
- // assert((token_text == "}"), "Expecting }");
- //get BEGIN
- m.Get_Next_Non_Seperator_Token(str, token_text, token_kind);
- assert((token_text == "BEGIN"), "Expecting BEGIN");
- //get BLOCK
- Parse_Block(str, m, token_text, token_kind);
- //get END
- m.Get_Next_Non_Seperator_Token(str, token_text, token_kind);
- assert((token_text == "END"), "Expecting END");
- //get name at end of file and check against name at top
- m.Get_Next_Non_Seperator_Token(str, token_text, token_kind);
- assert((token_text == p_name), "Invalid program identifier");
- }
Add Comment
Please, Sign In to add comment