help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: My baby text to HTML paragraph converter


From: Piotr Siupa
Subject: Re: My baby text to HTML paragraph converter
Date: Sat, 16 Dec 2023 02:47:52 +0100

Hi Steve,

Sorry if I'm reading too far into it but from the fact you're using a shell
script for building this, I'm assuming that you're pretty new to work with
bigger programming projects.
Because of that, I'm going to give you some homework. Specifically, I think
you should research two things:
- Build automation tools - They (similarly to your script) build the
program for you. However, they are a little smarter about it and keep track
of which files are already up-to-date with their sources which decreases
the time needed to finish the build. (You'll quickly learn to appreciate
that as your project gets bigger.) You can also order them to create only a
specific file or you can define some aliases for common operations. You
could start with "make". It's not the tool I use but it's very simple and
popular so you won't have any trouble finding tutorials. It should be
already preinstalled on your system.
- Version control - It tracks all changes you do to your project, letting
you compare or revert files to previous versions. That was the one-sentence
summary but there is a whole lot more to it. It's generally a must have for
any serious project. I don't think I'm in any way controversial by
recommending you to choose "Git". This topic is much more complicated than
"make" but the basics should be simple enough to learn in a few hours.

regards,
Piotr



On Thu, Dec 14, 2023 at 8:21 AM Steve Litt <slitt@troubleshooters.com>
wrote:

> Hi all,
>
> After over a week of trying and asking voluminous questions on this
> mailing list (and getting voluminous help, thank you), I finally made a
> text to HTML converter that took blank line separated paragraphs and
> installed <p> and </p> to surround them. All the relevant files are in
> this message body...
>
>
> ==================== Preprocessor ==================================
> #!/usr/bin/python
> # preproc.py
> import sys
> lines = sys.stdin.readlines()
> toptrash = True
> for line in lines:
>     line = line.strip()
>     if toptrash:
>         if line == "":
>             continue
>         else:
>             toptrash = False
>     print(line);
> print("\n\n")
> ====================================================================
>
>
> ======================= Compilation shellscript =================
> #!/bin/ksh
>
> rm paragraphs.tab.c
> rm paragraphs.tab.h
> rm paragraphs.exb
> rm paragraphs.lex.c
> rm a.out
>
> bison --html -d paragraphs.y
> flex -o paragraphs.lex.c paragraphs.l
> gcc -Wall -o paragraphs.exb paragraphs.tab.c paragraphs.lex.c -lfl
>
>
> # Following line runs the converter
> cat dataparagraphs.txt | ./preproc.py | ./paragraphs.exb
> ====================================================================
>
>
> =================== Input File ===================================
> Steve was here,
> and now is gone,
> but left his name
> to carry on.
>
> Flex and Bison:
> Use as one.
> When you need to parse,
> they get it done.
> ====================================================================
>
>
> ===================== Output =======================================
> <p>Steve was here,
> and now is gone,
> but left his name
> to carry on.</p>
>
> <p>Flex and Bison:
> Use as one.
> When you need to parse,
> they get it done.</p>
> ====================================================================
>
>
> ========================= paragraphs.l =============================
> %option noinput nounput
> %{
> #include "paragraphs.tab.h"
> %}
>
> %%
> (\n){2,} {return SEP;}
> . {strcpy (yylval.y_char, yytext); return CHARACTER;  };
>
> %%
>
>
> int yywrap(void)
> {
>      return 1;
> }
>
> int yyerror(char *errormsg)
> {
>       fprintf(stderr, "%s\n", errormsg);
>       exit(1);
> }
> ====================================================================
>
>
> ===================== paragraphs.y =================================
> %{
>
> #include <stdio.h>
> #include <stdlib.h>
> int yylex(void);
> int yyerror (char *errmsg);
> #define EOF_ 0
>
> int prevtok = 0;
> %}
>
> %union {
>         char    y_char [10000];
> }
>
> %token <y_char>   SEP
> %token <y_char>   CHARACTER
>
> %%
>
> wholefile : thing
>           | wholefile thing
> ;
>
> thing : character | sep;
>
> character : CHARACTER {
>         if(prevtok == SEP){
>                 printf("\n\n<p>");
>         }
>         printf($1);
>         prevtok = CHARACTER;
> }
>
> sep: SEP {
>         printf("</p>");
>         prevtok = SEP;
> }
>
> %%
>
> int main(int argc, char *argv[]){
>         printf("<p>");
>         yyparse();
>         if(prevtok == CHARACTER)
>                 printf("</p>");
>         printf("\n");
> }
> ====================================================================
>
> Thanks,
>
> SteveT
>
> Steve Litt
>
> Autumn 2023 featured book: Rapid Learning for the 21st Century
> http://www.troubleshooters.com/rl21
>
>


reply via email to

[Prev in Thread] Current Thread [Next in Thread]