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 9039753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T09:48:27+00:00 2026-06-16T09:48:27+00:00

I have to do a software to identify tokens in C. I have this

  • 0

I have to do a software to identify tokens in C. I have this code:

*main = do
   x <- readFile "progc.c"
   let resultado = lexCmm X
   print resultado
lexCmm :: String -> [Tok]
  lexCmm X = case X of
    c:cs   | isSpace c     -> lexCmm cs
    c:cs   | isAlpha c     -> getId s
    c:cs   | isDigit c     -> getInt s
    c:d:cs | isSymb [c,d]  -> TS [c,d] : lexCmm cs
    c:cs   | isSymb [c]    -> TS [c]   : lexCmm cs
    _                      -> []  
   where
    getId s  = lx i : lexCmm cs where (i,cs) = span isIdChar s
    getInt s = TI (read i) : lexCmm cs where (i,cs) = span isDigit s
    isIdChar c = isAlpha c || isDigit c
    lx i = if isReservedWord i then TS i else TI i

  isSymb s = elem s $ words "++ -- == <= >= ++ { } = , ; + * - ( ) < >"

  isReservedWord w = elem w $ words "else if int main printInt return while"*

The error is:

file:{Hugs}\prog.hs:7 - Syntax error in input (unexpected `=')
  • 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-06-16T09:48:29+00:00Added an answer on June 16, 2026 at 9:48 am

    In addition to the mentioned error of using an upper case X for a variable name, you have an indentation error, the defining equation of lexCmm is indented, but it ought to start in the leftmost column.

    If you unindent that line

    lexCmm :: String -> [Tok]
    lexCmm x = case x of
    

    and the definitions of isSymb and isReservedWord too, you will get some other errors.

    The alternatives of the case expression must be indented further than the case keyword.

    In

    c:cs   | isAlpha c     -> getId s
    c:cs   | isDigit c     -> getInt s
    

    you use an entity s that is not in scope (so you should probably change the argument of lexCmm to s, or these two s to x.

    getInt s = TI (read i) : lexCmm cs where (i,cs) = span isDigit s
    

    strongly suggests that the constructor TI of Tok takes an Int argument, but

    lx i = if isReservedWord i then TS i else TI i
    

    tries to apply it to a String. You probably want TI (read i) there.

    The following code, containing a quick mockup of a Tok type compiles:

    module Toks where
    
    import Data.Char
    
    data Tok
        = TS String
        | TI Int
          deriving Show
    
    main = do
       x <- readFile "progc.c"
       let resultado = lexCmm x
       print resultado
    
    lexCmm :: String -> [Tok]
    lexCmm s = case s of       -- No indentation for function definition
                c:cs   | isSpace c     -> lexCmm cs    -- alternatives indented further
                c:cs   | isAlpha c     -> getId s      -- than the `case', all to the same level
                c:cs   | isDigit c     -> getInt s
                c:d:cs | isSymb [c,d]  -> TS [c,d] : lexCmm cs
                c:cs   | isSymb [c]    -> TS [c]   : lexCmm cs
                _                      -> []  
          where  -- `where' indented less than the `case', so that it scopes over all alternatives
            getId s  = lx i : lexCmm cs where (i,cs) = span isIdChar s
            getInt s = TI (read i) : lexCmm cs where (i,cs) = span isDigit s
            isIdChar c = isAlpha c || isDigit c
            lx i = if isReservedWord i then TS i else TI (read i)
    
    isSymb s = elem s $ words "++ -- == <= >= ++ { } = , ; + * - ( ) < >"
    
    isReservedWord w = elem w $ words "else if int main printInt return while"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have this software that has a webservices component. Now, the administrator of this
We have a software house developing code for us on a project, .NET Web
We have software that runs fine under a normal Windows installation but when we
I have a software that is tracking an NTFS volume changes on a Windows
We have accounting software populating the name field on a magento webstore, the problem
I have a software that runs on mac (using terminal program) the program is
I have a software package placed in the root directory of my website. I'd
I have a software renderer that I am porting from PC to the iPhone.
I have some software written in VB.NET that performs a lot of calculations, mostly
Hi I have some software written in VB6.0 that uses an SQL Server, but

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.