hi everyone. im really stuck with a project in pasal requring some string and files procedures. i have tried severy ways but i still can get through. the project can be found at . i have attached 2 files one containg the code and the other containg a sample file to be read from. please if there is anyone out here who can help with the first procedure or the whole project ; ill be greatful. any small help / tips will be appreciated. thanks

Dani AI

Generated

A short, practical plan that builds on 's suggestion and gives actionable steps for .

Treat this as two problems: tokenization (turn file characters into tokens: text, tag-start, tag-name, attribute-name, attribute-value, tag-end) and parsing (consume tokens to build whatever output or structure your assignment requires). Read the file char-by-char with a TextFile loop and a small state machine; this is the most robust for mixed text and tags.

A tiny tokenizer sketch (illustrates the main loop and state idea):

procedure TokenizeFile(const FileName: string);
var
  F: TextFile;
  c: Char;
  state: (TextState, TagState, AttrValueState);
begin
  AssignFile(F, FileName);
  Reset(F);
  state := TextState;
  while not Eof(F) do
  begin
    Read(F, c);
    case state of
      TextState:
        if c = '<' then state := TagState
        else { append c to current text token };
      TagState:
        if c = '>' then state := TextState
        else if c = '"' then state := AttrValueState
        else { accumulate tag/attr characters };
      AttrValueState:
        if c = '"' then state := TagState
        else { accumulate attribute value };
    end;
  end;
  CloseFile(F);
end;

Practical tips and pitfalls:

  • Use small record types for tokens and a dynamic list (or linked list) to store them; keep comparisons case-insensitive for tag names.
  • Watch string limits in old Pascal (shortstring max 255). If using modern Delphi/FPC you can use long strings or TStringList for buffering.
  • Handle CR/LF and character-encoding carefully; read binary only if you need exact byte-level control.
  • For parsing attributes, accept both quoted and unquoted values only if your assignment demands it; quoted values are simpler and safer.
  • Debug by dumping tokens to a file first. That helps to find where the FSM fails on malformed input.

Focus first on a correct, simple tokenizer. Once tokens are reliable, the parser that follows (tree, counters or converters) becomes much easier.

Recommended Answers

All 2 Replies

i don't to be unkind, but since nobody gave you an answer i will do it. your problem is simple and nobody have the time to answer to you. i suggest you to "google it"! it must exist samples on how html parsers are made!
tips: i must make myself a parser and a compiler for school task. so what i have done until now: a dictionary(which is containing the reserved words- in your case table,tr,td and declare the limiters - your case <,>,space) and now i'm making the parser.

best regards,

i don't to be unkind, but since nobody gave you an answer i will do it. your problem is simple and nobody have the time to answer to you. i suggest you to "google it"! it must exist samples on how html parsers are made!
tips: i must make myself a parser and a compiler for school task. so what i have done until now: a dictionary(which is containing the reserved words- in your case table,tr,td and declare the limiters - your case <,>,space) and now i'm making the parser.

best regards,

thanks a lot for you time and kind attention. i will try googling it. if you do have any sample codes than you can show me ill appreciate it. thanks again.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.