Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7664155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:14:00+00:00 2026-05-31T14:14:00+00:00

We have a custom C template engine for web template processing. Let us say

  • 0

We have a custom C template engine for web template processing. Let us say that we have a file “index.html” with the following content:

{% #include <stdio.h> %}

<!doctype html>
<html>
    <head><title>{{ title }}</title></head>
    <body>
        {{ body }}
        {% printf("test"); %}
        {% printf("test2") %}
        {% printf("test3"); %}
        {%
            printf("test4");
            printf("test5");
        %}
        {%
            printf("test6");
            printf("test7")
        %}
        {% printf("%d", isalpha('a')); %}
    </body>
</html>

When the template engine is called (initialized), it scans all the files in a particular “views” folder. The “index.html” file happens to be in this folder. It is scanned and cached in memory of the main program which has called the template engine.

When a request is made, the template engine’s operation function is called. The function takes the cached code and an array of variables with their types and values as parameters and returns a constant char buffer with the updated variables and logical operations. For the sake of simplicity, let us say that logical operations have the {% … %} and variables the {{ … }} syntax respectively.

One should be able to use C functions and general logic in the markup language. You should even be able to define functions in templates. If something goes wrong, the variable or logical operation should return void. The end result of our called “index.html” page with “body” and “title” as the variables of {{ body }} and {{ title }} respectively should look like this:

<!doctype html>
<html>
    <head><title>title</title></head>
    <body>
        bodytesttest3test4test5
    </body>
</html>

How does one emulate the logic and syntax of the C language? Is this possible? Do you need to go as far as to develop a custom library of the language’s operations and function calls or is there a simpler solution? What is the best way of implementing such a solution?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T14:14:01+00:00Added an answer on May 31, 2026 at 2:14 pm

    There are two approaches. Both are not that easy to implement. The first, slightly simplier approach is to generate C from the template files and then use a compiler such as GCC to generate a shared object. This shared object can be loaded with dlopen()/dlsym() to generate the HTML code then.

    The second, more complicated but much more flexible approach is to implement an interpreter interpreting the „template language.” You can read about this in compiler building papers and books (the Dragon Book, e.g.).

    Of course you could also try to embed for example the PHP interpreter, but that has disadvantages, too.

    The „best way” does not exist. It highly depends on what you want. I for myself would implement an interpreter, I think. Generating .so files seems „dirty” to me.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two methods that I'm using as custom tags in a template engine:
I have a custom iterator template class that wraps up a std::list iterator. In
We're using the Google CSE (Custom Search Engine) paid service to index content on
I have created a custom editor template for DateTimeOffset: @model DateTimeOffset <div> @Html.LabelFor(m =>
I have created a custom editor template for input file in MVC3. I want
I have a custom editor template for a vehicle part that is used in
I have a custom template for an expander that is close to the code
I have a custom template checkbox that I am implementing using a viewbox (using
Experts, I have JQGrid with custom template column like Edit. the following screen display
I have a custom Sharepoint 2010 Web Template and I would like to set

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.