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

  • Home
  • SEARCH
  • 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 6894859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:50:06+00:00 2026-05-27T06:50:06+00:00

I am trying to do a syntax text corrector for my compilers’ class. The

  • 0

I am trying to do a syntax text corrector for my compilers’ class. The idea is: I have some rules, which are inherent to the language (in my case, Portuguese), like “A valid phrase is SUBJECT VERB ADJECTIVE”, as in “Ruby is great”.

Ok, so first I have to tokenize the input “Ruby is great”. So I have a text file “verbs”, with a lot of verbs, one by line. Then I have one text “adjectives”, one “pronouns”, etc.

I am trying to use Ragel to create a parser, but I don’t know how I could do something like:

%%{
  machine test;
  subject = <open-the-subjects-file-and-accept-each-one-of-them>;
  verb = <open-the-verbs-file-and-accept-each-one-of-them>;
  adjective = <open-the-adjective-file-and-accept-each-one-of-them>;
  main = subject verb adjective @ { print "Valid phrase!" } ;
}%%

I looked at ANTLR, Lex/Yacc, Ragel, etc. But couldn’t find one that seemed to solve this problem. The only way to do this that I could think of was to preprocess Ragel’s input file, so that my program reads the file and writes its contents at the right place. But I don’t like this solution either.

Does anyone knows how I could do this? There’s no problem if it isn’t with Ragel, I just want to solve this problem. I would like to use Ruby or Python, but that’s not really necessary either.

Thanks.

  • 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-27T06:50:06+00:00Added an answer on May 27, 2026 at 6:50 am

    If you want to read the files at compile time .. make them be of the format:

    subject = \
    ruby|\
    python|\
    c++
    

    then use ragel’s ‘include’ or ‘import’ statement (I forget which .. must check the manual) to import it.


    If you want to check the list of subjects at run time, maybe just make ragel read 3 words, then have an action associated with each word. The action can read the file and lookup if the word is good or not at runtime.

    The action reads the text file and compares the word’s contents.

    %%{
    machine test
    
    action startWord {
        lastWordStart = p;
    }
    action checkSubject {
       word = input[lastWordStart:p+1]  
       for possible in open('subjects.txt'):
           if possible == word:
               fgoto verb
       # If we get here do whatever ragel does to go to an error or just raise a python exception 
       raise Exception("Invalid subject '%s'" % word)
    }
    action checkVerb { .. exercise for reader .. ;) }
    action checkAdjective { .. put adjective checking code here .. }
    
    subject = ws*.(alnum*)>startWord%checkSubject
    verb := : ws*.(alnum*)>startWord%checkVerb
    adjective := ws*.)alnum*)>startWord%checkAdjective
    main := subject;
    }%%
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to have a text box that has syntax highlighting. To avoid the
I'm trying to build a small language with similar syntax and grammatical structure to
I am trying to use some PHP code within Javascript statement. Now the syntax
I'm trying to fix a subtitles (.srt) text file that has some incorrect data
I'm trying to work out some of the finer details of the Full-Text Search
Time is the class i'm trying to pass the values to. (txtHour.Text, txtMin.Text) are
I am trying to retrieve data in a JSON object (which I have validated
I'm trying to do some conditional text processing on Unix and struggling with the
i'm trying to read text from a text file that I have in my
I have a code in VB that looks like this: 'Server.Transfer(txtUser.Text + _page.aspx) which

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.